From owner-svn-src-all@freebsd.org Mon Apr 22 13:45:10 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 041A2159A640; Mon, 22 Apr 2019 13:45:10 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9E8A68B45F; Mon, 22 Apr 2019 13:45:09 +0000 (UTC) (envelope-from kevans@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 91D1FDC23; Mon, 22 Apr 2019 13:45:09 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3MDj9J8019134; Mon, 22 Apr 2019 13:45:09 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3MDj8aN019111; Mon, 22 Apr 2019 13:45:08 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201904221345.x3MDj8aN019111@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 22 Apr 2019 13:45:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346546 - in head: etc/mtree lib/libbe lib/libbe/tests X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in head: etc/mtree lib/libbe lib/libbe/tests X-SVN-Commit-Revision: 346546 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9E8A68B45F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_SHORT(-0.94)[-0.943,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 13:45:10 -0000 Author: kevans Date: Mon Apr 22 13:45:08 2019 New Revision: 346546 URL: https://svnweb.freebsd.org/changeset/base/346546 Log: libbe(3): Add a test for be creation Submitted by: Rob Fairbanks MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D18564 Added: head/lib/libbe/tests/ head/lib/libbe/tests/Makefile (contents, props changed) head/lib/libbe/tests/be_create.sh (contents, props changed) head/lib/libbe/tests/target_prog.c (contents, props changed) Modified: head/etc/mtree/BSD.tests.dist head/lib/libbe/Makefile Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Mon Apr 22 13:43:38 2019 (r346545) +++ head/etc/mtree/BSD.tests.dist Mon Apr 22 13:45:08 2019 (r346546) @@ -290,6 +290,8 @@ .. libarchive .. + libbe + .. libc c063 .. Modified: head/lib/libbe/Makefile ============================================================================== --- head/lib/libbe/Makefile Mon Apr 22 13:43:38 2019 (r346545) +++ head/lib/libbe/Makefile Mon Apr 22 13:45:08 2019 (r346546) @@ -1,5 +1,7 @@ # $FreeBSD$ +.include + PACKAGE= lib${LIB} LIB= be SHLIBDIR?= /lib @@ -27,5 +29,8 @@ CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/ CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/head CFLAGS+= -DNEED_SOLARIS_BOOLEAN + +HAS_TESTS= YES +SUBDIR.${MK_TESTS}+= tests .include Added: head/lib/libbe/tests/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libbe/tests/Makefile Mon Apr 22 13:45:08 2019 (r346546) @@ -0,0 +1,21 @@ +# $FreeBSD$ + +PACKAGE= tests + +ATF_TESTS_SH+= be_create + +PROGS= target_prog +SRCS_target_prog= target_prog.c +BINDIR_target_prog= ${TESTSDIR} + +LIBADD+= zfs +LIBADD+= nvpair +LIBADD+= be + +CFLAGS+= -I${SRCTOP}/lib/libbe +CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris +CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common + +CFLAGS+= -DNEED_SOLARIS_BOOLEAN + +.include Added: head/lib/libbe/tests/be_create.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libbe/tests/be_create.sh Mon Apr 22 13:45:08 2019 (r346546) @@ -0,0 +1,178 @@ +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Rob Wing +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# The code for the following tests was copied from the +# bectl tests found in src/sbin/bectl/tests, modified as needed. + +ZPOOL_NAME_FILE=zpool_name +get_zpool_name() +{ + cat $ZPOOL_NAME_FILE +} +make_zpool_name() +{ + mktemp -u libbe_test_XXXXXX > $ZPOOL_NAME_FILE + get_zpool_name +} + +# Establishes a libbe zpool that can be used for some light testing; contains +# a 'default' BE and not much else. +libbe_create_setup() +{ + zpool=$1 + disk=$2 + mnt=$3 + + # Sanity check to make sure `make_zpool_name` succeeded + atf_check test -n "$zpool" + + kldload -n -q zfs || atf_skip "ZFS module not loaded on the current system" + atf_check mkdir -p ${mnt} + atf_check truncate -s 1G ${disk} + atf_check zpool create -o altroot=${mnt} ${zpool} ${disk} + atf_check zfs create -o mountpoint=none ${zpool}/ROOT + atf_check zfs create -o mountpoint=/ -o canmount=noauto \ + ${zpool}/ROOT/default + atf_check zfs create -o mountpoint=/usr -o canmount=noauto \ + ${zpool}/ROOT/default/usr + atf_check zfs create -o mountpoint=/usr/obj -o canmount=noauto \ + ${zpool}/ROOT/default/usr/obj +} + +libbe_cleanup() +{ + zpool=$1 + cwd=$(atf_get_srcdir) + + if [ -z "$zpool" ]; then + echo "Skipping cleanup; zpool not set up" + elif zpool get health ${zpool} >/dev/null 2>&1; then + zpool destroy -f ${zpool} + fi + + if [ -f "${cwd}/disk.img" ]; then + rm ${cwd}/disk.img + fi +} + +atf_test_case libbe_create cleanup +libbe_create_head() +{ + atf_set "descr" "check _be_create from libbe" + atf_set "require.user" root +} +libbe_create_body() +{ + cwd=$(atf_get_srcdir) + zpool=$(make_zpool_name) + disk=${cwd}/disk.img + mount=${cwd}/mnt + prog=${cwd}/./target_prog + + # preliminary setup/checks + atf_require_prog $prog + libbe_create_setup ${zpool} ${disk} ${mount} + + # a recursive and non-recursive snapshot to test against + atf_check zfs snapshot ${zpool}/ROOT/default@non-recursive + atf_check zfs snapshot -r ${zpool}/ROOT/default@recursive + + # create a dataset after snapshots were taken + atf_check zfs create -o mountpoint=/usr/src -o canmount=noauto \ + ${zpool}/ROOT/default/usr/src + + # test boot environment creation with depth of 0 (i.e. a non-recursive boot environment). + atf_check $prog "${zpool}/ROOT" \ + nonrecursive \ + "${zpool}/ROOT/default@non-recursive" \ + 0 + # the dataset should exist + atf_check -o not-empty \ + zfs list "${zpool}/ROOT/nonrecursive" + # the child dataset should not exist. + atf_check -e not-empty -s not-exit:0 \ + zfs list "${zpool}/ROOT/nonrecursive/usr" + + # test boot environment creation with unlimited depth (i.e. a recursive boot environment). + atf_check $prog "${zpool}/ROOT" \ + recursive \ + "${zpool}/ROOT/default@recursive" \ + -1 + # the dataset should exist + atf_check -o not-empty \ + zfs list "${zpool}/ROOT/recursive" + # the child dataset should exist + atf_check -o not-empty \ + zfs list "${zpool}/ROOT/recursive/usr" + # the child dataset should exist + atf_check -o not-empty \ + zfs list "${zpool}/ROOT/recursive/usr/obj" + # the child dataset should not exist. + atf_check -e not-empty -s not-exit:0 \ + zfs list "${zpool}/ROOT/recursive/usr/src" + + # test boot environment creation with a depth of 1 + atf_check $prog "${zpool}/ROOT" \ + depth \ + "${zpool}/ROOT/default@recursive" \ + 1 + # the child dataset should exist + atf_check -o not-empty \ + zfs list "${zpool}/ROOT/depth/usr" + # the child dataset should not exist. + atf_check -e not-empty -s not-exit:0 \ + zfs list "${zpool}/ROOT/depth/usr/obj" + # the child dataset should not exist. + atf_check -e not-empty -s not-exit:0 \ + zfs list "${zpool}/ROOT/depth/usr/src" + + + # create a recursive boot environment named 'relative-snap'. + # This test is to ensure that a relative snapshot label can be used, + # (i.e. the format: 'bootenvironment@snapshot') + atf_check $prog "${zpool}/ROOT" \ + relative-snap \ + default@recursive \ + -1 + # the dataset should exist + atf_check -o not-empty \ + zfs list "${zpool}/ROOT/relative-snap" + # the child dataset should exist + atf_check -o not-empty \ + zfs list "${zpool}/ROOT/relative-snap/usr" +} + +libbe_create_cleanup() +{ + libbe_cleanup $(get_zpool_name) +} + +atf_init_test_cases() +{ + atf_add_test_case libbe_create +} Added: head/lib/libbe/tests/target_prog.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libbe/tests/target_prog.c Mon Apr 22 13:45:08 2019 (r346546) @@ -0,0 +1,53 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 Rob Wing + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +/* + * argv[1] = root boot environment (e.g. zroot/ROOT), + * argv[2] = name of boot environment to create + * argv[3] = snapshot to create boot environment from + * argv[4] = depth + */ +int main(int argc, char *argv[]) { + + libbe_handle_t *lbh; + + if (argc != 5) + return -1; + + if ((lbh = libbe_init(argv[1])) == NULL) + return -1; + + libbe_print_on_error(lbh, true); + + return (be_create_depth(lbh, argv[2], argv[3], atoi(argv[4]))); +}