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 121 122 123 124 125 126 127 128 129 130 131 132
|
#!/bin/bash
#
# Source reading 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_READ_TEST_WRAPPER:-}
function hexdump_col ()
{
hexdump -v -e '1/1 "%.2X\n"' "$@"
}
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 txt_output="`tempfile -s\"_$output_basename.txt\"`"
local test_txt_output="`tempfile -s\"_$output_basename.txt.test\"`"
local status
echo "Checking \"$format\" reading from \"$input\"" \
"against \"$output\"" \
"with options \"$options\"..." >&2
set +e
(
set -e
local output_size
local test_output_size
local max_size
$WRAPPER "$cmd" "$format" "$options" "$input" "$test_output"
output_size=`stat -c %s "$output"`
test_output_size=`stat -c %s "$test_output"`
if (( $test_output_size > $output_size )); then
max_size=$test_output_size
else
max_size=$output_size
fi
hexdump_col "$output" > "$txt_output"
hexdump_col "$test_output" > "$test_txt_output"
diff -u -U$max_size "$txt_output" "$test_txt_output" >&2
)
status=$?
set -e
rm -f "$test_output"
rm -f "$txt_output"
rm -f "$test_txt_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_READ_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_READ="`readlink -f \"\`which hidrd_read\`\"`"
cd "$DIR"
for INPUT_FILE in *.${EXT}; do
OUTPUT_FILE="${INPUT_FILE%.${EXT}}.bin"
OPTS_FILE="${INPUT_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_READ" "$FMT" "$OPTS" "$INPUT_FILE" "$OUTPUT_FILE"
done
|