diff --git a/releng/test_hardlinks b/releng/test_hardlinks index e314b208..a009e8b6 100755 --- a/releng/test_hardlinks +++ b/releng/test_hardlinks @@ -9,13 +9,44 @@ export prog=$(basename "$0") export xorriso=xorriso export image_file=/tmp/xorriso_hardlinks.iso export on_disk=/tmp/xorriso_hardlinks_test_dir -export in_iso="$on_disk" +export in_iso="" export copy_on_disk=/tmp/xorriso_hardlinks_copy_dir export keep=0 export failure=0 export next_is_xorriso=0 +export next_is_rc=0 export bad=0 + +config_by_var() { + # This is called once before option interpretation, and once for each + # option -rc. + # Variables get set to empty content to keep them from being applied + # more than once and thus overriding settings of higher precedence. + + # >>> The short names are not good. + # >>> Environment variables should have a common prefix. Like RELENG_ + # >>> In general, the names should be a bit more expressive. + # >>> Like RELENG_XORRISO + + test -n "$XOR" && xorriso="$XOR" && XOR= + test -n "$RELENG_XORRISO" && xorriso="$RELENG_XORRISO" && RELENG_XORRISO= + + test -n "$IMG" && image_file="$IMG" && IMG= + test -n "$RELENG_TMPIMAGE" && image_file="$RELENG_TMPIMAGE" \ + && RELENG_TMPIMAGE= + + # This is not $DIR, which would exist before and after the test, + # but a temporary directory which may not exist before. + test -n "$RELENG_TMPDIR" && on_disk="$RELENG_TMPDIR" && RELENG_TMPDIR= + + test -n "$RELENG_ISODIR" && in_iso="$RELENG_ISODIR" && RELENG_ISODIR= + + test -n "$RELENG_TMPCOPYDIR" && copy_on_disk="$RELENG_TMPCOPYDIR" \ + && RELENG_TMPCOPYDIR= + +} + clean_up() { if test "$keep" = 1 then @@ -27,20 +58,37 @@ clean_up() { fi } -skip=0 + +# Setup + +# Interpret a default configuration file here, if the test has one. +# This one has none. + +# >>> Best would be if the configuration file would not override env variables. + +# Process env variables and default configfile variables together +config_by_var + + +# Now interpret program arguments and possibly given config files for i in "$@" do if test "$next_is_xorriso" = 1 then xorriso="$i" next_is_xorriso=0 - elif test "$skip" -gt 0 + elif test "$next_is_rc" = 1 then - skip=$(expr $skip - 1) + + # >>> This looks darn dangerous. We need a trustworthy config interpreter. + # >>> http://www.netjeff.com/humor/item.cgi?file=ShootInFoot-OS + . "$i" + + config_by_var + next_is_rc=0 elif test x"$i" = x"-rc" then - # No configuration yet - skip=1 + next_is_rc=1 elif test x"$i" = x"-keep" then keep=1 @@ -58,21 +106,24 @@ do fi done +test -z "$in_iso" && in_iso="$on_disk" + + if test -e "$image_file" then - echo "TEST ENVIRONMENT ERROR: $prog : Existing image_file target:" >&2 + echo "=== TEST ENVIRONMENT ERROR: $prog : Existing image_file target:" >&2 ls -ld "$image_file" >&2 bad=1 fi if test -e "$on_disk" then - echo "TEST ENVIRONMENT ERROR: $prog : Existing on_disk target:" >&2 + echo "=== TEST ENVIRONMENT ERROR: $prog : Existing on_disk target:" >&2 ls -ld "$on_disk" >&2 bad=1 fi if test -e "$copy_on_disk" then - echo "TEST ENVIRONMENT ERROR: $prog : Existing copy_on_disk target:" >&2 + echo "=== TEST ENVIRONMENT ERROR: $prog : Existing copy_on_disk target:" >&2 ls -ld "$copy_on_disk" >&2 bad=1 fi @@ -93,7 +144,9 @@ ls -l "$on_disk"/* echo "=== Producing simple image" >&2 "$xorriso" \ + -version \ -for_backup \ + -padding 0 \ -outdev "$image_file" \ -update_r "$on_disk" "$in_iso" \ -hardlinks perform_update @@ -110,11 +163,12 @@ echo "=== Copying from image to temporary disk tree" >&2 ## For testing the test: Let it fail deliberately ## rm "$copy_on_disk"/file_1_link_b + echo "=== Comparing original disk tree and temporary one" >&2 diff -r "$on_disk" "$copy_on_disk" if test "$?" -ne 0 then - echo "WRONG: diff -r $on_disk $copy_on_disk reports differences" >&2 + echo "=== WRONG: diff -r $on_disk $copy_on_disk reports differences" >&2 failure=1 else echo "=== OK" >&2 @@ -128,9 +182,9 @@ if test x"$x" = x"$expected" then echo "=== OK" >&2 else - echo "WRONG: Link count of extracted files is not as expected." >&2 - echo "Expected: $expected" >&2 - echo "Got : $x" >&2 + echo "=== WRONG: Link count of extracted files is not as expected." >&2 + echo "=== Expected: $expected" >&2 + echo "=== Got : $x" >&2 failure=1 fi @@ -142,9 +196,9 @@ clean_up echo if test "$failure" = 1 then - echo "======== $prog :" 'FAILURE !!!' + echo "======== $prog :" 'FAILED' else - echo "======== $prog :" "Success." + echo "======== $prog :" "Passed" fi echo