Skip to content

Commit

Permalink
Add some more unit tests to make check
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Larsson <[email protected]>
  • Loading branch information
alexlarsson committed Sep 14, 2023
1 parent 4110ef4 commit fbdf4e4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ TEST_ASSETS = ${TEST_ASSETS_SMALL} \
f36-x86_64-silverblue.json.gz

if ENABLE_VALGRIND
WRITER_JSON_PREFIX=libtool --mode=execute ${VALGRIND} --quiet --leak-check=yes --error-exitcode=42
VALGRIND_PREFIX=libtool --mode=execute ${VALGRIND} --quiet --leak-check=yes --error-exitcode=42
endif

EXTRA_DIST = test-checksums.sh $(patsubst %,assets/%,${TEST_ASSETS_SMALL}) $(patsubst %,assets/%.sha256_erofs,${TEST_ASSETS_SMALL})

check-checksums:
$(srcdir)/test-checksums.sh "${WRITER_JSON_PREFIX} $(builddir)/../tools/" "$(srcdir)/assets" "${TEST_ASSETS}"
$(srcdir)/test-checksums.sh "${VALGRIND_PREFIX} $(builddir)/../tools/" "$(srcdir)/assets" "${TEST_ASSETS}"

check: check-checksums
check-units:
$(srcdir)/test-units.sh "${VALGRIND_PREFIX} $(builddir)/../tools/"

check: check-units check-checksums
63 changes: 63 additions & 0 deletions tests/test-units.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/bash

BINDIR="$1"

set -e

workdir=$(mktemp -d /var/tmp/lcfs-test.XXXXXX)
trap 'rm -rf -- "$workdir"' EXIT

function makeimage () {
local dir=$1
$BINDIR/mkcomposefs --digest-store=$dir/objects $dir/root $dir/test.cfs
}

function countobjects () {
local dir=$1
find $dir/objects -type f | wc -l
}

# Ensure small files are inlined
function test_inline () {
local dir=$1

echo foo > $dir/root/a-file

makeimage $dir

objects=$(countobjects $dir)
if [ $objects != 0 ]; then
return 1
fi
}

# Ensure we generate objects for large files
function test_objects () {
local dir=$1
dd if=/dev/zero bs=1 count=1024 2>/dev/null > $dir/root/a-file

makeimage $dir

objects=$(countobjects $dir)
if [ $objects != 1 ]; then
return 1
fi
}

TESTS="test_inline test_objects"
res=0
for i in $TESTS; do
testdir=$(mktemp -d $workdir/$i.XXXXXX)
mkdir $testdir/root
mkdir $testdir/objects
if $i $testdir ; then
echo "Test $i: OK"
else
res=1
echo "Test $i Failed"
fi

rm -rf $testdir
done

exit $res

0 comments on commit fbdf4e4

Please sign in to comment.