test suite reviews and discussions
 help / color / mirror / Atom feed
From: Yong Liu <yong.liu@intel.com>
To: dts@dpdk.org
Subject: [dts] [PATCH] Add simple tool to dump function and performance case
Date: Thu, 13 Aug 2015 12:09:57 +0800	[thread overview]
Message-ID: <1439438997-19205-1-git-send-email-yong.liu@intel.com> (raw)

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

                 reply	other threads:[~2015-08-13  4:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439438997-19205-1-git-send-email-yong.liu@intel.com \
    --to=yong.liu@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).