Skip to content

Commit 37daa74

Browse files
authored
Merge pull request #28368 from mrc0mmand/test-fail-on-error
test: a couple of clean ups
2 parents 681295c + 0726839 commit 37daa74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+58
-162
lines changed

test/units/testsuite-01.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fi
3636

3737
# Collect failed units & do one daemon-reload to a basic sanity check
3838
systemctl --state=failed --no-legend --no-pager | tee /failed
39+
test ! -s /failed
3940
systemctl daemon-reload
4041

4142
# Check that the early setup is actually skipped on reexec.
@@ -44,4 +45,4 @@ systemctl daemon-reload
4445
# of systemd-analyze blame. See issue #27187.
4546
systemd-analyze blame
4647

47-
echo OK >/testok
48+
touch /testok

test/units/testsuite-02.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ MAX_QUEUE_SIZE=${NPROC:-2}
2323
mapfile -t TEST_LIST < <(find /usr/lib/systemd/tests/unit-tests/ -maxdepth 1 -type f -name "${TESTS_GLOB}")
2424

2525
# Reset state
26-
rm -fv /failed-tests /skipped-tests /skipped
26+
rm -fv /failed /skipped /testok
2727

2828
if ! systemd-detect-virt -qc; then
2929
# Make sure ping works for unprivileged users (for test-bpf-firewall)
@@ -34,7 +34,7 @@ fi
3434
# Arguments:
3535
# $1: test path
3636
# $2: test exit code
37-
function report_result() {
37+
report_result() {
3838
if [[ $# -ne 2 ]]; then
3939
echo >&2 "check_result: missing arguments"
4040
exit 1
@@ -112,4 +112,5 @@ set -x
112112
# Test logs are sometimes lost, as the system shuts down immediately after
113113
journalctl --sync
114114

115-
exit 0
115+
test ! -s /failed
116+
touch /testok

test/units/testsuite-04.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ trap "journalctl --rotate --vacuum-size=16M" EXIT
99
# shellcheck source=test/units/test-control.sh
1010
. "$(dirname "$0")"/test-control.sh
1111

12-
: >/failed
13-
1412
run_subtests
1513

1614
touch /testok
17-
rm /failed

test/units/testsuite-07.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ set -o pipefail
66
# shellcheck source=test/units/test-control.sh
77
. "$(dirname "$0")"/test-control.sh
88

9-
: >/failed
10-
119
# Issue: https://github.com/systemd/systemd/issues/2730
1210
# See TEST-07-PID1/test.sh for the first "half" of the test
1311
mountpoint /issue2730
1412

1513
run_subtests
1614

1715
touch /testok
18-
rm /failed

test/units/testsuite-13.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ set -o pipefail
66
# shellcheck source=test/units/test-control.sh
77
. "$(dirname "$0")"/test-control.sh
88

9-
: >/failed
10-
119
run_subtests
1210

1311
touch /testok
14-
rm /failed

test/units/testsuite-15.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -o pipefail
66
# shellcheck source=test/units/test-control.sh
77
. "$(dirname "$0")"/test-control.sh
88

9-
clear_unit () {
9+
clear_unit() {
1010
local UNIT_NAME="${1:?}"
1111
systemctl stop "$UNIT_NAME" 2>/dev/null || :
1212
rm -f /{etc,run,usr/lib}/systemd/system/"$UNIT_NAME"
@@ -22,14 +22,14 @@ clear_unit () {
2222
fi
2323
}
2424

25-
clear_units () {
25+
clear_units() {
2626
for u in "$@"; do
2727
clear_unit "$u"
2828
done
2929
systemctl daemon-reload
3030
}
3131

32-
create_service () {
32+
create_service() {
3333
local SERVICE_NAME="${1:?}"
3434
clear_units "${SERVICE_NAME}".service
3535

@@ -43,25 +43,25 @@ EOF
4343
mkdir -p /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{d,wants,requires}
4444
}
4545

46-
create_services () {
46+
create_services() {
4747
for u in "$@"; do
4848
create_service "$u"
4949
done
5050
}
5151

52-
check_ok () {
52+
check_ok() {
5353
x="$(systemctl show --value -p "${2:?}" "${1:?}")"
5454
case "$x" in
5555
*${3:?}*) return 0 ;;
5656
*) return 1 ;;
5757
esac
5858
}
5959

60-
check_ko () {
60+
check_ko() {
6161
! check_ok "$@"
6262
}
6363

64-
testcase_basic_dropins () {
64+
testcase_basic_dropins() {
6565
echo "Testing basic dropins..."
6666

6767
echo "*** test a wants b wants c"
@@ -127,7 +127,7 @@ EOF
127127
clear_units test15-{a,b,c,c1}.service
128128
}
129129

130-
testcase_linked_units () {
130+
testcase_linked_units() {
131131
echo "Testing linked units..."
132132
echo "*** test linked unit (same basename)"
133133

@@ -180,7 +180,7 @@ testcase_template_alias() {
180180
clear_units test15-{a,b}@.service
181181
}
182182

183-
testcase_hierarchical_service_dropins () {
183+
testcase_hierarchical_service_dropins() {
184184
echo "Testing hierarchical service dropins..."
185185
echo "*** test service.d/ top level drop-in"
186186
create_services a-b-c
@@ -226,7 +226,7 @@ ExecCondition=echo $dropin
226226
clear_units a-b-c.service
227227
}
228228

229-
testcase_hierarchical_slice_dropins () {
229+
testcase_hierarchical_slice_dropins() {
230230
echo "Testing hierarchical slice dropins..."
231231
echo "*** test slice.d/ top level drop-in"
232232
# Slice units don't even need a fragment, so we test the defaults here
@@ -285,7 +285,7 @@ MemoryMax=1000000001
285285
clear_units a-b-c.slice
286286
}
287287

288-
testcase_transient_service_dropins () {
288+
testcase_transient_service_dropins() {
289289
echo "Testing dropins for a transient service..."
290290
echo "*** test transient service drop-ins"
291291

@@ -320,7 +320,7 @@ testcase_transient_service_dropins () {
320320
/etc/systemd/system/a-b-.service.d/drop3.conf
321321
}
322322

323-
testcase_transient_slice_dropins () {
323+
testcase_transient_slice_dropins() {
324324
echo "Testing dropins for a transient slice..."
325325
echo "*** test transient slice drop-ins"
326326

@@ -370,7 +370,7 @@ testcase_transient_slice_dropins () {
370370
/etc/systemd/system/a-b-.slice.d/drop3.conf
371371
}
372372

373-
testcase_template_dropins () {
373+
testcase_template_dropins() {
374374
echo "Testing template dropins..."
375375

376376
create_services foo bar@ yup@
@@ -519,7 +519,7 @@ EOF
519519
clear_units foo.service {bar,yup,bar-alias}@{,1,2,3}.service
520520
}
521521

522-
testcase_alias_dropins () {
522+
testcase_alias_dropins() {
523523
echo "Testing alias dropins..."
524524

525525
echo "*** test a wants b1 alias of b"
@@ -551,7 +551,7 @@ testcase_alias_dropins () {
551551
clear_units test15-{a,x,y}.service
552552
}
553553

554-
testcase_masked_dropins () {
554+
testcase_masked_dropins() {
555555
echo "Testing masked dropins..."
556556

557557
create_services test15-a test15-b
@@ -672,7 +672,7 @@ EOF
672672
clear_units test15-{a,b}.service
673673
}
674674

675-
testcase_invalid_dropins () {
675+
testcase_invalid_dropins() {
676676
echo "Testing invalid dropins..."
677677
# Assertion failed on earlier versions, command exits unsuccessfully on later versions
678678
systemctl cat [email protected] || true
@@ -685,7 +685,7 @@ testcase_invalid_dropins () {
685685
return 0
686686
}
687687

688-
testcase_symlink_dropin_directory () {
688+
testcase_symlink_dropin_directory() {
689689
# For issue #21920.
690690
echo "Testing symlink drop-in directory..."
691691
create_services test15-a

test/units/testsuite-16.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rm -f /test.log
77

88
TESTLOG=/test.log.XXXXXXXX
99

10-
function wait_for()
10+
wait_for()
1111
{
1212
local service="${1:-wait_for: missing service argument}"
1313
local result="${2:-success}"
@@ -23,7 +23,7 @@ function wait_for()
2323
fi
2424
}
2525

26-
function wait_for_timeout()
26+
wait_for_timeout()
2727
{
2828
local unit="$1"
2929
local time="$2"
@@ -117,4 +117,3 @@ if [[ -f "$TESTLOG" ]]; then
117117
fi
118118

119119
touch /testok
120-
exit 0

test/units/testsuite-17.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ set -o pipefail
66
# shellcheck source=test/units/test-control.sh
77
. "$(dirname "$0")"/test-control.sh
88

9-
: >/failed
10-
119
udevadm settle
1210

1311
run_subtests
1412

1513
touch /testok
16-
rm /failed

test/units/testsuite-19.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
set -eux
44
set -o pipefail
55

6-
: >/failed
7-
86
# shellcheck source=test/units/test-control.sh
97
. "$(dirname "$0")"/test-control.sh
108

119
run_subtests
1210

1311
touch /testok
14-
rm /failed

test/units/testsuite-21.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,4 @@ for bus in "${SESSION_BUS_LIST[@]}"; do
107107
systemctl --machine '[email protected]' --user daemon-reexec
108108
done
109109

110-
echo OK >/testok
111-
112-
exit 0
110+
touch /testok

0 commit comments

Comments
 (0)