3 # eCryptfs test suite harness
4 # Author: Tyler Hicks <tyhicks@canonical.com>
6 # Copyright (C) 2012 Canonical, Ltd.
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 # # ./tests/run_tests.sh -K -c destructive -d /dev/vdb -l /lower -u /upper
26 # This would run kernel tests in the destructive category, as defined in
27 # kernel/tests.rc. /dev/vdb would be the block device containing the lower
28 # filesystem, which would be mounted at /lower. The eCryptfs mount point would
32 run_tests_dir=$(dirname $0)
35 . ${run_tests_dir}/lib/etl_funcs.sh
41 default_lower_fses="ext4"
57 if [ $cleanup_upper_mnt -ne 0 ] && [ -n "$upper_mnt" ]; then
60 if [ $cleanup_lower_mnt -ne 0 ] && [ -n "$lower_mnt" ]; then
66 trap run_tests_cleanup 0 1 2 3 15
73 for etest in $tests; do
74 printf "%-16s\t" $(basename "$etest" .sh)
87 run_kernel_tests_on_existing_device()
89 echo "Running eCryptfs filesystem tests"
91 run_tests "${run_tests_dir}/kernel" "$ktests"
93 echo "Failed to run eCryptfs filesystem tests" 1>&2
98 if [ -n "$ETL_DISK" ]; then
103 run_kernel_tests_on_created_disk_image()
105 lower_fses=$(echo $lower_fses | tr ',' ' ')
106 for lower_fs in $lower_fses; do
107 echo "Running eCryptfs filesystem tests on $lower_fs"
109 if [ "$blocks" -gt 0 ]; then
110 export ETL_LFS=$lower_fs
111 etl_create_disk $blocks $disk_dir
112 if [ $? -ne 0 ]; then
113 echo "Failed to create disk for $lower_fs"\
114 "(skipping all tests on $lower_fs)" 1>&2
117 export ETL_LMOUNT_SRC=$ETL_DISK
120 run_tests "${run_tests_dir}/kernel" "$ktests"
121 if [ $? -ne 0 ]; then
122 echo "Failed to run eCryptfs filesystem tests on"\
128 if [ -n "$ETL_DISK" ]; then
136 echo "Usage: $(basename $0) [options] -K -c categories -b blocks"
137 echo " or: $(basename $0) [options] -K -c categories -d device"
138 echo " or: $(basename $0) [options] -U -c categories"
139 echo " or: $(basename $0) [options] -K -U -c categories -b blocks"
141 echo "eCryptfs test harness"
143 echo " -b blocks number of 1K blocks used when creating backing "
144 echo " disk for lower filesystem (not compatible "
146 echo " -c categories comma-separated test categories" \
147 "(e.g., -c safe,destructive)"
148 echo " -D disk_dir directory used to store created backing disk "
149 echo " when using -b (not compatible with -d)"
150 echo " -d device backing device to mount lower filesystem, such "
151 echo " as /dev/sdd3 (not compatible with -b)"
152 echo " -f lower_fses comma-separated lower filesystem types" \
153 "(e.g., -f ext4,btrfs)"
154 echo " defaults to $default_lower_fses" \
155 "(not compatible with -d)"
156 echo " -h display this help and exit"
157 echo " -K run tests relating to the kernel module"
158 echo " -l lower_mnt destination path to mount lower filesystem"
159 echo " -t tests comma-separated list of tests to run"
160 echo " -U run tests relating to the userspace utilities"
161 echo " -u upper_mnt destination path to mount upper filesystem"
164 while getopts "b:c:D:d:f:hKl:t:Uu:" opt; do
212 if ! $kernel && ! $userspace ; then
213 # Must specify at least one of these
214 echo "Must specify one of -U or -K" 1>&2
217 elif [ -z "$categories" ] && [ -z "$tests" ]; then
218 # Must either specify test categories or specific tests
219 echo "Must specify a list of test categories or a list of tests" 1>&2
225 if [ "$blocks" -lt 1 ] && [ -z "$device" ]; then
226 # Must specify blocks for disk creation *or* an existing device
227 echo "Blocks for disk creation or an existing device must be" \
231 elif [ "$blocks" -gt 0 ] && [ -n "$device" ]; then
232 # Can't specify blocks for disk *and* an existing device
233 echo "Cannot specify blocks for disk creation *and* also an" \
234 "existing device" 1>&2
237 elif [ -n "$disk_dir" ] && [ -n "$device" ]; then
238 # Can't specify a dir for disk creation and an existing device
239 echo "Cannot specify a directory for disk creation *and* also" \
240 "an existing device" 1>&2
243 elif [ -n "$device" ] && [ ! -b "$device" ]; then
244 # A small attempt at making sure we're dealing with a block dev
245 echo "Backing device must be a valid block device" 1>&2
248 elif [ -n "$device" ] && [ -n "$lower_fses" ]; then
249 # We currently don't reformat block devices so we shouldn't
250 # accept a list of lower filesystems to test on
251 echo "Lower filesystems cannot be specified when using" \
252 "existing block devices" 1>&2
255 elif [ -n "$lower_mnt" ] && [ ! -d "$lower_mnt" ]; then
256 # A small attempt at making sure we're dealing with directories
257 echo "Lower mount point must exist" 1>&2
260 elif [ -n "$upper_mnt" ] && [ ! -d "$upper_mnt" ]; then
261 # A small attempt at making sure we're dealing with directories
262 echo "Upper mount point must exist" 1>&2
265 elif [ -n "$disk_dir" ] && [ ! -d "$disk_dir" ]; then
266 # A small attempt at making sure we're dealing with a directory
267 echo "Directory used to store created backing disk must" \
274 if [ -n "$device" ]; then
275 export ETL_LMOUNT_SRC=$device
276 elif [ -z "$lower_fses" ]; then
277 lower_fses=$default_lower_fses
280 if [ -z "$lower_mnt" ]; then
282 lower_mnt=$(mktemp -dq /tmp/etl-lower-XXXXXXXXXX)
283 if [ $? -ne 0 ]; then
289 export ETL_LMOUNT_DST=$lower_mnt
290 export ETL_MOUNT_SRC=$lower_mnt
292 if [ -z "$upper_mnt" ]; then
294 upper_mnt=$(mktemp -dq /tmp/etl-upper-XXXXXXXXXX)
295 if [ $? -ne 0 ]; then
301 export ETL_MOUNT_DST=$upper_mnt
303 # Source in the kernel and/or userspace tests.rc files to build the test lists
304 categories=$(echo $categories | tr ',' ' ')
306 if [ -n "$tests" ]; then
307 ktests=$(echo $tests | tr ',' ' ')
309 . ${run_tests_dir}/kernel/tests.rc
310 for cat in $categories ; do
311 eval cat_tests=\$$cat
312 ktests="$ktests $cat_tests"
316 if [ -n "$device" ]; then
317 run_kernel_tests_on_existing_device
319 run_kernel_tests_on_created_disk_image
323 if [ -n "$tests" ]; then
324 utests=$(echo $tests | tr ',' ' ')
326 . ${run_tests_dir}/userspace/tests.rc
327 for cat in $categories ; do
328 eval cat_tests=\$$cat
329 utests="$utests $cat_tests"
333 echo "Running eCryptfs userspace tests"
335 run_tests "${run_tests_dir}/userspace" "$utests"
336 if [ $? -ne 0 ]; then
344 echo "$passed passed"
345 echo "$failed failed"