toaster: Update UI test runner
PATCH 1/1 toaster: Update UI test runner
From: Daniel Istrate <[email protected]>
Add new runner options:
--run-all-tests: finds all tests, ignores config --run-suite <suite> (from cfg)
Without arguments, run tests from current os section (config), e.g.:
1. ./run_toastertests
2. ./run_toastertests --run-all-tests
3. ./run_toastertests --run-suite darwin
Update toaster logging to meet QA CI requirements.
Signed-off-by Daniel Istrate <[email protected]>
Signed-off-by Elliot Smith <[email protected]>
--- .../contrib/tts/toasteruitest/run_toastertests.py | 164 +++++++++++++++------ .../tts/toasteruitest/toaster_automation_test.py | 92 +++++++----- 2 files changed, 172 insertions(+), 84 deletions(-)
bitbake/lib/toaster/contrib/tts/toasteruitest/run_toastertests.py +116 -48
@@ -28,60 +28,128 @@ # put chromedriver in PATH, (e.g. /usr/bin/, bear in mind to chmod) # For windows host, you may put chromedriver.exe in the same directory as chrome.exe - -import unittest, time, re, sys, getopt, os, logging, platform +import unittest, sys, os, platform import ConfigParser -import subprocess - - -class toaster_run_all(): - def __init__(self): - # in case this script is called from other directory - os.chdir(os.path.abspath(sys.path[0])) - self.starttime = time.strptime(time.ctime()) - self.parser = ConfigParser.SafeConfigParser() - found = self.parser.read('toaster_test.cfg') - self.host_os = platform.system().lower() - self.run_all_cases() - self.collect_log() - - def get_test_cases(self): - # we have config groups for different os type in toaster_test.cfg - cases_to_run = eval(self.parser.get('toaster_test_' + self.host_os, 'test_cases')) - return cases_to_run - - - def run_all_cases(self): - cases_temp = self.get_test_cases() - for case in cases_temp: - single_case_cmd = "python -m unittest toaster_automation_test.toaster_cases.test_" + str(case) - print single_case_cmd - subprocess.call(single_case_cmd, shell=True) - - def collect_log(self): +import argparse +from toaster_automation_test import toaster_cases + + +def get_args_parser(): + description = "Script that runs toaster auto tests." + parser = argparse.ArgumentParser(description=description) + parser.add_argument('--run-all-tests', required=False, action="store_true", dest="run_all_tests", default=False, + help='Run all tests.') + parser.add_argument('--run-suite', required=False, dest='run_suite', default=False, + help='run suite (defined in cfg file)') + + return parser + + +def get_tests(): + testslist = [] + + prefix = 'toaster_automation_test.toaster_cases' + + for t in dir(toaster_cases): + if t.startswith('test_'): + testslist.append('.'.join((prefix, t))) + + return testslist + + +def get_tests_from_cfg(suite=None): + + testslist = [] + config = ConfigParser.SafeConfigParser() + config.read('toaster_test.cfg') + + if suite is not None: + target_suite = suite.lower() + + # TODO: if suite is valid suite + + else: + target_suite = platform.system().lower() + + try: + tests_from_cfg = eval(config.get('toaster_test_' + target_suite, 'test_cases')) + except: + print 'Failed to get test cases from cfg file. Make sure the format is correct.' + return None + + prefix = 'toaster_automation_test.toaster_cases.test_' + for t in tests_from_cfg: + testslist.append(prefix + str(t)) + + return testslist + +def main(): + + # In case this script is called from other directory + os.chdir(os.path.abspath(sys.path[0])) + + parser = get_args_parser() + args = parser.parse_args() + + if args.run_all_tests: + testslist = get_tests() + elif args.run_suite: + testslist = get_tests_from_cfg(args.run_suite) + os.environ['TOASTER_SUITE'] = args.run_suite + else: + testslist = get_tests_from_cfg() + + if not testslist: + print 'Failed to get test cases.' + exit(1) + + suite = unittest.TestSuite() + loader = unittest.TestLoader() + loader.sortTestMethodsUsing = None + runner = unittest.TextTestRunner(verbosity=2, resultclass=buildResultClass(args)) + + for test in testslist: + try: + suite.addTests(loader.loadTestsFromName(test)) + except: + return 1 + + result = runner.run(suite) + + if result.wasSuccessful(): + return 0 + else: + return 1 + + +def buildResultClass(args): + """Build a Result Class to use in the testcase execution""" + + class StampedResult(unittest.TextTestResult): """ - the log files are temporarily stored in ./log/tmp/.. - After all cases are done, they should be transfered to ./log/$TIMESTAMP/ + Custom TestResult that prints the time when a test starts. As toaster-auto + can take a long time (ie a few hours) to run, timestamps help us understand + what tests are taking a long time to execute. """ - def comple(number): - if number < 10: - return str(0) + str(number) - else: - return str(number) - now = self.starttime - now_str = comple(now.tm_year) + comple(now.tm_mon) + comple(now.tm_mday) + \ - comple(now.tm_hour) + comple(now.tm_min) + comple(now.tm_sec) - log_dir = os.path.abspath(sys.path[0]) + os.sep + 'log' + os.sep + now_str - log_tmp_dir = os.path.abspath(sys.path[0]) + os.sep + 'log' + os.sep + 'tmp' - try: - os.renames(log_tmp_dir, log_dir) - except OSError : - logging.error(" Cannot create log dir(timestamp) under log, please check your privilege") + def startTest(self, test): + import time + self.stream.write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + " - ") + super(StampedResult, self).startTest(test) + return StampedResult -if __name__ == "__main__": - toaster_run_all() +if __name__ == "__main__": + try: + ret = main() + except: + ret = 1 + import traceback + traceback.print_exc(5) + finally: + if os.getenv('TOASTER_SUITE'): + del os.environ['TOASTER_SUITE'] + sys.exit(ret)
bitbake/lib/toaster/contrib/tts/toasteruitest/toaster_automation_test.py +56 -36
176 lines not on this page · raw message
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.