Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing overlhaul and refactoring #92

Merged
merged 29 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c1cede8
Auto cleanup temporary files
zdyxry Jun 25, 2023
8667191
Perform cleanup action only after executing commit
zdyxry Jun 27, 2023
e723d0a
Merge branch 'main' into cleanup
mgree Jun 27, 2023
f632f63
cleanup logic, formatting
mgree Jun 27, 2023
6b988d3
debugging in CI, yolo
mgree Jun 27, 2023
d539936
use `=` with test, not `==`
mgree Jun 27, 2023
6f339fe
explicitly unmount the overlay
mgree Jun 28, 2023
9f2c3b4
debugging
mgree Jun 28, 2023
f105015
fsync---a shot in the dark
mgree Jun 28, 2023
55412a4
s/fsync/sync/
mgree Jun 28, 2023
a8c93fe
debug test
mgree Jun 28, 2023
9b980af
the script didn't even exist?!
mgree Jun 28, 2023
60ad5be
durrrrr
mgree Jun 28, 2023
d4bb11f
debug test
mgree Jun 28, 2023
7369fba
debugging
mgree Jun 28, 2023
f5c54dd
test was faulty
mgree Jun 28, 2023
59c48ff
debugging
mgree Jun 28, 2023
1b2e1cc
overhaul tests
mgree Jun 28, 2023
603685c
cleaning up test harness
mgree Jun 28, 2023
ffde3f4
cleanup tests
mgree Jun 28, 2023
52ea6f1
Remove sandbox cleanup logic
angelhof Jun 29, 2023
e7c4a8d
test nit
angelhof Jun 29, 2023
ab11eec
Merge remote-tracking branch 'origin/main' into new-cleanup
angelhof Jun 29, 2023
5a77768
tiny bug
angelhof Jun 29, 2023
5f90836
Debugging info before cleanup
angelhof Jun 29, 2023
95b8b34
Merge remote-tracking branch 'origin/main' into new-cleanup
angelhof Jun 29, 2023
97d58fc
Add the ignore_file in the CLEANUP
angelhof Jun 29, 2023
d205146
revert cleanup for now
angelhof Jul 6, 2023
eb1c178
remove cleanup test
angelhof Jul 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 69 additions & 23 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ cleanup()
mkdir "$try_workspace"
}

TOTAL_TESTS=0
PASSED_TESTS=0
FAILING_TESTS=""

test_read_from_run_dir()
{
ls /run/systemd > /dev/null
Expand All @@ -56,24 +60,28 @@ run_test()
# Check if we can read from /run dir
test_read_from_run_dir

echo
echo -n "Running $test..."

# Run test
: $((TOTAL_TESTS += 1))
$test "$try_workspace"
test_try_ec=$?

if [ $test_try_ec -eq 0 ]; then
: $((PASSED_TESTS += 1))
echo -ne '\t\t\t'
echo "$test are identical" >> $output_dir/result_status
echo "$test passed" >> $output_dir/result_status
echo -e '\tOK'
else
echo -n " (!) EC mismatch"
echo "$test are not identical" >> $output_dir/result_status
FAILING_TESTS="$FAILING_TESTS $test"
echo -n " non-zero ec ($test_try_ec)"
echo "$test failed" >> $output_dir/result_status
echo -e '\t\tFAIL'
fi
}

test_untar_no_flag()
test_unzip_no_flag()
{
local try_workspace=$1
cp $RESOURCE_DIR/file.txt.gz "$try_workspace/"
Expand All @@ -82,11 +90,11 @@ test_untar_no_flag()
## Set up expected output
echo 'Hello World!' >expected.out

"$try" -y gunzip file.txt.gz
"$try" -y gunzip file.txt.gz || return 1
diff -q expected.out file.txt
}

test_untar_D_flag_commit()
test_unzip_D_flag_commit()
{
local try_workspace=$1
cp $RESOURCE_DIR/file.txt.gz "$try_workspace/"
Expand All @@ -96,11 +104,53 @@ test_untar_D_flag_commit()
echo 'Hello World!' >expected.out

try_example_dir=$(mktemp -d)
"$try" -D $try_example_dir gunzip file.txt.gz
"$try" -D $try_example_dir gunzip file.txt.gz || return 1
$try commit $try_example_dir
diff -q expected.out file.txt
}

