TestRunnerCommon.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. ###############################################################################
  2. # COMMON DATA
  3. ###############################################################################
  4. ON_OFF=(
  5. "OFF"
  6. "ON"
  7. )
  8. YUV_FORMAT_NAME=(
  9. "AUTO"
  10. "YUV420"
  11. "YUV422"
  12. "YUV444"
  13. "YUV400"
  14. )
  15. ENDIAN_NAME=(
  16. "VDI_64BIT_LE"
  17. "VDI_64BIT_BE"
  18. "VDI_32BIT_LE"
  19. "VDI_32BIT_BE"
  20. )
  21. MIRROR_NAME=(
  22. "NONE"
  23. "VERTICAL"
  24. "HORIZONTAL"
  25. "BOTH"
  26. )
  27. JUSTIFY_NAME=(
  28. "MSB_JUSTFIED"
  29. "LSB_JUSTFIED"
  30. )
  31. YUV_PACKING_NAME=(
  32. "PLANAR"
  33. "SEMI-PLANAR(CbCr)"
  34. "SEMI-PLANAR(CrCb)"
  35. "YUYV"
  36. "UYVY"
  37. "YVYU"
  38. "VYUY"
  39. "444 PACK(8BIT)"
  40. "PPM(12BIT)"
  41. )
  42. SCALEDOWN_NAME=(
  43. "NONE"
  44. "1/2"
  45. "1/4"
  46. "1/8"
  47. )
  48. PASS="PASS"
  49. FAIL="FAIL"
  50. PASS="{color:green}*PASS*{color}"
  51. FAIL="{color:red}*FAIL*{color}"
  52. ###############################################################################
  53. # GLOBAL VARIABLES
  54. ###############################################################################
  55. g_fpga_reset=0 # 1 : reset fpga every time
  56. g_jpeg_12bit="false"
  57. ######################## COMMON VARAIABLES FOR DECODER ########################
  58. g_yuv_fmt_list=("${YUV_FORMAT_LIST[@]}")
  59. g_match_mode=1 # 0 - nomatch, 1 - yuv
  60. g_aclk=20
  61. g_cclk=20
  62. g_secondary_axi=0
  63. g_stream_endian=0
  64. g_frame_endian=0
  65. g_tiled_mode=0
  66. g_cbcr_format=0 # 0 - none, 1 - NV12, 2 - NV21
  67. g_fake_test=0
  68. ########################## VARAIABLES FOR PPU #################################
  69. g_rotation=0
  70. g_mirror=0
  71. ###############################################################################
  72. cmodel_pn_val="" # planar format
  73. cmodel_pk_val="" # packed format
  74. cmodel_nv_val="" # semi-planar
  75. ###############################################################################
  76. # GLOBAL FUNCTIONS
  77. ###############################################################################
  78. # get_random start end
  79. # generate constraint random value with @start end @end.
  80. #
  81. function get_random {
  82. start=$1
  83. end=$2
  84. size=$(($end - $start + 1))
  85. val2=$RANDOM
  86. val1=$(($val2 % size))
  87. val=$(($start + $val1%$size))
  88. echo "$val"
  89. }
  90. function gen_val {
  91. local min_val=$1
  92. local max_val=$2
  93. local default_val=$3
  94. local val
  95. if [ -z $default_val ] || [ "$default_val" == "-99" ]; then
  96. # Generate random value
  97. val=$(get_random $min_val $max_val)
  98. else
  99. val=$default_val
  100. fi
  101. echo "$val"
  102. }
  103. function gen_val_angle {
  104. local default_val=$1
  105. local val
  106. if [ -z $default_val ] || [ "$default_val" == "-99" ]; then
  107. val=$(($(get_random 0 3)*90))
  108. else
  109. val=$default_val
  110. fi
  111. echo "$val"
  112. }
  113. function gen_yuv_pack_12bit {
  114. local yuv_format=$1
  115. local default=$2
  116. local val
  117. case $yuv_format in
  118. 0) # No conversion
  119. val=0;;
  120. 1) # YUV420, 3 for ppm format
  121. val=$(gen_val 1 3 $default)
  122. if [ "$val" == "3" ]; then
  123. val=8 # PPM
  124. fi
  125. ;;
  126. 2) # YUV422
  127. val=$(gen_val 1 8 $default)
  128. if [ "$val" == "7" ]; then
  129. # 7 - YUV444 pack mode for 8bit yuv
  130. val=8
  131. fi
  132. ;;
  133. 3) # YUV444, 3 for ppm format
  134. val=$(gen_val 1 3 $default)
  135. if [ "$val" == "3" ]; then
  136. val=8
  137. fi
  138. ;;
  139. 4) # YUV400, 1 for ppm format
  140. val=$(gen_val 0 1 $default)
  141. if [ "$val" == "1" ]; then
  142. val=8
  143. fi
  144. ;;
  145. *) echo "Unknown yuv_format: $yuv_format"
  146. exit;;
  147. esac
  148. echo "$val"
  149. }
  150. function gen_yuv_pack_8bit {
  151. local yuv_format=$1
  152. local default=$2
  153. local val
  154. case $yuv_format in
  155. 0) # No conversion
  156. val=0;;
  157. 1) # YUV420
  158. val=$(gen_val 1 2 $default)
  159. ;;
  160. 2) # YUV422
  161. val=$(gen_val 1 6 $default)
  162. ;;
  163. 3) # YUV444, 3 for YUV444 pack
  164. val=$(gen_val 1 3 $default)
  165. if [ "$val" == "3" ]; then
  166. val="7"
  167. fi
  168. ;;
  169. 4) # YUV400
  170. val=0
  171. ;;
  172. *) echo "Unknown yuv_format: $yuv_format"
  173. exit 1;;
  174. esac
  175. echo "$val"
  176. }
  177. function gen_yuv_pack {
  178. local yuv_12bit=$1
  179. local yuv_format=$2
  180. local default=$3
  181. local val
  182. if [ "$yuv_12bit" == "1" ]; then
  183. val=$(gen_yuv_pack_12bit $yuv_format $default)
  184. else
  185. val=$(gen_yuv_pack_8bit $yuv_format $default)
  186. fi
  187. echo "$val"
  188. }
  189. # log_conf log_message log_file
  190. # write @log_message to @log_file
  191. #
  192. function log_conf {
  193. echo "$1" | tee -a "$2"
  194. }
  195. # parse_streamset_file streamset_path *array
  196. # - parse streamset file and store data into @g_stream_file_array
  197. #
  198. function parse_streamset_file {
  199. local f="$1"
  200. local index=0
  201. local line=""
  202. while read -r line || [ -n "$line" ]; do
  203. line="${line#*( )}" # remove front whitespace
  204. line="${line%%[ $'\t']*}" # remove start of whitespace
  205. line="${line//\\//}" # replace backslash to slash
  206. line="${line/$'\r'/}" # remove carriage return
  207. firstchar=${line:0:1}
  208. case "$firstchar" in
  209. "@") break;; # exit flag
  210. "#") continue;; # comment
  211. ";") continue;; # comment
  212. "") continue;; # comment
  213. *)
  214. esac
  215. eval $2[$index]="$line"
  216. index=$(($index + 1))
  217. done < $f
  218. }
  219. function convert_fmt_val_for_cmodel {
  220. local subsample=$1
  221. local orig_subsample=$2
  222. local ordering=$3
  223. ordering=$(tr '[:upper:]' '[:lower:]' <<< $ordering)
  224. cmodel_pn_val=0
  225. cmodel_pk_val=0
  226. cmodel_nv_val=0
  227. if [ "$ordering" == "none" ]; then
  228. case $subsample in
  229. 420) cmodel_pn_val=0;;
  230. 422) cmodel_pn_val=1;;
  231. 444) cmodel_pn_val=3;;
  232. *) cmodel_pn_val=5;;
  233. esac
  234. else
  235. if [ "$ordering" == "nv12" ] || [ "$ordering" == "nv21" ]; then
  236. if [ "$subsample" == "none" ]; then
  237. cmodel_pn_val=5
  238. if [ "$ordering" == "nv12" ]; then
  239. cmodel_pk_val=1
  240. else
  241. cmodel_pk_val=2
  242. fi
  243. else
  244. case $subsample in
  245. 400) cmodel_pn_val=4;;
  246. 420) cmodel_pn_val=0;;
  247. 422) cmodel_pn_val=1;;
  248. 440) cmodel_pn_val=2;;
  249. 444) cmodel_pn_val=3;;
  250. esac
  251. if [ "$ordering" == "nv12" ]; then
  252. cmodel_nv_val=1
  253. else
  254. cmodel_nv_val=2
  255. fi
  256. fi
  257. else
  258. case $ordering in
  259. yuyv) cmodel_pn_val=1
  260. cmodel_pk_val=3;;
  261. uyvy) cmodel_pn_val=1
  262. cmodel_pk_val=4;;
  263. yvyu) cmodel_pn_val=1
  264. cmodel_pk_val=5;;
  265. vyuy) cmodel_pn_val=1
  266. cmodel_pk_val=6;;
  267. ayuv) cmodel_pn_val=3
  268. cmodel_pk_val=7;;
  269. esac
  270. fi
  271. fi
  272. if [ "$g_tiled_mode" == "1" ]; then
  273. if [ "$cmodel_pn_val" == "5" ]; then
  274. # no conversion
  275. cmodel_nv_val=0
  276. cmodel_pk_val=1
  277. fi
  278. fi
  279. }
  280. function convert_fmt_val_for_refsw {
  281. local fmt=$1
  282. local srcsample=$2
  283. g_subsample="none"
  284. g_ordering="none"
  285. case $fmt in
  286. 420p) g_subsample="420";;
  287. 422p) g_subsample="422";;
  288. 444p) g_subsample="444";;
  289. nv12) if [ "$srcsample" != "420" ]; then
  290. g_subsample="420"
  291. fi
  292. g_ordering="nv12";;
  293. nv21) if [ "$srcsample" != "420" ]; then
  294. g_subsample="420"
  295. fi
  296. g_ordering="nv21";;
  297. nv16) if [ "$srcsample" != "422" ]; then
  298. g_subsample="422"
  299. fi
  300. g_ordering="nv12";;
  301. nv61) if [ "$srcsample" != "422" ]; then
  302. g_subsample="422"
  303. fi
  304. g_ordering="nv21";;
  305. nv16v) g_ordering="nv12";;
  306. nv61v) g_ordering="nv21";;
  307. nv24) if [ "$srcsample" != "444" ]; then
  308. g_subsample="444"
  309. fi
  310. g_ordering="nv12";;
  311. nv42) if [ "$srcsample" != "444" ]; then
  312. g_subsample="444"
  313. fi
  314. g_ordering="nv21";;
  315. yuyv) g_ordering="yuyv";;
  316. uyvy) g_ordering="uyvy";;
  317. yvyu) g_ordering="yvyu";;
  318. vyuy) g_ordering="vyuy";;
  319. ayuv) g_ordering="ayuv";;
  320. esac
  321. }
  322. function generate_golden_stream {
  323. local input=$1
  324. local output=$2
  325. local exec_path="${bin_dir}/${refc_exec}"
  326. local param=""
  327. local cmd=""
  328. if [ "$jpeg_12bit" == "1" ]; then
  329. param="-u"
  330. fi
  331. # ref_c do not support tiled mode.
  332. # In case of tiled mode, ref_c output data is same with linear mode.
  333. if [ "$g_tiled_mode" == "1" ]; then
  334. input=$(echo $input | sed 's/_tiled//g')
  335. fi
  336. param="$param -i $input -o ${output}"
  337. param="$param -g $(($g_mirror<<2 | $g_rotation/90))"
  338. param="$param -m 1 -ps $yuv_dir -pc $cfg_dir"
  339. if [ "$g_slice_height" ]; then
  340. param="$param -sh $g_slice_height"
  341. fi
  342. cmd="$exec_path $param"
  343. echo "$cmd"
  344. $cmd
  345. return $?
  346. }
  347. function generate_golden_yuv {
  348. local input=$1
  349. local output=$2
  350. local exec_path="${bin_dir}/${refc_exec}"
  351. local param=""
  352. local cmd=""
  353. if [ "$g_jpeg_12bit" == "true" ]; then
  354. param="-u"
  355. fi
  356. if [ "$cmodel_pn_val" != "" ]; then
  357. param="$param -pn $cmodel_pn_val"
  358. fi
  359. if [ "$cmodel_pk_val" != "" ]; then
  360. param="$param -pk $cmodel_pk_val"
  361. fi
  362. if [ "$cmodel_nv_val" != "" ]; then
  363. param="$param -v $cmodel_nv_val"
  364. fi
  365. param="$param -i $input -o $output"
  366. param="$param -g $(($g_mirror<<2 | $g_rotation/90))"
  367. if [ "$g_scale_h" != "" ]; then
  368. param="$param -sx $g_scale_h"
  369. fi
  370. if [ "$g_scale_v" != "" ]; then
  371. param="$param -sy $g_scale_v"
  372. fi
  373. if [ "$g_pixel_just" == "1" ]; then
  374. param="$param -z"
  375. fi
  376. cmd="$exec_path $param -c"
  377. echo "$cmd"
  378. $cmd
  379. return $?
  380. }
  381. function generate_input_yuv {
  382. local input_cfg=$1
  383. local param=""
  384. local cmd=""
  385. local bit_depth=0
  386. local input_yuv=""
  387. local _srcyuv=""
  388. local _width=0
  389. local _height=0
  390. local _format=0
  391. local _name=""
  392. local _firstchar=""
  393. # Parse input cfg file.
  394. while read cfg_line; do
  395. _firstchar=${cfg_line:0:1}
  396. case "$_firstchar" in
  397. "#") continue;; # comment
  398. ";") continue;; # comment
  399. "") continue;;
  400. esac
  401. _name=$(echo ${cfg_line} | cut -d' ' -f1)
  402. if [ "$_name" = "YUV_SRC_IMG" ]; then
  403. _srcyuv=$(echo ${cfg_line} | cut -d' ' -f2)
  404. elif [ "$_name" = "PICTURE_WIDTH" ]; then
  405. _width=$(echo ${cfg_line} | cut -d' ' -f2)
  406. elif [ "$_name" = "PICTURE_HEIGHT" ]; then
  407. _height=$(echo ${cfg_line} | cut -d' ' -f2)
  408. elif [ "$_name" = "IMG_FORMAT" ]; then
  409. _format=$(echo ${cfg_line} | cut -d' ' -f2)
  410. fi
  411. done < $input_cfg
  412. # Check the file exist
  413. echo "${yuv_dir}/${_srcyuv}"
  414. if [ -f "${yuv_dir}/${_srcyuv}" ]; then
  415. echo "File exist : ${yuv_dir}/${_srcyuv}"
  416. return 0
  417. fi
  418. # Copy lenear yuv
  419. input_yuv=$(echo $_srcyuv | sed 's/_tiled//g')
  420. cp "${yuv_dir}/${input_yuv}" ./
  421. if [ "$jpeg_12bit" == "1" ]; then
  422. bit_depth="16"
  423. else
  424. bit_depth="8"
  425. fi
  426. param="-i ${input_yuv} -o ${_srcyuv} --width=${_width} --height=${_height} --bit-depth=${bit_depth} --format=${_format} --map-type=1"
  427. # Execute tiled_mode program
  428. if [ "$simulation" == "true" ]; then
  429. gcc -o $tiled_exec ../../../fpga/board/ref-sw/tools/tiled_mode.c
  430. else
  431. gcc -o $tiled_exec tools/tiled_mode.c
  432. fi
  433. cmd="$tiled_exec $param"
  434. echo "$cmd"
  435. $cmd
  436. result=$?
  437. if [ "$result" != "0" ]; then
  438. return 1
  439. fi
  440. cp "${_srcyuv}" "${yuv_dir}/${_srcyuv}"
  441. return 0
  442. }
  443. # string get_stream_path(cfgfile)
  444. function generate_golden_stream_path {
  445. local cfgfile=$1
  446. streamset_name=$(basename $streamset_path)
  447. temp=`expr match "$streamset_name" '.*\(_[0-9]*\.cmd\)'`
  448. if [ "$temp" != "" ]; then
  449. streamset_name="${streamset_name%_[0-9]*\.cmd}.cmd"
  450. fi
  451. echo "streamset_name: $streamset_name"
  452. path="${stream_dir}/$codec_dir/$streamset_name"
  453. cfgname=$(basename $cfgfile)
  454. if [ ! -d "$path" ]; then
  455. mkdir -p "$path"
  456. fi
  457. path="$path/${cfgname}_0.$ext"
  458. g_func_ret_str=$path
  459. }
  460. function read_cfg {
  461. local cfg=$1
  462. if [ -f ${cfg} ]; then
  463. while read line2; do
  464. # remove right comment
  465. line2=$(echo $line2 | tr -d '\n')
  466. line2=$(echo $line2 | tr -d '\r')
  467. line2="${line2%%\#*}"
  468. attr=$(echo $line2 | cut -d' ' -f1)
  469. attr=$(echo $attr | tr -d ' ')
  470. value=$(echo $line2 | cut -d' ' -f2)
  471. #echo "attr=$attr, value=$value"
  472. case "$attr" in
  473. PICTURE_WIDTH) cfg_width="$value";;
  474. PICTURE_HEIGHT) cfg_height="$value";;
  475. IMG_FORMAT) cfg_img_format="$value";;
  476. *) ;;
  477. esac
  478. done < $cfg
  479. else
  480. echo "File is not exist ($cfg)"
  481. exit 1
  482. fi
  483. }
  484. function get_jpeg_info {
  485. local format=""
  486. local cmd="${bin_dir}/${refc_exec} -i $1 -m 1"
  487. if [ "$2" == "1" ]; then
  488. cmd="$cmd -u"
  489. fi
  490. $cmd > result.txt
  491. while read line; do
  492. line=$(echo $line | tr -d '\n')
  493. line=$(echo $line | tr -d '\r')
  494. line="${line%%\#*}"
  495. attr=$(echo $line | cut -d':' -f1)
  496. attr=$(echo $attr | tr -d ' ')
  497. value=$(echo $line | cut -d':' -f2-)
  498. value=$(echo $value | tr -d ' ')
  499. value="${value//:/}"
  500. if [ "$attr" == "OutputYUVformat" ]; then
  501. jpg_format="$value"
  502. break
  503. elif [ "$attr" == "Pictureconfig" ]; then
  504. value=${value%@*}
  505. jpg_width=$(echo $value | cut -d'x' -f1)
  506. jpg_height=$(echo $value | cut -d'x' -f2)
  507. fi
  508. done < result.txt
  509. echo "$format"
  510. }
  511. function gen_valid_slice_height {
  512. local pic_width=$1
  513. local pic_height=$2
  514. local fmt=$3
  515. local default=$4
  516. local temp=0
  517. local sample_factor_x=1
  518. local sample_factor_y=1
  519. local mcu_height=8
  520. local slice_height=0
  521. local num_mcu_h=0
  522. if [ ! -z $default ] && [ "$default" != "-99" ]; then
  523. echo "$default"
  524. return
  525. fi
  526. case $fmt in
  527. 0) # YUV420
  528. sample_factor_x=2
  529. sample_factor_y=2
  530. mcu_height=16;;
  531. 1) # YUV422
  532. sample_factor_x=2
  533. mcu_height=8;;
  534. 2) # YUV440
  535. sample_factor_y=2
  536. mcu_height=16;;
  537. 4) # YUV400
  538. mcu_height=32;;
  539. *) ;;
  540. esac
  541. num_mcu_h=$(($pic_height/$mcu_height))
  542. mcu_num_x_fac=$(($sample_factor_x * 8))
  543. mcu_num_y_fac=$(($sample_factor_y * 8))
  544. mcu_num_w=$((($pic_width+($mcu_num_x_fac-1))/$mcu_num_x_fac))
  545. temp=$(gen_val 1 $(($pic_height / $mcu_height)) $default)
  546. while [ $temp -gt 0 ] ; do
  547. slice_height=$(($temp * $mcu_height))
  548. s_mcu_num_h=$((($slice_height+($mcu_num_y_fac-1))/$mcu_num_y_fac))
  549. total_mcu_in_slice=$(($mcu_num_w * $s_mcu_num_h))
  550. if [ $total_mcu_in_slice -lt 65536 ]; then
  551. # A value of restart interval should be less than 65536
  552. break
  553. fi
  554. temp=$(gen_val 1 $(($pic_height / $mcu_height)) $default)
  555. done
  556. if [ "$slice_height" == "$pic_height" ]; then
  557. slice_height=$(($slice_height - $mcu_height))
  558. fi
  559. echo "$slice_height"
  560. }