From 5f0043ac76b2c4108bbabebc223e7cc1db2ec398 Mon Sep 17 00:00:00 2001 From: MyungJoo Ham Date: Thu, 17 May 2018 20:09:45 +0900 Subject: [PATCH] [Convert] Add test cases based on randomly generated PNG files 1. Test more input sources 2. Test with offset case 3. Added doxygen entries (Updated with test case 2 fix for the cases where width % 4 > 0) Signed-off-by: MyungJoo Ham --- tensor_converter/test/.gitignore | 1 + tensor_converter/test/generateGoldenTestResult.py | 58 ++++++++++++++++++++++- tensor_converter/test/runTest.sh | 1 + tensor_converter/test/testcase01.sh | 10 ++++ tensor_converter/test/testcase02.sh | 49 +++++++++++++++++++ 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100755 tensor_converter/test/testcase02.sh diff --git a/tensor_converter/test/.gitignore b/tensor_converter/test/.gitignore index 07d04a6..90e6bcf 100644 --- a/tensor_converter/test/.gitignore +++ b/tensor_converter/test/.gitignore @@ -1,2 +1,3 @@ *.log *.golden +*.png diff --git a/tensor_converter/test/generateGoldenTestResult.py b/tensor_converter/test/generateGoldenTestResult.py index a3debd4..0e2ed72 100755 --- a/tensor_converter/test/generateGoldenTestResult.py +++ b/tensor_converter/test/generateGoldenTestResult.py @@ -1,4 +1,6 @@ #!/usr/bin/env python + +## # Copyright (C) 2018 Samsung Electronics # License: Apache-2.0 # @@ -9,8 +11,13 @@ from __future__ import print_function from struct import * +from PIL import Image +import random -# Returns: (string, string_size, expected_size) +## +# @brief Generate Golden Test Case 01, a single videosrctest frame of 280x40xRGB +# @return (string, string_size, expected_size) +# # If string_size < expected_size, you do not need to check the results offset >= string_size. # string: binary string (b'\xff\x00....') def genCase01_RGB(): @@ -99,6 +106,10 @@ def genCase01_RGB(): string_size = string_size * 3 return (string, string_size, expected_size) +## +# @brief Generate Golden Test Case 01, a single videosrctest frame of 280x40xBGRx +# @return (string, string_size, expected_size) +# def genCase01_BGRx(): string = "" string_size = 0 @@ -185,11 +196,54 @@ def genCase01_BGRx(): string_size = string_size * 4 return (string, string_size, expected_size) +## +# @brief Generate Golden Test Case 02, a randomly generated PNG image +# @return (string, string_size, expected_size) +# +def genCase02_PNG_random(colorType, width, height): + string = "" + string_size = 0 + sizePerPixel = 3 + if (colorType == 'BGRx'): + sizePerPixel = 4 + expected_size = width * height * sizePerPixel + img = Image.new('RGB', (width, height)) + imgbin = [] + + # The result has no stride for other/tensor types. + + if (colorType == 'BGRx'): + for y in range(0, height): + for x in range(0, width): + pval = (random.randrange(256), random.randrange(256), random.randrange(256)) + pixel = pack('BBBB', pval[2], pval[1], pval[0], 255) + string += pixel + imgbin.append(pval) + string_size += 4 + else: + # Assume RGB + for y in range(0, height): + for x in range(0, width): + pval = (random.randrange(256), random.randrange(256), random.randrange(256)) + pixel = pack('BBB', pval[0], pval[1], pval[2]) + string += pixel + imgbin.append(pval) + string_size += 3 + + img.putdata(imgbin) + img.save('testcase02_'+colorType+'_'+str(width)+'x'+str(height)+'.png') + return (string, string_size, expected_size) +## +# @brief Write the generated data +# def write(filename, string): newfile = open(filename, 'wb') newfile.write(string) write('testcase01.rgb.golden', genCase01_RGB()[0]) write('testcase01.bgrx.golden', genCase01_BGRx()[0]) - +write('testcase02_RGB_640x480.golden', genCase02_PNG_random('RGB', 640, 480)[0]) +write('testcase02_BGRx_640x480.golden', genCase02_PNG_random('BGRx', 640, 480)[0]) +write('testcase02_RGB_642x480.golden', genCase02_PNG_random('RGB', 642, 480)[0]) +write('testcase02_BGRx_642x480.golden', genCase02_PNG_random('BGRx', 642, 480)[0]) diff --git a/tensor_converter/test/runTest.sh b/tensor_converter/test/runTest.sh index 7e2f200..6521488 100755 --- a/tensor_converter/test/runTest.sh +++ b/tensor_converter/test/runTest.sh @@ -4,6 +4,7 @@ failed=0 python generateGoldenTestResult.py ./testcase01.sh $1 || failed=1 +./testcase02.sh $1 || failed=1 echo "" diff --git a/tensor_converter/test/testcase01.sh b/tensor_converter/test/testcase01.sh index 43f581a..8167745 100755 --- a/tensor_converter/test/testcase01.sh +++ b/tensor_converter/test/testcase01.sh @@ -1,4 +1,14 @@ #!/usr/bin/env bash + +## +# Copyright (C) 2018 Samsung Electronics +# License: Apache-2.0 +# +# @file testcase01.sh +# @brief Test tensor_converter for testcase 01 +# @author MyungJoo Ham +# @dependency cmp + if [ $# -eq 0 ] then PATH_TO_PLUGIN="$PWD/../../build" diff --git a/tensor_converter/test/testcase02.sh b/tensor_converter/test/testcase02.sh new file mode 100755 index 0000000..07b77ed --- /dev/null +++ b/tensor_converter/test/testcase02.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +## +# Copyright (C) 2018 Samsung Electronics +# License: Apache-2.0 +# +# @file testcase02.sh +# @brief Test tensor_converter for testcase 02 +# @author MyungJoo Ham +# @dependency cmp + +if [ $# -eq 0 ] +then + PATH_TO_PLUGIN="$PWD/../../build" +else + PATH_TO_PLUGIN="$1" +fi + +failed=0 + +# Generate one frame only (num-buffers=1) +do_test() +{ + echo + echo "Case 2 - $1 $2 x $3" + echo + echo gst-launch-1.0 -q --gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=testcase02_${1}_${2}x${3}.png ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=${1},width=${2},height=${3},framerate=0/1 ! tensor_converter ! filesink location="testcase02_${1}_${2}x${3}.log" sync=true + gst-launch-1.0 --gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=testcase02_${1}_${2}x${3}.png ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=${1},width=${2},height=${3},framerate=0/1 ! tensor_converter ! filesink location="testcase02_${1}_${2}x${3}.log" sync=true || failed=1 + + if [ "$failed" -eq "1" ] + then + echo gst-launch failed + fi + cmp -n `stat --printf="%s" testcase02_${1}_${2}x${3}.golden` testcase02_${1}_${2}x${3}.log testcase02_${1}_${2}x${3}.golden || failed=1 +} + +do_test BGRx 640 480 +do_test RGB 640 480 +do_test BGRx 642 480 +do_test RGB 642 480 + +if [ "$failed" -eq "0" ] +then + echo Testcase 02: SUCCESS + exit 0 +else + echo Testcase 02: FAILED + exit -1 +fi -- 2.7.4