From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id F09468D88 for ; Thu, 13 Aug 2015 06:10:03 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 12 Aug 2015 21:10:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,667,1432623600"; d="scan'208";a="540917653" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by FMSMGA003.fm.intel.com with ESMTP; 12 Aug 2015 21:10:02 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t7D4A0HK026236; Thu, 13 Aug 2015 12:10:00 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t7D49ws5019241; Thu, 13 Aug 2015 12:10:00 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t7D49wtF019237; Thu, 13 Aug 2015 12:09:58 +0800 From: Yong Liu To: dts@dpdk.org Date: Thu, 13 Aug 2015 12:09:57 +0800 Message-Id: <1439438997-19205-1-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dts] [PATCH] Add simple tool to dump function and performance case X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Aug 2015 04:10:04 -0000 From: Marvin Liu Dump separated performance and function case with json format. Signed-off-by: Marvin Liu 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