[Transform] Add testcases for transpose
authorjijoong.moon <jijoong.moon@samsung.com>
Mon, 5 Nov 2018 01:24:27 +0000 (10:24 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Mon, 5 Nov 2018 07:02:08 +0000 (16:02 +0900)
Add thress trasnpose test cases
1. Tensor 100:50:3:1  --> Tensor 3:100:50:1
2. Tensor 200:100:3:1  --> Tensor 3:200:100:1
3. Tensor 200:100:3:1  --> Tensor 100:200:3:1

**Self evaluation:**
1. Build test:  [X]Passed [ ]Failed [ ]Skipped
2. Run test:  [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: jijoong.moon <jijoong.moon@samsung.com>
tests/transform_transpose/generateTest.py [new file with mode: 0755]
tests/transform_transpose/runTest.sh [new file with mode: 0755]

diff --git a/tests/transform_transpose/generateTest.py b/tests/transform_transpose/generateTest.py
new file mode 100755 (executable)
index 0000000..a35c2b0
--- /dev/null
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+
+##
+# Copyright (C) 2018 Samsung Electronics
+# License: LGPL-2.1
+#
+# @file generateTest.py
+# @brief Generate golden test results for test cases
+# @author Jijoong Moon <jijoong.moon@samsung.com>
+
+import sys
+import os
+sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+from struct import pack
+import random
+
+import numpy as np
+
+def saveTestData(filename, channel, height, width, batch, idx_i, idx_j, idx_k, idx_l):
+    string = b''
+    data = []
+
+    for b in range(0,batch):
+        for c in range(0,channel):
+            for h in range(0,height):
+                for w in range(0,width):
+                    n = random.uniform(0.0, 10.0)
+                    string += pack('f', n)
+                    data.append(n)
+
+    with open(filename,'wb') as file:
+        file.write(string)
+
+    file.close()
+
+    a=np.ndarray((batch, channel, height, width), np.float32);
+
+    for b in range(0,batch):
+        for c in range(0,channel):
+            for h in range(0,height):
+                for w in range(0,width):
+                    a[b][c][h][w] = data[b*channel*height*width+c*height*width+h*width+w]
+
+    a=np.transpose(a, (idx_i,idx_j,idx_k,idx_l))
+
+    a=a.copy(order='C')
+
+    with open(filename+".golden",'wb') as file1:
+        file1.write(a)
+    file1.close()
+
+    return a
+
+buf = saveTestData("test01_00.dat", 3, 50, 100, 1, 0, 2, 3, 1)
+
+buf = saveTestData("test02_00.dat", 3, 100, 200, 1, 0, 2, 3, 1)
+
+buf = saveTestData("test03_00.dat", 3, 100, 200, 1, 0, 1, 3, 2)
diff --git a/tests/transform_transpose/runTest.sh b/tests/transform_transpose/runTest.sh
new file mode 100755 (executable)
index 0000000..6a5a991
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+##
+## @file runTest.sh
+## @author MyungJoo Ham <myungjoo.ham@gmail.com>
+## @date Nov 01 2018
+## @brief SSAT Test Cases for NNStreamer
+##
+if [[ "$SSATAPILOADED" != "1" ]]
+then
+       SILENT=0
+       INDEPENDENT=1
+       search="ssat-api.sh"
+       source $search
+       printf "${Blue}Independent Mode${NC}
+"
+fi
+
+# This is compatible with SSAT (https://github.com/myungjoo/SSAT)
+testInit $1
+
+if [ "$SKIPGEN" == "YES" ]
+then
+  echo "Test Case Generation Skipped"
+  sopath=$2
+else
+  echo "Test Case Generation Started"
+  python generateTest.py
+  sopath=$1
+fi
+
+# 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 0 0 $PERFORMANCE
+
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test01_%02d.dat\" caps=\"application/octet-stream\" ! tensor_converter input-dim=100:50:3:1 input-type=float32 ! tensor_transform mode=transpose option=2:0:1:3 ! multifilesink location=\"./result01_%02d.log\" sync=true" 1 0 0 $PERFORMANCE
+
+callCompareTest test01_00.dat.golden result01_00.log 1 "Compare 1" 1 0
+
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test02_%02d.dat\" caps=\"application/octet-stream\" ! tensor_converter input-dim=200:100:3:1 input-type=float32 ! tensor_transform mode=transpose option=2:0:1:3 ! multifilesink location=\"./result02_%02d.log\" sync=true" 2 0 0 $PERFORMANCE
+
+callCompareTest test02_00.dat.golden result02_00.log 2 "Compare 2" 1 0
+
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test03_%02d.dat\" caps=\"application/octet-stream\" ! tensor_converter input-dim=200:100:3:1 input-type=float32 ! tensor_transform mode=transpose option=1:0:2:3 ! multifilesink location=\"./result03_%02d.log\" sync=true" 3 0 0 $PERFORMANCE
+
+callCompareTest test03_00.dat.golden result03_00.log 3 "Compare 3" 1 0
+
+report