Skip to content

Commit b827f37

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 b827f37

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

tests/functional/end-to-end.bats

Lines changed: 26 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,62 @@ 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
399+
echo ${output}
393400
[ "$count" -eq 1 ]
394401
count=$(echo ${output} | grep -o "foo_data_t" | wc -l)
395402
echo "Status: $status, Count: $count (expected 1)"
396-
echo $output
403+
echo ${output}
397404
[ "$count" -eq 1 ]
398405
count=$(echo ${output} | grep -o "foo_log_t" | wc -l)
399406
echo "Status: $status, Count: $count (expected 0)"
400-
echo $output
407+
echo ${output}
401408
[ "$count" -eq 0 ]
402409
}
403410

404411
@test "disable comment" {
405412
run ${SELINT_PATH} -c configs/default.conf -F -e W-002 -E -s policies/misc/disable.*
413+
echo ${output}
406414
[ "$status" -eq 0 ]
407415
count=$(echo ${output} | grep -o "W-002" | wc -l)
408416
echo "Status: $status, Count: $count (expected 0)"
409-
echo $output
417+
echo ${output}
410418
[ "$count" -eq 0 ]
411419

412420
echo "Part I"
413421
run ${SELINT_PATH} -F -s -c configs/default.conf policies/misc/disable_multiple*
422+
echo ${output}
414423
[ "$status" -eq 0 ]
415424

416425
echo "Part II"
417426
run ${SELINT_PATH} -F -s -c configs/default.conf -d S-008 policies/misc/disable_require_start.*
427+
echo ${output}
418428
[ "$status" -eq 0 ]
419429

420430
echo "Part III"
421431
run ${SELINT_PATH} -F -s -c configs/default.conf policies/misc/disable_require_decl.*
432+
echo ${output}
422433
[ "$status" -eq 0 ]
423434
}
424435

425436
@test "nonexistent file" {
426437
run ${SELINT_PATH} -s -c configs/default.conf doesnt_exist.te
438+
echo ${output}
427439
[ "$status" -eq 70 ]
428440
run ${SELINT_PATH} -s -c configs/default.conf doesnt_exist.if
441+
echo ${output}
429442
[ "$status" -eq 70 ]
430443
run ${SELINT_PATH} -s -c configs/default.conf doesnt_exist.fc
444+
echo ${output}
431445
[ "$status" -eq 70 ]
432446
}
433447

@@ -438,28 +452,34 @@ test_report_format_impl() {
438452
fi
439453

440454
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
455+
echo ${output}
441456
[ "$status" -eq 78 ]
442457
}
443458

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

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

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

457475
run ${SELINT_PATH} -s -c configs/bad_ids.conf policies/misc/no_issues.te
458476
count=$(echo ${output} | grep -o "not a valid check id" | wc -l)
477+
echo ${output}
459478
[ "$count" -eq 2 ]
460479

461480
run ${SELINT_PATH} -s -c configs/bad_ids.conf -e foo -d bar -d baz policies/misc/no_issues.te
462481
count=$(echo ${output} | grep -o "not a valid check id" | wc -l)
482+
echo ${output}
463483
[ "$count" -eq 5 ]
464484
}
465485

@@ -475,6 +495,7 @@ test_report_format_impl() {
475495
@test "run_summary" {
476496
run ${SELINT_PATH} -c configs/default.conf -rsS policies/check_triggers
477497
count=$(echo ${output} | grep -o "Found the following issue counts" | wc -l)
498+
echo ${output}
478499
[ "$count" -eq 1 ]
479500
for SEV in "C" "S" "W" "E"
480501
do

0 commit comments

Comments
 (0)