1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#!/bin/bash
#
# Sink writing test script
#
# Copyright (C) 2010 Nikolai Kondrashov
#
# This file is part of hidrd.
#
# Hidrd is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Hidrd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with hidrd; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
set -e -u -o pipefail
shopt -s nullglob
WRAPPER=${HIDRD_WRITE_TEST_WRAPPER:-}
function run ()
{
local cmd="$1"; shift
local format="$1"; shift
local options="$1"; shift
local input="$1"; shift
local output="$1"; shift
local output_basename="`basename \"$output\"`"
local test_output="`tempfile -s\"_$output_basename.test\"`"
local status
echo "Checking \"$format\" writing of \"$input\"" \
"against \"$output\"" \
"with options \"$options\"..." >&2
set +e
(
set -e
local output_lines
local test_output_lines
local max_lines
$WRAPPER "$cmd" "$format" "$options" "$input" "$test_output"
output_lines=`wc -l < "$output"`
test_output_lines=`wc -l < "$test_output"`
if (( $test_output_lines > $output_lines )); then
max_lines=$test_output_lines
else
max_lines=$output_lines
fi
diff -u -U$max_lines "$output" "$test_output" >&2
)
status=$?
set -e
rm -f "$test_output"
if (( $status == 0 )); then
echo "PASSED." >&2
else
echo "FAILED." >&2
fi
return $status
}
function usage_exit ()
{
echo "Usage: `basename \"$0\"` <format> <options> <extension> <data_dir>" >&2
echo
exit 1
}
FMT=${1:-}
GOPTS=${2:-}
EXT=${3:-}
DIR=${4:-${HIDRD_WRITE_TEST_DATA:-}}
if [ -z "$FMT" ]; then
echo "Format is not specified." >&2
usage_exit
fi
if [ -z "$EXT" ]; then
echo "Extension is not specified." >&2
usage_exit
fi
if [ -z "$DIR" ]; then
echo "Data directory is not specified." >&2
usage_exit
fi
HIDRD_WRITE="`readlink -f \"\`which hidrd_write\`\"`"
cd "$DIR"
for OUTPUT_FILE in *.${EXT}; do
INPUT_FILE="${OUTPUT_FILE%.${EXT}}.bin"
OPTS_FILE="${OUTPUT_FILE}.opt"
if [ -e "$OPTS_FILE" ]; then
SOPTS=`cat "$OPTS_FILE"`
fi
# Join global and specific options with comma, if necessary
OPTS="${GOPTS:-}${GOPTS:+${SOPTS:+,}}${SOPTS:-}"
run "$HIDRD_WRITE" "$FMT" "$OPTS" "$INPUT_FILE" "$OUTPUT_FILE"
done
|