btrfs-progs: Add some simple end-to-end tests for btrfs-convert
[platform/upstream/btrfs-progs.git] / tests / convert-tests.sh
1 #!/bin/bash
2 #
3 # convert ext2/3/4 images to btrfs images, and make sure the results are
4 # clean.
5 #
6
7 here=`pwd`
8
9 _fail()
10 {
11         echo "$*" | tee -a convert-tests-results.txt
12         exit 1
13 }
14
15 rm -f convert-tests-results.txt
16 rm -f test.img
17
18 test(){
19         echo "     [TEST]    $1"
20         shift
21         echo "creating ext image with: $*" >> convert-tests-results.txt
22         # 256MB is the smallest acceptable btrfs image.
23         dd if=/dev/zero of=$here/test.img bs=1024 count=$((256*1024)) \
24                 >> convert-tests-results.txt 2>&1 || _fail "dd failed"
25         $* -F $here/test.img >> convert-tests-results.txt 2>&1 \
26                 || _fail "filesystem create failed"
27         $here/btrfs-convert $here/test.img >> convert-tests-results.txt 2>&1 \
28                 || _fail "btrfs-convert failed"
29         $here/btrfsck $here/test.img >> convert-tests-results.txt 2>&1 \
30                 || _fail "btrfsck detected errors"
31 }
32
33 test "ext2, 4k blocksize" mke2fs -b 4096
34 test "ext3, 4k blocksize" mke2fs -j -b 4096
35 test "ext4, 4k blocksize" mke2fs -t ext4 -b 4096