[Test/Transform/Arithmetic] Update checkResult script to support integer
authorWook Song <wook16.song@samsung.com>
Wed, 13 Mar 2019 06:33:29 +0000 (15:33 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 15 Mar 2019 01:31:42 +0000 (10:31 +0900)
Since the python script for checking unit test results has only
supported values of floating-point type until now, this patch updates
the script to support integer so that more test cases using integer
values could be added.

Signed-off-by: Wook Song <wook16.song@samsung.com>
tests/transform_arithmetic/checkResult.py

index d381e4f..cab20a0 100644 (file)
@@ -14,6 +14,17 @@ import sys
 import struct
 
 ##
+# @brief Get value of proper type corresponding to the unpack format string
+#
+def getValue (val, unpack_format):
+    if unpack_format in ['b', 'B', 'h', 'H', 'i', 'I', 'q', 'Q']:
+        return int(val)
+    elif unpack_format in ['f', 'd']:
+        return float(val)
+    else:
+        return None
+
+##
 # @brief Check typecast from typea to typeb with file fna/fnb
 #
 def testArithmetic (fna, fnb, typeasize, typebsize,typeapack, typebpack, mode, value1, value2):
@@ -27,23 +38,28 @@ def testArithmetic (fna, fnb, typeasize, typebsize,typeapack, typebpack, mode, v
     return 11
   limitb = 2 ** (8 * typebsize)
   maskb = limitb - 1
+  value1 = getValue(value1, typeapack)
+  value2 = getValue(value2, typebpack)
+  if value1 is None or value2 is None:
+      return 12
+
   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 (mode == 'add'):
-      diff = vala + float(value1) - valb
+      diff = vala  + value1 - valb
       if diff > 0.01 or diff < -0.01:
         return 20
     elif (mode == 'mul'):
-      diff = vala * float(value1) - valb
+      diff = vala * value1 - valb
       if diff > 0.01 or diff < -0.01:
         return 20
     elif (mode == 'add-mul'):
-      diff = (vala + float(value1)) * float(value2) - valb
+      diff = (vala + value1) * value2 - valb
       if diff > 0.01 or diff < -0.01:
         return 20
     elif (mode == 'mul-add'):
-      diff = (vala * float(value1)) + float(value2) - valb
+      diff = (vala * value1) + value2 - valb
       if diff > 0.01 or diff < -0.01:
         return 20
     else: