Files
Kir Kolyshkin 07cd18c9c9 tests/int: use assert for substring and regexp comparisons
The point of the assert helpers is that a failed test says what it
wanted and what it got, so leaving most comparisons as bare [[ ]]
defeats it.

Convert the rest of the checks on $output and $lines. Those using a glob
to look for a substring become --partial, the rest become --regexp (the
patterns are translated to extended regular expressions, and anchored
where the glob was).

The few remaining [[ ]] are not assertions: one is an if condition, and
another one is the left hand side of ||, offering an alternative to the
assert that follows it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-10-02 14:47:43 -07:00

123 lines
3.3 KiB
Bash

#!/usr/bin/env bats
load helpers
function setup() {
setup_busybox
}
function teardown() {
teardown_bundle
}
@test "runc run memory policy interleave without flags" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
"mode": "MPOL_INTERLEAVE",
"nodes": "0"
}'
run -0 runc run test_busybox
assert_line --index 0 "interleave:0"
}
@test "runc run memory policy bind static" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
"mode": "MPOL_BIND",
"nodes": "0",
"flags": ["MPOL_F_STATIC_NODES"]
}'
run -0 runc run test_busybox
assert_line --index 0 --regexp "^bind.*static.*0$"
}
@test "runc run and exec memory policy prefer relative" {
update_config '
.linux.memoryPolicy = {
"mode": "MPOL_PREFERRED",
"nodes": "0",
"flags": ["MPOL_F_RELATIVE_NODES"]
}'
run -0 runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
run -0 runc exec test_busybox /bin/sh -c "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"
assert_line --index 0 --regexp "^prefer.*relative.*0$"
}
@test "runc run empty memory policy" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
}'
run -1 runc run test_busybox
assert_line --index 0 --regexp 'mem(ory )?policy'
}
@test "runc run memory policy with non-existing mode" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
"mode": "INTERLEAVE",
"nodes": "0"
}'
run -1 runc run test_busybox
assert_line --index 0 --regexp 'mem(ory )?policy'
}
@test "runc run memory policy with invalid flag" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
"mode": "MPOL_PREFERRED",
"nodes": "0",
"flags": ["MPOL_F_RELATIVE_NODES", "badflag"]
}'
run -1 runc run test_busybox
assert_line --index 0 --regexp 'mem(ory )?policy.*flag'
}
@test "runc run memory policy default with missing nodes" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
"mode": "MPOL_DEFAULT"
}'
run -0 runc run test_busybox
assert_line --index 0 --partial "default"
}
@test "runc run memory policy with missing mode" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
"nodes": "0-7"
}'
run -1 runc run test_busybox
assert_line --index 0 --regexp 'mem(ory )?policy.*mode'
}
@test "runc run memory policy calls syscall with invalid arguments" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
"mode": "MPOL_DEFAULT",
"nodes": "0-7",
}'
run -1 runc run test_busybox
assert_output --partial "mode requires 0 nodes but got 8"
}
@test "runc run memory policy bind way too large a node number" {
update_config '
.process.args = ["/bin/sh", "-c", "head -n 1 /proc/self/numa_maps | cut -d \" \" -f 2"]
| .linux.memoryPolicy = {
"mode": "MPOL_BIND",
"nodes": "0-9876543210",
"flags": []
}'
run -1 runc run test_busybox
assert_line --index 0 --partial "0-9876543210"
}