github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/tests/integration/pidfd-socket.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  function setup() {
     6  	requires root
     7  	requires_kernel 5.3
     8  	setup_busybox
     9  	update_config '.process.args = ["/bin/sleep", "1d"]'
    10  }
    11  
    12  function teardown() {
    13  	teardown_pidfd_kill
    14  	teardown_bundle
    15  }
    16  
    17  @test "runc create [ --pidfd-socket ] " {
    18  	setup_pidfd_kill "SIGTERM"
    19  
    20  	runc create --console-socket "$CONSOLE_SOCKET" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd
    21  	[ "$status" -eq 0 ]
    22  	testcontainer test_pidfd created
    23  
    24  	pidfd_kill
    25  	wait_for_container 10 1 test_pidfd stopped
    26  }
    27  
    28  @test "runc run [ --pidfd-socket ] " {
    29  	setup_pidfd_kill "SIGKILL"
    30  
    31  	runc run -d --console-socket "$CONSOLE_SOCKET" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd
    32  	[ "$status" -eq 0 ]
    33  	testcontainer test_pidfd running
    34  
    35  	pidfd_kill
    36  	wait_for_container 10 1 test_pidfd stopped
    37  }
    38  
    39  @test "runc exec [ --pidfd-socket ] [cgroups_v1] " {
    40  	requires cgroups_v1
    41  
    42  	set_cgroups_path
    43  
    44  	runc run -d --console-socket "$CONSOLE_SOCKET" test_pidfd
    45  	[ "$status" -eq 0 ]
    46  	testcontainer test_pidfd running
    47  
    48  	# Use sub-cgroup to ensure that exec process has been killed
    49  	test_pidfd_cgroup_path=$(get_cgroup_path "pids")
    50  	mkdir "${test_pidfd_cgroup_path}/exec_pidfd"
    51  	[ "$status" -eq 0 ]
    52  
    53  	setup_pidfd_kill "SIGKILL"
    54  
    55  	__runc exec -d --cgroup "pids:exec_pidfd" --pid-file "exec_pid.txt" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd sleep 1d
    56  	[ "$status" -eq 0 ]
    57  
    58  	exec_pid=$(cat exec_pid.txt)
    59  	exec_pid_in_cgroup=$(cat "${test_pidfd_cgroup_path}/exec_pidfd/cgroup.procs")
    60  	[ "${exec_pid}" -eq "${exec_pid_in_cgroup}" ]
    61  
    62  	pidfd_kill
    63  
    64  	# ensure exec process has been reaped
    65  	retry 10 1 rmdir "${test_pidfd_cgroup_path}/exec_pidfd"
    66  
    67  	testcontainer test_pidfd running
    68  }
    69  
    70  @test "runc exec [ --pidfd-socket ] [cgroups_v2] " {
    71  	requires cgroups_v2
    72  
    73  	set_cgroups_path
    74  
    75  	runc run -d --console-socket "$CONSOLE_SOCKET" test_pidfd
    76  	[ "$status" -eq 0 ]
    77  	testcontainer test_pidfd running
    78  
    79  	# Use sub-cgroup to ensure that exec process has been killed
    80  	test_pidfd_cgroup_path=$(get_cgroup_path "pids")
    81  	mkdir "${test_pidfd_cgroup_path}/exec_pidfd"
    82  	[ "$status" -eq 0 ]
    83  
    84  	setup_pidfd_kill "SIGKILL"
    85  
    86  	__runc exec -d --cgroup "exec_pidfd" --pid-file "exec_pid.txt" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd sleep 1d
    87  	[ "$status" -eq 0 ]
    88  
    89  	exec_pid=$(cat exec_pid.txt)
    90  	exec_pid_in_cgroup=$(cat "${test_pidfd_cgroup_path}/exec_pidfd/cgroup.procs")
    91  	[ "${exec_pid}" -eq "${exec_pid_in_cgroup}" ]
    92  
    93  	pidfd_kill
    94  
    95  	# ensure exec process has been reaped
    96  	retry 10 1 rmdir "${test_pidfd_cgroup_path}/exec_pidfd"
    97  
    98  	testcontainer test_pidfd running
    99  }