From b46ae1930e537a9e7aa0dc23be7d84592cd8c1ac Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 20 Sep 2023 17:11:34 +0200 Subject: [PATCH 1/3] gendir: Generate correct minor/major for device nodes Signed-off-by: Alexander Larsson --- tests/gendir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gendir b/tests/gendir index 78a532a5..812f3dc9 100755 --- a/tests/gendir +++ b/tests/gendir @@ -135,7 +135,7 @@ def make_node(path): if not args.privileged: return target = gen_filename() - os.mknod(path, gen_file_mode() | random.choice([stat.S_IFCHR,stat.S_IFBLK]), os.makedev(0,0)) + os.mknod(path, gen_file_mode() | random.choice([stat.S_IFCHR,stat.S_IFBLK]), os.makedev(random.randrange(1, 255),random.randrange(1, 255))) def make_whiteout(path): if args.nowhiteout: From 4b14b818e2f0374b02bb5d35e4c31fba59fe8f98 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 20 Sep 2023 17:12:24 +0200 Subject: [PATCH 2/3] dumpdir: ADd --no-root-nlink It turns out that composefs can't properly show the nlink of the root directory (its always 1) because this comes from the overlayfs top dir, not from the backing dir in the erofs image. Signed-off-by: Alexander Larsson --- tests/dumpdir | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/dumpdir b/tests/dumpdir index 6aff0a02..3e2d4bd7 100755 --- a/tests/dumpdir +++ b/tests/dumpdir @@ -39,7 +39,7 @@ def dumpfile(file, root): xattrs["user.overlay.whiteouts"] = b'' nlink = s.st_nlink; - if args.no_nlink: + if args.no_nlink or (args.no_root_nlink and file == root): nlink = 1 print(f"{shlex.quote(rel)} {oct(st_mode)} {nlink} {s.st_uid}:{s.st_gid} {s.st_rdev} {s.st_mtime_ns}",end="") if stat.S_ISREG(st_mode): @@ -77,6 +77,7 @@ def dumpdir(root): argParser = argparse.ArgumentParser() argParser.add_argument("--no-nlink", action='store_true') +argParser.add_argument("--no-root-nlink", action='store_true') argParser.add_argument("--userxattr", action='store_true') argParser.add_argument("--whiteout", action='store_true') argParser.add_argument("--noescaped", action='store_true') From a422a59812003404d6bac00119e75fa61178af32 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 20 Sep 2023 14:46:14 +0200 Subject: [PATCH 3/3] tests: Add a new gendir based integration tests We previously only made an image of the host /usr/bin and verified it. This also adds a new image based on the gendir helper that generates a random image, which uses more file types. Signed-off-by: Alexander Larsson --- tests/integration.sh | 59 ++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/tests/integration.sh b/tests/integration.sh index 6d1dfa83..5973d23a 100755 --- a/tests/integration.sh +++ b/tests/integration.sh @@ -10,30 +10,41 @@ rm ${cfsroot}/tmp -rf mkdir -p ${cfsroot}/{objects,roots,tmp} cd ${cfsroot}/tmp -testsrc=/usr/bin -mkcomposefs --print-digest --digest-store=${cfsroot}/objects ${testsrc} ${cfsroot}/roots/test.cfs | tee digest.txt -prev_digest=$(cat digest.txt) -new_digest=$(mkcomposefs --by-digest --print-digest-only ${testsrc}) -test "$prev_digest" = "$new_digest" - -if which fsck.erofs &>/dev/null; then - fsck.erofs ${cfsroot}/roots/test.cfs -fi - -mkdir -p mnt -mount.composefs -o basedir=${cfsroot}/objects ${cfsroot}/roots/test.cfs mnt -$orig/tests/dumpdir --no-nlink ${testsrc} > src-dump.txt -$orig/tests/dumpdir --no-nlink mnt > mnt-dump.txt -failed= -if ! diff -u src-dump.txt mnt-dump.txt; then - failed=1 -fi -if test -n "${failed}"; then + +run_test() { + local testsrc=$1 + local dumpdir_args="$2" + mkcomposefs --print-digest --digest-store=${cfsroot}/objects ${testsrc} ${cfsroot}/roots/test.cfs | tee digest.txt + prev_digest=$(cat digest.txt) + new_digest=$(mkcomposefs --by-digest --print-digest-only ${testsrc}) + test "$prev_digest" = "$new_digest" + + if which fsck.erofs &>/dev/null; then + fsck.erofs ${cfsroot}/roots/test.cfs + fi + + mkdir -p mnt + mount.composefs -o basedir=${cfsroot}/objects ${cfsroot}/roots/test.cfs mnt + $orig/tests/dumpdir $dumpdir_args ${testsrc} > src-dump.txt + $orig/tests/dumpdir $dumpdir_args mnt > mnt-dump.txt + failed= + if ! diff -u src-dump.txt mnt-dump.txt; then + failed=1 + fi + if test -n "${failed}"; then + umount mnt + exit 1 + fi + + new_digest=$(mkcomposefs --by-digest --print-digest-only mnt) + test "$prev_digest" = "$new_digest" + umount mnt - exit 1 -fi +} -new_digest=$(mkcomposefs --by-digest --print-digest-only mnt) -test "$prev_digest" = "$new_digest" +run_test /usr/bin "--no-nlink" -umount mnt +# Don't create whiteouts, as they depend on a very recent kernel to work at all +$orig/tests/gendir --privileged --nowhiteout ${cfsroot}/tmp/rootfs +# nlink doesn't work for the toplevel dir in composefs, because that is from overlayfs, not erofs +run_test ${cfsroot}/tmp/rootfs "--no-root-nlink"