Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: tc-testing: Refactor test-runner

Split the test_runner function into the loop part (test_runner)
and the contents (run_one_test) for maintainability.
It makes it a little easier to catch exceptions
in an individual test, and keep going (and flush a bunch
of tap results for the skipped tests).

Signed-off-by: Brenda J. Butler <bjb@mojatatu.com>
Acked-by: Lucas Bates <lucasb@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Brenda J. Butler and committed by
David S. Miller
6fac733d f87c7f64

+53 -30
+53 -30
tools/testing/selftests/tc-testing/tdc.py
··· 85 85 print("\nError message:") 86 86 print(foutput) 87 87 print("\nAborting test run.") 88 - ns_destroy() 89 - exit(1) 88 + # ns_destroy() 89 + raise Exception('prepare_env did not complete successfully') 90 90 91 + def run_one_test(index, tidx): 92 + result = True 93 + tresult = "" 94 + tap = "" 95 + print("Test " + tidx["id"] + ": " + tidx["name"]) 96 + prepare_env(tidx["setup"]) 97 + (p, procout) = exec_cmd(tidx["cmdUnderTest"]) 98 + exit_code = p.returncode 99 + 100 + if (exit_code != int(tidx["expExitCode"])): 101 + result = False 102 + print("exit:", exit_code, int(tidx["expExitCode"])) 103 + print(procout) 104 + else: 105 + match_pattern = re.compile(str(tidx["matchPattern"]), 106 + re.DOTALL | re.MULTILINE) 107 + (p, procout) = exec_cmd(tidx["verifyCmd"]) 108 + match_index = re.findall(match_pattern, procout) 109 + if len(match_index) != int(tidx["matchCount"]): 110 + result = False 111 + 112 + if not result: 113 + tresult += "not " 114 + tresult += "ok {} - {} # {}\n".format(str(index), tidx['id'], tidx["name"]) 115 + tap += tresult 116 + 117 + if result == False: 118 + tap += procout 119 + 120 + prepare_env(tidx["teardown"]) 121 + index += 1 122 + 123 + return tap 91 124 92 125 def test_runner(filtered_tests, args): 93 126 """ ··· 137 104 tap = str(index) + ".." + str(tcount) + "\n" 138 105 139 106 for tidx in testlist: 140 - result = True 141 - tresult = "" 142 107 if "flower" in tidx["category"] and args.device == None: 143 108 continue 144 - print("Test " + tidx["id"] + ": " + tidx["name"]) 145 - prepare_env(tidx["setup"]) 146 - (p, procout) = exec_cmd(tidx["cmdUnderTest"]) 147 - exit_code = p.returncode 148 - 149 - if (exit_code != int(tidx["expExitCode"])): 150 - result = False 151 - print("exit:", exit_code, int(tidx["expExitCode"])) 152 - print(procout) 153 - else: 154 - match_pattern = re.compile(str(tidx["matchPattern"]), re.DOTALL) 155 - (p, procout) = exec_cmd(tidx["verifyCmd"]) 156 - match_index = re.findall(match_pattern, procout) 157 - if len(match_index) != int(tidx["matchCount"]): 158 - result = False 159 - 160 - if result == True: 161 - tresult += "ok " 162 - else: 163 - tresult += "not ok " 164 - tap += tresult + str(index) + " " + tidx["id"] + " " + tidx["name"] + "\n" 165 - 166 - if result == False: 167 - tap += procout 168 - 169 - prepare_env(tidx["teardown"]) 109 + try: 110 + badtest = tidx # in case it goes bad 111 + tap += run_one_test(index, tidx) 112 + except Exception as ee: 113 + print('Exception {} (caught in test_runner, running test {} {} {})'. 114 + format(ee, index, tidx['id'], tidx['name'])) 115 + break 170 116 index += 1 117 + 118 + count = index 119 + tap += 'about to flush the tap output if tests need to be skipped\n' 120 + if tcount + 1 != index: 121 + for tidx in testlist[index - 1:]: 122 + msg = 'skipped - previous setup or teardown failed' 123 + tap += 'ok {} - {} # {} {} {} \n'.format( 124 + count, tidx['id'], msg, index, badtest.get('id', '--Unknown--')) 125 + count += 1 126 + 127 + tap += 'done flushing skipped test tap output\n' 171 128 172 129 return tap 173 130