]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-execute: add tests for CPUAffinity= 7497/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 6 Dec 2017 01:44:20 +0000 (10:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 6 Dec 2017 01:44:20 +0000 (10:44 +0900)
src/test/test-execute.c
test/meson.build
test/test-execute/exec-cpuaffinity1.service [new file with mode: 0644]
test/test-execute/exec-cpuaffinity2.service [new file with mode: 0644]
test/test-execute/exec-cpuaffinity3.service [new file with mode: 0644]

index 1ef6bb4efaa584a1c237d799e58273bb4dba1acf..2bff00a9f7fc36275cda4eaf60116f492b568113 100644 (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,
index c50757a46b242734527c77e1f37efeb87c901c21..750f5c037964871a59b69d72c6f30b53e5c4df92 100644 (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
diff --git a/test/test-execute/exec-cpuaffinity1.service b/test/test-execute/exec-cpuaffinity1.service
new file mode 100644 (file)
index 0000000..84d550a
--- /dev/null
@@ -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
diff --git a/test/test-execute/exec-cpuaffinity2.service b/test/test-execute/exec-cpuaffinity2.service
new file mode 100644 (file)
index 0000000..0dda77f
--- /dev/null
@@ -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
diff --git a/test/test-execute/exec-cpuaffinity3.service b/test/test-execute/exec-cpuaffinity3.service
new file mode 100644 (file)
index 0000000..4a45d3b
--- /dev/null
@@ -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