libisoburn/releng/auto_isocontent

217 lines
5.6 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2011 Thomas Schmitt <scdbackup@gmx.net>
# Copyright 2011 George Danchev <danchev@spnet.net>
# Licensed under GNU GPL version 2 or later
# Test the correct handling of hardlinks by xorriso options
# -update_r , -hardlinks perform_update , and -extract
not_in_releng_exit() {
printf "\nPlease execute the tests from releng directory.\n\n"
exit 1
}
. inc/releng_getopts.inc || not_in_releng_exit
print_specific_help() {
cat << HLP
Specific options:
none yet.
Overview:
Tests ISO image contents by performing various
image generation, extractions and comparisons.
HLP
}
if test "$SPECIFIC_HELP" = 1; then
print_specific_help
exit 0
fi
if [ ! -x $RELENG_XORRISO ]; then
print_help
printf "\n${SELF}: -x absolute or relative path to binary to be run.\n\n"
exit 31
fi
# check data dir, if any and after checking -x xorriso
if [ -d "${GEN_DATA_DIR}" ]; then
printf "\n${SELF}: directory %s exists!" ${GEN_DATA_DIR}
printf "\n${SELF}: use '${SELF} -c' to remove.\n"
exit 8
else
mkdir "${GEN_DATA_DIR}"
fi
export xorriso=${RELENG_XORRISO}
export workdir=${GEN_DATA_DIR}
export image_file="$workdir"/xorriso_hardlinks.iso
export on_disk="$workdir"/xorriso_hardlinks_test_dir
export in_iso=""
export copy_on_disk="$workdir"/xorriso_hardlinks_copy_dir
export failure=0
export simulate_failure=${SIMULATE_FAILURE}
export next_is_xorriso=0
export next_is_rc=0
export bad=0
export report_about="-report_about UPDATE"
test -z "$in_iso" && in_iso="$on_disk"
# mkdir "$workdir" || bad=1
mkdir "$on_disk" || bad=1
if test "$bad" = 1
then
echo -e "\nFAIL : ${SELF} : Test environment error : Cannot make directories"
exit 3
fi
# All must be set at this point
printf "\n${SELF}: Setting up $on_disk with several hardlinks\n" >&2
echo test_content >"$on_disk"/file_1 || 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_b || exit 1
ln "$on_disk"/file_2 "$on_disk"/file_2_link_a || exit 1
ls -l "$on_disk"/*
# trivial ISO 9660 image validation routine
is_valid_iso9660() {
ISOfile="$1"
if [ ! -f ${ISOfile} ]; then
failure=1
printf "\nFAIL : ${SELF} : Not found: ${ISOfile}\n"
fi
file ${ISOfile}
if file ${ISOfile} | grep "ISO *9660" >/dev/null 2>&1; then
printf "\n${SELF}: Resulting ${ISOfile} OK. Looks like ISO 9660 filesystem.\n"
else
failure=1
printf "\nFAIL : ${SELF} : ${ISOfile} DOES NOT look like ISO 9660 filesystem data.\n"
fi
}
echo -e "\n${SELF}: Producing simple image via -o" >&2
"$xorriso" -as mkisofs "$on_disk" -o "$workdir"/image_minus_o.iso
is_valid_iso9660 "$workdir"/image_minus_o.iso
echo -e "\n${SELF}: Producing simple image via redirect" >&2
"$xorriso" -as mkisofs "$on_disk" > "$workdir"/image_redirected.iso
is_valid_iso9660 "$workdir"/image_redirected.iso
echo -e "\n${SELF}: Producing simple image via pipe" >&2
"$xorriso" -as mkisofs "$on_disk" | cat > "$workdir"/image_piped.iso
is_valid_iso9660 "$workdir"/image_piped.iso
echo -e "\n${SELF}: Producing simple image with for_backup/update_r/hardlinks" >&2
"$xorriso" \
$report_about \
-version \
-for_backup \
-padding 0 \
-outdev "$image_file" \
-volid TEST_AUTO_ISOCONTENT \
-update_r "$on_disk" "$in_iso" \
-hardlinks perform_update
ret=$?
if test "$ret" -gt 0 -a "$ret" -lt 32
then
printf "\n${SELF}: xorriso write run failed\n\n" >&2
cleanup
printf "${SELF}: FAILED\n"
exit 1
fi
is_valid_iso9660 "$image_file"
# It must refuse to load and go on with -assert_volid and non-matching pattern.
msg=$(\
"$xorriso" \
-abort_on FATAL \
-return_with FAILURE 32 \
-assert_volid 'NON_MATCHING*' FATAL \
-indev "$image_file" \
2>&1
)
ret=$?
if test "$ret" -gt 0 -a "$ret" -lt 32
then
printf "\n${SELF}: Ok. -assert_volid snapped.\n"
elif test "$ret" -ne 0
then
failure=1
echo >&2
echo "$msg" >&2
printf "\nFAIL : ${SELF} : -assert_volid test not properly performed\n\n" >&2
else
failure=1
printf "\nFAIL : ${SELF} : -assert_volid did not snap\n\n" >&2
fi
echo -e "\n${SELF}: Copying from image to temporary disk tree" >&2
"$xorriso" \
$report_about \
-for_backup \
-assert_volid 'TEST_AUTO_ISOCONT*' FATAL \
-indev "$image_file" \
-osirrox on \
-find "$in_iso" -exec lsdl -- \
-extract "$in_iso" "$copy_on_disk"
ret=$?
if test "$ret" -gt 0 -a "$ret" -lt 32
then
printf "\n${SELF}: xorriso file extraction run failed\n\n" >&2
cleanup
printf "${SELF}: FAILED\n"
exit 1
fi
if test "$simulate_failure" = 1
then
echo -e "\n${SELF}: SIMULATING FAILURE BY REMOVING AN EXTRACTED FILE" >&2
echo -e "\nFAIL : ${SELF} : Simulated failure caused by option -fail"
rm "$copy_on_disk"/file_1_link_b
fi
printf "\n${SELF}: Comparing original disk tree and temporary one..." >&2
diff -r "$on_disk" "$copy_on_disk"
if test "$?" -ne 0
then
echo -e "\nFAIL : ${SELF} : diff -r $on_disk $copy_on_disk reports differences" >&2
echo -e "\nFAIL : ${SELF} : diff -r reports differences"
failure=1
else
printf "OK" >&2
fi
printf "\n${SELF}: Checking for hardlinks being siblings...\n"
ls -l "$copy_on_disk"/*
x=$(echo $(ls -l "$copy_on_disk"/* | awk '{print $2}'))
expected="3 3 3 2 2"
if test x"$x" = x"$expected"
then
printf "\n${SELF}: Checking for hardlinks being siblings. Done. OK.\n" >&2
else
printf "\nFAIL : ${SELF} : Link count of extracted files is not as expected." >&2
printf "\n${SELF}: Expected: $expected" >&2
printf "\n${SELF}: Got : $x\n" >&2
failure=1
fi
#
cleanup
# Report result
echo
if test "$failure" = 1
then
printf "${SELF}: FAILED"
echo
exit 1
else
printf "${SELF}: Passed"
echo
fi
exit 0