[Convert] Add test cases based on randomly generated PNG files
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 17 May 2018 11:09:45 +0000 (20:09 +0900)
committer함명주/동작제어Lab(SR)/Principal Engineer/삼성전자 <myungjoo.ham@samsung.com>
Tue, 29 May 2018 00:56:04 +0000 (09:56 +0900)
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 <myungjoo.ham@samsung.com>
tensor_converter/test/.gitignore
tensor_converter/test/generateGoldenTestResult.py
tensor_converter/test/runTest.sh
tensor_converter/test/testcase01.sh
tensor_converter/test/testcase02.sh [new file with mode: 0755]

index a3debd4..0e2ed72 100755 (executable)
@@ -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])
index 7e2f200..6521488 100755 (executable)
@@ -4,6 +4,7 @@ failed=0
 
 python generateGoldenTestResult.py
 ./testcase01.sh $1 || failed=1
+./testcase02.sh $1 || failed=1
 
 
 echo ""
index 43f581a..8167745 100755 (executable)
@@ -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 <myungjoo.ham@samsung.com>
+# @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 (executable)
index 0000000..07b77ed
--- /dev/null
@@ -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 <myungjoo.ham@samsung.com>
+# @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