bugfix: Allow exact test names 63/1363/4
authorBilly O'Mahony <billy.o.mahony@intel.com>
Fri, 28 Aug 2015 15:09:07 +0000 (16:09 +0100)
committerMaryam Tahhan <maryam.tahhan@intel.com>
Tue, 8 Sep 2015 12:57:31 +0000 (12:57 +0000)
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<billy.o.mahony@intel.com>
Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com>
Reviewed-by: Martin Klozik <martinx.klozik@intel.com>
Reviewed-by: Radek Zetik <radekx.zetik@intel.com>
Reviewed-by: Dino Madarang <dino.simeonx.madarang@intel.com>
Reviewed-by: Brian Castelli <brian.castelli@spirent.com>
Change-Id: Ib820bdae96d6257d785f4e310a3b3d1fbfa1b575

vsperf

diff --git a/vsperf b/vsperf
index d5086ac..7c9f018 100755 (executable)
--- 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', '<Name not set>'))
             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))