mirror of
https://github.com/systemd/systemd.git
synced 2026-08-05 07:30:30 +00:00
Merge pull request #1736 from ronnychevalier/rc/test_execute_more_tests2
test-execute: add more tests
This commit is contained in:
90
Makefile.am
90
Makefile.am
@@ -1515,7 +1515,6 @@ EXTRA_DIST += \
|
||||
test/h.service \
|
||||
test/parent-deep.slice \
|
||||
test/parent.slice \
|
||||
test/paths.target \
|
||||
test/sched_idle_bad.service \
|
||||
test/sched_idle_ok.service \
|
||||
test/sched_rr_bad.service \
|
||||
@@ -1529,43 +1528,58 @@ EXTRA_DIST += \
|
||||
test/testsuite.target \
|
||||
test/timers.target \
|
||||
test/unstoppable.service \
|
||||
test/path-changed.service \
|
||||
test/path-directorynotempty.service \
|
||||
test/path-existsglob.service \
|
||||
test/path-exists.service \
|
||||
test/path-makedirectory.service \
|
||||
test/path-modified.service \
|
||||
test/path-mycustomunit.service \
|
||||
test/path-service.service \
|
||||
test/path-changed.path \
|
||||
test/path-directorynotempty.path \
|
||||
test/path-existsglob.path \
|
||||
test/path-exists.path \
|
||||
test/path-makedirectory.path \
|
||||
test/path-modified.path \
|
||||
test/path-unit.path \
|
||||
test/exec-environment-empty.service \
|
||||
test/exec-environment-multiple.service \
|
||||
test/exec-environment.service \
|
||||
test/exec-group.service \
|
||||
test/exec-ignoresigpipe-no.service \
|
||||
test/exec-ignoresigpipe-yes.service \
|
||||
test/exec-personality-x86-64.service \
|
||||
test/exec-personality-x86.service \
|
||||
test/exec-personality-s390.service \
|
||||
test/exec-privatedevices-no.service \
|
||||
test/exec-privatedevices-yes.service \
|
||||
test/exec-privatetmp-no.service \
|
||||
test/exec-privatetmp-yes.service \
|
||||
test/exec-systemcallerrornumber.service \
|
||||
test/exec-systemcallfilter-failing2.service \
|
||||
test/exec-systemcallfilter-failing.service \
|
||||
test/exec-systemcallfilter-not-failing2.service \
|
||||
test/exec-systemcallfilter-not-failing.service \
|
||||
test/exec-user.service \
|
||||
test/exec-workingdirectory.service \
|
||||
test/exec-umask-0177.service \
|
||||
test/exec-umask-default.service \
|
||||
test/test-path/paths.target \
|
||||
test/test-path/basic.target \
|
||||
test/test-path/sysinit.target \
|
||||
test/test-path/path-changed.service \
|
||||
test/test-path/path-directorynotempty.service \
|
||||
test/test-path/path-existsglob.service \
|
||||
test/test-path/path-exists.service \
|
||||
test/test-path/path-makedirectory.service \
|
||||
test/test-path/path-modified.service \
|
||||
test/test-path/path-mycustomunit.service \
|
||||
test/test-path/path-service.service \
|
||||
test/test-path/path-changed.path \
|
||||
test/test-path/path-directorynotempty.path \
|
||||
test/test-path/path-existsglob.path \
|
||||
test/test-path/path-exists.path \
|
||||
test/test-path/path-makedirectory.path \
|
||||
test/test-path/path-modified.path \
|
||||
test/test-path/path-unit.path \
|
||||
test/test-execute/exec-environment-empty.service \
|
||||
test/test-execute/exec-environment-multiple.service \
|
||||
test/test-execute/exec-environment.service \
|
||||
test/test-execute/exec-group.service \
|
||||
test/test-execute/exec-ignoresigpipe-no.service \
|
||||
test/test-execute/exec-ignoresigpipe-yes.service \
|
||||
test/test-execute/exec-personality-x86-64.service \
|
||||
test/test-execute/exec-personality-x86.service \
|
||||
test/test-execute/exec-personality-s390.service \
|
||||
test/test-execute/exec-privatedevices-no.service \
|
||||
test/test-execute/exec-privatedevices-yes.service \
|
||||
test/test-execute/exec-privatetmp-no.service \
|
||||
test/test-execute/exec-privatetmp-yes.service \
|
||||
test/test-execute/exec-systemcallerrornumber.service \
|
||||
test/test-execute/exec-systemcallfilter-failing2.service \
|
||||
test/test-execute/exec-systemcallfilter-failing.service \
|
||||
test/test-execute/exec-systemcallfilter-not-failing2.service \
|
||||
test/test-execute/exec-systemcallfilter-not-failing.service \
|
||||
test/test-execute/exec-user.service \
|
||||
test/test-execute/exec-workingdirectory.service \
|
||||
test/test-execute/exec-umask-0177.service \
|
||||
test/test-execute/exec-umask-default.service \
|
||||
test/test-execute/exec-privatenetwork-yes.service \
|
||||
test/test-execute/exec-environmentfile.service \
|
||||
test/test-execute/exec-oomscoreadjust-positive.service \
|
||||
test/test-execute/exec-oomscoreadjust-negative.service \
|
||||
test/test-execute/exec-ioschedulingclass-best-effort.service \
|
||||
test/test-execute/exec-ioschedulingclass-idle.service \
|
||||
test/test-execute/exec-ioschedulingclass-none.service \
|
||||
test/test-execute/exec-ioschedulingclass-realtime.service \
|
||||
test/test-execute/exec-capabilityboundingset-invert.service \
|
||||
test/test-execute/exec-capabilityboundingset-merge.service \
|
||||
test/test-execute/exec-capabilityboundingset-reset.service \
|
||||
test/test-execute/exec-capabilityboundingset-simple.service \
|
||||
test/bus-policy/hello.conf \
|
||||
test/bus-policy/methods.conf \
|
||||
test/bus-policy/ownerships.conf \
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "macro.h"
|
||||
#include "manager.h"
|
||||
@@ -147,6 +148,26 @@ static void test_exec_environment(Manager *m) {
|
||||
test(m, "exec-environment-empty.service", 0, CLD_EXITED);
|
||||
}
|
||||
|
||||
static void test_exec_environmentfile(Manager *m) {
|
||||
static const char e[] =
|
||||
"VAR1='word1 word2'\n"
|
||||
"VAR2=word3 \n"
|
||||
"# comment1\n"
|
||||
"\n"
|
||||
"; comment2\n"
|
||||
" ; # comment3\n"
|
||||
"line without an equal\n"
|
||||
"VAR3='$word 5 6'\n";
|
||||
int r;
|
||||
|
||||
r = write_string_file("/tmp/test-exec_environmentfile.conf", e, WRITE_STRING_FILE_CREATE);
|
||||
assert_se(r == 0);
|
||||
|
||||
test(m, "exec-environmentfile.service", 0, CLD_EXITED);
|
||||
|
||||
unlink("/tmp/test-exec_environmentfile.conf");
|
||||
}
|
||||
|
||||
static void test_exec_umask(Manager *m) {
|
||||
test(m, "exec-umask-default.service", 0, CLD_EXITED);
|
||||
test(m, "exec-umask-0177.service", 0, CLD_EXITED);
|
||||
@@ -178,6 +199,30 @@ static void test_exec_capabilityboundingset(Manager *m) {
|
||||
test(m, "exec-capabilityboundingset-invert.service", 0, CLD_EXITED);
|
||||
}
|
||||
|
||||
static void test_exec_privatenetwork(Manager *m) {
|
||||
int r;
|
||||
|
||||
r = find_binary("ip", NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Skipping test_exec_privatenetwork, could not find ip binary: %m");
|
||||
return;
|
||||
}
|
||||
|
||||
test(m, "exec-privatenetwork-yes.service", 0, CLD_EXITED);
|
||||
}
|
||||
|
||||
static void test_exec_oomscoreadjust(Manager *m) {
|
||||
test(m, "exec-oomscoreadjust-positive.service", 0, CLD_EXITED);
|
||||
test(m, "exec-oomscoreadjust-negative.service", 0, CLD_EXITED);
|
||||
}
|
||||
|
||||
static void test_exec_ioschedulingclass(Manager *m) {
|
||||
test(m, "exec-ioschedulingclass-none.service", 0, CLD_EXITED);
|
||||
test(m, "exec-ioschedulingclass-idle.service", 0, CLD_EXITED);
|
||||
test(m, "exec-ioschedulingclass-realtime.service", 0, CLD_EXITED);
|
||||
test(m, "exec-ioschedulingclass-best-effort.service", 0, CLD_EXITED);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_function_t tests[] = {
|
||||
test_exec_workingdirectory,
|
||||
@@ -185,14 +230,18 @@ int main(int argc, char *argv[]) {
|
||||
test_exec_ignoresigpipe,
|
||||
test_exec_privatetmp,
|
||||
test_exec_privatedevices,
|
||||
test_exec_privatenetwork,
|
||||
test_exec_systemcallfilter,
|
||||
test_exec_systemcallerrornumber,
|
||||
test_exec_user,
|
||||
test_exec_group,
|
||||
test_exec_environment,
|
||||
test_exec_environmentfile,
|
||||
test_exec_umask,
|
||||
test_exec_runtimedirectory,
|
||||
test_exec_capabilityboundingset,
|
||||
test_exec_oomscoreadjust,
|
||||
test_exec_ioschedulingclass,
|
||||
NULL,
|
||||
};
|
||||
test_function_t *test = NULL;
|
||||
@@ -209,7 +258,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0);
|
||||
assert_se(set_unit_path(TEST_DIR) >= 0);
|
||||
assert_se(set_unit_path(TEST_DIR "/test-execute/") >= 0);
|
||||
|
||||
r = manager_new(MANAGER_USER, true, &m);
|
||||
if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT)) {
|
||||
|
||||
@@ -258,7 +258,7 @@ int main(int argc, char *argv[]) {
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
assert_se(set_unit_path(TEST_DIR) >= 0);
|
||||
assert_se(set_unit_path(TEST_DIR "/test-path/") >= 0);
|
||||
|
||||
for (test = tests; test && *test; test++) {
|
||||
int r;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../units/paths.target
|
||||
7
test/test-execute/exec-environmentfile.service
Normal file
7
test/test-execute/exec-environmentfile.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Test for EnvironmentFile
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -c 'exit $(test "$VAR1" = "word1 word2") && $(test "$VAR2" = word3) && $(test "$VAR3" = \'$word 5 6\')'
|
||||
Type=oneshot
|
||||
EnvironmentFile=/tmp/test-exec_environmentfile.conf
|
||||
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Test for IOSchedulingClass=best-effort
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c 'c=$(ionice); echo $c; [[ "$c" == best-effort* ]]'
|
||||
Type=oneshot
|
||||
IOSchedulingClass=best-effort
|
||||
7
test/test-execute/exec-ioschedulingclass-idle.service
Normal file
7
test/test-execute/exec-ioschedulingclass-idle.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Test for IOSchedulingClass=idle
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c 'c=$(ionice); echo $c; [[ "$c" == idle* ]]'
|
||||
Type=oneshot
|
||||
IOSchedulingClass=idle
|
||||
7
test/test-execute/exec-ioschedulingclass-none.service
Normal file
7
test/test-execute/exec-ioschedulingclass-none.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Test for IOSchedulingClass=none
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c 'c=$(ionice); echo $c; [[ "$c" == none* ]]'
|
||||
Type=oneshot
|
||||
IOSchedulingClass=none
|
||||
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Test for IOSchedulingClass=realtime
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c 'c=$(ionice); echo $c; [[ "$c" == realtime* ]]'
|
||||
Type=oneshot
|
||||
IOSchedulingClass=realtime
|
||||
7
test/test-execute/exec-oomscoreadjust-negative.service
Normal file
7
test/test-execute/exec-oomscoreadjust-negative.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Test for OOMScoreAdjust
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c 'c=$(cat /proc/self/oom_score_adj); echo $c; exit $(test $c -eq -100)'
|
||||
OOMScoreAdjust=-100
|
||||
Type=oneshot
|
||||
7
test/test-execute/exec-oomscoreadjust-positive.service
Normal file
7
test/test-execute/exec-oomscoreadjust-positive.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Test for OOMScoreAdjust
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c 'c=$(cat /proc/self/oom_score_adj); echo $c; exit $(test $c -eq 100)'
|
||||
OOMScoreAdjust=100
|
||||
Type=oneshot
|
||||
6
test/test-execute/exec-privatenetwork-yes.service
Normal file
6
test/test-execute/exec-privatenetwork-yes.service
Normal file
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Test for PrivateNetwork
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -c 'i=$(ip link | grep ": " | grep -v lo); echo $i; exit $(test -z $i)'
|
||||
PrivateNetwork=yes
|
||||
1
test/test-path/basic.target
Symbolic link
1
test/test-path/basic.target
Symbolic link
@@ -0,0 +1 @@
|
||||
../../units/basic.target
|
||||
1
test/test-path/paths.target
Symbolic link
1
test/test-path/paths.target
Symbolic link
@@ -0,0 +1 @@
|
||||
../../units/paths.target
|
||||
1
test/test-path/sysinit.target
Symbolic link
1
test/test-path/sysinit.target
Symbolic link
@@ -0,0 +1 @@
|
||||
../../units/sysinit.target
|
||||
Reference in New Issue
Block a user