File: exit_status_test.py

package info (click to toggle)
dumb-init 1.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 268 kB
  • sloc: python: 677; ansic: 260; makefile: 86; sh: 49
file content (40 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download | duplicates (3)
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
import signal
import sys
from subprocess import Popen

import pytest


@pytest.mark.parametrize('exit_status', [0, 1, 2, 32, 64, 127, 254, 255])
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
def test_exit_status_regular_exit(exit_status):
    """dumb-init should exit with the same exit status as the process that it
    supervises when that process exits normally.
    """
    proc = Popen(('dumb-init', 'sh', '-c', 'exit {}'.format(exit_status)))
    proc.wait()
    assert proc.returncode == exit_status


@pytest.mark.parametrize(
    'signal', [
        signal.SIGTERM,
        signal.SIGHUP,
        signal.SIGQUIT,
        signal.SIGKILL,
    ],
)
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
def test_exit_status_terminated_by_signal(signal):
    """dumb-init should exit with status 128 + signal when the child process is
    terminated by a signal.
    """
    # We use Python because sh is "dash" on Debian and "bash" on others.
    # https://github.com/Yelp/dumb-init/issues/115
    proc = Popen((
        'dumb-init', sys.executable, '-c', 'import os; os.kill(os.getpid(), {})'.format(
            signal,
        ),
    ))
    proc.wait()
    assert proc.returncode == 128 + signal