From: Ariel Miculas <[email protected]>

This test builds a PuzzleFS image using the PuzzleFS user space tools,
builds a Linux kernel with PuzzleFS enabled, mounts the PuzzleFS image
using the kernel driver and then compares the two filesystems: the
source filesystem used when building the PuzzleFS image and the final
PuzzleFS filesystem mounted directly from the PuzzleFS image.

This test is similar to the build_from_ext4 test in single_device.ktest.

Two packages are added to the root_image: capnproto required for
building the PuzzleFS user space tools and jq, which is used for
extracting the PuzzleFS image manifest from index.json.

Signed-off-by: Ariel Miculas <[email protected]>
---
 root_image                    |  3 ++
 tests/puzzlefs/puzzlefs.ktest | 94 +++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100755 tests/puzzlefs/puzzlefs.ktest

diff --git a/root_image b/root_image
index 65d0a72..386fdfb 100755
--- a/root_image
+++ b/root_image
@@ -117,6 +117,9 @@ PACKAGES+=(cryptsetup)
 # weird block layer crap
 PACKAGES+=(multipath-tools sg3-utils srptools)
 
+# PuzzleFS support
+PACKAGES+=(capnproto jq)
+
 # ZFS support
 #PACKAGES+=("linux-headers-generic" dkms zfsutils-linux zfs-dkms)
 
diff --git a/tests/puzzlefs/puzzlefs.ktest b/tests/puzzlefs/puzzlefs.ktest
new file mode 100755
index 0000000..ffe68c4
--- /dev/null
+++ b/tests/puzzlefs/puzzlefs.ktest
@@ -0,0 +1,94 @@
+#!/bin/bash
+#
+# PuzzleFS tests
+#
+
+. $(dirname $(readlink -e ${BASH_SOURCE[0]}))/../test-libs.sh
+
+require-git https://github.com/project-machine/puzzlefs
+require-make puzzlefs
+
+config-mem 4G
+config-compiler clang
+require-kernel-config RUST
+require-kernel-config MISC_FILESYSTEMS
+require-kernel-config PUZZLEFS_FS
+config-scratch-devs 4G
+
+check_rsync_log()
+{
+    # rsync itemized output
+    # https://jhpce.jhu.edu/files/rsync-itemize-table/
+    # .: the item is not being updated (though it might have attributes that 
are being modified)
+    # h: the item is a hard link to another item (requires --hard-links).
+
+    # We don't expect any lines to start with anything other than a dot or h
+    # Ideally the output should be empty, but the lost+found/ directory is
+    # ignored and the mountpoints themselves could have a modified time
+    # Sample expected output:
+    # .d..t...... ./
+    # .d..t...... lost+found/
+    ! grep -E '^[^.h]' $1
+}
+
+prepare_source_fs()
+{
+    local fstype=$1
+
+    if [[ $fstype = ext4 ]]; then
+       run_quiet "" mkfs.$fstype -F ${ktest_scratch_dev[0]}
+       mount -t $fstype -o user_xattr ${ktest_scratch_dev[0]} /mnt
+    else
+       run_quiet "" mkfs.$fstype -f ${ktest_scratch_dev[0]}
+       mount -t $fstype ${ktest_scratch_dev[0]} /mnt
+    fi
+
+    # Copy only /usr/bin until PuzzleFS can handle larger filesystems
+    cp -a /usr/bin /mnt
+
+    for i in /mnt/bin/*; do
+       if [ ! -L $i ]; then
+           ln $i ${i}-migrate2
+           setfattr -n user.foo -v test $i
+       fi
+    done
+}
+
+# build a filesystem from a source
+build_from_fs()
+{
+    set_watchdog 180
+
+    prepare_source_fs $1
+
+    puzzlefs build /mnt /tmp/puzzlefs-oci pfs_image
+
+    echo "Attempting to mount puzzlefs filesystem"
+    local image_manifest=$(jq -r ".manifests[] | .digest" 
/tmp/puzzlefs-oci/index.json | cut -d ':' -f2)
+
+    mkdir -p /mnt2
+    mount -t puzzlefs -o oci_root_dir="/tmp/puzzlefs-oci" -o 
image_manifest="$image_manifest" none /mnt2
+
+    rsync --archive                            \
+       --acls                                  \
+       --xattrs                                \
+       --checksum                              \
+       --hard-links                            \
+       --dry-run                               \
+       --itemize-changes                       \
+       /mnt/ /mnt2/ > /root/rsynclog-build
+
+    check_rsync_log /root/rsynclog-build
+
+    umount /mnt2
+    echo "rsync passed"
+
+    umount /mnt
+}
+
+test_build_from_ext4()
+{
+    build_from_fs ext4
+}
+
+main "$@"
-- 
2.34.1


Reply via email to