From 392f6ba0a0f92f4370a73b6ed2b1c70ca48f607f Mon Sep 17 00:00:00 2001 From: George Danchev Date: Fri, 15 Jul 2011 06:08:29 +0000 Subject: [PATCH] merge back enhancements from Thomas --- releng/inc/releng_getopts.inc | 85 ++++++++++++- releng/inc/releng_getopts_ts.inc | 208 ------------------------------- releng/manual_devices | 182 ++++++++++++++++++++------- releng/manual_devices_ts | 176 -------------------------- 4 files changed, 218 insertions(+), 433 deletions(-) delete mode 100644 releng/inc/releng_getopts_ts.inc delete mode 100755 releng/manual_devices_ts diff --git a/releng/inc/releng_getopts.inc b/releng/inc/releng_getopts.inc index baa87562..6a1b6fdc 100644 --- a/releng/inc/releng_getopts.inc +++ b/releng/inc/releng_getopts.inc @@ -1,11 +1,13 @@ # Copyright 2011 George Danchev -# Licensed under GNU GPL version 2 +# Copyright 2011 Thomas Schmitt +# Licensed under GNU GPL version 2 or later 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} @@ -14,12 +16,15 @@ GEN_DATA_DIR=releng_generated_data/${SELF} print_help() { cat << EOF -Usage: $SELF -x path/to/xorriso [-k0|1] [-f0|1] [-h] +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 } @@ -79,9 +84,73 @@ cleanup() { } ############################################# + +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 + +if test "$next_is" = x +then + echo >&2 + echo "Option -x expects an argument (the path to the xorriso program)" >&2 + print_help + exit 31 +fi + +# no_getopts = 1 +else +# no_getopts != 1 + while getopts "x:k:c:f:h" OPTION do - case $OPTION in + case $OPTION in x) RELENG_XORRISO=$OPTARG ;; @@ -101,12 +170,16 @@ do exit 0 ;; *) - print_help - exit 31 +# 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 @@ -126,6 +199,8 @@ if [ x"$CLEANUP" != x"0" -a x"$CLEANUP" != x"1" ]; then exit 31 fi + +# <<< This cannot happen if $no_getopts = 1 if [ x"$SIMULATE_FAILURE" != x"0" -a x"$SIMULATE_FAILURE" != x"1" ]; then print_help printf "\n${SELF}: -f simulate failure.\n\n" diff --git a/releng/inc/releng_getopts_ts.inc b/releng/inc/releng_getopts_ts.inc deleted file mode 100644 index 6a1b6fdc..00000000 --- a/releng/inc/releng_getopts_ts.inc +++ /dev/null @@ -1,208 +0,0 @@ -# Copyright 2011 George Danchev -# Copyright 2011 Thomas Schmitt -# Licensed under GNU GPL version 2 or later - -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 - -if test "$next_is" = x -then - echo >&2 - echo "Option -x expects an argument (the path to the xorriso program)" >&2 - print_help - exit 31 -fi - -# no_getopts = 1 -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 - - -# <<< This cannot happen if $no_getopts = 1 -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/releng/manual_devices b/releng/manual_devices index 8be5aa53..d5bf5492 100755 --- a/releng/manual_devices +++ b/releng/manual_devices @@ -1,21 +1,74 @@ #!/bin/bash # Copyright 2011 George Danchev -# Licensed under GNU GPL version 2 +# Copyright 2011 Thomas Schmitt +# Licensed under GNU GPL version 2 or later # set -e -not_in_releng_exit() { - printf "\nPlease execute the tests from releng directory.\n\n" - exit 1 +print_specific_help() { + # Print own help text + echo "Test specific options:" + echo " --dev path Suppress dialog and use path as drive address." + echo "This test insists in getting a path to xorriso by option -x." + echo } -# Include common bits -. inc/releng_getopts.inc || not_in_releng_exit +# Include common bits and interpret general options +getopts_ts=1 +if test "$getopts_ts" = 1 +then + getopts_inc=inc/releng_getopts_ts.inc +else + getopts_inc=inc/releng_getopts.inc +fi +if test -e "$getopts_inc" +then + . "$getopts_inc" -# Each releng_ test should decide whether or not it needs -# a xorriso binary to test, since some do compilations only. -if [ ! -x $RELENG_XORRISO ]; then + if test "$RELENG_PRINTED_HELP" = 1 + then + print_specific_help + exit 0 + fi +else + echo >&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, they begin after the first --. +dev= +next_is=ignore +for i in "$@" +do + 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" = "--dev" + then + next_is="dev" + else + echo >&2 + echo "Unknown test specific option: $i" >&2 + print_help + print_specific_help + exit 31 + fi +done + +# Insist in having a xorriso +if [ ! -x "$RELENG_XORRISO" ]; then print_help printf "\n${SELF}: -x absolute or relative path to binary to be run.\n\n" exit 31 @@ -23,60 +76,101 @@ fi # get_speeds() { - echo -e "\n${SELF}: Running: ${RELENG_XORRISO} -outdev ${1} -list_speeds" - ${RELENG_XORRISO} -outdev ${1} -list_speeds - RET_SPEEDS="$?" - case ${RET_SPEEDS} in - 0) - ;; - *) - boldify - echo -e "\n${SELF}: ${RELENG_XORRISO} -outdev ${1} -list_speeds returned ${RET_SPEEDS}." - unboldify - ;; - esac + echo -e "\n${SELF}: Running: ${RELENG_XORRISO} -report_about WARNING -outdev ${1} -toc -list_formats -list_profiles out -list_speeds" + "$RELENG_XORRISO" -report_about WARNING -outdev "$1" \ + -print '---toc :' -toc \ + -print '---list_formats :' -list_formats \ + -print '---list_profiles :' -list_profiles out \ + -print '---list_speeds :' -list_speeds +} + +cat_var() { +# $1 = variable to put out with line feeds +cat <<+ +$1 ++ } get_devices() { - echo -e "\n${SELF}: Running: $RELENG_XORRISO -devices 2>/dev/null | grep \"\-dev\"" - DEVICES=`$RELENG_XORRISO -devices 2>/dev/null | grep "\-dev"` - NUM_DEV=`(cat <<+ -${DEVICES} -+ -) | wc -l` + # $1 = if not empty: device lines from xorriso -devices + # $2 = if not empty: suppress dialog and use $2 as input + if test -n "$1" + then + DEVICES="$1" + else + DEVICES=$("$RELENG_XORRISO" -devices 2>/dev/null | grep "\-dev") + fi + NUM_DEV=$(cat_var "$DEVICES" | wc -l) case "${NUM_DEV}" in 0) - echo -e "${SELF}: No drives found." + echo -e "\n${SELF}: No drives found." exit 1 ;; 1) - echo -e "${SELF}: Single drive found:\n${DEVICES}" - OUTDEV=`${RELENG_XORRISO} -devices 2>/dev/null | perl -pe "s#^\d+\s+\-dev\s+\'## and s#\'.*##"` - get_speeds ${OUTDEV} + echo -e "\n${SELF}: 1 drive found:\n" ;; *) - echo -e "${SELF}: Multiple drives found. NOT FINISHED YET." - exit 2 + echo -e "\n${SELF}: ${NUM_DEV} drives found:\n" ;; esac + echo ================================================================= + echo "$DEVICES" + echo ================================================================= + + OUTDEV=$( cat_var "$DEVICES" | head -1 | \ + sed -e "s/[0-9] *-dev '\//\//" -e "s/'.*$//" ) + if test -n "$2" + then + x="$2" + else + echo >&2 + echo "WARNING: The following tests might pull in the drive tray." >&2 + echo " Best is if you now put in a suitable media and" >&2 + echo " load it manually, so nobody gets surprised. :))" >&2 + echo >&2 + echo "Which drive to examine ? (Empty input = ${OUTDEV})" >&2 + read x + fi + if test -n "$x" + then + OUTDEV="$x" + fi + + get_speeds "$OUTDEV" } # main +"$RELENG_XORRISO" -version echo -e "\n${SELF}: Running: $RELENG_XORRISO -devices..." -$RELENG_XORRISO -devices -RET_DEVICES="$?" -case ${RET_DEVICES} in +devices=$("$RELENG_XORRISO" -report_about WARNING -devices | grep "\-dev") +RET="$?" +if test "$SIMULATE_FAILURE" = 1 +then + echo "===" >&2 + echo "=== SIMULATING FAILURE BY OVERRIDING EXIT VALUE OF XORRISO" >&2 + echo "===" >&2 + echo "FAIL : ${SELF} : Simulated failure caused by option -f" + RET=1 +fi +case ${RET} in 0) - get_devices - ;; + get_devices "$devices" "$dev" + RET="$?" + if test "$RET" = 0 + then + dummy=dummy + else + echo "FAIL : ${SELF} : Device scan or single drive listing failed" + exit "$RET" + fi + ;; *) - boldify - echo -ne "\n${SELF}: ${RELENG_XORRISO} -devices returned ${RET_DEVICES}." - unboldify - echo -e "\n${SELF}: Already mounted?" - df -kh - ;; + boldify + echo -ne "\n${SELF}: ${RELENG_XORRISO} -devices returned ${RET}." + unboldify + echo -e "\n${SELF}: Already mounted?" + df -kh esac exit 0 diff --git a/releng/manual_devices_ts b/releng/manual_devices_ts deleted file mode 100755 index d5bf5492..00000000 --- a/releng/manual_devices_ts +++ /dev/null @@ -1,176 +0,0 @@ -#!/bin/bash - -# Copyright 2011 George Danchev -# Copyright 2011 Thomas Schmitt -# Licensed under GNU GPL version 2 or later - -# set -e - -print_specific_help() { - # Print own help text - echo "Test specific options:" - echo " --dev path Suppress dialog and use path as drive address." - echo "This test insists in getting a path to xorriso by option -x." - echo -} - -# Include common bits and interpret general options -getopts_ts=1 -if test "$getopts_ts" = 1 -then - 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: $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, they begin after the first --. -dev= -next_is=ignore -for i in "$@" -do - 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" = "--dev" - then - next_is="dev" - else - echo >&2 - echo "Unknown test specific option: $i" >&2 - print_help - print_specific_help - exit 31 - fi -done - -# Insist in having a xorriso -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 - -# -get_speeds() { - echo -e "\n${SELF}: Running: ${RELENG_XORRISO} -report_about WARNING -outdev ${1} -toc -list_formats -list_profiles out -list_speeds" - "$RELENG_XORRISO" -report_about WARNING -outdev "$1" \ - -print '---toc :' -toc \ - -print '---list_formats :' -list_formats \ - -print '---list_profiles :' -list_profiles out \ - -print '---list_speeds :' -list_speeds -} - -cat_var() { -# $1 = variable to put out with line feeds -cat <<+ -$1 -+ -} - -get_devices() { - # $1 = if not empty: device lines from xorriso -devices - # $2 = if not empty: suppress dialog and use $2 as input - - if test -n "$1" - then - DEVICES="$1" - else - DEVICES=$("$RELENG_XORRISO" -devices 2>/dev/null | grep "\-dev") - fi - NUM_DEV=$(cat_var "$DEVICES" | wc -l) - case "${NUM_DEV}" in - 0) - echo -e "\n${SELF}: No drives found." - exit 1 - ;; - 1) - echo -e "\n${SELF}: 1 drive found:\n" - ;; - *) - echo -e "\n${SELF}: ${NUM_DEV} drives found:\n" - ;; - esac - echo ================================================================= - echo "$DEVICES" - echo ================================================================= - - OUTDEV=$( cat_var "$DEVICES" | head -1 | \ - sed -e "s/[0-9] *-dev '\//\//" -e "s/'.*$//" ) - if test -n "$2" - then - x="$2" - else - echo >&2 - echo "WARNING: The following tests might pull in the drive tray." >&2 - echo " Best is if you now put in a suitable media and" >&2 - echo " load it manually, so nobody gets surprised. :))" >&2 - echo >&2 - echo "Which drive to examine ? (Empty input = ${OUTDEV})" >&2 - read x - fi - if test -n "$x" - then - OUTDEV="$x" - fi - - get_speeds "$OUTDEV" -} - -# main -"$RELENG_XORRISO" -version -echo -e "\n${SELF}: Running: $RELENG_XORRISO -devices..." -devices=$("$RELENG_XORRISO" -report_about WARNING -devices | grep "\-dev") -RET="$?" -if test "$SIMULATE_FAILURE" = 1 -then - echo "===" >&2 - echo "=== SIMULATING FAILURE BY OVERRIDING EXIT VALUE OF XORRISO" >&2 - echo "===" >&2 - echo "FAIL : ${SELF} : Simulated failure caused by option -f" - RET=1 -fi -case ${RET} in - 0) - get_devices "$devices" "$dev" - RET="$?" - if test "$RET" = 0 - then - dummy=dummy - else - echo "FAIL : ${SELF} : Device scan or single drive listing failed" - exit "$RET" - fi - ;; - *) - boldify - echo -ne "\n${SELF}: ${RELENG_XORRISO} -devices returned ${RET}." - unboldify - echo -e "\n${SELF}: Already mounted?" - df -kh -esac - -exit 0