Skip to content

Commit

Permalink
Merge pull request #193 from alexlarsson/more-integration-tests
Browse files Browse the repository at this point in the history
tests: Add a new gendir based integration tests
  • Loading branch information
cgwalters authored Sep 20, 2023
2 parents f122d93 + a422a59 commit 07a1a09
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
3 changes: 2 additions & 1 deletion tests/dumpdir
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/gendir
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
59 changes: 35 additions & 24 deletions tests/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 07a1a09

Please sign in to comment.