aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-02-26 11:36:11 -0500
committerDavid S. Miller <davem@davemloft.net>2018-02-26 11:36:11 -0500
commit9e25b6f52a3cefe3c5152591346fd79825ebabd8 (patch)
treef647bf8fa7ba2f3f0686e507bfc617d87f5b4e6c /tools
parent9baeb5eb1f83b8c64a80ee9926204909e275b5cc (diff)
parentf9b63a1c91d4d2b4fcac5c786cdd7de1242c162b (diff)
Merge branch 'tools-tc-testing-better-error-reporting'
Brenda J. Butler says: ==================== tools: tc-testing: better error reporting This patch set contains a bit of cleanup and better error reporting, esp. in pre- and post-suite, and pre- and post-case commands. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/testing/selftests/tc-testing/tdc.py88
1 files changed, 72 insertions, 16 deletions
diff --git a/tools/testing/selftests/tc-testing/tdc.py b/tools/testing/selftests/tc-testing/tdc.py
index b3754b9aa302..6c220bc26d9f 100755
--- a/tools/testing/selftests/tc-testing/tdc.py
+++ b/tools/testing/selftests/tc-testing/tdc.py
@@ -15,6 +15,7 @@ import importlib
15import json 15import json
16import subprocess 16import subprocess
17import time 17import time
18import traceback
18from collections import OrderedDict 19from collections import OrderedDict
19from string import Template 20from string import Template
20 21
@@ -23,6 +24,13 @@ from tdc_helper import *
23 24
24import TdcPlugin 25import TdcPlugin
25 26
27
28class PluginMgrTestFail(Exception):
29 def __init__(self, stage, output, message):
30 self.stage = stage
31 self.output = output
32 self.message = message
33
26class PluginMgr: 34class PluginMgr:
27 def __init__(self, argparser): 35 def __init__(self, argparser):
28 super().__init__() 36 super().__init__()
@@ -135,7 +143,7 @@ def exec_cmd(args, pm, stage, command):
135 return proc, foutput 143 return proc, foutput
136 144
137 145
138def prepare_env(args, pm, stage, prefix, cmdlist): 146def prepare_env(args, pm, stage, prefix, cmdlist, output = None):
139 """ 147 """
140 Execute the setup/teardown commands for a test case. 148 Execute the setup/teardown commands for a test case.
141 Optionally terminate test execution if the command fails. 149 Optionally terminate test execution if the command fails.
@@ -164,7 +172,9 @@ def prepare_env(args, pm, stage, prefix, cmdlist):
164 print("\n{} *** Aborting test run.".format(prefix), file=sys.stderr) 172 print("\n{} *** Aborting test run.".format(prefix), file=sys.stderr)
165 print("\n\n{} *** stdout ***".format(proc.stdout), file=sys.stderr) 173 print("\n\n{} *** stdout ***".format(proc.stdout), file=sys.stderr)
166 print("\n\n{} *** stderr ***".format(proc.stderr), file=sys.stderr) 174 print("\n\n{} *** stderr ***".format(proc.stderr), file=sys.stderr)
167 raise Exception('"{}" did not complete successfully'.format(prefix)) 175 raise PluginMgrTestFail(
176 stage, output,
177 '"{}" did not complete successfully'.format(prefix))
168 178
169def run_one_test(pm, args, index, tidx): 179def run_one_test(pm, args, index, tidx):
170 result = True 180 result = True
@@ -194,8 +204,11 @@ def run_one_test(pm, args, index, tidx):
194 match_pattern = re.compile( 204 match_pattern = re.compile(
195 str(tidx["matchPattern"]), re.DOTALL | re.MULTILINE) 205 str(tidx["matchPattern"]), re.DOTALL | re.MULTILINE)
196 (p, procout) = exec_cmd(args, pm, 'verify', tidx["verifyCmd"]) 206 (p, procout) = exec_cmd(args, pm, 'verify', tidx["verifyCmd"])
197 match_index = re.findall(match_pattern, procout) 207 if procout:
198 if len(match_index) != int(tidx["matchCount"]): 208 match_index = re.findall(match_pattern, procout)
209 if len(match_index) != int(tidx["matchCount"]):
210 result = False
211 elif int(tidx["matchCount"]) != 0:
199 result = False 212 result = False
200 213
201 if not result: 214 if not result:
@@ -204,9 +217,12 @@ def run_one_test(pm, args, index, tidx):
204 tap += tresult 217 tap += tresult
205 218
206 if result == False: 219 if result == False:
207 tap += procout 220 if procout:
221 tap += procout
222 else:
223 tap += 'No output!\n'
208 224
209 prepare_env(args, pm, 'teardown', '-----> teardown stage', tidx['teardown']) 225 prepare_env(args, pm, 'teardown', '-----> teardown stage', tidx['teardown'], procout)
210 pm.call_post_case() 226 pm.call_post_case()
211 227
212 index += 1 228 index += 1
@@ -227,30 +243,70 @@ def test_runner(pm, args, filtered_tests):
227 index = 1 243 index = 1
228 tap = str(index) + ".." + str(tcount) + "\n" 244 tap = str(index) + ".." + str(tcount) + "\n"
229 badtest = None 245 badtest = None
246 stage = None
247 emergency_exit = False
248 emergency_exit_message = ''
230 249
231 pm.call_pre_suite(tcount, [tidx['id'] for tidx in testlist]) 250 try:
232 251 pm.call_pre_suite(tcount, [tidx['id'] for tidx in testlist])
252 except Exception as ee:
253 ex_type, ex, ex_tb = sys.exc_info()
254 print('Exception {} {} (caught in pre_suite).'.
255 format(ex_type, ex))
256 # when the extra print statements are uncommented,
257 # the traceback does not appear between them
258 # (it appears way earlier in the tdc.py output)
259 # so don't bother ...
260 # print('--------------------(')
261 # print('traceback')
262 traceback.print_tb(ex_tb)
263 # print('--------------------)')
264 emergency_exit_message = 'EMERGENCY EXIT, call_pre_suite failed with exception {} {}\n'.format(ex_type, ex)
265 emergency_exit = True
266 stage = 'pre-SUITE'
267
268 if emergency_exit:
269 pm.call_post_suite(index)
270 return emergency_exit_message
233 if args.verbose > 1: 271 if args.verbose > 1:
234 print('Run tests here') 272 print('give test rig 2 seconds to stabilize')
273 time.sleep(2)
235 for tidx in testlist: 274 for tidx in testlist:
236 if "flower" in tidx["category"] and args.device == None: 275 if "flower" in tidx["category"] and args.device == None:
276 if args.verbose > 1:
277 print('Not executing test {} {} because DEV2 not defined'.
278 format(tidx['id'], tidx['name']))
237 continue 279 continue
238 try: 280 try:
239 badtest = tidx # in case it goes bad 281 badtest = tidx # in case it goes bad
240 tap += run_one_test(pm, args, index, tidx) 282 tap += run_one_test(pm, args, index, tidx)
241 except Exception as ee: 283 except PluginMgrTestFail as pmtf:
242 print('Exception {} (caught in test_runner, running test {} {} {})'. 284 ex_type, ex, ex_tb = sys.exc_info()
243 format(ee, index, tidx['id'], tidx['name'])) 285 stage = pmtf.stage
286 message = pmtf.message
287 output = pmtf.output
288 print(message)
289 print('Exception {} {} (caught in test_runner, running test {} {} {} stage {})'.
290 format(ex_type, ex, index, tidx['id'], tidx['name'], stage))
291 print('---------------')
292 print('traceback')
293 traceback.print_tb(ex_tb)
294 print('---------------')
295 if stage == 'teardown':
296 print('accumulated output for this test:')
297 if pmtf.output:
298 print(pmtf.output)
299 print('---------------')
244 break 300 break
245 index += 1 301 index += 1
246 302
247 # if we failed in setup or teardown, 303 # if we failed in setup or teardown,
248 # fill in the remaining tests with not ok 304 # fill in the remaining tests with ok-skipped
249 count = index 305 count = index
250 tap += 'about to flush the tap output if tests need to be skipped\n' 306 tap += 'about to flush the tap output if tests need to be skipped\n'
251 if tcount + 1 != index: 307 if tcount + 1 != index:
252 for tidx in testlist[index - 1:]: 308 for tidx in testlist[index - 1:]:
253 msg = 'skipped - previous setup or teardown failed' 309 msg = 'skipped - previous {} failed'.format(stage)
254 tap += 'ok {} - {} # {} {} {}\n'.format( 310 tap += 'ok {} - {} # {} {} {}\n'.format(
255 count, tidx['id'], msg, index, badtest.get('id', '--Unknown--')) 311 count, tidx['id'], msg, index, badtest.get('id', '--Unknown--'))
256 count += 1 312 count += 1
@@ -347,9 +403,9 @@ def check_default_settings(args, remaining, pm):
347 global NAMES 403 global NAMES
348 404
349 if args.path != None: 405 if args.path != None:
350 NAMES['TC'] = args.path 406 NAMES['TC'] = args.path
351 if args.device != None: 407 if args.device != None:
352 NAMES['DEV2'] = args.device 408 NAMES['DEV2'] = args.device
353 if not os.path.isfile(NAMES['TC']): 409 if not os.path.isfile(NAMES['TC']):
354 print("The specified tc path " + NAMES['TC'] + " does not exist.") 410 print("The specified tc path " + NAMES['TC'] + " does not exist.")
355 exit(1) 411 exit(1)