Skip to content

Commit 76c82ee

Browse files
committed
tests: dump output of invoked commands
Dump the output of invoked commands in the functional tests, so that they are shown when the testcase fails, to ease debugging. (The output is not shown in case the testcase succeeds.) Inspired due to a valgrind failure on armhf on Debian buildd.
1 parent a6caa65 commit 76c82ee

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

tests/functional/end-to-end.bats

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ do_test() {
2222
local EXPECT=$3
2323
local ARGS=$4
2424
run ${SELINT_PATH} -s -c tmp.conf ${ARGS} ./policies/check_triggers/${FILENAME} ./policies/check_triggers/modules.conf ./policies/check_triggers/obj_perm_sets.spt ./policies/check_triggers/access_vectors ./policies/check_triggers/security_classes
25-
echo $output
25+
echo ${output}
2626
[ "$status" -eq 0 ]
2727
count=$(echo ${output} | grep -o ${CHECK_ID} | wc -l)
2828
echo "Status: $status, Count: $count (expected ${EXPECT})"
@@ -108,6 +108,7 @@ test_parse_error_impl() {
108108

109109
if [ $USE_VALGRIND -eq 1 ]; then
110110
run valgrind --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all --error-exitcode=23 ${SELINT_PATH} -c configs/default.conf ./policies/parse_errors/${SOURCE_FILENAME}
111+
echo ${output}
111112
[ "$status" -eq 70 ]
112113
else
113114
run ${SELINT_PATH} -c configs/default.conf ./policies/parse_errors/${SOURCE_FILENAME}
@@ -342,11 +343,13 @@ test_report_format_impl() {
342343

343344
@test "usage" {
344345
run ${SELINT_PATH} -c configs/empty.conf
346+
echo ${output}
345347
[ "$status" -eq 64 ]
346348
usage_presence=$(echo ${output} | grep -o "^Usage" | wc -l)
347349
[ "$usage_presence" -eq 1 ]
348350

349351
run ${SELINT_PATH} -c configs/empty.conf -Z
352+
echo ${output}
350353
[ "$status" -eq 64 ]
351354
usage_presence=$(echo ${output} | grep -o "Usage" | wc -l)
352355
[ "$usage_presence" -eq 1 ]
@@ -356,6 +359,7 @@ test_report_format_impl() {
356359

357360
@test "Enable/disable" {
358361
run ${SELINT_PATH} -c configs/empty.conf -e W-002 -e W-003 -d S-002 -d C-002 -r -s policies/check_triggers
362+
echo ${output}
359363
[ "$status" -eq 0 ]
360364
count=$(echo ${output} | grep -o "S-002" | wc -l)
361365
[ "$count" -eq 0 ]
@@ -369,6 +373,7 @@ test_report_format_impl() {
369373

370374
@test "verbose mode" {
371375
run ${SELINT_PATH} -c configs/default.conf -r -s -v policies/check_triggers
376+
echo ${output}
372377
[ "$status" -eq 0 ]
373378
verbose_presence=$(echo ${output} | grep -o "^Verbose" | wc -l)
374379
[ "$verbose_presence" -eq 1 ]
@@ -381,53 +386,58 @@ test_report_format_impl() {
381386
fi
382387

383388
run valgrind --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all --error-exitcode=1 ${SELINT_PATH} -c configs/default.conf -r -s policies/check_triggers
389+
echo ${output}
384390
[ "$status" -eq 0 ]
385391
}
386392

387393
@test "nesting_gen_req" {
388394
run ${SELINT_PATH} -c configs/default.conf -e W-002 -E -s policies/misc/nesting.*
395+
echo ${output}
389396
[ "$status" -eq 0 ]
390397
count=$(echo ${output} | grep -o "W-002" | wc -l)
391398
echo "Status: $status, Count: $count (expected 1)"
392-
echo $output
393399
[ "$count" -eq 1 ]
394400
count=$(echo ${output} | grep -o "foo_data_t" | wc -l)
395401
echo "Status: $status, Count: $count (expected 1)"
396-
echo $output
397402
[ "$count" -eq 1 ]
398403
count=$(echo ${output} | grep -o "foo_log_t" | wc -l)
399404
echo "Status: $status, Count: $count (expected 0)"
400-
echo $output
401405
[ "$count" -eq 0 ]
402406
}
403407

404408
@test "disable comment" {
405409
run ${SELINT_PATH} -c configs/default.conf -F -e W-002 -E -s policies/misc/disable.*
410+
echo ${output}
406411
[ "$status" -eq 0 ]
407412
count=$(echo ${output} | grep -o "W-002" | wc -l)
408413
echo "Status: $status, Count: $count (expected 0)"
409-
echo $output
410414
[ "$count" -eq 0 ]
411415

412416
echo "Part I"
413417
run ${SELINT_PATH} -F -s -c configs/default.conf policies/misc/disable_multiple*
418+
echo ${output}
414419
[ "$status" -eq 0 ]
415420

416421
echo "Part II"
417422
run ${SELINT_PATH} -F -s -c configs/default.conf -d S-008 policies/misc/disable_require_start.*
423+
echo ${output}
418424
[ "$status" -eq 0 ]
419425

420426
echo "Part III"
421427
run ${SELINT_PATH} -F -s -c configs/default.conf policies/misc/disable_require_decl.*
428+
echo ${output}
422429
[ "$status" -eq 0 ]
423430
}
424431

425432
@test "nonexistent file" {
426433
run ${SELINT_PATH} -s -c configs/default.conf doesnt_exist.te
434+
echo ${output}
427435
[ "$status" -eq 70 ]
428436
run ${SELINT_PATH} -s -c configs/default.conf doesnt_exist.if
437+
echo ${output}
429438
[ "$status" -eq 70 ]
430439
run ${SELINT_PATH} -s -c configs/default.conf doesnt_exist.fc
440+
echo ${output}
431441
[ "$status" -eq 70 ]
432442
}
433443

@@ -438,28 +448,34 @@ test_report_format_impl() {
438448
fi
439449

440450
run valgrind --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all --error-exitcode=1 ${SELINT_PATH} -c configs/broken.conf -rs policies/check_triggers
451+
echo ${output}
441452
[ "$status" -eq 78 ]
442453
}
443454

444455
@test "Bad check ids" {
445456
run ${SELINT_PATH} -s -c configs/default.conf policies/misc/no_issues.te
446457
count=$(echo ${output} | grep -o "Warning: Failed to locate modules.conf file." | wc -l)
458+
echo ${output}
447459
[ "$count" -eq 1 ] #"Failed to find a valid modules.conf"
448460

449461
run ${SELINT_PATH} -s -c configs/default.conf -e foo policies/misc/no_issues.te
450462
count=$(echo ${output} | grep -o "not a valid check id" | wc -l)
463+
echo ${output}
451464
[ "$count" -eq 1 ]
452465

453466
run ${SELINT_PATH} -s -c configs/default.conf -d foo policies/misc/no_issues.te
454467
count=$(echo ${output} | grep -o "not a valid check id" | wc -l)
468+
echo ${output}
455469
[ "$count" -eq 1 ]
456470

457471
run ${SELINT_PATH} -s -c configs/bad_ids.conf policies/misc/no_issues.te
458472
count=$(echo ${output} | grep -o "not a valid check id" | wc -l)
473+
echo ${output}
459474
[ "$count" -eq 2 ]
460475

461476
run ${SELINT_PATH} -s -c configs/bad_ids.conf -e foo -d bar -d baz policies/misc/no_issues.te
462477
count=$(echo ${output} | grep -o "not a valid check id" | wc -l)
478+
echo ${output}
463479
[ "$count" -eq 5 ]
464480
}
465481

@@ -475,6 +491,7 @@ test_report_format_impl() {
475491
@test "run_summary" {
476492
run ${SELINT_PATH} -c configs/default.conf -rsS policies/check_triggers
477493
count=$(echo ${output} | grep -o "Found the following issue counts" | wc -l)
494+
echo ${output}
478495
[ "$count" -eq 1 ]
479496
for SEV in "C" "S" "W" "E"
480497
do

0 commit comments

Comments
 (0)