test_streams.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #!/bin/sh -e
  2. # FLAC - Free Lossless Audio Codec
  3. # Copyright (C) 2001-2009 Josh Coalson
  4. # Copyright (C) 2011-2023 Xiph.Org Foundation
  5. #
  6. # This file is part the FLAC project. FLAC is comprised of several
  7. # components distributed under different licenses. The codec libraries
  8. # are distributed under Xiph.Org's BSD-like license (see the file
  9. # COPYING.Xiph in this distribution). All other programs, libraries, and
  10. # plugins are distributed under the GPL (see COPYING.GPL). The documentation
  11. # is distributed under the Gnu FDL (see COPYING.FDL). Each file in the
  12. # FLAC distribution contains at the top the terms under which it may be
  13. # distributed.
  14. #
  15. # Since this particular file is relevant to all components of FLAC,
  16. # it may be distributed under the Xiph.Org license, which is the least
  17. # restrictive of those mentioned above. See the file COPYING.Xiph in this
  18. # distribution.
  19. . ./common.sh
  20. PATH=../src/flac:$PATH
  21. PATH=../src/test_streams:$PATH
  22. PATH=../objs/$BUILD/bin:$PATH
  23. if [ -z "$FLAC__TEST_LEVEL" ] ; then
  24. FLAC__TEST_LEVEL=1
  25. fi
  26. flac${EXE} --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
  27. run_flac ()
  28. {
  29. if [ "$FLAC__TEST_WITH_VALGRIND" = yes ] ; then
  30. echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_streams.valgrind.log
  31. valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac --no-error-on-compression-fail $* 4>>test_streams.valgrind.log
  32. else
  33. flac${EXE} --no-error-on-compression-fail $*
  34. fi
  35. }
  36. echo "Generating streams..."
  37. if [ ! -f wacky1.wav ] ; then
  38. test_streams || die "ERROR: missing files"
  39. fi
  40. #
  41. # single-file test routines
  42. #
  43. test_file ()
  44. {
  45. name=$1
  46. channels=$2
  47. bps=$3
  48. encode_options="$4"
  49. echo $ECHO_N "$name (--channels=$channels --bps=$bps $encode_options): encode..." $ECHO_C
  50. cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding $name.raw"
  51. echo "### ENCODE $name #######################################################" >> ./streams.log
  52. echo "### cmd=$cmd" >> ./streams.log
  53. $cmd 2>>./streams.log || die "ERROR during encode of $name"
  54. echo $ECHO_N "decode..." $ECHO_C
  55. cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --output-name=$name.cmp $name.flac"
  56. echo "### DECODE $name #######################################################" >> ./streams.log
  57. echo "### cmd=$cmd" >> ./streams.log
  58. $cmd 2>>./streams.log || die "ERROR during decode of $name"
  59. ls -1l $name.raw >> ./streams.log
  60. ls -1l $name.flac >> ./streams.log
  61. ls -1l $name.cmp >> ./streams.log
  62. echo $ECHO_N "compare..." $ECHO_C
  63. cmp $name.raw $name.cmp || die "ERROR during compare of $name"
  64. echo OK
  65. }
  66. test_file_piped ()
  67. {
  68. name=$1
  69. channels=$2
  70. bps=$3
  71. encode_options="$4"
  72. if [ "$(env | grep -ic '^comspec=')" != 0 ] ; then
  73. is_win=yes
  74. else
  75. is_win=no
  76. fi
  77. echo $ECHO_N "$name: encode via pipes..." $ECHO_C
  78. if [ $is_win = yes ] ; then
  79. cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding --stdout $name.raw"
  80. echo "### ENCODE $name #######################################################" >> ./streams.log
  81. echo "### cmd=$cmd" >> ./streams.log
  82. $cmd 1>$name.flac 2>>./streams.log || die "ERROR during encode of $name"
  83. else
  84. cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding --stdout -"
  85. echo "### ENCODE $name #######################################################" >> ./streams.log
  86. echo "### cmd=$cmd" >> ./streams.log
  87. $cmd < $name.raw 1>$name.flac 2>>./streams.log || die "ERROR during encode of $name"
  88. fi
  89. echo $ECHO_N "decode via pipes..." $ECHO_C
  90. if [ $is_win = yes ] ; then
  91. cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --stdout $name.flac"
  92. echo "### DECODE $name #######################################################" >> ./streams.log
  93. echo "### cmd=$cmd" >> ./streams.log
  94. $cmd 1>$name.cmp 2>>./streams.log || die "ERROR during decode of $name"
  95. else
  96. cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --stdout -"
  97. echo "### DECODE $name #######################################################" >> ./streams.log
  98. echo "### cmd=$cmd" >> ./streams.log
  99. $cmd < $name.flac 1>$name.cmp 2>>./streams.log || die "ERROR during decode of $name"
  100. fi
  101. ls -1l $name.raw >> ./streams.log
  102. ls -1l $name.flac >> ./streams.log
  103. ls -1l $name.cmp >> ./streams.log
  104. echo $ECHO_N "compare..." $ECHO_C
  105. cmp $name.raw $name.cmp || die "ERROR during compare of $name"
  106. echo OK
  107. }
  108. test_corrupted_file ()
  109. {
  110. name=$1
  111. channels=$2
  112. bps=$3
  113. encode_options="$4"
  114. echo $ECHO_N "$name (--channels=$channels --bps=$bps $encode_options): encode..." $ECHO_C
  115. 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"
  116. echo "### ENCODE $name #######################################################" >> ./streams.log
  117. echo "### cmd=$cmd" >> ./streams.log
  118. $cmd 2>>./streams.log || die "ERROR during encode of $name"
  119. filesize=$(wc -c < $name.flac)
  120. bs=$((filesize/13))
  121. # Overwrite with 'garbagegarbagegarbage....'
  122. yes garbage 2>/dev/null | dd of=$name.flac conv=notrunc bs=$bs seek=1 count=2 2>> ./streams.log
  123. # Overwrite with 0x00
  124. dd if=/dev/zero of=$name.flac conv=notrunc bs=$bs seek=4 count=2 2>> ./streams.log
  125. # Overwrite with 0xFF
  126. tr '\0' '\377' < /dev/zero | dd of=$name.flac conv=notrunc bs=$bs seek=7 count=2 2>> ./streams.log
  127. # Remove section
  128. cp $name.flac $name.tmp.flac
  129. dd if=$name.tmp.flac of=$name.flac bs=$bs skip=12 seek=10 2>> ./streams.log
  130. echo $ECHO_N "decode..." $ECHO_C
  131. cmd="run_flac --silent --decode-through-errors --force --endian=little --sign=signed --decode --force-raw-format --output-name=$name.cmp $name.flac"
  132. echo "### DECODE $name.corrupt #######################################################" >> ./streams.log
  133. echo "### cmd=$cmd" >> ./streams.log
  134. $cmd 2>>./streams.log || die "ERROR during decode of $name"
  135. ls -1l $name.raw >> ./streams.log
  136. ls -1l $name.flac >> ./streams.log
  137. ls -1l $name.cmp >> ./streams.log
  138. echo $ECHO_N "compare..." $ECHO_C
  139. if [ "$(wc -c < $name.raw)" -ne "$(wc -c < $name.cmp)" ]; then
  140. die "ERROR, length of decoded file not equal to length of original"
  141. fi
  142. echo OK
  143. }
  144. if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
  145. max_lpc_order=32
  146. else
  147. max_lpc_order=16
  148. fi
  149. echo "Testing noise through pipes..."
  150. test_file_piped noise 1 8 "-0"
  151. echo "Testing small files..."
  152. test_file test01 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
  153. test_file test02 2 16 "-0 -l $max_lpc_order --lax -m -e -p"
  154. test_file test03 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
  155. test_file test04 2 16 "-0 -l $max_lpc_order --lax -m -e -p"
  156. for bps in 8 16 24 32 ; do
  157. echo "Testing $bps-bit full-scale deflection streams..."
  158. for b in 01 02 03 04 05 06 07 ; do
  159. test_file fsd$bps-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e -p"
  160. done
  161. done
  162. echo "Testing 16-bit wasted-bits-per-sample streams..."
  163. for b in 01 ; do
  164. test_file wbps16-$b 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
  165. done
  166. for bps in 8 16 24 32; do
  167. echo "Testing $bps-bit sine wave streams..."
  168. for b in 00 ; do
  169. test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=48000"
  170. done
  171. for b in 01 ; do
  172. test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=96000"
  173. done
  174. for b in 02 03 04 ; do
  175. test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e"
  176. done
  177. for b in 10 11 ; do
  178. test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=48000"
  179. done
  180. for b in 12 ; do
  181. test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=96000"
  182. done
  183. for b in 13 14 15 16 17 18 19 ; do
  184. test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e"
  185. done
  186. done
  187. echo "Testing blocksize variations..."
  188. for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
  189. for blocksize in 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
  190. for lpc_order in 0 1 2 3 4 5 7 8 9 15 16 17 31 32 ; do
  191. if [ $lpc_order = 0 ] || [ $lpc_order -le $blocksize ] ; then
  192. test_file noise8m32 1 8 "-8 -p -e -l $lpc_order --lax --blocksize=$blocksize $disable"
  193. fi
  194. done
  195. done
  196. done
  197. echo "Testing blocksize variations with subdivide apodization..."
  198. for blocksize in 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
  199. for lpc_order in 0 1 2 3 4 5 7 8 9 15 16 17 31 32 ; do
  200. if [ $lpc_order = 0 ] || [ $lpc_order -le $blocksize ] ; then
  201. test_file noise8m32 1 8 "-8 -p -e -A \"subdivide_tukey(32)\" -l $lpc_order --lax --blocksize=$blocksize"
  202. fi
  203. done
  204. done
  205. echo "Testing some frame header variations..."
  206. test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b $max_lpc_order"
  207. test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b 65535"
  208. test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
  209. test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
  210. test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
  211. test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
  212. test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
  213. test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
  214. echo "Testing option variations..."
  215. for f in 00 01 02 03 04 ; do
  216. for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
  217. if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
  218. for opt in 0 1 2 4 5 6 8 ; do
  219. for extras in '' '-p' '-e' ; do
  220. if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
  221. test_file sine16-$f 1 16 "-$opt $extras $disable"
  222. fi
  223. done
  224. done
  225. if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
  226. test_file sine16-$f 1 16 "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
  227. fi
  228. fi
  229. done
  230. done
  231. for f in 10 11 12 13 14 15 16 17 18 19 ; do
  232. for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
  233. if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
  234. for opt in 0 1 2 4 5 6 8 ; do
  235. for extras in '' '-p' '-e' ; do
  236. if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
  237. test_file sine16-$f 2 16 "-$opt $extras $disable"
  238. fi
  239. done
  240. done
  241. if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
  242. test_file sine16-$f 2 16 "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
  243. fi
  244. fi
  245. done
  246. done
  247. echo "Testing corruption handling..."
  248. for bps in 8 16 24 ; do
  249. for f in 00 01 02 03 04 10 11 12 13 14 15 16 17 18 19; do
  250. for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
  251. if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
  252. for opt in 0 1 2 4 5 6 8 ; do
  253. for extras in '' '-p' '-e' ; do
  254. if [ -z "$extras" -o "$FLAC__TEST_LEVEL" -gt 0 ] && { [ "$bps" -eq 16 -a "$f" -lt 15 ] || [ "$FLAC__TEST_LEVEL" -gt 1 ]; } ; then
  255. if [ "$f" -lt 10 ] ; then
  256. test_corrupted_file sine$bps-$f 1 $bps "-$opt $extras $disable"
  257. else
  258. test_corrupted_file sine$bps-$f 2 $bps "-$opt $extras $disable"
  259. fi
  260. fi
  261. done
  262. done
  263. fi
  264. done
  265. done
  266. done
  267. echo "Testing noise..."
  268. for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
  269. if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
  270. for channels in 1 2 4 8 ; do
  271. if [ $channels -le 2 ] || [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
  272. for bps in 8 16 24 32; do
  273. for opt in 0 1 2 3 4 5 6 7 8 ; do
  274. for extras in '' '-p' '-e' ; do
  275. if { [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ]; } && { [ "$extras" != '-p' ] || [ "$opt" -gt 2 ]; } ; then
  276. for blocksize in '' '--lax -b 32' '--lax -b 32768' '--lax -b 65535' ; do
  277. if [ -z "$blocksize" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
  278. test_file noise $channels $bps "-$opt $extras $blocksize $disable"
  279. fi
  280. done
  281. fi
  282. done
  283. done
  284. if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
  285. test_file noise $channels $bps "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
  286. fi
  287. done
  288. fi
  289. done
  290. fi
  291. done