summaryrefslogtreecommitdiff
path: root/tests/misc-tests
diff options
context:
space:
mode:
authorNick Terrell <terrelln@fb.com>2017-09-11 21:27:52 +0200
committerDavid Sterba <dsterba@suse.com>2017-09-25 15:17:15 +0200
commit0766330f8504dfa876894795fecf8feaff8c1e9c (patch)
tree153fce2ebcbd9a23c11c139cca91cc8384e2c548 /tests/misc-tests
parent717a8b1e5d1ba69154ef84b35be75c9cf7730e1d (diff)
btrfs-progs: tests: add testing image for zstd for btrfs-restore
Adds tests for the new features based on a prebuilt btrfs image with a zstd compressed file. Split from the previous patch. Signed-off-by: Nick Terrell <terrelln@fb.com> [ with some cleanups ] Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'tests/misc-tests')
-rw-r--r--tests/misc-tests/025-zstd-compression/compress.raw.xzbin0 -> 18220 bytes
-rwxr-xr-xtests/misc-tests/025-zstd-compression/test.sh56
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/misc-tests/025-zstd-compression/compress.raw.xz b/tests/misc-tests/025-zstd-compression/compress.raw.xz
new file mode 100644
index 00000000..67aaf17f
--- /dev/null
+++ b/tests/misc-tests/025-zstd-compression/compress.raw.xz
Binary files differ
diff --git a/tests/misc-tests/025-zstd-compression/test.sh b/tests/misc-tests/025-zstd-compression/test.sh
new file mode 100755
index 00000000..e95dcb36
--- /dev/null
+++ b/tests/misc-tests/025-zstd-compression/test.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+# Test zstd compression support on a prebuilt btrfs image
+
+source "$TOP/tests/common"
+
+check_prereq btrfs
+check_global_prereq md5sum
+
+# Extract the test image
+image=$(extract_image compress.raw.xz)
+
+check_dump_tree() {
+ local image=$1
+ local string=$2
+
+ run_check_stdout "$TOP/btrfs" inspect-internal dump-tree "$image" \
+ | grep -q "$string" \
+ || _fail "btrfs inspect-internal dump-tree didn't print $string"
+}
+
+# Check that there are blocks of each compression type
+check_dump_tree "$image" "extent compression 1 (zlib)"
+check_dump_tree "$image" "extent compression 2 (lzo)"
+check_dump_tree "$image" "extent compression 3 (zstd)"
+
+# Check that the filesystem has incompat COMPRESS_ZSTD
+run_check_stdout "$TOP/btrfs" inspect-internal dump-super -f "$image" \
+ | grep -q COMPRESS_ZSTD \
+ || _fail "btrfs inspect-internal dump-super no incompat COMPRESS_ZSTD"
+
+# Create a temporary directory and restore the filesystem
+restore_tmp=$(mktemp --tmpdir -d btrfs-progs-022-zstd-compression.XXXXXXXXXX)
+run_check "$TOP/btrfs" restore "$image" "$restore_tmp"
+
+# Expect 3 files
+num_files=$(ls -1 "$restore_tmp" | wc -l)
+[ "$num_files" == 3 ] || _fail "number of files does not match"
+
+check_md5() {
+ local file="$1"
+ local expect_md5="$2"
+
+ md5=$(run_check_stdout md5sum "$file" | cut -d ' ' -f 1)
+ [ "$md5" == "$expect_md5" ] \
+ || _fail "$file digest $md5 does not match $expect_md5"
+}
+
+# Each should be 200K of zeros
+expect_md5=$(dd if=/dev/zero bs=1K count=200 status=none | md5sum | cut -d ' ' -f 1)
+check_md5 "$restore_tmp/zlib" "$expect_md5"
+check_md5 "$restore_tmp/lzo" "$expect_md5"
+check_md5 "$restore_tmp/zstd" "$expect_md5"
+
+# Clean up
+rm -r -- "$restore_tmp"
+rm -- "$image"