summaryrefslogtreecommitdiffstats
path: root/debian/tests/killall
blob: 609717325958b7094f767670dc1d0d528a1d66bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

exec 2>&1

test_no_arguments() {
    ( killall >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "exit value" "1" "${rtrn}"
    grep -E '^Usage: killall \[OPTION\]' "${stderrF}" > /dev/null
    assertTrue 'error message' $?
}

test_list_signals() {
    ( killall -l >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "exit value" "0" "${rtrn}"
    grep -qE '^([A-Z12]+\s*)+$' "${stdoutF}"
    assertTrue 'STDOUT lists signals' $?
}

test_not_found() {
    ( killall  "${fakeproc}" >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "exit value" "1" "${rtrn}"
    th_assertNoProcFound 'STDOUT says no process found'
}

test_all_signals() {
    allSIGNALS=$(killall -l)
    for signame in ${allSIGNALS}; do
	( killall -"${signame}" "${fakeproc}" >"${stdoutF}" 2>"${stderrF}" )
	th_assertNoProcFound "STDOUT no process found for -${signame}"
	( killall -"SIG${signame}" "${fakeproc}" >"${stdoutF}" 2>"${stderrF}" )
	th_assertNoProcFound "STDOUT no process found for -SIG${signame}"
    done
}

th_assertNoProcFound() {
    msg=$1
    grep -qE "^${fakeproc}: no process found$" "${stderrF}"
    assertTrue "${msg}" $?
}

oneTimeSetUp() {
  # Define global variables for command output.
  stdoutF="${AUTOPKGTEST_TMP}/stdout"
  stderrF="${AUTOPKGTEST_TMP}/stderr"
  fakeproc="fakename-test"
}

setUp() {
  # Truncate the output files.
  cp /dev/null "${stdoutF}"
  cp /dev/null "${stderrF}"
}

# shellcheck disable=SC1091
. shunit2