test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH] Add simple tool to dump function and performance case
@ 2015-08-13  4:09 Yong Liu
  0 siblings, 0 replies; only message in thread
From: Yong Liu @ 2015-08-13  4:09 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Dump separated performance and function case with json format.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

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()
-- 
1.9.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-13  4:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-13  4:09 [dts] [PATCH] Add simple tool to dump function and performance case Yong Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).