From b692cc26a2a84f0b0c0d36f4224b78de5c06672e Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Thu, 14 Jul 2011 11:57:50 +0000 Subject: [PATCH] Proposal for test ./manual_devices and inc/releng_getopts_ts.inc --- .../trunk/releng/inc/releng_getopts_ts.inc | 201 ++++++++++++++++++ libisoburn/trunk/releng/manual_devices_ts | 53 +++-- 2 files changed, 241 insertions(+), 13 deletions(-) create mode 100644 libisoburn/trunk/releng/inc/releng_getopts_ts.inc diff --git a/libisoburn/trunk/releng/inc/releng_getopts_ts.inc b/libisoburn/trunk/releng/inc/releng_getopts_ts.inc new file mode 100644 index 00000000..9ed88bfc --- /dev/null +++ b/libisoburn/trunk/releng/inc/releng_getopts_ts.inc @@ -0,0 +1,201 @@ +# Copyright 2011 George Danchev +# Licensed under GNU GPL version 2 + +SELF=$(basename $0) +RELENG_XORRISO=0 +KEEP=0 +SIMULATE_FAILURE=0 +CLEANUP=1 +RELENG_PRINTED_HELP=0 + +START_DIR_DONT_CHANGE=`pwd` +GEN_DATA_DIR=releng_generated_data/${SELF} + +############################################# +print_help() { +cat << EOF + +Usage: $SELF -x path/to/xorriso [-k0|1] [-f0|1] [-c0|1] [-h] + [-- ...test specific options...] +General options: + -x absolute or relative path to binary to be run. + -k keep selfgenerated data (values 0,1, default 0). + -c cleanup selfgenerated data kept from previous + run and exit (values 0,1, default 0). + -f simulate failure (values 0,1, default 0). + -- end of general options, begin of test specific options. +EOF +} + +boldify() { + if which tput >/dev/null 2>&1; then tput smso; fi +} + +unboldify() { + if which tput >/dev/null 2>&1; then tput rmso; fi +} + +############################################# +cleanup() { + if [ ${KEEP} -eq 0 -a ${CLEANUP} -eq 1 ]; then + # safety net, just in case -> we want to be in the starting + # directory before removing whatever self-generated stuff + if [ -d "${GEN_DATA_DIR}" ]; then + cd "${START_DIR_DONT_CHANGE}" || exit 2 + + # Verify once again we are in the releng_generated_data directory + # Check for both returned code of grep and returned matching string + READ_CANON_EXISTS=`readlink -e "${GEN_DATA_DIR}"` + DIR_NAME_GEN_DATA=`dirname "${READ_CANON_EXISTS}"` + set +e + RET_NON_EMPTY_STRING=`echo "${DIR_NAME_GEN_DATA}" | grep -P "\w+\/releng_generated_data$"` + GREP_RET_GEN_DATA="$?" + case "${GREP_RET_GEN_DATA}" in + 0) + if [ x"${RET_NON_EMPTY_STRING}" != x"" ]; then + # now call the nastiness + chmod +w -R ${GEN_DATA_DIR} + rm -rf ${GEN_DATA_DIR} + boldify + printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR} + unboldify + else + printf "${SELF}: FAIL: Safety check for being in releng_generated_data directory.\n" + printf "${SELF}: FAIL: GREP returned empty string: ${RET_NON_EMPTY_STRING}.\n" + printf "${SELF}: FAIL: Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n" + fi + ;; + *) + printf "${SELF}: FAIL: Safety check for being in releng_generated_data directory.\n" + printf "${SELF}: FAIL: GREP returned code: ${GREP_RET_GEN_DATA}.\n" + printf "${SELF}: FAIL: Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n" + exit 30 + ;; + esac + else + printf "${SELF}: ${GEN_DATA_DIR} does not exist. Nothing to clean.\n" + fi + else + boldify + printf "${SELF}: Leaving (self-generated) %s\n" ${GEN_DATA_DIR} + unboldify + fi +} + +############################################# + +no_getopts=1 +if test "$no_getopts" = 1 +then + +next_is= +for i in "$@" +do + if test "$next_is" = "ignore" + then + dummy=dummy + elif test "$next_is" = "x" + then + RELENG_XORRISO="$i" + next_is= + elif test x"$i" = x"-x" + then + next_is="x" + elif test x"$i" = x"-k" -o x"$i" = x"-k0" + then + KEEP=0 + elif test x"$i" = x"-k1" + then + KEEP=1 + elif test x"$i" = x"-c" -o x"$i" = x"-c0" + then + CLEANUP=0 + elif test x"$i" = x"-c1" + then + CLEANUP=1 + elif test x"$i" = x"-f" -o x"$i" = x"-f0" + then + SIMULATE_FAILURE=0 + elif test x"$i" = x"-f1" + then + SIMULATE_FAILURE=1 + elif test x"$i" = x"-h" + then + print_help + RELENG_PRINTED_HELP=1 + elif test x"$i" = x"--" + then + # Begin of private arguments for caller + next_is="ignore" + else + echo >&2 + echo "Unknown general option: $i" >&2 + print_help + exit 31 + fi +done + +else +# no_getopts != 1 + +while getopts "x:k:c:f:h" OPTION +do + case $OPTION in + x) + RELENG_XORRISO=$OPTARG + ;; + k) + KEEP=$OPTARG + ;; + c) + CLEANUP=$OPTARG + cleanup + exit 0 + ;; + f) + SIMULATE_FAILURE=$OPTARG + ;; + h) + print_help + exit 0 + ;; + *) +# print_help +# exit 31 + ;; + esac +done + +# no_getopts != 1 +fi + + +# Each releng_ test should decide whether or not to check that +#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 + +if [ x"$KEEP" != x"0" -a x"$KEEP" != x"1" ]; then + print_help + printf "\n${SELF}: -k keep selfgenerated data.\n\n" + exit 31 +fi + +if [ x"$CLEANUP" != x"0" -a x"$CLEANUP" != x"1" ]; then + print_help + printf "\n${SELF}: -c cleanup selfgenerated data kept from previous run.\n\n" + exit 31 +fi + + +# ts B10714 I do not see much sense in flat failure. +# The tests should rather simulate an error condition +# and then let act their error reporting facilities +# if they have some. +# if [ x"$SIMULATE_FAILURE" != x"0" -a x"$SIMULATE_FAILURE" != x"1" ]; then +# print_help +# printf "\n${SELF}: -f simulate failure.\n\n" +# exit 31 +# fi diff --git a/libisoburn/trunk/releng/manual_devices_ts b/libisoburn/trunk/releng/manual_devices_ts index 406ae5a0..dd7097a0 100755 --- a/libisoburn/trunk/releng/manual_devices_ts +++ b/libisoburn/trunk/releng/manual_devices_ts @@ -6,36 +6,63 @@ # set -e -# Include common bits -if test -e inc/releng_getopts.inc +print_specific_help() { + # Print own help text + echo "Test specific options:" + echo " --dev path Suppress dialog and use path as drive address." + echo +} + +# Include common bits and interpret general options +getopts_ts=1 +if test "$getopts_ts" = 1 then - . inc/releng_getopts.inc + getopts_inc=inc/releng_getopts_ts.inc +else + getopts_inc=inc/releng_getopts.inc +fi +if test -e "$getopts_inc" +then + . "$getopts_inc" + + if test "$RELENG_PRINTED_HELP" = 1 + then + print_specific_help + exit 0 + fi else echo >&2 - echo "File not found: inc/releng_getopts.inc" >&2 + echo "File not found: $getopts_inc" >&2 echo "Are we in the ./releng directory of a libisoburn SVN checkout ?" >&2 echo "(Please execute the tests from that ./releng directory.)" >&2 echo >&2 exit 2 fi -# Interpret private options +# Interpret private options, they begin after the first --. dev= -next_is= - -echo >&2 -echo "args= ""$@" >&2 -echo >&2 - +next_is=ignore for i in "$@" do - if test "$next_is" = "dev" + if test "$next_is" = "ignore" + then + if test "$i" = "--" + then + next_is="" + fi + elif test "$next_is" = "dev" then dev="$i" next_is="" - elif test "$i" = "--outdev" -o "$i" = "--dev" + elif test "$i" = "--dev" then next_is="dev" + else + echo >&2 + echo "Unknown test specific option: $i" >&2 + print_help + print_specific_help + exit 31 fi done