1#!/usr/bin/env bats
2
3load helpers
4
5function setup() {
6	teardown_busybox
7	setup_busybox
8}
9
10function teardown() {
11	teardown_busybox
12}
13
14@test "ps" {
15	# ps is not supported, it requires cgroups
16	requires root
17
18	# start busybox detached
19	runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
20	[ "$status" -eq 0 ]
21
22	# check state
23	testcontainer test_busybox running
24
25	runc ps test_busybox
26	[ "$status" -eq 0 ]
27	[[ ${lines[0]} =~ UID\ +PID\ +PPID\ +C\ +STIME\ +TTY\ +TIME\ +CMD+ ]]
28	[[ "${lines[1]}" == *"$(id -un 2>/dev/null)"*[0-9]* ]]
29}
30
31@test "ps -f json" {
32	# ps is not supported, it requires cgroups
33	requires root
34
35	# start busybox detached
36	runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
37	[ "$status" -eq 0 ]
38
39	# check state
40	testcontainer test_busybox running
41
42	runc ps -f json test_busybox
43	[ "$status" -eq 0 ]
44	[[ ${lines[0]} =~ [0-9]+ ]]
45}
46
47@test "ps -e -x" {
48	# ps is not supported, it requires cgroups
49	requires root
50
51	# start busybox detached
52	runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
53	[ "$status" -eq 0 ]
54
55	# check state
56	testcontainer test_busybox running
57
58	runc ps test_busybox -e -x
59	[ "$status" -eq 0 ]
60	[[ ${lines[0]} =~ \ +PID\ +TTY\ +STAT\ +TIME\ +COMMAND+ ]]
61	[[ "${lines[1]}" =~ [0-9]+ ]]
62}
63
64@test "ps after the container stopped" {
65	# ps requires cgroups
66	[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
67	set_cgroups_path "$BUSYBOX_BUNDLE"
68
69	# start busybox detached
70	runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
71	[ "$status" -eq 0 ]
72
73	# check state
74	testcontainer test_busybox running
75
76	runc ps test_busybox
77	[ "$status" -eq 0 ]
78
79	runc kill test_busybox KILL
80	[ "$status" -eq 0 ]
81
82	retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
83
84	runc ps test_busybox
85	[ "$status" -eq 0 ]
86}
87