test-execute: add tests for CPUAffinity=

This commit is contained in:
Yu Watanabe 2017-12-06 10:44:20 +09:00
parent 784b9a1a32
commit 4e79aeaa65
5 changed files with 50 additions and 0 deletions

View File

@ -24,6 +24,7 @@
#include <sys/prctl.h>
#include <sys/types.h>
#include "cpu-set-util.h"
#include "errno-list.h"
#include "fileio.h"
#include "fs-util.h"
@ -112,6 +113,30 @@ static void test_exec_bindpaths(Manager *m) {
(void) rm_rf("/tmp/test-exec-bindreadonlypaths", REMOVE_ROOT|REMOVE_PHYSICAL);
}
static void test_exec_cpuaffinity(Manager *m) {
_cleanup_cpu_free_ cpu_set_t *c = NULL;
unsigned n;
assert_se(c = cpu_set_malloc(&n));
assert_se(sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0);
if (CPU_ISSET_S(0, CPU_ALLOC_SIZE(n), c) == 0) {
log_notice("Cannot use CPU 0, skipping %s", __func__);
return;
}
test(m, "exec-cpuaffinity1.service", 0, CLD_EXITED);
test(m, "exec-cpuaffinity2.service", 0, CLD_EXITED);
if (CPU_ISSET_S(1, CPU_ALLOC_SIZE(n), c) == 0 ||
CPU_ISSET_S(2, CPU_ALLOC_SIZE(n), c) == 0) {
log_notice("Cannot use CPU 1 or 2, skipping remaining tests in %s", __func__);
return;
}
test(m, "exec-cpuaffinity3.service", 0, CLD_EXITED);
}
static void test_exec_workingdirectory(Manager *m) {
assert_se(mkdir_p("/tmp/test-exec_workingdirectory", 0755) >= 0);
@ -521,6 +546,7 @@ int main(int argc, char *argv[]) {
test_exec_bindpaths,
test_exec_capabilityambientset,
test_exec_capabilityboundingset,
test_exec_cpuaffinity,
test_exec_environment,
test_exec_environmentfile,
test_exec_group,

View File

@ -54,6 +54,9 @@ test_data_files = '''
test-execute/exec-capabilityboundingset-merge.service
test-execute/exec-capabilityboundingset-reset.service
test-execute/exec-capabilityboundingset-simple.service
test-execute/exec-cpuaffinity1.service
test-execute/exec-cpuaffinity2.service
test-execute/exec-cpuaffinity3.service
test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service
test-execute/exec-dynamicuser-fixeduser.service
test-execute/exec-dynamicuser-statedir-migrate-step1.service

View File

@ -0,0 +1,6 @@
[Unit]
Description=Test for CPUAffinity (simple)
[Service]
ExecStart=/bin/sh -c 'test $$(cat /proc/self/status | grep Cpus_allowed: | rev | cut -c 1) = 1'
CPUAffinity=0

View File

@ -0,0 +1,8 @@
[Unit]
Description=Test for CPUAffinity (reset)
[Service]
ExecStart=/bin/sh -c 'test $$(cat /proc/self/status | grep Cpus_allowed: | rev | cut -c 1) = 1'
CPUAffinity=0-1 3
CPUAffinity=
CPUAffinity=0

View File

@ -0,0 +1,7 @@
[Unit]
Description=Test for CPUAffinity (merge)
[Service]
ExecStart=/bin/sh -c 'test $$(cat /proc/self/status | grep Cpus_allowed: | rev | cut -c 1) = 7'
CPUAffinity=0,1
CPUAffinity=1-2