unification

This commit is contained in:
George Danchev 2011-07-09 15:57:52 +00:00
parent e15224a43a
commit f63d7bb596

View File

@ -13,22 +13,20 @@ if [ ! -x $RELENG_XORRISO ]; then
fi fi
# check data dir, if any and after checking -x xorriso # check data dir, if any and after checking -x xorriso
#if [ -d "${GEN_DATA_DIR}" ]; then if [ -d "${GEN_DATA_DIR}" ]; then
# printf "\n${SELF}: directory %s exists!" ${GEN_DATA_DIR} printf "\n${SELF}: directory %s exists!" ${GEN_DATA_DIR}
# printf "\n${SELF}: use '${SELF} -c1' to remove.\n" printf "\n${SELF}: use '${SELF} -c1' to remove.\n"
# exit 8 exit 8
#else else
# mkdir "${GEN_DATA_DIR}" mkdir "${GEN_DATA_DIR}"
#fi fi
export prog=${SELF}
export xorriso=${RELENG_XORRISO} export xorriso=${RELENG_XORRISO}
export workdir=${GEN_DATA_DIR} export workdir=${GEN_DATA_DIR}
export image_file="$workdir"/xorriso_hardlinks.iso export image_file="$workdir"/xorriso_hardlinks.iso
export on_disk="$workdir"/xorriso_hardlinks_test_dir export on_disk="$workdir"/xorriso_hardlinks_test_dir
export in_iso="" export in_iso=""
export copy_on_disk="$workdir"/xorriso_hardlinks_copy_dir export copy_on_disk="$workdir"/xorriso_hardlinks_copy_dir
export keep=${KEEP}
export failure=0 export failure=0
export simulate_failure=${SIMULATE_FAILURE} export simulate_failure=${SIMULATE_FAILURE}
export next_is_xorriso=0 export next_is_xorriso=0
@ -36,145 +34,18 @@ export next_is_rc=0
export bad=0 export bad=0
export report_about="-report_about UPDATE" export report_about="-report_about UPDATE"
#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.
# test -n "$RELENG_XORRISO" && xorriso="$RELENG_XORRISO" && RELENG_XORRISO=
# test -n "$RELENG_WORKIMAGE" && image_file="$RELENG_WORKIMAGE" \
# && RELENG_WORKIMAGE=
# test -n "$RELENG_WORKDIR" && on_disk="$RELENG_WORKDIR" && RELENG_WORKDIR=
# test -n "$RELENG_ISODIR" && in_iso="$RELENG_ISODIR" && RELENG_ISODIR=
# test -n "$RELENG_WORKCOPYDIR" && copy_on_disk="$RELENG_WORKCOPYDIR" \
# && RELENG_WORKCOPYDIR=
#}
#clean_up() {
# if test "$keep" = 1
# then
# echo "=== Kept test area because of option -keep" >&2
# echo "$on_disk" "$copy_on_disk" "$image_file" "$workdir" >&2
# else
# echo "=== Removing test area" >&2
# rm -r "$on_disk" "$copy_on_disk" "$image_file"
# rm -r "$workdir"
# fi
#}
# 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 "$next_is_rc" = 1
# then
# >>> 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
# next_is_rc=1
# elif test x"$i" = x"-keep"
# then
# keep=1
# elif test x"$i" = x"-cleanup"
# then
# keep=0
# cleanup
# exit 0
# elif test x"$i" = x"-xorriso"
# then
# next_is_xorriso=1
# elif test x"$i" = x"-v"
# then
# report_about="-report_about ALL"
# elif test x"$i" = x"-fail"
# then
# simulate_failure=1
# else
# echo "Usage: $0 [-rc FILE] [-keep] [-cleanup] [-fail] [-xorriso PATH] [-v]" >&2
# exit 2
# fi
# done
test -z "$in_iso" && in_iso="$on_disk" test -z "$in_iso" && in_iso="$on_disk"
if test -d ./releng_generated_data # mkdir "$workdir" || bad=1
then
dummy=dummy
else
echo "=== TEST ENVIRONMENT ERROR: $prog : No ./releng_generated_data directory existing" >&2
echo "=== Is the current working directory really ./releng of libisoburn ?" >&2
echo "FAIL : $prog : Test environment error : No ./releng_generated_data directory"
exit 3
fi
if test -e "$workdir"
then
echo "=== TEST ENVIRONMENT ERROR: $prog : Existing work directory:" >&2
ls -ld "$workdir" >&2
bad=1
fi
if test -e "$image_file"
then
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
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
ls -ld "$copy_on_disk" >&2
bad=1
fi
if test "$bad" = 1
then
echo "FAIL : $prog : Test environment error : Existing work files"
exit 3
fi
bad=0
mkdir "$workdir" || bad=1
mkdir "$on_disk" || bad=1 mkdir "$on_disk" || bad=1
if test "$bad" = 1 if test "$bad" = 1
then then
echo "FAIL : $prog : Test environment error : Cannot make directories" echo -e "\n${SELF}: FAIL : Test environment error : Cannot make directories"
exit 3 exit 3
fi fi
# All must be set at this point
echo "=== Setting up $on_disk with several hardlinks" >&2 printf "\n${SELF}: Setting up $on_disk with several hardlinks" >&2
echo test_content >"$on_disk"/file_1 || exit 1 echo test_content >"$on_disk"/file_1 || exit 1
echo test_content >"$on_disk"/file_2 || exit 1 echo test_content >"$on_disk"/file_2 || exit 1
ln "$on_disk"/file_1 "$on_disk"/file_1_link_a || exit 1 ln "$on_disk"/file_1 "$on_disk"/file_1_link_a || exit 1
@ -182,31 +53,32 @@ ln "$on_disk"/file_1 "$on_disk"/file_1_link_b || exit 1
ln "$on_disk"/file_2 "$on_disk"/file_2_link_a || exit 1 ln "$on_disk"/file_2 "$on_disk"/file_2_link_a || exit 1
ls -l "$on_disk"/* ls -l "$on_disk"/*
# trivial ISO 9660 image validation routine
is_valid_iso9660() { is_valid_iso9660() {
ISOfile="$1" ISOfile="$1"
if [ ! -f ${ISOfile} ]; then if [ ! -f ${ISOfile} ]; then
failure=1 failure=1
printf "${prog}: FAIL: Not found: ${ISOfile}\n" printf "\n${SELF}: FAIL: Not found: ${ISOfile}\n"
fi fi
if file ${ISOfile} | grep -P "ISO\s+9660\s+CD-ROM\s+filesystem\s+data" >/dev/null 2>&1; then if file ${ISOfile} | grep -P "ISO\s+9660\s+CD-ROM\s+filesystem\s+data" >/dev/null 2>&1; then
printf "=== Resulting ${ISOfile} OK. Looks like ISO 9660 filesystem.\n" printf "\n${SELF}: Resulting ${ISOfile} OK. Looks like ISO 9660 filesystem.\n"
else else
failure=1 failure=1
printf "${prog}: FAIL: ${ISOfile} DOES NOT look like ISO 9660 filesystem data.\n" printf "\n${SELF}: FAIL: ${ISOfile} DOES NOT look like ISO 9660 filesystem data.\n"
fi fi
} }
echo -e "\n=== Producing simple image via -o" >&2 echo -e "\n${SELF}: Producing simple image via -o" >&2
"$xorriso" -as mkisofs "$on_disk" -o "$workdir"/image_minus_o.iso "$xorriso" -as mkisofs "$on_disk" -o "$workdir"/image_minus_o.iso
is_valid_iso9660 "$workdir"/image_minus_o.iso is_valid_iso9660 "$workdir"/image_minus_o.iso
echo -e "\n=== Producing simple image via redirect" >&2 echo -e "\n${SELF}: Producing simple image via redirect" >&2
"$xorriso" -as mkisofs "$on_disk" > "$workdir"/image_redirected.iso "$xorriso" -as mkisofs "$on_disk" > "$workdir"/image_redirected.iso
is_valid_iso9660 "$workdir"/image_redirected.iso is_valid_iso9660 "$workdir"/image_redirected.iso
echo -e "\n=== Producing simple image via pipe" >&2 echo -e "\n${SELF}: Producing simple image via pipe" >&2
"$xorriso" -as mkisofs "$on_disk" | cat > "$workdir"/image_piped.iso "$xorriso" -as mkisofs "$on_disk" | cat > "$workdir"/image_piped.iso
is_valid_iso9660 "$workdir"/image_piped.iso is_valid_iso9660 "$workdir"/image_piped.iso
echo -e "\n=== Producing simple image - for_backup/update_r/hardlinks" >&2 echo -e "\n${SELF}: Producing simple image with for_backup/update_r/hardlinks" >&2
"$xorriso" \ "$xorriso" \
$report_about \ $report_about \
-version \ -version \
@ -217,7 +89,7 @@ echo -e "\n=== Producing simple image - for_backup/update_r/hardlinks" >&2
-hardlinks perform_update -hardlinks perform_update
is_valid_iso9660 "$image_file" is_valid_iso9660 "$image_file"
echo "=== Copying from image to temporary disk tree" >&2 echo -e "\n${SELF}: Copying from image to temporary disk tree" >&2
"$xorriso" \ "$xorriso" \
$report_about \ $report_about \
-for_backup \ -for_backup \
@ -229,53 +101,49 @@ echo "=== Copying from image to temporary disk tree" >&2
if test "$simulate_failure" = 1 if test "$simulate_failure" = 1
then then
echo "===" >&2 echo -e "\n${SELF}: SIMULATING FAILURE BY REMOVING AN EXTRACTED FILE" >&2
echo "=== SIMULATING FAILURE BY REMOVING AN EXTRACTED FILE" >&2 echo -e "\n${SELF}: FAIL : Simulated failure caused by option -fail"
echo "===" >&2
echo "FAIL : $prog : Simulated failure caused by option -fail"
rm "$copy_on_disk"/file_1_link_b rm "$copy_on_disk"/file_1_link_b
fi fi
echo "=== Comparing original disk tree and temporary one" >&2 printf "\n${SELF}: Comparing original disk tree and temporary one..." >&2
diff -r "$on_disk" "$copy_on_disk" diff -r "$on_disk" "$copy_on_disk"
if test "$?" -ne 0 if test "$?" -ne 0
then then
echo "=== WRONG: diff -r $on_disk $copy_on_disk reports differences" >&2 echo -e "\n${SELF}: FAIL : diff -r $on_disk $copy_on_disk reports differences" >&2
echo "FAIL : $prog : diff -r reports differences" echo -e "\n${SELF}: FAIL : diff -r reports differences"
failure=1 failure=1
else else
echo "=== OK" >&2 printf "OK" >&2
fi fi
echo "=== Checking for hardlinks being siblings" >&2 printf "\n${SELF}: Checking for hardlinks being siblings...\n"
ls -l "$copy_on_disk"/* ls -l "$copy_on_disk"/*
x=$(echo $(ls -l "$copy_on_disk"/* | awk '{print $2}')) x=$(echo $(ls -l "$copy_on_disk"/* | awk '{print $2}'))
expected="3 3 3 2 2" expected="3 3 3 2 2"
if test x"$x" = x"$expected" if test x"$x" = x"$expected"
then then
echo "=== OK" >&2 printf "\n${SELF}: Checking for hardlinks being siblings. Done. OK.\n" >&2
else else
echo "=== WRONG: Link count of extracted files is not as expected." >&2 printf "\n${SELF}: FAIL : Link count of extracted files is not as expected." >&2
echo "=== Expected: $expected" >&2 printf "\n${SELF}: Expected: $expected" >&2
echo "=== Got : $x" >&2 printf "\n${SELF}: Got : $x\n" >&2
echo "FAIL : $prog : Link count of extracted files is not as expected."
failure=1 failure=1
fi fi
#
cleanup cleanup
# Report result # Report result
echo echo
if test "$failure" = 1 if test "$failure" = 1
then then
echo "======== $prog :" 'FAILED' printf "${SELF}: FAILED"
echo echo
exit 1 exit 1
else else
echo "======== $prog :" "Passed" printf "${SELF}: Passed"
echo echo
fi fi