test_unzip_D_flag_commit_without_cleanup()
{
local try_workspace=$1
cp $RESOURCE_DIR/* "$try_workspace/"
cd "$try_workspace/"

try_example_dir=$(mktemp -d)
"$try" -D $try_example_dir gunzip file.txt.gz || return 1
if ! [ -d "$try_example_dir" ]; then
echo "try_example_dir disappeared with no commit"
return 1
fi
"$try" commit $try_example_dir || return 1
if ! [ -d "$try_example_dir" ]; then
echo "try_example_dir disappeared after manual commit"
return 1
fi
}

# KK 2023-07-06 This test checks whether try has correctly cleaned up its temporary directories
# but is not working now. I am leaving it in so that its logic can be reused for a new test.
#
# test_touch_and_rm_with_cleanup()
# {
# local try_workspace=$1
# cp $RESOURCE_DIR/file.txt.gz "$try_workspace/"
# cd "$try_workspace/"

# : ${TMPDIR=/tmp}

# orig_tmp=$(ls "$TMPDIR")
# "$try" -y -- "touch file_1.txt; echo test > file_2.txt; rm file.txt.gz" || return 1
# new_tmp=$(ls "$TMPDIR")

# if ! diff -q <(echo "$orig_tmp") <(echo "$new_tmp")
# then
# echo "temporary directory was not cleaned up; diff:"
# diff --color -u <(echo "$orig_tmp") <(echo "$new_tmp")
# return 1
# fi
# }

test_touch_and_rm_no_flag()
{
local try_workspace=$1
Expand All @@ -111,7 +161,7 @@ test_touch_and_rm_no_flag()
touch expected1.txt
echo 'test' >expected2.txt

"$try" -y "touch file_1.txt; echo test > file_2.txt; rm file.txt.gz"
"$try" -y "touch file_1.txt; echo test > file_2.txt; rm file.txt.gz" || return 1

diff -q expected1.txt file_1.txt &&
diff -q expected2.txt file_2.txt &&
Expand All @@ -129,7 +179,7 @@ test_touch_and_rm_D_flag_commit()
echo 'test' >expected2.txt

try_example_dir=$(mktemp -d)
"$try" -D $try_example_dir "touch file_1.txt; echo test > file_2.txt; rm file.txt.gz"
"$try" -D $try_example_dir "touch file_1.txt; echo test > file_2.txt; rm file.txt.gz" || return 1
$try commit $try_example_dir

diff -q expected1.txt file_1.txt &&
Expand Down Expand Up @@ -201,7 +251,7 @@ test_pipeline()
## Set up expected output
echo 'TesT' >expected.out

"$try" 'echo test | tr t T' > out.txt
"$try" 'echo test | tr t T' > out.txt || return 1

diff -q expected.out out.txt
}
Expand All @@ -218,7 +268,7 @@ test_cmd_sbst_and_var()
echo $(pwd)
EOF

"$try" sh script.sh >out.txt
"$try" sh script.sh >out.txt || return 1

diff -q expected.out out.txt
}
Expand Down Expand Up @@ -354,10 +404,12 @@ test_fail()

# We run all tests composed with && to exit on the first that fails
if [ "$#" -eq 0 ]; then
run_test test_untar_no_flag
run_test test_untar_D_flag_commit
run_test test_unzip_no_flag
run_test test_unzip_D_flag_commit
run_test test_touch_and_rm_no_flag
run_test test_touch_and_rm_D_flag_commit
# run_test test_touch_and_rm_with_cleanup
run_test test_unzip_D_flag_commit_without_cleanup
run_test test_reuse_sandbox
run_test test_reuse_problematic_sandbox
run_test test_non_existent_sandbox
Expand Down Expand Up @@ -399,16 +451,10 @@ case "$distro" in
;;
esac

echo -e "\n====================| Test Summary |====================\n"
echo "> Below follow the identical outputs:"
grep "are identical" "$output_dir"/result_status | awk '{print $1}' | tee $output_dir/passed.log

echo "> Below follow the non-identical outputs:"
grep "are not identical" "$output_dir"/result_status | awk '{print $1}' | tee $output_dir/failed.log
echo "========================================================"
TOTAL_TESTS=$(cat "$output_dir"/result_status | wc -l | xargs)
PASSED_TESTS=$(grep -c "are identical" "$output_dir"/result_status)
echo "Summary: ${PASSED_TESTS}/${TOTAL_TESTS} tests passed." | tee $output_dir/results.log
echo
echo "====================| Test Summary |===================="
echo "Failing tests:${FAILING_TESTS}"
echo "Summary: ${PASSED_TESTS}/${TOTAL_TESTS} tests passed."
echo "========================================================"

if [ $PASSED_TESTS -ne $TOTAL_TESTS ]
Expand Down
3 changes: 2 additions & 1 deletion try
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ try() {
for mountpoint in /* $(findmnt --real -r -o target -n | grep -v "^/$")
do
## Only make the directory if the original is a directory too
if [ -d "$mountpoint" ]; then
if [ -d "$mountpoint" ]
then
mkdir -p "$SANDBOX_DIR"/upperdir/"$mountpoint" "$SANDBOX_DIR"/workdir"/$mountpoint" "$SANDBOX_DIR"/temproot/"$mountpoint"
fi
done
Expand Down