@@ -13,6 +13,7 @@ echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
13
13
echo " Options:"
14
14
echo " -h|--help Show help message"
15
15
echo " -k|--keep Keep passed test logs"
16
+ echo " -K|--ktap Output in KTAP format"
16
17
echo " -v|--verbose Increase verbosity of test messages"
17
18
echo " -vv Alias of -v -v (Show all results in stdout)"
18
19
echo " -vvv Alias of -v -v -v (Show all commands immediately)"
@@ -85,6 +86,10 @@ parse_opts() { # opts
85
86
KEEP_LOG=1
86
87
shift 1
87
88
;;
89
+ --ktap|-K)
90
+ KTAP=1
91
+ shift 1
92
+ ;;
88
93
--verbose|-v|-vv|-vvv)
89
94
if [ $VERBOSE -eq -1 ]; then
90
95
usage " --console can not use with --verbose"
@@ -178,6 +183,7 @@ TEST_DIR=$TOP_DIR/test.d
178
183
TEST_CASES=` find_testcases $TEST_DIR `
179
184
LOG_DIR=$TOP_DIR /logs/` date +%Y%m%d-%H%M%S` /
180
185
KEEP_LOG=0
186
+ KTAP=0
181
187
DEBUG=0
182
188
VERBOSE=0
183
189
UNSUPPORTED_RESULT=0
@@ -229,7 +235,7 @@ prlog() { # messages
229
235
newline=
230
236
shift
231
237
fi
232
- printf " $* $newline "
238
+ [ " $KTAP " != " 1 " ] && printf " $* $newline "
233
239
[ " $LOG_FILE " ] && printf " $* $newline " | strip_esc >> $LOG_FILE
234
240
}
235
241
catlog () { # file
@@ -260,11 +266,11 @@ TOTAL_RESULT=0
260
266
261
267
INSTANCE=
262
268
CASENO=0
269
+ CASENAME=
263
270
264
271
testcase () { # testfile
265
272
CASENO=$(( CASENO+ 1 ))
266
- desc=` grep " ^#[ \t]*description:" $1 | cut -f2- -d:`
267
- prlog -n " [$CASENO ]$INSTANCE$desc "
273
+ CASENAME=` grep " ^#[ \t]*description:" $1 | cut -f2- -d:`
268
274
}
269
275
270
276
checkreq () { # testfile
@@ -277,40 +283,68 @@ test_on_instance() { # testfile
277
283
grep -q " ^#[ \t]*flags:.*instance" $1
278
284
}
279
285
286
+ ktaptest () { # result comment
287
+ if [ " $KTAP " != " 1" ]; then
288
+ return
289
+ fi
290
+
291
+ local result=
292
+ if [ " $1 " = " 1" ]; then
293
+ result=" ok"
294
+ else
295
+ result=" not ok"
296
+ fi
297
+ shift
298
+
299
+ local comment=$*
300
+ if [ " $comment " != " " ]; then
301
+ comment=" # $comment "
302
+ fi
303
+
304
+ echo $CASENO $result $INSTANCE$CASENAME $comment
305
+ }
306
+
280
307
eval_result () { # sigval
281
308
case $1 in
282
309
$PASS )
283
310
prlog " [${color_green} PASS${color_reset} ]"
311
+ ktaptest 1
284
312
PASSED_CASES=" $PASSED_CASES $CASENO "
285
313
return 0
286
314
;;
287
315
$FAIL )
288
316
prlog " [${color_red} FAIL${color_reset} ]"
317
+ ktaptest 0
289
318
FAILED_CASES=" $FAILED_CASES $CASENO "
290
319
return 1 # this is a bug.
291
320
;;
292
321
$UNRESOLVED )
293
322
prlog " [${color_blue} UNRESOLVED${color_reset} ]"
323
+ ktaptest 0 UNRESOLVED
294
324
UNRESOLVED_CASES=" $UNRESOLVED_CASES $CASENO "
295
325
return $UNRESOLVED_RESULT # depends on use case
296
326
;;
297
327
$UNTESTED )
298
328
prlog " [${color_blue} UNTESTED${color_reset} ]"
329
+ ktaptest 1 SKIP
299
330
UNTESTED_CASES=" $UNTESTED_CASES $CASENO "
300
331
return 0
301
332
;;
302
333
$UNSUPPORTED )
303
334
prlog " [${color_blue} UNSUPPORTED${color_reset} ]"
335
+ ktaptest 1 SKIP
304
336
UNSUPPORTED_CASES=" $UNSUPPORTED_CASES $CASENO "
305
337
return $UNSUPPORTED_RESULT # depends on use case
306
338
;;
307
339
$XFAIL )
308
340
prlog " [${color_green} XFAIL${color_reset} ]"
341
+ ktaptest 1 XFAIL
309
342
XFAILED_CASES=" $XFAILED_CASES $CASENO "
310
343
return 0
311
344
;;
312
345
* )
313
346
prlog " [${color_blue} UNDEFINED${color_reset} ]"
347
+ ktaptest 0 error
314
348
UNDEFINED_CASES=" $UNDEFINED_CASES $CASENO "
315
349
return 1 # this must be a test bug
316
350
;;
@@ -371,6 +405,7 @@ __run_test() { # testfile
371
405
run_test () { # testfile
372
406
local testname=` basename $1 `
373
407
testcase $1
408
+ prlog -n " [$CASENO ]$INSTANCE$CASENAME "
374
409
if [ ! -z " $LOG_FILE " ] ; then
375
410
local testlog=` mktemp $LOG_DIR /${CASENO} -${testname} -log.XXXXXX`
376
411
else
@@ -405,6 +440,17 @@ run_test() { # testfile
405
440
# load in the helper functions
406
441
. $TEST_DIR /functions
407
442
443
+ if [ " $KTAP " = " 1" ]; then
444
+ echo " TAP version 13"
445
+
446
+ casecount=` echo $TEST_CASES | wc -w`
447
+ for t in $TEST_CASES ; do
448
+ test_on_instance $t || continue
449
+ casecount=$(( casecount+ 1 ))
450
+ done
451
+ echo " 1..${casecount} "
452
+ fi
453
+
408
454
# Main loop
409
455
for t in $TEST_CASES ; do
410
456
run_test $t
@@ -439,6 +485,17 @@ prlog "# of unsupported: " `echo $UNSUPPORTED_CASES | wc -w`
439
485
prlog " # of xfailed: " ` echo $XFAILED_CASES | wc -w`
440
486
prlog " # of undefined(test bug): " ` echo $UNDEFINED_CASES | wc -w`
441
487
488
+ if [ " $KTAP " = " 1" ]; then
489
+ echo -n " # Totals:"
490
+ echo -n " pass:" ` echo $PASSED_CASES | wc -w`
491
+ echo -n " faii:" ` echo $FAILED_CASES | wc -w`
492
+ echo -n " xfail:" ` echo $XFAILED_CASES | wc -w`
493
+ echo -n " xpass:0"
494
+ echo -n " skip:" ` echo $UNTESTED_CASES $UNSUPPORTED_CASES | wc -w`
495
+ echo -n " error:" ` echo $UNRESOLVED_CASES $UNDEFINED_CASES | wc -w`
496
+ echo
497
+ fi
498
+
442
499
cleanup
443
500
444
501
# if no error, return 0
0 commit comments