aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing')
-rwxr-xr-xtools/testing/selftests/tc-testing/tdc.py81
1 files changed, 52 insertions, 29 deletions
diff --git a/tools/testing/selftests/tc-testing/tdc.py b/tools/testing/selftests/tc-testing/tdc.py
index ef3a8881e458..a2624eda34db 100755
--- a/tools/testing/selftests/tc-testing/tdc.py
+++ b/tools/testing/selftests/tc-testing/tdc.py
@@ -85,9 +85,42 @@ def prepare_env(cmdlist):
85 print("\nError message:") 85 print("\nError message:")
86 print(foutput) 86 print(foutput)
87 print("\nAborting test run.") 87 print("\nAborting test run.")
88 ns_destroy() 88 # ns_destroy()
89 exit(1) 89 raise Exception('prepare_env did not complete successfully')
90
91def 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
90 116
117 if result == False:
118 tap += procout
119
120 prepare_env(tidx["teardown"])
121 index += 1
122
123 return tap
91 124
92def test_runner(filtered_tests, args): 125def test_runner(filtered_tests, args):
93 """ 126 """
@@ -104,37 +137,27 @@ def test_runner(filtered_tests, args):
104 tap = str(index) + ".." + str(tcount) + "\n" 137 tap = str(index) + ".." + str(tcount) + "\n"
105 138
106 for tidx in testlist: 139 for tidx in testlist:
107 result = True
108 tresult = ""
109 if "flower" in tidx["category"] and args.device == None: 140 if "flower" in tidx["category"] and args.device == None:
110 continue 141 continue
111 print("Test " + tidx["id"] + ": " + tidx["name"]) 142 try:
112 prepare_env(tidx["setup"]) 143 badtest = tidx # in case it goes bad
113 (p, procout) = exec_cmd(tidx["cmdUnderTest"]) 144 tap += run_one_test(index, tidx)
114 exit_code = p.returncode 145 except Exception as ee:
115 146 print('Exception {} (caught in test_runner, running test {} {} {})'.
116 if (exit_code != int(tidx["expExitCode"])): 147 format(ee, index, tidx['id'], tidx['name']))
117 result = False 148 break
118 print("exit:", exit_code, int(tidx["expExitCode"])) 149 index += 1
119 print(procout)
120 else:
121 match_pattern = re.compile(str(tidx["matchPattern"]), re.DOTALL)
122 (p, procout) = exec_cmd(tidx["verifyCmd"])
123 match_index = re.findall(match_pattern, procout)
124 if len(match_index) != int(tidx["matchCount"]):
125 result = False
126
127 if result == True:
128 tresult += "ok "
129 else:
130 tresult += "not ok "
131 tap += tresult + str(index) + " " + tidx["id"] + " " + tidx["name"] + "\n"
132 150
133 if result == False: 151 count = index
134 tap += procout 152 tap += 'about to flush the tap output if tests need to be skipped\n'
153 if tcount + 1 != index:
154 for tidx in testlist[index - 1:]:
155 msg = 'skipped - previous setup or teardown failed'
156 tap += 'ok {} - {} # {} {} {} \n'.format(
157 count, tidx['id'], msg, index, badtest.get('id', '--Unknown--'))
158 count += 1
135 159
136 prepare_env(tidx["teardown"]) 160 tap += 'done flushing skipped test tap output\n'
137 index += 1
138 161
139 return tap 162 return tap
140 163