btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
[platform/upstream/btrfs-progs.git] / tests / convert-tests / 005-delete-all-rollback / test.sh
1 #!/bin/bash
2 # create a base image, convert to btrfs, remove all files, rollback the ext4 image
3 # note: ext4 only
4
5 source "$TEST_TOP/common"
6 source "$TEST_TOP/common.convert"
7
8 setup_root_helper
9 prepare_test_dev
10 check_prereq btrfs-convert
11 check_global_prereq mke2fs
12
13 # simple wrapper for a convert test
14 # $1: btrfs features, argument to -O
15 # $2: message
16 # $3: nodesize value
17 # $4 + rest: command to create the ext2 image
18 do_test() {
19         local features
20         local msg
21         local nodesize
22         local CHECKSUMTMP
23         local here
24
25         features="$1"
26         msg="$2"
27         nodesize="$3"
28         shift 3
29         convert_test_preamble "$features" "$msg" "$nodesize" "$@"
30         convert_test_prep_fs ext4 "$@"
31         populate_fs
32         CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
33         convert_test_gen_checksums "$CHECKSUMTMP"
34
35         run_check_umount_test_dev
36
37         convert_test_do_convert "$features" "$nodesize"
38
39         run_check_mount_test_dev
40         convert_test_post_check_checksums "$CHECKSUMTMP"
41
42         here=$(pwd)
43         cd "$TEST_MNT" || _fail "cannot cd to TEST_MNT"
44         # ext2_saved/image must not be deleted
45         run_mayfail $SUDO_HELPER find "$TEST_MNT"/ -mindepth 1 -path '*ext2_saved' -prune -o -exec rm -vrf "{}" \;
46         cd "$here"
47         run_check "$TOP/btrfs" filesystem sync "$TEST_MNT"
48         run_check_umount_test_dev
49         convert_test_post_rollback ext4
50
51         run_check_mount_convert_dev ext4
52         convert_test_post_check_checksums "$CHECKSUMTMP"
53         run_check_umount_test_dev
54
55         # mount again and verify checksums
56         run_check_mount_convert_dev ext4
57         convert_test_post_check_checksums "$CHECKSUMTMP"
58         run_check_umount_test_dev
59
60         rm "$CHECKSUMTMP"
61 }
62
63 for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
64         do_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096
65         do_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096
66         do_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096
67         do_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096
68         do_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096
69 done