Skip to content

Commit

Permalink
Imporove integration test
Browse files Browse the repository at this point in the history
Instead of ls -lR we have a custom directory dumper that also
dumps sha256 checksums as well as file xattrs. This gives
us more thorough checking.

Also, try to build a composefs image from the mounted composefs and
ensure we get the same digest again.

Signed-off-by: Alexander Larsson <[email protected]>
  • Loading branch information
alexlarsson committed Sep 13, 2023
1 parent d636bee commit 53f6a2b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
47 changes: 47 additions & 0 deletions tests/dumpdir
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/python3

import os
import sys
import shlex
import hashlib
import stat
import argparse

def log_error(error):
print("Readdir error: " + error)

def dumpfile(file, root):
rel = os.path.relpath(file, root)
s = os.lstat(file)
nlink = s.st_nlink;
if args.no_nlink:
nlink = 1
print(f"{shlex.quote(rel)} {s.st_mode} {nlink} {s.st_uid}:{s.st_gid} {s.st_rdev} {s.st_mtime_ns}",end="")
if stat.S_ISREG(s.st_mode):
digest = hashlib.sha256(open(file,'rb').read()).hexdigest()
print(f" {s.st_size} sha256:{digest}",end="")
elif stat.S_ISLNK(s.st_mode):
link = os.readlink(file)
print(f" ->{shlex.quote(link)}",end="")

for attr in sorted(os.listxattr(file, follow_symlinks=False)):
v = os.getxattr(file, attr, follow_symlinks=False)
print(f" {attr}={v}", end="")

print()



def dumpdir(root):
dumpfile(root, root)
for parent, dirs, files in os.walk(root, topdown=True, onerror=log_error):
for file in sorted(dirs + files):
dumpfile(os.path.join(parent, file), root)

argParser = argparse.ArgumentParser()
argParser.add_argument("--no-nlink", action='store_true')
argParser.add_argument('path')

args = argParser.parse_args()

dumpdir(args.path)
19 changes: 10 additions & 9 deletions tests/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
# the output of ls -lR (without hardlink counts).
set -xeuo pipefail

# ls -l but without hardlinks
nonhardlink_ls() {
ls "$@" | sed -e 's,^\([^ ]*\) *\([0-9][0-9]*\)\(.*\)$,\1\3,'
}

orig=$(pwd)
cfsroot=${cfsroot:-/composefs}
rm ${cfsroot}/tmp -rf
mkdir -p ${cfsroot}/{objects,roots,tmp}
Expand All @@ -22,13 +18,18 @@ test "$prev_digest" = "$new_digest"

mkdir -p mnt
mount.composefs -o basedir=${cfsroot}/objects ${cfsroot}/roots/test.cfs mnt
(cd ${testsrc} && nonhardlink_ls -lR .) > src-ls.txt
(cd mnt && nonhardlink_ls -lR .) > mnt-ls.txt
$orig/tests/dumpdir --no-nlink ${testsrc} > src-dump.txt
$orig/tests/dumpdir --no-nlink mnt > mnt-dump.txt
failed=
if ! diff -u src-ls.txt mnt-ls.txt; then
if ! diff -u src-dump.txt mnt-dump.txt; then
failed=1
fi
umount mnt
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

0 comments on commit 53f6a2b

Please sign in to comment.