From owner-svn-src-user@freebsd.org Tue Dec 22 23:21:08 2015 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 118C8A4F703 for ; Tue, 22 Dec 2015 23:21:08 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9E17E119E; Tue, 22 Dec 2015 23:21:07 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBMNL6fb092307; Tue, 22 Dec 2015 23:21:06 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBMNL6jH092301; Tue, 22 Dec 2015 23:21:06 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201512222321.tBMNL6jH092301@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Tue, 22 Dec 2015 23:21:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r292637 - in user/ngie/stable-10-libnv: lib/libnv lib/libnv/tests sys/conf sys/kern sys/sys X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2015 23:21:08 -0000 Author: ngie Date: Tue Dec 22 23:21:06 2015 New Revision: 292637 URL: https://svnweb.freebsd.org/changeset/base/292637 Log: MFC r279434,r279435,r279436,r279438,r279439,r279440,r279760,r282254,r282257,r282304,r282312: r279434 (by rstone): Add function to force an nvlist into the error state Add an nvlist_set_error() function that can be used to force an nvlist into the error state. This is useful both for writing tests and for writing APIs that use nvlists internally. Differential Revision: https://reviews.freebsd.org/D1878 Reviewed by: pjd, jfv MFC After: 1 month Sponsored by: Sandvine Inc. r279435 (by rstone): Don't allocate memory for operations that do not insert Almost every operation performed on an nvlist was allocating a new string to hold the key name. The nvlist_exists* family of functions would always return false if they failed to allocate the string. The rest of the functions would outright abort(). Fix the non-varargs variants of the functions to perform the requested operations directly and the varargs versions to allocate the string and call into the non-varargs versions. The varargs versions are still broken and really can't be fixed, so we might consider axing them entirely. However, now the non- varargs functions are always safe to call. Differential Revision: https://reviews.freebsd.org/D1879 Reviewed by: pjd, jfv Sponsored by: Sandvine Inc. r279436 (by rstone): Prevent creation of an invalid nvlist If an nvlist is set as a child of another nvlist with nvlist_move_nvlist then fail the operation and set the parent nvlist to the error state. Differential Revision: https://reviews.freebsd.org/D1880 Reviewers: jfv Sponsored by: Sandvine Inc r279438 (by rstone): Add macros to make code compile in kernel Make it possible to compile libnv in the kernel. Mostly this involves wrapping functions that have a different signature in the kernel and in userland (e.g. malloc()) in a macro that will conditionally expand to the right API depending on whether the code is being compiled for the kernel or not. I have also #ifdef'ed out all of file descriptor-handling code, as well as the unsafe varargs functions. Differential Revision: https://reviews.freebsd.org/D1882 Reviewed by: jfv Sponsored by: Sandvine Inc r279439 (by rstone): Move libnv into the kernel and hook it into the kernel build Differential Revision: https://reviews.freebsd.org/D1883 Reviewed by: jfv Sponsored by: Sandvine Inc. r279440 (by rstone): Fix build of nv_tests.cc nv_tests.cc managed to get two copies of several functions due to me applying a patch in an unclean working tree. My kingdom for an "svn clean" command. X-MFC-With: r279424 r279760 (by dim): Fix lib/libnv tests compilation with -std=c++11, by adding appropriate casts for NULL to invocations of the ATF_REQUIER_EQ() macro. Reviewed by: rstone, jmmv Differential Revision: https://reviews.freebsd.org/D2027 r282254 (by oshogbo): Remove the use of nvlist_.*[fv] functions from tests. Approved by: pjd (mentor) r282257 (by oshogbo): Remove the nvlist_.*[fv] functions. Those functions are problematic, because there is no way to report memory allocation problems without complicating the API, so we can either abort or potentially return invalid results. None of which is acceptable. In most cases the caller knows the size of the name, so he can allocate buffer on the stack and use snprintf(3) to prepare the name. After some discussion the conclusion is to removed those functions, which also simplifies the API. Discussed with: pjd, rstone Approved by: pjd (mentor) r282304 (by oshogbo): Sort MLINKS alphabetically. Approved by: pjd (mentor) r282312 (by oshogbo): Add nvlist_flags() function, which returns nvlist's public flags. Approved by: pjd (mentor) Added: user/ngie/stable-10-libnv/sys/kern/subr_dnvlist.c - copied, changed from r279439, head/sys/kern/subr_dnvlist.c user/ngie/stable-10-libnv/sys/kern/subr_nvlist.c - copied, changed from r279439, head/sys/kern/subr_nvlist.c user/ngie/stable-10-libnv/sys/kern/subr_nvpair.c - copied, changed from r279439, head/sys/kern/subr_nvpair.c user/ngie/stable-10-libnv/sys/sys/dnv.h - copied unchanged from r279439, head/sys/sys/dnv.h user/ngie/stable-10-libnv/sys/sys/nv.h - copied, changed from r279439, head/sys/sys/nv.h user/ngie/stable-10-libnv/sys/sys/nv_impl.h - copied, changed from r279439, head/sys/sys/nv_impl.h user/ngie/stable-10-libnv/sys/sys/nvlist_impl.h - copied unchanged from r279439, head/sys/sys/nvlist_impl.h user/ngie/stable-10-libnv/sys/sys/nvpair_impl.h - copied unchanged from r279439, head/sys/sys/nvpair_impl.h Deleted: user/ngie/stable-10-libnv/lib/libnv/dnv.h user/ngie/stable-10-libnv/lib/libnv/dnvlist.c user/ngie/stable-10-libnv/lib/libnv/nv.h user/ngie/stable-10-libnv/lib/libnv/nv_impl.h user/ngie/stable-10-libnv/lib/libnv/nvlist.c user/ngie/stable-10-libnv/lib/libnv/nvlist_impl.h user/ngie/stable-10-libnv/lib/libnv/nvpair.c user/ngie/stable-10-libnv/lib/libnv/nvpair_impl.h Modified: user/ngie/stable-10-libnv/lib/libnv/Makefile user/ngie/stable-10-libnv/lib/libnv/nv.3 user/ngie/stable-10-libnv/lib/libnv/tests/dnv_tests.cc user/ngie/stable-10-libnv/lib/libnv/tests/nv_tests.cc user/ngie/stable-10-libnv/sys/conf/files Directory Properties: user/ngie/stable-10-libnv/ (props changed) Modified: user/ngie/stable-10-libnv/lib/libnv/Makefile ============================================================================== --- user/ngie/stable-10-libnv/lib/libnv/Makefile Tue Dec 22 23:11:49 2015 (r292636) +++ user/ngie/stable-10-libnv/lib/libnv/Makefile Tue Dec 22 23:21:06 2015 (r292637) @@ -7,10 +7,13 @@ SHLIBDIR?= /lib LIB= nv SHLIB_MAJOR= 0 -SRCS= dnvlist.c +.PATH: ${.CURDIR}/../../sys/kern ${.CURDIR}/../../sys/sys +CFLAGS+=-I${.CURDIR}/../../sys -I${.CURDIR} + +SRCS= subr_dnvlist.c SRCS+= msgio.c -SRCS+= nvlist.c -SRCS+= nvpair.c +SRCS+= subr_nvlist.c +SRCS+= subr_nvpair.c INCS= dnv.h INCS+= nv.h @@ -19,146 +22,66 @@ MAN+= nv.3 MLINKS+=nv.3 libnv.3 \ nv.3 nvlist.3 -MLINKS+=nv.3 nvlist_create.3 \ - nv.3 nvlist_destroy.3 \ - nv.3 nvlist_error.3 \ - nv.3 nvlist_empty.3 \ +MLINKS+=nv.3 nvlist_add_binary.3 \ + nv.3 nvlist_add_bool.3 \ + nv.3 nvlist_add_descriptor.3 \ + nv.3 nvlist_add_null.3 \ + nv.3 nvlist_add_number.3 \ + nv.3 nvlist_add_nvlist.3 \ + nv.3 nvlist_add_string.3 \ + nv.3 nvlist_add_stringf.3 \ + nv.3 nvlist_add_stringv.3 \ nv.3 nvlist_clone.3 \ + nv.3 nvlist_create.3 \ + nv.3 nvlist_destroy.3 \ nv.3 nvlist_dump.3 \ - nv.3 nvlist_fdump.3 \ - nv.3 nvlist_size.3 \ - nv.3 nvlist_pack.3 \ - nv.3 nvlist_unpack.3 \ - nv.3 nvlist_send.3 \ - nv.3 nvlist_recv.3 \ - nv.3 nvlist_xfer.3 \ - nv.3 nvlist_next.3 \ + nv.3 nvlist_empty.3 \ + nv.3 nvlist_error.3 \ nv.3 nvlist_exists.3 \ - nv.3 nvlist_exists_type.3 \ - nv.3 nvlist_exists_null.3 \ + nv.3 nvlist_exists_binary.3 \ nv.3 nvlist_exists_bool.3 \ + nv.3 nvlist_exists_descriptor.3 \ + nv.3 nvlist_exists_null.3 \ nv.3 nvlist_exists_number.3 \ - nv.3 nvlist_exists_string.3 \ nv.3 nvlist_exists_nvlist.3 \ - nv.3 nvlist_exists_descriptor.3 \ - nv.3 nvlist_exists_binary.3 \ - nv.3 nvlist_add_null.3 \ - nv.3 nvlist_add_bool.3 \ - nv.3 nvlist_add_number.3 \ - nv.3 nvlist_add_string.3 \ - nv.3 nvlist_add_stringf.3 \ - nv.3 nvlist_add_stringv.3 \ - nv.3 nvlist_add_nvlist.3 \ - nv.3 nvlist_add_descriptor.3 \ - nv.3 nvlist_add_binary.3 \ - nv.3 nvlist_move_string.3 \ - nv.3 nvlist_move_nvlist.3 \ - nv.3 nvlist_move_descriptor.3 \ - nv.3 nvlist_move_binary.3 \ + nv.3 nvlist_exists_string.3 \ + nv.3 nvlist_exists_type.3 \ + nv.3 nvlist_fdump.3 \ + nv.3 nvlist_flags.3 \ + nv.3 nvlist_free.3 \ + nv.3 nvlist_free_binary.3 \ + nv.3 nvlist_free_bool.3 \ + nv.3 nvlist_free_descriptor.3 \ + nv.3 nvlist_free_null.3 \ + nv.3 nvlist_free_number.3 \ + nv.3 nvlist_free_nvlist.3 \ + nv.3 nvlist_free_string.3 \ + nv.3 nvlist_free_type.3 \ + nv.3 nvlist_get_binary.3 \ nv.3 nvlist_get_bool.3 \ + nv.3 nvlist_get_descriptor.3 \ nv.3 nvlist_get_number.3 \ - nv.3 nvlist_get_string.3 \ nv.3 nvlist_get_nvlist.3 \ - nv.3 nvlist_get_descriptor.3 \ - nv.3 nvlist_get_binary.3 \ nv.3 nvlist_get_parent.3 \ + nv.3 nvlist_get_string.3 \ + nv.3 nvlist_move_binary.3 \ + nv.3 nvlist_move_descriptor.3 \ + nv.3 nvlist_move_nvlist.3 \ + nv.3 nvlist_move_string.3 \ + nv.3 nvlist_next.3 \ + nv.3 nvlist_pack.3 \ + nv.3 nvlist_recv.3 \ + nv.3 nvlist_send.3 \ + nv.3 nvlist_set_error.3 \ + nv.3 nvlist_size.3 \ + nv.3 nvlist_take_binary.3 \ nv.3 nvlist_take_bool.3 \ + nv.3 nvlist_take_descriptor.3 \ nv.3 nvlist_take_number.3 \ - nv.3 nvlist_take_string.3 \ nv.3 nvlist_take_nvlist.3 \ - nv.3 nvlist_take_descriptor.3 \ - nv.3 nvlist_take_binary.3 \ - nv.3 nvlist_free.3 \ - nv.3 nvlist_free_type.3 \ - nv.3 nvlist_free_null.3 \ - nv.3 nvlist_free_bool.3 \ - nv.3 nvlist_free_number.3 \ - nv.3 nvlist_free_string.3 \ - nv.3 nvlist_free_nvlist.3 \ - nv.3 nvlist_free_descriptor.3 \ - nv.3 nvlist_free_binary.3 -MLINKS+=nv.3 nvlist_existsf.3 \ - nv.3 nvlist_existsf_type.3 \ - nv.3 nvlist_existsf_null.3 \ - nv.3 nvlist_existsf_bool.3 \ - nv.3 nvlist_existsf_number.3 \ - nv.3 nvlist_existsf_string.3 \ - nv.3 nvlist_existsf_nvlist.3 \ - nv.3 nvlist_existsf_descriptor.3 \ - nv.3 nvlist_existsf_binary.3 \ - nv.3 nvlist_addf_null.3 \ - nv.3 nvlist_addf_bool.3 \ - nv.3 nvlist_addf_number.3 \ - nv.3 nvlist_addf_string.3 \ - nv.3 nvlist_addf_nvlist.3 \ - nv.3 nvlist_addf_descriptor.3 \ - nv.3 nvlist_addf_binary.3 \ - nv.3 nvlist_movef_string.3 \ - nv.3 nvlist_movef_nvlist.3 \ - nv.3 nvlist_movef_descriptor.3 \ - nv.3 nvlist_movef_binary.3 \ - nv.3 nvlist_getf_bool.3 \ - nv.3 nvlist_getf_number.3 \ - nv.3 nvlist_getf_string.3 \ - nv.3 nvlist_getf_nvlist.3 \ - nv.3 nvlist_getf_descriptor.3 \ - nv.3 nvlist_getf_binary.3 \ - nv.3 nvlist_takef_bool.3 \ - nv.3 nvlist_takef_number.3 \ - nv.3 nvlist_takef_string.3 \ - nv.3 nvlist_takef_nvlist.3 \ - nv.3 nvlist_takef_descriptor.3 \ - nv.3 nvlist_takef_binary.3 \ - nv.3 nvlist_freef.3 \ - nv.3 nvlist_freef_type.3 \ - nv.3 nvlist_freef_null.3 \ - nv.3 nvlist_freef_bool.3 \ - nv.3 nvlist_freef_number.3 \ - nv.3 nvlist_freef_string.3 \ - nv.3 nvlist_freef_nvlist.3 \ - nv.3 nvlist_freef_descriptor.3 \ - nv.3 nvlist_freef_binary.3 -MLINKS+=nv.3 nvlist_existsv.3 \ - nv.3 nvlist_existsv_type.3 \ - nv.3 nvlist_existsv_null.3 \ - nv.3 nvlist_existsv_bool.3 \ - nv.3 nvlist_existsv_number.3 \ - nv.3 nvlist_existsv_string.3 \ - nv.3 nvlist_existsv_nvlist.3 \ - nv.3 nvlist_existsv_descriptor.3 \ - nv.3 nvlist_existsv_binary.3 \ - nv.3 nvlist_addv_null.3 \ - nv.3 nvlist_addv_bool.3 \ - nv.3 nvlist_addv_number.3 \ - nv.3 nvlist_addv_string.3 \ - nv.3 nvlist_addv_nvlist.3 \ - nv.3 nvlist_addv_descriptor.3 \ - nv.3 nvlist_addv_binary.3 \ - nv.3 nvlist_movev_string.3 \ - nv.3 nvlist_movev_nvlist.3 \ - nv.3 nvlist_movev_descriptor.3 \ - nv.3 nvlist_movev_binary.3 \ - nv.3 nvlist_getv_bool.3 \ - nv.3 nvlist_getv_number.3 \ - nv.3 nvlist_getv_string.3 \ - nv.3 nvlist_getv_nvlist.3 \ - nv.3 nvlist_getv_descriptor.3 \ - nv.3 nvlist_getv_binary.3 \ - nv.3 nvlist_takev_bool.3 \ - nv.3 nvlist_takev_number.3 \ - nv.3 nvlist_takev_string.3 \ - nv.3 nvlist_takev_nvlist.3 \ - nv.3 nvlist_takev_descriptor.3 \ - nv.3 nvlist_takev_binary.3 \ - nv.3 nvlist_freev.3 \ - nv.3 nvlist_freev_type.3 \ - nv.3 nvlist_freev_null.3 \ - nv.3 nvlist_freev_bool.3 \ - nv.3 nvlist_freev_number.3 \ - nv.3 nvlist_freev_string.3 \ - nv.3 nvlist_freev_nvlist.3 \ - nv.3 nvlist_freev_descriptor.3 \ - nv.3 nvlist_freev_binary.3 + nv.3 nvlist_take_string.3 \ + nv.3 nvlist_unpack.3 \ + nv.3 nvlist_xfer.3 WARNS?= 6 Modified: user/ngie/stable-10-libnv/lib/libnv/nv.3 ============================================================================== --- user/ngie/stable-10-libnv/lib/libnv/nv.3 Tue Dec 22 23:11:49 2015 (r292636) +++ user/ngie/stable-10-libnv/lib/libnv/nv.3 Tue Dec 22 23:21:06 2015 (r292637) @@ -28,14 +28,16 @@ .\" .\" $FreeBSD$ .\" -.Dd January 30, 2015 +.Dd May 1, 2015 .Dt NV 3 .Os .Sh NAME .Nm nvlist_create , .Nm nvlist_destroy , .Nm nvlist_error , +.Nm nvlist_set_error , .Nm nvlist_empty , +.Nm nvlist_flags , .Nm nvlist_exists , .Nm nvlist_free , .Nm nvlist_clone , @@ -63,8 +65,12 @@ .Fn nvlist_destroy "nvlist_t *nvl" .Ft int .Fn nvlist_error "const nvlist_t *nvl" +.Ft void +.Fn nvlist_set_error "nvlist_t *nvl, int error" .Ft bool .Fn nvlist_empty "const nvlist_t *nvl" +.Ft int +.Fn nvlist_flags "const nvlist_t *nvl" .\" .Ft "nvlist_t *" .Fn nvlist_clone "const nvlist_t *nvl" @@ -248,8 +254,17 @@ the error will be returned. .Pp The +.Fn nvlist_set_error +function sets an nvlist to be in the error state. +Subsequent calls to +.Fn nvlist_error +will return the given error value. +This function cannot be used to clear the error state from an nvlist. +This function does nothing if the nvlist is already in the error state. +.Pp +The .Fn nvlist_empty -functions returns +function returns .Dv true if the given nvlist is empty and .Dv false @@ -257,6 +272,12 @@ otherwise. The nvlist must not be in error state. .Pp The +.Fn nvlist_flags +function returns flags used to create the nvlist with the +.Fn nvlist_create +function. +.Pp +The .Fn nvlist_clone functions clones the given nvlist. The clone shares no resources with its origin. Modified: user/ngie/stable-10-libnv/lib/libnv/tests/dnv_tests.cc ============================================================================== --- user/ngie/stable-10-libnv/lib/libnv/tests/dnv_tests.cc Tue Dec 22 23:11:49 2015 (r292636) +++ user/ngie/stable-10-libnv/lib/libnv/tests/dnv_tests.cc Tue Dec 22 23:21:06 2015 (r292637) @@ -45,7 +45,7 @@ ATF_TEST_CASE_BODY(dnvlist_get_bool__pre nvlist_add_bool(nvl, key, value); ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, key, false), value); - ATF_REQUIRE_EQ(dnvlist_getf_bool(nvl, false, "%c%s", 'n', "ame"), value); + ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "name", false), value); nvlist_destroy(nvl); } @@ -60,12 +60,12 @@ ATF_TEST_CASE_BODY(dnvlist_get_bool__def nvl = nvlist_create(0); ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, key, false), false); - ATF_REQUIRE_EQ(dnvlist_getf_bool(nvl, true, "%d", 123), true); + ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "123", true), true); nvlist_add_bool(nvl, key, true); ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "otherkey", true), true); - ATF_REQUIRE_EQ(dnvlist_getf_bool(nvl, false, "%d%c", 12, 'c'), false); + ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "12c", false), false); nvlist_destroy(nvl); } @@ -84,7 +84,7 @@ ATF_TEST_CASE_BODY(dnvlist_get_number__p nvlist_add_number(nvl, key, value); ATF_REQUIRE_EQ(dnvlist_get_number(nvl, key, 19), value); - ATF_REQUIRE_EQ(dnvlist_getf_number(nvl, 65, "key"), value); + ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "key", 65), value); nvlist_destroy(nvl); } @@ -99,12 +99,11 @@ ATF_TEST_CASE_BODY(dnvlist_get_number__d nvl = nvlist_create(0); ATF_REQUIRE_EQ(dnvlist_get_number(nvl, key, 5), 5); - ATF_REQUIRE_EQ(dnvlist_getf_number(nvl, 12, "%s", key), 12); + ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "1234", 5), 5); nvlist_add_number(nvl, key, 24841); - ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "hthth", 184), 184); - ATF_REQUIRE_EQ(dnvlist_getf_number(nvl, 5641, "%d", 1234), 5641); + ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "1234", 5641), 5641); nvlist_destroy(nvl); } @@ -124,7 +123,7 @@ ATF_TEST_CASE_BODY(dnvlist_get_string__p ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, key, "g"), value), 0); - actual_value = dnvlist_getf_string(nvl, "rs", "%s", key); + actual_value = dnvlist_get_string(nvl, key, "rs"); ATF_REQUIRE_EQ(strcmp(actual_value, value), 0); nvlist_destroy(nvl); @@ -142,13 +141,13 @@ ATF_TEST_CASE_BODY(dnvlist_get_string__d ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, key, "bar"), "bar"), 0); - actual_value = dnvlist_getf_string(nvl, "d", "%s", key); + actual_value = dnvlist_get_string(nvl, key, "d"); ATF_REQUIRE_EQ(strcmp(actual_value, "d"), 0); nvlist_add_string(nvl, key, "cxhweh"); ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, "hthth", "fd"), "fd"), 0); - actual_value = dnvlist_getf_string(nvl, "5", "%s", "5"); + actual_value = dnvlist_get_string(nvl, "5", "5"); ATF_REQUIRE_EQ(strcmp("5", "5"), 0); nvlist_destroy(nvl); @@ -172,10 +171,6 @@ ATF_TEST_CASE_BODY(dnvlist_get_nvlist__p ATF_REQUIRE(actual_value != NULL); ATF_REQUIRE(nvlist_empty(actual_value)); - actual_value = dnvlist_getf_nvlist(nvl, NULL, "%s", key); - ATF_REQUIRE(actual_value != NULL); - ATF_REQUIRE(nvlist_empty(actual_value)); - nvlist_destroy(nvl); } @@ -191,11 +186,10 @@ ATF_TEST_CASE_BODY(dnvlist_get_nvlist__d dummy = nvlist_create(0); ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, key, dummy), dummy); - ATF_REQUIRE_EQ(dnvlist_getf_nvlist(nvl, dummy, "%s", key), dummy); nvlist_move_nvlist(nvl, key, nvlist_create(0)); ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, "456", dummy), dummy); - ATF_REQUIRE_EQ(dnvlist_getf_nvlist(nvl, dummy, "%s", "gh"), dummy); + ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, "gh", dummy), dummy); nvlist_destroy(nvl); } @@ -226,10 +220,6 @@ ATF_TEST_CASE_BODY(dnvlist_get_binary__p ATF_REQUIRE_EQ(value_size, actual_size); ATF_REQUIRE_EQ(memcmp(actual_value, value, actual_size), 0); - actual_value = dnvlist_getf_binary(nvl, &actual_size, "g", 1, "%s", k); - ATF_REQUIRE_EQ(value_size, actual_size); - ATF_REQUIRE_EQ(memcmp(actual_value, value, actual_size), 0); - nvlist_destroy(nvl); } @@ -251,8 +241,8 @@ ATF_TEST_CASE_BODY(dnvlist_get_binary__d ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0); set_const_binary_value(default_value, default_size, "atf"); - actual_value = dnvlist_getf_binary(nvl, &actual_size, default_value, - default_size, "%s", key); + actual_value = dnvlist_get_binary(nvl, key, &actual_size, default_value, + default_size); ATF_REQUIRE_EQ(default_size, actual_size); ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0); @@ -266,8 +256,8 @@ ATF_TEST_CASE_BODY(dnvlist_get_binary__d set_const_binary_value(default_value, default_size, "rrhgrythtyrtgbrhgrtdsvdfbtjlkul"); - actual_value = dnvlist_getf_binary(nvl, &actual_size, default_value, - default_size, "s"); + actual_value = dnvlist_get_binary(nvl, "s", &actual_size, default_value, + default_size); ATF_REQUIRE_EQ(default_size, actual_size); ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0); @@ -450,7 +440,7 @@ ATF_TEST_CASE_BODY(dnvlist_take_nvlist__ nvl = nvlist_create(0); actual_val = dnvlist_take_nvlist(nvl, "123", NULL); - ATF_REQUIRE_EQ(actual_val, NULL); + ATF_REQUIRE_EQ(actual_val, static_cast(NULL)); free(actual_val); nvlist_destroy(nvl); Modified: user/ngie/stable-10-libnv/lib/libnv/tests/nv_tests.cc ============================================================================== --- user/ngie/stable-10-libnv/lib/libnv/tests/nv_tests.cc Tue Dec 22 23:11:49 2015 (r292636) +++ user/ngie/stable-10-libnv/lib/libnv/tests/nv_tests.cc Tue Dec 22 23:21:06 2015 (r292637) @@ -54,7 +54,7 @@ ATF_TEST_CASE_BODY(nvlist_create__is_emp ATF_REQUIRE(nvlist_empty(nvl)); it = NULL; - ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), NULL); + ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), static_cast(NULL)); nvlist_destroy(nvl); } @@ -77,15 +77,14 @@ ATF_TEST_CASE_BODY(nvlist_add_null__sing ATF_REQUIRE(!nvlist_empty(nvl)); ATF_REQUIRE(nvlist_exists(nvl, key)); - ATF_REQUIRE(nvlist_existsf(nvl, "%s", key)); ATF_REQUIRE(nvlist_exists_null(nvl, key)); - ATF_REQUIRE(nvlist_existsf_null(nvl, "key")); + ATF_REQUIRE(nvlist_exists_null(nvl, "key")); /* Iterate over the nvlist; ensure that it has only our one key. */ it = NULL; ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_NULL); - ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL); + ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast(NULL)); nvlist_destroy(nvl); } @@ -108,17 +107,16 @@ ATF_TEST_CASE_BODY(nvlist_add_bool__sing ATF_REQUIRE(!nvlist_empty(nvl)); ATF_REQUIRE(nvlist_exists(nvl, key)); - ATF_REQUIRE(nvlist_existsf(nvl, "%s%s", "na", "me")); + ATF_REQUIRE(nvlist_exists(nvl, "name")); ATF_REQUIRE(nvlist_exists_bool(nvl, key)); - ATF_REQUIRE(nvlist_existsf_bool(nvl, "%s%c", "nam", 'e')); + ATF_REQUIRE(nvlist_exists_bool(nvl, "name")); ATF_REQUIRE_EQ(nvlist_get_bool(nvl, key), true); - ATF_REQUIRE_EQ(nvlist_getf_bool(nvl, "%c%s", 'n', "ame"), true); /* Iterate over the nvlist; ensure that it has only our one key. */ it = NULL; ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_BOOL); - ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL); + ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast(NULL)); nvlist_destroy(nvl); } @@ -143,17 +141,15 @@ ATF_TEST_CASE_BODY(nvlist_add_number__si ATF_REQUIRE(!nvlist_empty(nvl)); ATF_REQUIRE(nvlist_exists(nvl, key)); - ATF_REQUIRE(nvlist_existsf(nvl, "%s%d", "foo", 123)); + ATF_REQUIRE(nvlist_exists(nvl, "foo123")); ATF_REQUIRE(nvlist_exists_number(nvl, key)); - ATF_REQUIRE(nvlist_existsf_number(nvl, "%s", key)); ATF_REQUIRE_EQ(nvlist_get_number(nvl, key), value); - ATF_REQUIRE_EQ(nvlist_getf_number(nvl, "%s", key), value); /* Iterate over the nvlist; ensure that it has only our one key. */ it = NULL; ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER); - ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL); + ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast(NULL)); nvlist_destroy(nvl); } @@ -178,11 +174,10 @@ ATF_TEST_CASE_BODY(nvlist_add_string__si ATF_REQUIRE(!nvlist_empty(nvl)); ATF_REQUIRE(nvlist_exists(nvl, key)); - ATF_REQUIRE(nvlist_existsf(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists(nvl, "test")); ATF_REQUIRE(nvlist_exists_string(nvl, key)); - ATF_REQUIRE(nvlist_existsf_string(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists_string(nvl, "test")); ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, key), value), 0); - ATF_REQUIRE_EQ(strcmp(nvlist_getf_string(nvl, "%s", key), value), 0); /* nvlist_add_* is required to clone the value, so check for that. */ ATF_REQUIRE(nvlist_get_string(nvl, key) != value); @@ -191,7 +186,7 @@ ATF_TEST_CASE_BODY(nvlist_add_string__si it = NULL; ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_STRING); - ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL); + ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast(NULL)); nvlist_destroy(nvl); } @@ -219,9 +214,9 @@ ATF_TEST_CASE_BODY(nvlist_add_nvlist__si ATF_REQUIRE(!nvlist_empty(nvl)); ATF_REQUIRE(nvlist_exists(nvl, key)); - ATF_REQUIRE(nvlist_existsf(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists(nvl, "test")); ATF_REQUIRE(nvlist_exists_nvlist(nvl, key)); - ATF_REQUIRE(nvlist_existsf_nvlist(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists_nvlist(nvl, "test")); value = nvlist_get_nvlist(nvl, key); ATF_REQUIRE(nvlist_exists_null(value, subkey)); @@ -229,20 +224,32 @@ ATF_TEST_CASE_BODY(nvlist_add_nvlist__si /* nvlist_add_* is required to clone the value, so check for that. */ ATF_REQUIRE(sublist != value); - value = nvlist_getf_nvlist(nvl, "%s", key); - ATF_REQUIRE(nvlist_exists_null(value, subkey)); - ATF_REQUIRE(sublist != value); - /* Iterate over the nvlist; ensure that it has only our one key. */ it = NULL; ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST); - ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL); + ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast(NULL)); nvlist_destroy(sublist); nvlist_destroy(nvl); } +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__child_with_error); +ATF_TEST_CASE_BODY(nvlist_add_nvlist__child_with_error) +{ + nvlist_t *nvl, *parent; + + nvl = nvlist_create(0); + parent = nvlist_create(0); + + nvlist_set_error(nvl, EBADF); + nvlist_add_nvlist(parent, "test", nvl); + ATF_REQUIRE_EQ(nvlist_error(parent), EBADF); + + nvlist_destroy(nvl); + nvlist_destroy(parent); +} + ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_binary__single_insert); ATF_TEST_CASE_BODY(nvlist_add_binary__single_insert) { @@ -267,9 +274,9 @@ ATF_TEST_CASE_BODY(nvlist_add_binary__si ATF_REQUIRE(!nvlist_empty(nvl)); ATF_REQUIRE(nvlist_exists(nvl, key)); - ATF_REQUIRE(nvlist_existsf(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists(nvl, "binary")); ATF_REQUIRE(nvlist_exists_binary(nvl, key)); - ATF_REQUIRE(nvlist_existsf_binary(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists_binary(nvl, "binary")); ret_value = nvlist_get_binary(nvl, key, &ret_size); ATF_REQUIRE_EQ(value_size, ret_size); @@ -278,16 +285,11 @@ ATF_TEST_CASE_BODY(nvlist_add_binary__si /* nvlist_add_* is required to clone the value, so check for that. */ ATF_REQUIRE(value != ret_value); - ret_value = nvlist_getf_binary(nvl, &ret_size, "%s", key); - ATF_REQUIRE_EQ(value_size, ret_size); - ATF_REQUIRE_EQ(memcmp(value, ret_value, ret_size), 0); - ATF_REQUIRE(value != ret_value); - /* Iterate over the nvlist; ensure that it has only our one key. */ it = NULL; ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_BINARY); - ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL); + ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast(NULL)); nvlist_destroy(nvl); free(value); @@ -336,7 +338,7 @@ ATF_TEST_CASE_BODY(nvlist_clone__nonempt it = NULL; ATF_REQUIRE_EQ(strcmp(nvlist_next(clone, &type, &it), key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER); - ATF_REQUIRE_EQ(nvlist_next(clone, &type, &it), NULL); + ATF_REQUIRE_EQ(nvlist_next(clone, &type, &it), static_cast(NULL)); nvlist_destroy(clone); nvlist_destroy(nvl); @@ -384,13 +386,13 @@ verify_test_nvlist(const nvlist_t *nvl) ATF_REQUIRE_EQ(strcmp(nvlist_next(value, &type, &it), test_string_key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_STRING); - ATF_REQUIRE_EQ(nvlist_next(value, &type, &it), NULL); + ATF_REQUIRE_EQ(nvlist_next(value, &type, &it), static_cast(NULL)); it = NULL; ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), test_subnvlist_key), 0); ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST); - ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), NULL); + ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), static_cast(NULL)); } ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nested_nvlist); @@ -409,6 +411,22 @@ ATF_TEST_CASE_BODY(nvlist_clone__nested_ nvlist_destroy(nvl); } +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__error_nvlist); +ATF_TEST_CASE_BODY(nvlist_clone__error_nvlist) +{ + nvlist_t *nvl, *clone; + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + + nvlist_set_error(nvl, ENOMEM); + + clone = nvlist_clone(nvl); + ATF_REQUIRE(clone == NULL); + + nvlist_destroy(nvl); +} + ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__empty_nvlist); ATF_TEST_CASE_BODY(nvlist_pack__empty_nvlist) { @@ -550,6 +568,24 @@ ATF_TEST_CASE_BODY(nvlist_pack__multiple free(packed); } +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__error_nvlist); +ATF_TEST_CASE_BODY(nvlist_pack__error_nvlist) +{ + nvlist_t *nvl; + void *packed; + size_t size; + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + + nvlist_set_error(nvl, ENOMEM); + + packed = nvlist_pack(nvl, &size); + ATF_REQUIRE(packed == NULL); + + nvlist_destroy(nvl); +} + ATF_TEST_CASE_WITHOUT_HEAD(nvlist_unpack__duplicate_key); ATF_TEST_CASE_BODY(nvlist_unpack__duplicate_key) { @@ -620,1778 +656,17 @@ ATF_TEST_CASE_BODY(nvlist_move_nvlist__n nvlist_destroy(parent); } -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert); -ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert) -{ - nvlist_t *nvl; - const char *key; - nvlist_t *value; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - key = "testkey"; - value = nvlist_create(0); - ATF_REQUIRE(value != NULL); - - nvlist_move_nvlist(nvl, key, value); - ATF_REQUIRE_EQ(nvlist_get_nvlist(nvl, key), value); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_binary__single_insert); -ATF_TEST_CASE_BODY(nvlist_move_binary__single_insert) -{ - nvlist_t *nvl; - const char *key; - void *value; - size_t size, actual_size; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - key = "testkey"; - size = 73; - value = malloc(size); - ATF_REQUIRE(value != NULL); - - nvlist_move_binary(nvl, key, value, size); - ATF_REQUIRE_EQ(nvlist_get_binary(nvl, key, &actual_size), value); - ATF_REQUIRE_EQ(size, actual_size); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__single_remove); -ATF_TEST_CASE_BODY(nvlist_take_bool__single_remove) -{ - nvlist_t *nvl; - const char *testkey; - bool testval; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - testkey = "boolkey"; - testval = false; - nvlist_add_bool(nvl, testkey, testval); - - ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval); - ATF_REQUIRE(nvlist_empty(nvl)); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__other_keys_unchanged); -ATF_TEST_CASE_BODY(nvlist_take_bool__other_keys_unchanged) -{ - nvlist_t *nvl; - const char *testkey, *otherkey1, *otherkey2; - bool testval, otherval1; - nvlist_t *otherval2; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - testkey = "boolkey"; - testval = true; - nvlist_add_bool(nvl, testkey, testval); - - otherkey1 = "key1"; - otherval1 = false; - nvlist_add_bool(nvl, otherkey1, otherval1); - - otherkey2 = "key2"; - otherval2 = create_test_nvlist(); - nvlist_move_nvlist(nvl, otherkey2, otherval2); - - ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval); - - ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey1)); - ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey1), otherval1); - - ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey2)); - verify_test_nvlist(nvlist_get_nvlist(nvl, otherkey2)); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__single_remove); -ATF_TEST_CASE_BODY(nvlist_take_number__single_remove) -{ - nvlist_t *nvl; - const char *testkey; - uint64_t testval; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - testkey = "numkey"; - testval = std::numeric_limits::max(); - nvlist_add_number(nvl, testkey, testval); - - ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval); - ATF_REQUIRE(nvlist_empty(nvl)); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__other_keys_unchanged); -ATF_TEST_CASE_BODY(nvlist_take_number__other_keys_unchanged) -{ - nvlist_t *nvl; - const char *testkey, *otherkey1, *otherkey2; - uint64_t testval, otherval1; - const char *otherval2; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - otherkey1 = "key1"; - otherval1 = 5; - nvlist_add_number(nvl, otherkey1, otherval1); - - testkey = "numkey"; - testval = 1654; - nvlist_add_number(nvl, testkey, testval); - - otherkey2 = "key2"; - otherval2 = "string"; - nvlist_add_string(nvl, otherkey2, otherval2); - - ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval); - - ATF_REQUIRE(nvlist_exists_number(nvl, otherkey1)); - ATF_REQUIRE_EQ(nvlist_get_number(nvl, otherkey1), otherval1); - - ATF_REQUIRE(nvlist_exists_string(nvl, otherkey2)); - ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey2), otherval2), 0); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__single_remove); -ATF_TEST_CASE_BODY(nvlist_take_string__single_remove) -{ - nvlist_t *nvl; - const char *testkey; - const char *testval; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - testkey = "numkey"; - testval = "nvlist"; - nvlist_add_string(nvl, testkey, testval); - - ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0); - ATF_REQUIRE(nvlist_empty(nvl)); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__other_keys_unchanged); -ATF_TEST_CASE_BODY(nvlist_take_string__other_keys_unchanged) -{ - nvlist_t *nvl; - const char *testkey, *otherkey1, *otherkey2; - const char *testval, *otherval1; - bool otherval2; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - otherkey1 = "key1"; - otherval1 = "fjdifjdk"; - nvlist_add_string(nvl, otherkey1, otherval1); - - otherkey2 = "key2"; - otherval2 = true; - nvlist_add_bool(nvl, otherkey2, otherval2); - - testkey = "strkey"; - testval = "1654"; - nvlist_add_string(nvl, testkey, testval); - - ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0); - - ATF_REQUIRE(nvlist_exists_string(nvl, otherkey1)); - ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey1), otherval1), 0); - - ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2)); - ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__single_remove); -ATF_TEST_CASE_BODY(nvlist_take_nvlist__single_remove) +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__child_with_error); +ATF_TEST_CASE_BODY(nvlist_move_nvlist__child_with_error) { - nvlist_t *nvl; - const char *testkey; - nvlist_t *testval; + nvlist_t *nvl, *parent; nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); + parent = nvlist_create(0); - testkey = "numkey"; - testval = create_test_nvlist(); - nvlist_move_nvlist(nvl, testkey, testval); - - verify_test_nvlist(nvlist_take_nvlist(nvl, testkey)); - ATF_REQUIRE(nvlist_empty(nvl)); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__other_keys_unchanged); -ATF_TEST_CASE_BODY(nvlist_take_nvlist__other_keys_unchanged) -{ - nvlist_t *nvl; - const char *testkey, *otherkey1, *otherkey2; - nvlist_t *testval, *otherval1; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - testkey = "strkey"; - testval = create_test_nvlist(); - nvlist_move_nvlist(nvl, testkey, testval); - - otherkey1 = "key1"; - otherval1 = nvlist_create(0); - nvlist_move_nvlist(nvl, otherkey1, otherval1); - - otherkey2 = "key2"; - nvlist_add_null(nvl, otherkey2); - - verify_test_nvlist(nvlist_take_nvlist(nvl, testkey)); - - ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey1)); - ATF_REQUIRE(nvlist_empty(nvlist_get_nvlist(nvl, otherkey1))); - - ATF_REQUIRE(nvlist_exists_null(nvl, otherkey2)); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__single_remove); -ATF_TEST_CASE_BODY(nvlist_take_binary__single_remove) -{ - nvlist_t *nvl; - const char *testkey; - void *testval; - const void *actual_val; - size_t testsize, actual_size; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - testkey = "numkey"; - testsize = 457; - testval = malloc(testsize); - memset(testval, '5', testsize); - nvlist_move_binary(nvl, testkey, testval, testsize); - - actual_val = nvlist_take_binary(nvl, testkey, &actual_size); - ATF_REQUIRE_EQ(testsize, actual_size); - ATF_REQUIRE_EQ(memcmp(actual_val, testval, testsize), 0); - ATF_REQUIRE(nvlist_empty(nvl)); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__other_keys_unchanged); -ATF_TEST_CASE_BODY(nvlist_take_binary__other_keys_unchanged) -{ - nvlist_t *nvl; - const char *testkey, *otherkey1, *otherkey2; - const void *actual_value; - char testval[] = "gjiertj"; - char otherval1[] = "fdreg"; - size_t testsize, othersize, actual_size; - bool otherval2; - - nvl = nvlist_create(0); - ATF_REQUIRE(nvl != NULL); - - otherkey1 = "key1"; - othersize = sizeof(otherval1); - nvlist_add_binary(nvl, otherkey1, otherval1, othersize); - - otherkey2 = "key2"; - otherval2 = true; - nvlist_add_bool(nvl, otherkey2, otherval2); - - testkey = "strkey"; - testsize = sizeof(testval); - nvlist_add_binary(nvl, testkey, testval, testsize); - - actual_value = nvlist_take_binary(nvl, testkey, &actual_size); - ATF_REQUIRE_EQ(testsize, actual_size); - ATF_REQUIRE_EQ(memcmp(actual_value, testval, testsize), 0); - - ATF_REQUIRE(nvlist_exists_binary(nvl, otherkey1)); - actual_value = nvlist_get_binary(nvl, otherkey1, &actual_size); - ATF_REQUIRE_EQ(othersize, actual_size); - ATF_REQUIRE_EQ(memcmp(actual_value, otherval1, othersize), 0); - - ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2)); - ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2); - - nvlist_destroy(nvl); -} - -ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_null); -ATF_TEST_CASE_BODY(nvlist_free__single_null) -{ - nvlist_t *nvl; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***