forked from docker-archive/runc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As per - opencontainers/runtime-spec#1253 - opencontainers/runtime-spec#1261 Add some tests (alas it's impossible to test initial CPU affinity without adding debug logging). Signed-off-by: Kir Kolyshkin <[email protected]>
- Loading branch information
Showing
9 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env bats | ||
# Exec CPU affinity tests. For more details, see: | ||
# - https://github.com/opencontainers/runtime-spec/pull/1253 | ||
|
||
load helpers | ||
|
||
function setup() { | ||
requires smp cgroups_cpuset | ||
setup_busybox | ||
} | ||
|
||
function teardown() { | ||
teardown_bundle | ||
} | ||
|
||
function all_cpus() { | ||
cat /sys/devices/system/cpu/online | ||
} | ||
|
||
function first_cpu() { | ||
all_cpus | sed 's/[-,].*//g' | ||
} | ||
|
||
@test "runc exec [CPU affinity, initial set via process.json]" { | ||
first="$(first_cpu)" | ||
second=$((first + 1)) # Hacky; might not work in all environments. | ||
|
||
runc run -d --console-socket "$CONSOLE_SOCKET" ct1 | ||
[ "$status" -eq 0 ] | ||
|
||
for cpus in "$first" "$first-$second" "$first,$second" "$second"; do | ||
proc=' | ||
{ | ||
"terminal": false, | ||
"execCPUAffinity": { | ||
"initial": "'$cpus'" | ||
}, | ||
"args": [ "/bin/true" ], | ||
"cwd": "/" | ||
}' | ||
exp=${cpus//,/-} # 1. "," --> "-". | ||
exp=${exp//-/ } # 2. "-" --> " ". | ||
echo "CPUS: $cpus, exp: $exp" | ||
runc --debug exec --process <(echo "$proc") ct1 | ||
[[ "$output" == *"Initial CPU affinity: $cpus"* ]] | ||
[[ "$output" == *"Initial CPUs: [$exp]"* ]] | ||
done | ||
} | ||
|
||
@test "runc exec [CPU affinity, initial and final are set]" { | ||
first="$(first_cpu)" | ||
second=$((first + 1)) # Hacky; might not work in all environments. | ||
|
||
update_config " .process.execCPUAffinity.initial = \"$first\" | ||
| .process.execCPUAffinity.final = \"$second\"" | ||
|
||
runc run -d --console-socket "$CONSOLE_SOCKET" ct1 | ||
[ "$status" -eq 0 ] | ||
|
||
runc --debug exec ct1 grep "Cpus_allowed_list:" /proc/self/status | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"Initial CPUs: [$first]"* ]] | ||
[[ "$output" == *"Cpus_allowed_list: $second"* ]] # Mind the literal tab. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters