From 6ac1324ba4548d474914e6061dd8e70bc9f3fdde Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Jan 19 2023 17:20:15 +0000 Subject: [PATCH 1/4] Remove link count from fs_test Using the second field of ls -l is problematic because it depends on used filesystem. --- diff --git a/tests/fs_test b/tests/fs_test index b5f7a11..44cf63f 100755 --- a/tests/fs_test +++ b/tests/fs_test @@ -70,7 +70,7 @@ filtered_ls() { ( cd "$1"; LC_ALL=C ls -lnR | \ - awk 'NF > 3 { printf("%.10s %d %4d %4d %s\n", $1, $2, $3, $4, $9); } + awk 'NF > 3 { printf("%.10s %4d %4d %s\n", $1, $3, $4, $9); } NF <= 3 && !/total/ { print }'; ) } @@ -107,8 +107,8 @@ run_test test_lu_homedir_remove > "$workdir"/rm_output diff "$workdir"/rm_output - < "$workdir"/mv_output # preserved. diff "$workdir"/mv_output - < "$workdir"/pop_output # ownership is changed to the desired values except for non-root groups diff "$workdir"/pop_output - < Date: Jan 19 2023 17:23:59 +0000 Subject: [PATCH 2/4] Add error message to fs_test It was not clear which test fails. This patch prints the test name that failed to stderr --- diff --git a/tests/fs_test b/tests/fs_test index 44cf63f..2627a20 100755 --- a/tests/fs_test +++ b/tests/fs_test @@ -111,6 +111,7 @@ diff "$workdir"/rm_output - <&1 exit 1 fi @@ -142,6 +143,7 @@ diff "$workdir"/rm_owned_output1 - <&1 exit 1 fi @@ -185,6 +187,7 @@ drwxrwxr-x 0 0 non-owned-dir -rw-rw-r-- 0 0 f EOF if [ $? -ne 0 ]; then + echo "Failed: test_lu_homedir_remove_for_user_if_owned2" >&1 exit 1 fi @@ -261,6 +264,7 @@ lrwxrwxrwx 555 444 symlink ---------- 555 555 f EOF if [ $? -ne 0 ]; then + echo "Failed: test_lu_homedir_move1" >&2 exit 1 fi @@ -278,6 +282,7 @@ Error creating \`$workdir/mv2home2': File exists 1 EOF if [ $? -ne 0 ]; then + echo "Failed: test_lu_homedir_move2" >&2 exit 1 fi @@ -331,6 +336,7 @@ lrwxrwxrwx 556 444 symlink ---------- 556 557 f EOF if [ $? -ne 0 ]; then + echo "Failed: test_lu_homedir_populate1" >&2 exit 1 fi @@ -349,5 +355,6 @@ Error creating \`$workdir/pop2': File exists 1 EOF if [ $? -ne 0 ]; then + echo "Failed: test_lu_homedir_populate2" >&2 exit 1 fi From eb1d25e16f60e1c2b1e6b8046cd438060f3378e6 Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Jan 19 2023 20:22:23 +0000 Subject: [PATCH 3/4] Hide mkfifo error message Under some fakeroot implementation mkfifo does not work but the test works without it well. This patch hides the error message so we do not confuse the packager with false positive. --- diff --git a/tests/fs_test b/tests/fs_test index 2627a20..1f52083 100755 --- a/tests/fs_test +++ b/tests/fs_test @@ -82,7 +82,7 @@ test_lu_homedir_remove() { # User's "own" content mkdir -p "$workdir"/rm/root/{dir,unreadable} touch "$workdir"/rm/{kept,root/{dir,unreadable}/f} - mkfifo "$workdir"/rm/root/fifo + mkfifo "$workdir"/rm/root/fifo 2>/dev/null ln -s ../kept "$workdir"/rm/root/symlink chown -R 555:555 "$workdir"/rm/root chmod 701 "$workdir"/rm/root @@ -199,7 +199,7 @@ create_source_directory() { # User's "own" content for i in "$1" "$1"/dir "$1"/group-owned; do touch "$i"/f "$i"/setuid - mkfifo "$i"/fifo + mkfifo "$i"/fifo 2>/dev/null ln -s ../outside "$i"/symlink done mkdir "$1"/setgid From 68fe257e49c6662a87d3a97904d4b5448af01a19 Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Jan 19 2023 21:21:53 +0000 Subject: [PATCH 4/4] Skip tests that does not work under fakeroot Some of fs_test does not run in fakeroot environment. With this patch tests - test_lu_homedir_move1 - test_lu_homedir_move2 - test_lu_homedir_populate1 are skipped when we use fakeroot --- diff --git a/tests/fs_test b/tests/fs_test index 1f52083..dad1de0 100755 --- a/tests/fs_test +++ b/tests/fs_test @@ -19,19 +19,29 @@ # # Author: Miloslav Trmač -if ! fakeroot --version &>/dev/null; then - echo 'fakeroot not available, skipping test' >&2 - exit 77 +# Some tests runs only as root. If you want to run those tests, +# you must run it as a real root and set the variable USE_FAKEROOT=no +# Make sure you have backups! +if [ -z "$USE_FAKEROOT" ] ; then + USE_FAKEROOT=yes +fi + +export USE_FAKEROOT + +if [ "$USE_FAKEROOT" != "no" ]; then + if ! fakeroot --version &>/dev/null; then + echo 'fakeroot not available, skipping test' >&2 + exit 77 + fi fi run_test() { - fakeroot "$@" + if [ "$USE_FAKEROOT" = "no" ]; then + ( "$@"; ) + else + fakeroot "$@" + fi } -# If you want to test this as real root, use the following instead, and run the -# test manually. Make sure you have backups! -#run_test() { -# ( "$@"; ) -#} srcdir=$srcdir/tests @@ -232,12 +242,14 @@ test_lu_homedir_move1() { filtered_ls "$workdir"/home2 } -export -f test_lu_homedir_move1 -run_test test_lu_homedir_move1 > "$workdir"/mv_output -# Special files and fifos are not copied over. Ownership and permissions are -# preserved. -diff "$workdir"/mv_output - < "$workdir"/mv_output + + # Special files and fifos are not copied over. Ownership and permissions are + # preserved. + diff "$workdir"/mv_output - <&2 - exit 1 + if [ $? -ne 0 ]; then + echo "Failed: test_lu_homedir_move1" >&2 + exit 1 + fi +else + echo "Skipped: test_lu_homedir_move1" >&2 fi # Moving onto an existing directory is prohibited @@ -275,18 +290,22 @@ test_lu_homedir_move2() { $VALGRIND $PYTHON "$srcdir"/fs_test.py --move "$workdir"/mv2home{1,2} echo $? } -export -f test_lu_homedir_move2 -run_test test_lu_homedir_move2 > "$workdir"/mv2_output 2>&1 -diff "$workdir"/mv2_output - < "$workdir"/mv2_output 2>&1 + diff "$workdir"/mv2_output - <&2 - exit 1 + if [ $? -ne 0 ]; then + echo "Failed: test_lu_homedir_move2" >&2 + exit 1 + fi +else + echo "Skipped: test_lu_homedir_move2" >&2 fi - # Test lu_homedir_populate() function test_lu_homedir_populate1() { create_source_directory "$workdir"/skel @@ -304,12 +323,14 @@ function test_lu_homedir_populate1() { filtered_ls "$workdir"/newhome } -export -f test_lu_homedir_populate1 -run_test test_lu_homedir_populate1 > "$workdir"/pop_output -# Special files and fifos are not copied over. Permissions are preserved, -# ownership is changed to the desired values except for non-root groups -diff "$workdir"/pop_output - < "$workdir"/pop_output + + # Special files and fifos are not copied over. Permissions are preserved, + # ownership is changed to the desired values except for non-root groups + diff "$workdir"/pop_output - <&2 - exit 1 + if [ $? -ne 0 ]; then + echo "Failed: test_lu_homedir_populate1" >&2 + exit 1 + fi +else + echo "Skipped: test_lu_homedir_populate1" >&2 fi # Populating an existing directory is prohibited