File: pidfd-socket.bats

package info (click to toggle)
runc 1.3.3%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,136 kB
  • sloc: sh: 2,298; ansic: 1,125; makefile: 229
file content (99 lines) | stat: -rw-r--r-- 2,504 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bats

load helpers

function setup() {
	requires root
	requires_kernel 5.3
	setup_busybox
	update_config '.process.args = ["/bin/sleep", "1d"]'
}

function teardown() {
	teardown_pidfd_kill
	teardown_bundle
}

@test "runc create [ --pidfd-socket ] " {
	setup_pidfd_kill "SIGTERM"

	runc create --console-socket "$CONSOLE_SOCKET" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd
	[ "$status" -eq 0 ]
	testcontainer test_pidfd created

	pidfd_kill
	wait_for_container 10 1 test_pidfd stopped
}

@test "runc run [ --pidfd-socket ] " {
	setup_pidfd_kill "SIGKILL"

	runc run -d --console-socket "$CONSOLE_SOCKET" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd
	[ "$status" -eq 0 ]
	testcontainer test_pidfd running

	pidfd_kill
	wait_for_container 10 1 test_pidfd stopped
}

@test "runc exec [ --pidfd-socket ] [cgroups_v1] " {
	requires cgroups_v1

	set_cgroups_path

	runc run -d --console-socket "$CONSOLE_SOCKET" test_pidfd
	[ "$status" -eq 0 ]
	testcontainer test_pidfd running

	# Use sub-cgroup to ensure that exec process has been killed
	test_pidfd_cgroup_path=$(get_cgroup_path "pids")
	mkdir "${test_pidfd_cgroup_path}/exec_pidfd"
	[ "$status" -eq 0 ]

	setup_pidfd_kill "SIGKILL"

	__runc exec -d --cgroup "pids:exec_pidfd" --pid-file "exec_pid.txt" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd sleep 1d
	[ "$status" -eq 0 ]

	exec_pid=$(cat exec_pid.txt)
	exec_pid_in_cgroup=$(cat "${test_pidfd_cgroup_path}/exec_pidfd/cgroup.procs")
	[ "${exec_pid}" -eq "${exec_pid_in_cgroup}" ]

	pidfd_kill

	# ensure exec process has been reaped
	retry 10 1 rmdir "${test_pidfd_cgroup_path}/exec_pidfd"

	testcontainer test_pidfd running
}

@test "runc exec [ --pidfd-socket ] [cgroups_v2] " {
	requires cgroups_v2

	set_cgroups_path

	runc run -d --console-socket "$CONSOLE_SOCKET" test_pidfd
	[ "$status" -eq 0 ]
	testcontainer test_pidfd running

	# Use sub-cgroup to ensure that exec process has been killed
	test_pidfd_cgroup_path=$(get_cgroup_path "pids")
	mkdir "${test_pidfd_cgroup_path}/exec_pidfd"
	[ "$status" -eq 0 ]

	setup_pidfd_kill "SIGKILL"

	__runc exec -d --cgroup "exec_pidfd" --pid-file "exec_pid.txt" --pidfd-socket "${PIDFD_SOCKET}" test_pidfd sleep 1d
	[ "$status" -eq 0 ]

	exec_pid=$(cat exec_pid.txt)
	exec_pid_in_cgroup=$(cat "${test_pidfd_cgroup_path}/exec_pidfd/cgroup.procs")
	[ "${exec_pid}" -eq "${exec_pid_in_cgroup}" ]

	pidfd_kill

	# ensure exec process has been reaped
	retry 10 1 rmdir "${test_pidfd_cgroup_path}/exec_pidfd"

	testcontainer test_pidfd running
}