summaryrefslogtreecommitdiffstats
path: root/vsperf
diff options
context:
space:
mode:
authorBilly O'Mahony <billy.o.mahony@intel.com>2015-06-23 12:10:04 +0100
committerMaryam Tahhan <maryam.tahhan@intel.com>2015-07-09 10:04:02 +0000
commit4251323ac8c739ce8de670fd77c9d4399f9f66ce (patch)
tree8c43594eddaabd53358705447957ba102b21f8ca /vsperf
parenta8397a24dc759a650bbc2d54c69eb8c3af6c778a (diff)
vsperf: Add --xunit support
Generate xmlrunner output for use by Jenkins, but without actually using xmlrunner to discover & run tests. JIRA: VSPERF-27 Change-Id: I000099c841f3755043104f251837e3d4c214c6bb Signed-off-by: Billy O'mahony <billy.o.mahony@intel.com> Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com> Reviewed-by: Al Morton <acmorton@att.com> Reviewed-by: Eugene Snider <Eugene.Snider@huawei.com> Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com> Reviewed-by: Gurpreet Singh <gurpreet.singh@spirent.com> Reviewed-by: Tv Rao <tv.rao@freescale.com>
Diffstat (limited to 'vsperf')
-rwxr-xr-xvsperf45
1 files changed, 44 insertions, 1 deletions
diff --git a/vsperf b/vsperf
index 0747a205..cb02d6db 100755
--- a/vsperf
+++ b/vsperf
@@ -24,6 +24,8 @@ import argparse
import time
import datetime
import shutil
+import unittest
+import xmlrunner
sys.dont_write_bytecode = True
@@ -130,6 +132,10 @@ def parse_arguments():
group.add_argument('--trafficgen', help='traffic generator to use')
group.add_argument('--sysmetrics', help='system metrics logger to use')
group = parser.add_argument_group('test behavior options')
+ group.add_argument('--xunit', action='store_true',
+ help='enable xUnit-formatted output')
+ group.add_argument('--xunit-dir', action=_ValidateDirAction,
+ help='output directory of xUnit-formatted output')
group.add_argument('--load-env', action='store_true',
help='enable loading of settings from the environment')
group.add_argument('--conf-file', action=_ValidateFileAction,
@@ -231,6 +237,34 @@ def apply_filter(tests, tc_filter):
return result
+class MockTestCase(unittest.TestCase):
+ """Allow use of xmlrunner to generate Jenkins compatible output without
+ using xmlrunner to actually run tests.
+
+ Usage:
+ suite = unittest.TestSuite()
+ suite.addTest(MockTestCase('Test1 passed ', True, 'Test1'))
+ suite.addTest(MockTestCase('Test2 failed because...', False, 'Test2'))
+ xmlrunner.XMLTestRunner(...).run(suite)
+ """
+
+ def __init__(self, msg, is_pass, test_name):
+ #remember the things
+ self.msg = msg
+ self.is_pass = is_pass
+
+ #dynamically create a test method with the right name
+ #but point the method at our generic test method
+ setattr(MockTestCase, test_name, self.generic_test)
+
+ super(MockTestCase, self).__init__(test_name)
+
+ def generic_test(self):
+ """Provide a generic function that raises or not based
+ on how self.is_pass was set in the constructor"""
+ self.assertTrue(self.is_pass, self.msg)
+
+
def main():
"""Main function.
"""
@@ -317,15 +351,24 @@ def main():
logger.info("Creating result directory: " + results_path)
os.makedirs(results_path)
+ suite = unittest.TestSuite()
+
# run tests
for test in all_tests:
try:
test.run()
+ suite.addTest(MockTestCase('', True, test.name))
#pylint: disable=broad-except
- except (Exception) as _:
+ except (Exception) as ex:
logger.exception("Failed to run test: %s", test.name)
+ suite.addTest(MockTestCase(str(ex), False, test.name))
logger.info("Continuing with next test...")
+ if settings.getValue('XUNIT'):
+ xmlrunner.XMLTestRunner(
+ output=settings.getValue('XUNIT_DIR'), outsuffix="",
+ verbosity=0).run(suite)
+
#remove directory if no result files were created.
if os.path.exists(results_path):
if os.listdir(results_path) == []: