[Filter/Custom/Example] Add unittest case for "Average"
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 4 Jul 2018 05:53:48 +0000 (14:53 +0900)
committer문지중/동작제어Lab(SR)/Principal Engineer/삼성전자 <jijoong.moon@samsung.com>
Wed, 4 Jul 2018 06:58:54 +0000 (15:58 +0900)
Added unittest case for "Average" filter.
Fixed bug found by the unittest.

Fixes #58

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
nnstreamer_example/custom_example_average/nnstreamer_customfilter_example_average.c
tests/nnstreamer_filter_custom/runTest.sh

index 15779d1..7b3fcdb 100644 (file)
@@ -63,8 +63,8 @@ set_inputDim (void *private_data, const GstTensor_Filter_Properties * prop,
 }
 
 
-#define do_avg(type) do {\
-      type *avg = (type *) malloc(sizeof(type) * prop->inputDimension[0]); \
+#define do_avg(type, sumtype) do {\
+      sumtype *avg = (sumtype *) malloc(sizeof(sumtype) * prop->inputDimension[0]); \
       type *iptr = (type *) inptr; \
       type *optr = (type *) outptr; \
       for (z = 0; z < prop->inputDimension[3]; z++) { \
@@ -111,28 +111,28 @@ pt_invoke (void *private_data, const GstTensor_Filter_Properties * prop,
 
   switch (prop->inputType) {
     case _NNS_INT8:
-      do_avg (int8_t);
+      do_avg (int8_t, int64_t);
       break;
     case _NNS_INT16:
-      do_avg (int16_t);
+      do_avg (int16_t, int64_t);
       break;
     case _NNS_INT32:
-      do_avg (int32_t);
+      do_avg (int32_t, int64_t);
       break;
     case _NNS_UINT8:
-      do_avg (uint8_t);
+      do_avg (uint8_t, uint64_t);
       break;
     case _NNS_UINT16:
-      do_avg (uint16_t);
+      do_avg (uint16_t, uint64_t);
       break;
     case _NNS_UINT32:
-      do_avg (uint32_t);
+      do_avg (uint32_t, uint64_t);
       break;
     case _NNS_FLOAT32:
-      do_avg (float);
+      do_avg (float, long double);
       break;
     case _NNS_FLOAT64:
-      do_avg (double);
+      do_avg (double, long double);
       break;
 
     default:
index cd408f6..7d36d26 100755 (executable)
@@ -32,12 +32,19 @@ compareAll testcase04.direct.log testcase04.passthrough.log 4
 # Test scaler (5, 6, 7)
 PATH_TO_MODEL_S="../../build/nnstreamer_example/custom_example_scaler/libnnstreamer_customfilter_scaler.so"
 
-gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=1 ! video/x-raw,format=RGB,width=640,height=480,framerate=0/1 ! videoconvert ! video/x-raw, format=RGB ! tensor_converter ! tee name=t ! queue ! tensor_filter framework=\"custom\" model=\"${PATH_TO_MODEL_S}\" custom=\"640x480\" ! filesink location=\"testcase05.passthrough.log\" sync=true t. ! queue ! filesink location=\"testcase05.direct.log\" sync=true" 5
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=1 ! video/x-raw,format=RGB,width=640,height=480,framerate=0/1 ! videoconvert ! video/x-raw, format=RGB ! tensor_converter ! tee name=t ! queue ! tensor_filter framework=\"custom\" model=\"${PATH_TO_MODEL_S}\" ! filesink location=\"testcase05.passthrough.log\" sync=true t. ! queue ! filesink location=\"testcase05.direct.log\" sync=true" 5
 compareAll testcase05.direct.log testcase05.passthrough.log 5
 
 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=1 ! video/x-raw,format=RGB,width=640,height=480,framerate=0/1 ! videoconvert ! video/x-raw, format=RGB ! tensor_converter ! tee name=t ! queue ! tensor_filter framework=\"custom\" model=\"${PATH_TO_MODEL_S}\" custom=\"320x240\" ! filesink location=\"testcase06.scaled.log\" sync=true t. ! queue ! filesink location=\"testcase06.direct.log\" sync=true" 6
 python checkScaledTensor.py testcase06.direct.log 640 480 testcase06.scaled.log 320 240 3
 casereport 6 $? "Golden test comparison"
 
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=1 ! video/x-raw,format=RGB,width=640,height=480,framerate=0/1 ! videoconvert ! video/x-raw, format=RGB ! tensor_converter ! tee name=t ! queue ! tensor_filter framework=\"custom\" model=\"${PATH_TO_MODEL_S}\" custom=\"1280X960\" ! filesink location=\"testcase07.scaled.log\" sync=true t. ! queue ! filesink location=\"testcase07.direct.log\" sync=true" 6
+python checkScaledTensor.py testcase07.direct.log 640 480 testcase07.scaled.log 1280 960 3
+casereport 7 $? "Golden test comparison"
+
+# Test average (8)
+PATH_TO_MODEL_A="../../build/nnstreamer_example/custom_example_average/libnnstreamer_customfilter_average.so"
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=1 ! video/x-raw,format=RGB,width=640,height=480,framerate=0/1 ! videoconvert ! video/x-raw, format=RGB ! tensor_converter ! tee name=t ! queue ! tensor_filter framework=\"custom\" model=\"${PATH_TO_MODEL_A}\" ! filesink location=\"testcase08.average.log\" sync=true t. ! queue ! filesink location=\"testcase08.direct.log\" sync=true" 8
 
 report