summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMartijn van Beurden <mvanb1@gmail.com>2022-04-27 12:16:15 +0200
committerGitHub <noreply@github.com>2022-04-27 12:16:15 +0200
commit1793632ee6988deb933ff7551fee92134622b558 (patch)
treeae8412dd8e1a6ffef6eb4d7aebc1edd854a2efb1 /test
parent7e785eb9a84f9147246eb2b0e5e35ec01db5a815 (diff)
downloadflac-1793632ee6988deb933ff7551fee92134622b558.tar.gz
Rework error handling (#283)
This commit reworks the code decoding a frame, to add silence when frames are missing and output silence when something other than the frame header seems corrupted. Tests are added to the test suite for this functionality. Also, decoded values are checked to be within bps
Diffstat (limited to 'test')
-rwxr-xr-xtest/test_streams.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/test_streams.sh b/test/test_streams.sh
index f4cbd006..e86fce96 100755
--- a/test/test_streams.sh
+++ b/test/test_streams.sh
@@ -125,6 +125,50 @@ test_file_piped ()
echo OK
}
+test_corrupted_file ()
+{
+ name=$1
+ channels=$2
+ bps=$3
+ encode_options="$4"
+
+ echo $ECHO_N "$name (--channels=$channels --bps=$bps $encode_options): encode..." $ECHO_C
+ cmd="run_flac --verify --silent --no-padding --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding $name.raw"
+ echo "### ENCODE $name #######################################################" >> ./streams.log
+ echo "### cmd=$cmd" >> ./streams.log
+ $cmd 2>>./streams.log || die "ERROR during encode of $name"
+
+ filesize=$(wc -c < $name.flac)
+ bs=$((filesize/13))
+
+ # Overwrite with 'garbagegarbagegarbage....'
+ yes garbage 2>/dev/null | dd of=$name.flac conv=notrunc bs=$bs seek=1 count=2 2>> ./streams.log
+ # Overwrite with 0x00
+ dd if=/dev/zero of=$name.flac conv=notrunc bs=$bs seek=4 count=2 2>> ./streams.log
+ # Overwrite with 0xFF
+ tr '\0' '\377' < /dev/zero | dd of=$name.flac conv=notrunc bs=$bs seek=7 count=2 2>> ./streams.log
+ # Remove section
+ cp $name.flac $name.tmp.flac
+ dd if=$name.tmp.flac of=$name.flac bs=$bs skip=12 seek=10 2>> ./streams.log
+
+ echo $ECHO_N "decode..." $ECHO_C
+ cmd="run_flac --silent --decode-through-errors --force --endian=little --sign=signed --decode --force-raw-format --output-name=$name.cmp $name.flac"
+ echo "### DECODE $name.corrupt #######################################################" >> ./streams.log
+ echo "### cmd=$cmd" >> ./streams.log
+ $cmd 2>>./streams.log || die "ERROR during decode of $name"
+
+ ls -1l $name.raw >> ./streams.log
+ ls -1l $name.flac >> ./streams.log
+ ls -1l $name.cmp >> ./streams.log
+
+ echo $ECHO_N "compare..." $ECHO_C
+ if [ $(wc -c < $name.raw) -ne $(wc -c < $name.cmp) ]; then
+ die "ERROR, length of decoded file not equal to length of original"
+ fi
+
+ echo OK
+}
+
if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
max_lpc_order=32
else
@@ -230,6 +274,27 @@ for f in 10 11 12 13 14 15 16 17 18 19 ; do
done
done
+echo "Testing corruption handling..."
+for bps in 8 16 24 ; do
+ for f in 00 01 02 03 04 10 11 12 13 14 15 16 17 18 19; do
+ for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
+ if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
+ for opt in 0 1 2 4 5 6 8 ; do
+ for extras in '' '-p' '-e' ; do
+ if ([ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ]) && (([ "$bps" -eq 16 ] && [ "$f" -lt 15 ]) || [ "$FLAC__TEST_LEVEL" -gt 1 ]) ; then
+ if [ "$f" -lt 10 ] ; then
+ test_corrupted_file sine$bps-$f 1 $bps "-$opt $extras $disable"
+ else
+ test_corrupted_file sine$bps-$f 2 $bps "-$opt $extras $disable"
+ fi
+ fi
+ done
+ done
+ fi
+ done
+ done
+done
+
echo "Testing noise..."
for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then