From 3954f35080b8a2b63a66c96a92128cc9b3c6c3a2 Mon Sep 17 00:00:00 2001 From: Billy O'Mahony Date: Fri, 28 Aug 2015 16:09:07 +0100 Subject: bugfix: Allow exact test names The current --tests option can make it hard to specify a single test to run. This patch allows specification of tests using exact names. JIRA: VSPERF-58 Signed-off-by: Billy O'Mahony Reviewed-by: Maryam Tahhan Reviewed-by: Martin Klozik Reviewed-by: Radek Zetik Reviewed-by: Dino Madarang Reviewed-by: Brian Castelli Change-Id: Ib820bdae96d6257d785f4e310a3b3d1fbfa1b575 --- vsperf | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/vsperf b/vsperf index d5086ac4..7c9f0187 100755 --- a/vsperf +++ b/vsperf @@ -126,7 +126,10 @@ def parse_arguments(): help='list all system vnfs and exit') parser.add_argument('--list-settings', action='store_true', help='list effective settings configuration and exit') - parser.add_argument('test', nargs='*', help='test specification(s)') + parser.add_argument('exact_test_name', nargs='*', help='Exact names of\ + tests to run. E.g "vsperf phy2phy_tput phy2phy_cont"\ + runs only the two tests with those exact names.\ + To run all tests omit both positional args and --tests arg.') group = parser.add_argument_group('test selection options') group.add_argument('-f', '--test-spec', help='test specification file') @@ -353,9 +356,6 @@ def main(): cfg.get('Name', '')) raise - # TODO(BOM) Apply filter to select requested tests - all_tests = apply_filter(all_tests, args['tests']) - # if required, handle list-* operations if args['list']: @@ -385,15 +385,34 @@ def main(): print(str(settings)) exit() + # select requested tests + if args['exact_test_name'] and args['tests']: + logger.error("Cannot specify tests with both positional args and --test.") + sys.exit(1) + + if args['exact_test_name']: + exact_names = args['exact_test_name'] + # positional args => exact matches only + selected_tests = [test for test in all_tests if test.name in exact_names] + elif args['tests']: + # --tests => apply filter to select requested tests + selected_tests = apply_filter(all_tests, args['tests']) + else: + # Default - run all tests + selected_tests = all_tests + + if not selected_tests: + logger.error("No tests matched --test option or positional args. Done.") + sys.exit(1) + # create results directory if not os.path.exists(results_path): logger.info("Creating result directory: " + results_path) os.makedirs(results_path) - suite = unittest.TestSuite() - # run tests - for test in all_tests: + suite = unittest.TestSuite() + for test in selected_tests: try: test.run() suite.addTest(MockTestCase('', True, test.name)) -- cgit 1.2.3-korg