[Test/Transform] Add testcases for typecast transform
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 20 Jul 2018 05:41:56 +0000 (14:41 +0900)
committer문지중/동작제어Lab(SR)/Principal Engineer/삼성전자 <jijoong.moon@samsung.com>
Wed, 25 Jul 2018 07:27:52 +0000 (16:27 +0900)
This probides unit test cases (golden tests) for
typecast transform.

Fixes #306

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
tests/transform_typecast/checkResult.py [new file with mode: 0644]
tests/transform_typecast/runTest.sh [new file with mode: 0755]

diff --git a/tests/transform_typecast/checkResult.py b/tests/transform_typecast/checkResult.py
new file mode 100644 (file)
index 0000000..441b2a5
--- /dev/null
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+##
+# Copyright (C) 2018 Samsung Electronics
+# License: LGPL-2.1
+#
+# @file checkResult.py
+# @brief Check if the tranform results are correct with typecast
+# @author MyungJoo Ham <myungjoo.ham@samsung.com>
+# @date 20 Jul 2018
+# @bug No known bugs
+
+import sys
+import struct
+
+##
+# @brief Check typecast from typea to typeb with file fna/fnb
+#
+def testTypeCast (fna, fnb, typea, typeasize, typeapack, typeb, typebsize, typebpack):
+  lena = len(fna)
+  lenb = len(fnb)
+
+  if (0 < (lena % typeasize)) or (0 < (lenb % typebsize)):
+    return 10
+  num = lena / typeasize
+  if num != (lenb / typebsize):
+    return 11
+  limitb = 2 ** (8 * typebsize)
+  maskb = limitb - 1
+
+  for x in range(0, num):
+    vala = struct.unpack(typeapack, fna[x * typeasize: x * typeasize + typeasize])[0]
+    valb = struct.unpack(typebpack, fnb[x * typebsize: x * typebsize + typebsize])[0]
+    if (typeb[0:5] == 'float'):
+      diff = float(vala) - valb
+      if diff > 0.01 or diff < -0.01:
+        return 20
+    elif (typeb[0:4] == 'uint' or typeb[0:3] == 'int'):
+      vala = int(vala)
+      vala = vala & maskb
+      valb = int(valb)
+
+      # Remove the signedness characteristics!
+      diff = (vala ^ valb) & maskb
+      if (diff != 0):
+        print ("WTH?? "+str(vala)+"->"+str(valb)+"\n")
+        return 20
+    else:
+      return 21
+  return 0
+
+def readfile (filename):
+  F = open(filename, 'r')
+  readfile = F.read()
+  F.close
+  return readfile
+
+if len(sys.argv) < 2:
+  exit(5)
+
+if (sys.argv[1] == 'typecast'):
+  if len(sys.argv) < 10:
+    exit(5)
+  fna = readfile(sys.argv[2])
+  fnb = readfile(sys.argv[3])
+  typea = sys.argv[4]
+  typeasize = int(sys.argv[5])
+  typeapack = sys.argv[6]
+  typeb = sys.argv[7]
+  typebsize = int(sys.argv[8])
+  typebpack = sys.argv[9]
+  exit(testTypeCast(fna, fnb, typea, typeasize, typeapack, typeb, typebsize, typebpack))
+
+exit(5)
diff --git a/tests/transform_typecast/runTest.sh b/tests/transform_typecast/runTest.sh
new file mode 100755 (executable)
index 0000000..65a4e3c
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+source ../testAPI.sh
+
+if [ "$SKIPGEN" == "YES" ]
+then
+  echo "Test Case Generation Skipped"
+  sopath=$2
+else
+  echo "Test Case Generation Started"
+  python ../nnstreamer_converter/generateGoldenTestResult.py 8
+  sopath=$1
+fi
+convertBMP2PNG
+
+# Test gst availability. (0)
+gstTest "videotestsrc num-buffers=1 ! video/x-raw,format=RGB,width=280,height=40,framerate=0/1 ! videoconvert ! video/x-raw, format=RGB ! filesink location=\"testcase.apitest.log\" sync=true" 0
+
+# Test with small stream (1, 2)
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"testsequence_%1d.png\" index=0 caps=\"image/png,framerate=\(fraction\)30/1\" ! pngdec ! videoconvert ! video/x-raw, format=RGB ! tensor_converter ! tee name=t ! queue ! tensor_transform mode=typecast option=uint32 ! filesink location=\"testcase01.typecast.log\" sync=true t. ! queue ! filesink location=\"testcase01.direct.log\" sync=true" 1
+# uint8 -> uint32
+python checkResult.py typecast testcase01.direct.log testcase01.typecast.log uint8 1 B uint32 4 I
+casereport 1 $? "Golden test comparison"
+
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"testsequence_%1d.png\" index=0 caps=\"image/png,framerate=\(fraction\)30/1\" ! pngdec ! videoconvert ! video/x-raw, format=BGRx ! tensor_converter ! tee name=t ! queue ! tensor_transform mode=typecast option=uint16 ! filesink location=\"testcase02.typecast.log\" sync=true t. ! queue ! filesink location=\"testcase02.direct.log\" sync=true" 2
+# uint8 -> uint32
+python checkResult.py typecast testcase02.direct.log testcase02.typecast.log uint8 1 B uint16 2 H
+casereport 2 $? "Golden test comparison"
+
+
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"testsequence_%1d.png\" index=0 caps=\"image/png,framerate=\(fraction\)30/1\" ! pngdec ! videoconvert ! video/x-raw, format=BGRx ! tensor_converter ! tee name=t ! queue ! tensor_transform mode=typecast option=int8 ! filesink location=\"testcase03.typecast.log\" sync=true t. ! queue ! filesink location=\"testcase03.direct.log\" sync=true" 3
+# uint8 -> int8
+python checkResult.py typecast testcase03.direct.log testcase03.typecast.log uint8 1 B int8 1 b
+casereport 3 $? "Golden test comparison"
+
+
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"testsequence_%1d.png\" index=0 caps=\"image/png,framerate=\(fraction\)30/1\" ! pngdec ! videoconvert ! video/x-raw, format=BGRx ! tensor_converter ! tee name=t ! queue ! tensor_transform mode=typecast option=uint32 ! tensor_transform mode=typecast option=uint8 ! filesink location=\"testcase04.typecast.log\" sync=true t. ! queue ! filesink location=\"testcase04.direct.log\" sync=true" 4
+# uint8 -> uint32 -> uint8
+python checkResult.py typecast testcase04.direct.log testcase04.typecast.log uint8 1 B uint8 1 B
+casereport 4 $? "Golden test comparison"
+
+report