mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-21 18:03:41 +03:00
test-execute: add tests for CPUAffinity=
This commit is contained in:
parent
784b9a1a32
commit
4e79aeaa65
@ -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,
|
||||
|
@ -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
|
||||
|
6
test/test-execute/exec-cpuaffinity1.service
Normal file
6
test/test-execute/exec-cpuaffinity1.service
Normal 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
|
8
test/test-execute/exec-cpuaffinity2.service
Normal file
8
test/test-execute/exec-cpuaffinity2.service
Normal 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
|
7
test/test-execute/exec-cpuaffinity3.service
Normal file
7
test/test-execute/exec-cpuaffinity3.service
Normal 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
|
Loading…
x
Reference in New Issue
Block a user