2 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 # Copyright (c) 2019 Rob Wing
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 # The code for the following tests was copied from the
30 # bectl tests found in src/sbin/bectl/tests, modified as needed.
32 ZPOOL_NAME_FILE=zpool_name
39 mktemp -u libbe_test_XXXXXX > $ZPOOL_NAME_FILE
43 # Establishes a libbe zpool that can be used for some light testing; contains
44 # a 'default' BE and not much else.
51 # Sanity check to make sure `make_zpool_name` succeeded
52 atf_check test -n "$zpool"
54 kldload -n -q zfs || atf_skip "ZFS module not loaded on the current system"
55 atf_check mkdir -p ${mnt}
56 atf_check truncate -s 1G ${disk}
57 atf_check zpool create -o altroot=${mnt} ${zpool} ${disk}
58 atf_check zfs create -o mountpoint=none ${zpool}/ROOT
59 atf_check zfs create -o mountpoint=/ -o canmount=noauto \
61 atf_check zfs create -o mountpoint=/usr -o canmount=noauto \
62 ${zpool}/ROOT/default/usr
63 atf_check zfs create -o mountpoint=/usr/obj -o canmount=noauto \
64 ${zpool}/ROOT/default/usr/obj
72 if [ -z "$zpool" ]; then
73 echo "Skipping cleanup; zpool not set up"
74 elif zpool get health ${zpool} >/dev/null 2>&1; then
75 zpool destroy -f ${zpool}
78 if [ -f "${cwd}/disk.img" ]; then
83 atf_test_case libbe_create cleanup
86 atf_set "descr" "check _be_create from libbe"
87 atf_set "require.user" root
92 zpool=$(make_zpool_name)
95 prog=${cwd}/./target_prog
97 # preliminary setup/checks
98 atf_require_prog $prog
99 libbe_create_setup ${zpool} ${disk} ${mount}
101 # a recursive and non-recursive snapshot to test against
102 atf_check zfs snapshot ${zpool}/ROOT/default@non-recursive
103 atf_check zfs snapshot -r ${zpool}/ROOT/default@recursive
105 # create a dataset after snapshots were taken
106 atf_check zfs create -o mountpoint=/usr/src -o canmount=noauto \
107 ${zpool}/ROOT/default/usr/src
109 # test boot environment creation with depth of 0 (i.e. a non-recursive boot environment).
110 atf_check $prog "${zpool}/ROOT" \
112 "${zpool}/ROOT/default@non-recursive" \
114 # the dataset should exist
115 atf_check -o not-empty \
116 zfs list "${zpool}/ROOT/nonrecursive"
117 # the child dataset should not exist.
118 atf_check -e not-empty -s not-exit:0 \
119 zfs list "${zpool}/ROOT/nonrecursive/usr"
121 # test boot environment creation with unlimited depth (i.e. a recursive boot environment).
122 atf_check $prog "${zpool}/ROOT" \
124 "${zpool}/ROOT/default@recursive" \
126 # the dataset should exist
127 atf_check -o not-empty \
128 zfs list "${zpool}/ROOT/recursive"
129 # the child dataset should exist
130 atf_check -o not-empty \
131 zfs list "${zpool}/ROOT/recursive/usr"
132 # the child dataset should exist
133 atf_check -o not-empty \
134 zfs list "${zpool}/ROOT/recursive/usr/obj"
135 # the child dataset should not exist.
136 atf_check -e not-empty -s not-exit:0 \
137 zfs list "${zpool}/ROOT/recursive/usr/src"
139 # test boot environment creation with a depth of 1
140 atf_check $prog "${zpool}/ROOT" \
142 "${zpool}/ROOT/default@recursive" \
144 # the child dataset should exist
145 atf_check -o not-empty \
146 zfs list "${zpool}/ROOT/depth/usr"
147 # the child dataset should not exist.
148 atf_check -e not-empty -s not-exit:0 \
149 zfs list "${zpool}/ROOT/depth/usr/obj"
150 # the child dataset should not exist.
151 atf_check -e not-empty -s not-exit:0 \
152 zfs list "${zpool}/ROOT/depth/usr/src"
155 # create a recursive boot environment named 'relative-snap'.
156 # This test is to ensure that a relative snapshot label can be used,
157 # (i.e. the format: 'bootenvironment@snapshot')
158 atf_check $prog "${zpool}/ROOT" \
162 # the dataset should exist
163 atf_check -o not-empty \
164 zfs list "${zpool}/ROOT/relative-snap"
165 # the child dataset should exist
166 atf_check -o not-empty \
167 zfs list "${zpool}/ROOT/relative-snap/usr"
170 libbe_create_cleanup()
172 libbe_cleanup $(get_zpool_name)
175 atf_init_test_cases()
177 atf_add_test_case libbe_create