summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Liu <yong.liu@intel.com>2015-08-13 12:09:57 +0800
committerMarvin Liu <yong.liu@intel.com>2015-08-13 13:17:06 +0800
commit836e580abe87becc244265120e1f64d11ce1036c (patch)
tree771f814f4d2a892b2108d96a9cdd27bf975c673a
parentfafde327bf4584da4d00f9e6ee9a6a911f176d9c (diff)
downloaddts-836e580abe87becc244265120e1f64d11ce1036c.zip
dts-836e580abe87becc244265120e1f64d11ce1036c.tar.gz
dts-836e580abe87becc244265120e1f64d11ce1036c.tar.xz
Add simple tool to dump function and performance case
Dump separated performance and function case with json format. Signed-off-by: Marvin Liu <yong.liu@intel.com>
-rwxr-xr-xtools/dump_case.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/tools/dump_case.py b/tools/dump_case.py
new file mode 100755
index 0000000..cb866fc
--- /dev/null
+++ b/tools/dump_case.py
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+import sys
+import os
+import re
+import inspect
+import json
+
+exec_file = os.path.realpath(__file__)
+DTS_PATH = exec_file.replace('/tools/dump_case.py', '')
+
+DTS_SUITES = DTS_PATH + '/tests'
+DTS_FRAMEWORK = DTS_PATH + '/framework'
+
+sys.path.append(DTS_SUITES)
+sys.path.append(DTS_FRAMEWORK)
+
+import dts
+from test_case import TestCase
+from utils import pprint
+
+
+def get_subclasses(module, clazz):
+ """
+ Get module attribute name and attribute.
+ """
+ for subclazz_name, subclazz in inspect.getmembers(module):
+ if hasattr(subclazz, '__bases__') and clazz in subclazz.__bases__:
+ yield (subclazz_name, subclazz)
+
+
+def scan_suites():
+ global suites
+ suite_reg = r'TestSuite_(.*).py$'
+
+ suites = []
+ files = os.listdir(DTS_SUITES)
+ for file_name in files:
+ m = re.match(suite_reg, file_name)
+ if m:
+ suites.append(m.group(1))
+
+ suites = sorted(suites)
+
+
+def get_cases(test_suite, test_name_regex):
+ """
+ Return case list which name matched regex.
+ """
+ cases = []
+ for test_case_name in dir(test_suite):
+ test_case = getattr(test_suite, test_case_name)
+ if callable(test_case) and re.match(test_name_regex, test_case_name):
+ cases.append(test_case_name)
+
+ return cases
+
+
+def get_functional_test_cases(test_suite):
+ """
+ Get all functional test cases.
+ """
+ return get_cases(test_suite, r'test_(?!perf_)')
+
+
+def get_performance_test_cases(test_suite):
+ """
+ Get all performance test cases.
+ """
+ return get_cases(test_suite, r'test_perf_')
+
+
+class simple_dut(object):
+
+ def __init__(self):
+ self.ports_info = []
+
+
+def load_cases():
+ dut = simple_dut()
+ suite_func_list = {}
+ suite_perf_list = {}
+ for suite in suites:
+ test_module = __import__('TestSuite_' + suite)
+ for classname, test_class in get_subclasses(test_module, TestCase):
+ test_suite = test_class(dut, None, None, suite)
+ func_cases = get_functional_test_cases(test_suite)
+ perf_cases = get_performance_test_cases(test_suite)
+ suite_func_list[suite] = func_cases
+ suite_perf_list[suite] = perf_cases
+
+ print pprint(suite_func_list)
+ print pprint(suite_perf_list)
+
+
+if __name__ == '__main__':
+ scan_suites()
+ load_cases()