2016-03-15 03:55:05 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
teardown_busybox
|
|
|
|
setup_busybox
|
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
teardown_busybox
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "events --stats" {
|
2016-05-11 15:45:00 +08:00
|
|
|
# XXX: currently cgroups require root containers.
|
2020-04-25 13:54:06 +08:00
|
|
|
requires root
|
|
|
|
init_cgroup_paths
|
2016-05-11 15:45:00 +08:00
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2016-05-16 16:21:52 +08:00
|
|
|
# generate stats
|
2016-05-09 21:06:42 +08:00
|
|
|
runc events --stats test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
|
2016-04-26 19:00:21 +08:00
|
|
|
[[ "${lines[0]}" == *"data"* ]]
|
2016-03-15 03:55:05 +08:00
|
|
|
}
|
|
|
|
|
2020-04-25 13:54:06 +08:00
|
|
|
@test "events --interval default" {
|
2016-05-11 15:45:00 +08:00
|
|
|
# XXX: currently cgroups require root containers.
|
2020-04-25 13:54:06 +08:00
|
|
|
requires root
|
|
|
|
init_cgroup_paths
|
2016-05-11 15:45:00 +08:00
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2016-05-16 16:21:52 +08:00
|
|
|
# spawn two sub processes (shells)
|
|
|
|
# the first sub process is an event logger that sends stats events to events.log
|
2018-09-07 11:37:40 +08:00
|
|
|
# the second sub process waits for an event that includes test_busybox then
|
2016-03-15 03:55:05 +08:00
|
|
|
# kills the test_busybox container which causes the event logger to exit
|
2016-05-09 21:06:42 +08:00
|
|
|
(__runc events test_busybox > events.log) &
|
2016-05-16 16:21:52 +08:00
|
|
|
(
|
2016-03-15 03:55:05 +08:00
|
|
|
retry 10 1 eval "grep -q 'test_busybox' events.log"
|
|
|
|
teardown_running_container test_busybox
|
|
|
|
) &
|
2016-05-16 16:21:52 +08:00
|
|
|
wait # wait for the above sub shells to finish
|
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
[ -e events.log ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
run cat events.log
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
|
2016-04-26 19:00:21 +08:00
|
|
|
[[ "${lines[0]}" == *"data"* ]]
|
2016-03-15 03:55:05 +08:00
|
|
|
}
|
|
|
|
|
2020-04-25 13:54:06 +08:00
|
|
|
@test "events --interval 1s" {
|
2016-05-11 15:45:00 +08:00
|
|
|
# XXX: currently cgroups require root containers.
|
2020-04-25 13:54:06 +08:00
|
|
|
requires root
|
|
|
|
init_cgroup_paths
|
2016-05-11 15:45:00 +08:00
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2016-05-16 16:21:52 +08:00
|
|
|
# spawn two sub processes (shells)
|
|
|
|
# the first sub process is an event logger that sends stats events to events.log once a second
|
|
|
|
# the second sub process tries 3 times for an event that incudes test_busybox
|
|
|
|
# pausing 1s between each attempt then kills the test_busybox container which
|
2016-03-15 03:55:05 +08:00
|
|
|
# causes the event logger to exit
|
2016-05-09 21:06:42 +08:00
|
|
|
(__runc events --interval 1s test_busybox > events.log) &
|
2016-05-16 16:21:52 +08:00
|
|
|
(
|
2016-03-15 03:55:05 +08:00
|
|
|
retry 3 1 eval "grep -q 'test_busybox' events.log"
|
|
|
|
teardown_running_container test_busybox
|
|
|
|
) &
|
2016-05-16 16:21:52 +08:00
|
|
|
wait # wait for the above sub shells to finish
|
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
[ -e events.log ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
run eval "grep -q 'test_busybox' events.log"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2020-04-25 13:54:06 +08:00
|
|
|
@test "events --interval 100ms" {
|
2016-05-11 15:45:00 +08:00
|
|
|
# XXX: currently cgroups require root containers.
|
2020-04-25 13:54:06 +08:00
|
|
|
requires root
|
|
|
|
init_cgroup_paths
|
2016-05-11 15:45:00 +08:00
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
#prove there is no carry over of events.log from a prior test
|
|
|
|
[ ! -e events.log ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
|
|
|
# spawn two sub processes (shells)
|
|
|
|
# the first sub process is an event logger that sends stats events to events.log once every 100ms
|
|
|
|
# the second sub process tries 3 times for an event that incudes test_busybox
|
|
|
|
# pausing 100s between each attempt then kills the test_busybox container which
|
2016-03-15 03:55:05 +08:00
|
|
|
# causes the event logger to exit
|
2016-05-09 21:06:42 +08:00
|
|
|
(__runc events --interval 100ms test_busybox > events.log) &
|
2016-05-16 16:21:52 +08:00
|
|
|
(
|
2016-03-15 03:55:05 +08:00
|
|
|
retry 3 0.100 eval "grep -q 'test_busybox' events.log"
|
|
|
|
teardown_running_container test_busybox
|
|
|
|
) &
|
2016-05-16 16:21:52 +08:00
|
|
|
wait # wait for the above sub shells to finish
|
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
[ -e events.log ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
run eval "grep -q 'test_busybox' events.log"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
2020-04-25 13:54:06 +08:00
|
|
|
|
2020-05-29 10:56:57 +08:00
|
|
|
@test "events oom" {
|
2020-04-25 13:54:06 +08:00
|
|
|
# XXX: currently cgroups require root containers.
|
2020-05-29 10:56:57 +08:00
|
|
|
requires root cgroups_swap
|
2020-04-25 13:54:06 +08:00
|
|
|
init_cgroup_paths
|
2020-05-29 10:56:57 +08:00
|
|
|
|
2020-04-25 13:54:06 +08:00
|
|
|
# we need the container to hit OOM, so disable swap
|
2020-05-25 08:54:13 +08:00
|
|
|
update_config '(.. | select(.resources? != null)) .resources.memory |= {"limit": 33554432, "swap": 33554432}' ${BUSYBOX_BUNDLE}
|
2020-04-25 13:54:06 +08:00
|
|
|
|
|
|
|
# run busybox detached
|
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# spawn two sub processes (shells)
|
|
|
|
# the first sub process is an event logger that sends stats events to events.log
|
|
|
|
# the second sub process exec a memory hog process to cause a oom condition
|
|
|
|
# and waits for an oom event
|
|
|
|
(__runc events test_busybox > events.log) &
|
|
|
|
(
|
|
|
|
retry 10 1 eval "grep -q 'test_busybox' events.log"
|
|
|
|
__runc exec -d test_busybox sh -c 'test=$(dd if=/dev/urandom ibs=5120k)'
|
|
|
|
retry 10 1 eval "grep -q 'oom' events.log"
|
|
|
|
__runc delete -f test_busybox
|
|
|
|
) &
|
|
|
|
wait # wait for the above sub shells to finish
|
|
|
|
|
|
|
|
grep -q '{"type":"oom","id":"test_busybox"}' events.log
|
|
|
|
}
|