Merge pull request #14338 from keszybz/functional-test-rework

Functional test rework
This commit is contained in:
Frantisek Sumsal 2020-03-30 16:25:12 +02:00 committed by GitHub
commit 15529f5cea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
273 changed files with 1851 additions and 2501 deletions

View File

@ -49,9 +49,12 @@ fuzzer_build = want_ossfuzz or want_libfuzzer
#####################################################################
# Try to install the git pre-commit hook
git_hook = run_command(join_paths(project_source_root, 'tools/add-git-hook.sh'))
if git_hook.returncode() == 0
message(git_hook.stdout().strip())
add_git_hook_sh = find_program('tools/add-git-hook.sh', required : false)
if add_git_hook_sh.found()
git_hook = run_command(add_git_hook_sh)
if git_hook.returncode() == 0
message(git_hook.stdout().strip())
endif
endif
#####################################################################
@ -2503,7 +2506,7 @@ if conf.get('ENABLE_BINFMT') == 1
endif
if conf.get('ENABLE_REPART') == 1
executable('systemd-repart',
exe = executable('systemd-repart',
systemd_repart_sources,
include_directories : includes,
link_with : [libshared],
@ -2515,6 +2518,12 @@ if conf.get('ENABLE_REPART') == 1
install_rpath : rootlibexecdir,
install : true,
install_dir : rootbindir)
if want_tests != 'false'
test('test-repart',
test_repart_sh,
args : exe.full_path())
endif
endif
if conf.get('ENABLE_VCONSOLE') == 1
@ -2959,13 +2968,20 @@ if conf.get('ENABLE_NETWORKD') == 1
install_dir : rootbindir)
public_programs += exe
executable('systemd-network-generator',
exe = executable('systemd-network-generator',
network_generator_sources,
include_directories : includes,
link_with : [networkd_link_with],
install_rpath : rootlibexecdir,
install : true,
install_dir : rootlibexecdir)
if want_tests != 'false'
test('test-network-generator-conversion',
test_network_generator_conversion_sh,
# https://github.com/mesonbuild/meson/issues/2681
args : exe.full_path())
endif
endif
executable('systemd-sulogin-shell',
@ -3467,6 +3483,7 @@ foreach tuple : [
['debug siphash'],
['valgrind', conf.get('VALGRIND') == 1],
['trace logging', conf.get('LOG_TRACE') == 1],
['install tests', install_tests],
['link-udev-shared', get_option('link-udev-shared')],
['link-systemctl-shared', get_option('link-systemctl-shared')],
['link-networkd-shared', get_option('link-networkd-shared')],

View File

@ -17,7 +17,7 @@ PHASES=(${@:-SETUP RUN})
create_container() {
# create autopkgtest LXC image; this sometimes fails with "Unable to fetch
# GPG key from keyserver", so retry a few times
for retry in $(seq 5); do
for retry in {1..5}; do
sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH --keyserver hkp://keyserver.ubuntu.com:80 && break
sleep $((retry*retry))
done

View File

@ -3,3 +3,5 @@
systemd_repart_sources = files('''
repart.c
'''.split())
test_repart_sh = find_program('test-repart.sh')

111
src/partition/test-repart.sh Executable file
View File

@ -0,0 +1,111 @@
#!/usr/bin/env bash
set -ex
repart=$1
test -x $repart
D=$(mktemp --directory)
trap "rm -rf '$D'" EXIT INT QUIT PIPE
mkdir -p $D/definitions
truncate -s 1G $D/zzz
SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8
$repart $D/zzz --empty=force --dry-run=no --seed=$SEED
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' > $D/empty
cmp $D/empty - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
EOF
cat >$D/definitions/root.conf <<EOF
[Partition]
Type=root
EOF
ln -s root.conf $D/definitions/root2.conf
cat >$D/definitions/home.conf <<EOF
[Partition]
Type=home
EOF
cat > $D/definitions/swap.conf <<EOF
[Partition]
Type=swap
SizeMaxBytes=64M
PaddingMinBytes=92M
EOF
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated
cmp $D/populated - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
$D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
$D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
$D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
$D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
EOF
cat >$D/definitions/swap.conf <<EOF
[Partition]
Type=swap
SizeMaxBytes=64M
EOF
cat >$D/definitions/extra.conf <<EOF
[Partition]
Type=linux-generic
EOF
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated2
cmp $D/populated2 - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
$D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
$D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
$D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
$D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
$D/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=03477476-06AD-44E8-9EF4-BC2BD7771289, name="linux-generic"
EOF
truncate -s 2G $D/zzz
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated3
cmp $D/populated3 - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz
unit: sectors
first-lba: 2048
last-lba: 4194270
$D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
$D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
$D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
$D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
$D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=03477476-06AD-44E8-9EF4-BC2BD7771289, name="linux-generic"
EOF

View File

@ -92,7 +92,6 @@ static void test_packet_from_file(const char* filename, bool canonical) {
int main(int argc, char **argv) {
int i, N;
_cleanup_free_ char *pkts_glob = NULL;
_cleanup_globfree_ glob_t g = {};
char **fnames;
@ -102,7 +101,8 @@ int main(int argc, char **argv) {
N = argc - 1;
fnames = argv + 1;
} else {
pkts_glob = path_join(get_testdata_dir(), "test-resolve/*.pkts");
_cleanup_free_ char *pkts_glob = NULL;
assert_se(get_testdata_dir("test-resolve/*.pkts", &pkts_glob) >= 0);
assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0);
N = g.gl_pathc;
fnames = g.gl_pathv;

View File

@ -58,21 +58,25 @@ static void load_testdata_env(void) {
setenv(*k, *v, 0);
}
const char* get_testdata_dir(void) {
const char *env;
int get_testdata_dir(const char *suffix, char **ret) {
const char *dir;
char *p;
load_testdata_env();
/* if the env var is set, use that */
env = getenv("SYSTEMD_TEST_DATA");
if (!env)
env = SYSTEMD_TEST_DATA;
if (access(env, F_OK) < 0) {
fprintf(stderr, "ERROR: $SYSTEMD_TEST_DATA directory [%s] does not exist\n", env);
exit(EXIT_FAILURE);
}
dir = getenv("SYSTEMD_TEST_DATA");
if (!dir)
dir = SYSTEMD_TEST_DATA;
if (access(dir, F_OK) < 0)
return log_error_errno(errno, "ERROR: $SYSTEMD_TEST_DATA directory [%s] not accesible: %m", dir);
return env;
p = path_join(dir, suffix);
if (!p)
return log_oom();
*ret = p;
return 0;
}
const char* get_catalog_dir(void) {

View File

@ -20,7 +20,7 @@ static inline bool manager_errno_skip_test(int r) {
char* setup_fake_runtime_dir(void);
int enter_cgroup_subroot(char **ret_cgroup);
const char* get_testdata_dir(void);
int get_testdata_dir(const char *suffix, char **ret);
const char* get_catalog_dir(void);
bool slow_tests_enabled(void);
void test_setup_logging(int level);

View File

@ -48,7 +48,9 @@ int main(int argc, char *argv[]) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
assert_se(set_unit_path(get_testdata_dir()) >= 0);
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, &p);

View File

@ -38,7 +38,9 @@ static int test_cgroup_mask(void) {
return log_tests_skipped("cgroupfs not available");
/* Prepare the manager. */
assert_se(set_unit_path(get_testdata_dir()) >= 0);
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (IN_SET(r, -EPERM, -EACCES)) {

View File

@ -22,7 +22,9 @@ static int test_default_memory_low(void) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
assert_se(set_unit_path(get_testdata_dir()) >= 0);
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (IN_SET(r, -EPERM, -EACCES)) {

View File

@ -26,8 +26,11 @@ int main(int argc, char *argv[]) {
return log_tests_skipped("cgroupfs not available");
/* prepare the test */
assert_se(set_unit_path(get_testdata_dir()) >= 0);
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (manager_errno_skip_test(r))
return log_tests_skipped_errno(r, "manager_new");

View File

@ -806,7 +806,6 @@ static int run_tests(UnitFileScope scope, const test_entry tests[], char **patte
int main(int argc, char *argv[]) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
_cleanup_free_ char *test_execute_path = NULL;
static const test_entry user_tests[] = {
entry(test_exec_basic),
@ -878,9 +877,10 @@ int main(int argc, char *argv[]) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("test-execute/", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
test_execute_path = path_join(get_testdata_dir(), "test-execute");
assert_se(set_unit_path(test_execute_path) >= 0);
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
* cases, otherwise (and if they are present in the environment),

View File

@ -444,20 +444,20 @@ static void test_write_string_file_verify(void) {
_cleanup_free_ char *buf = NULL, *buf2 = NULL;
int r;
assert_se(read_one_line_file("/proc/cmdline", &buf) >= 0);
assert_se(read_one_line_file("/proc/version", &buf) >= 0);
assert_se(buf2 = strjoin(buf, "\n"));
r = write_string_file("/proc/cmdline", buf, 0);
r = write_string_file("/proc/version", buf, 0);
assert_se(IN_SET(r, -EACCES, -EIO));
r = write_string_file("/proc/cmdline", buf2, 0);
r = write_string_file("/proc/version", buf2, 0);
assert_se(IN_SET(r, -EACCES, -EIO));
assert_se(write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
assert_se(write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
r = write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE);
r = write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE);
assert_se(IN_SET(r, -EACCES, -EIO));
assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
}
static void test_load_env_file_pairs(void) {
@ -757,7 +757,7 @@ static void test_read_line3(void) {
_cleanup_free_ char *line = NULL;
int r;
f = fopen("/proc/cmdline", "re");
f = fopen("/proc/uptime", "re");
if (!f && IN_SET(errno, ENOENT, EPERM))
return;
assert_se(f);

View File

@ -25,7 +25,7 @@ static void test_basic_parsing(void) {
_cleanup_free_ char *journal_data_path = NULL;
int r;
journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-1.txt");
assert_se(get_testdata_dir("journal-data/journal-1.txt", &journal_data_path) >= 0);
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);
@ -56,7 +56,7 @@ static void test_bad_input(void) {
_cleanup_free_ char *journal_data_path = NULL;
int r;
journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-2.txt");
assert_se(get_testdata_dir("journal-data/journal-1.txt", &journal_data_path) >= 0);
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);

View File

@ -251,7 +251,7 @@ int main(int argc, char *argv[]) {
test_setup_logging(LOG_INFO);
test_path = path_join(get_testdata_dir(), "test-path");
assert_se(get_testdata_dir("test-path", &test_path) >= 0);
assert_se(set_unit_path(test_path) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());

View File

@ -25,8 +25,11 @@ int main(int argc, char *argv[]) {
return log_tests_skipped("cgroupfs not available");
/* prepare the test */
assert_se(set_unit_path(get_testdata_dir()) >= 0);
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (manager_errno_skip_test(r))
return log_tests_skipped_errno(r, "manager_new");

View File

@ -15,8 +15,10 @@ static void test_mount_points_list(const char *fname) {
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
if (fname)
fname = testdata_fname = path_join(get_testdata_dir(), fname);
if (fname) {
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
fname = testdata_fname;
}
LIST_HEAD_INIT(mp_list_head);
assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
@ -37,8 +39,10 @@ static void test_swap_list(const char *fname) {
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
if (fname)
fname = testdata_fname = path_join(get_testdata_dir(), fname);
if (fname) {
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
fname = testdata_fname;
}
LIST_HEAD_INIT(mp_list_head);
assert_se(swap_list_get(fname, &mp_list_head) >= 0);

View File

@ -20,7 +20,10 @@ int main(int argc, char *argv[]) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
assert_se(set_unit_path(get_testdata_dir()) >= 0);
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units/", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
assert_se(manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m) >= 0);

View File

@ -10,10 +10,10 @@ ninja: no work to do.
--x-- Running TEST-01-BASIC --x--
+ make -C TEST-01-BASIC BUILD_DIR=/home/zbyszek/src/systemd/build clean setup run
make: Entering directory '/home/zbyszek/src/systemd/test/TEST-01-BASIC'
TEST CLEANUP: Basic systemd setup
TEST SETUP: Basic systemd setup
TEST-01-BASIC CLEANUP: Basic systemd setup
TEST-01-BASIC SETUP: Basic systemd setup
...
TEST RUN: Basic systemd setup [OK]
TEST-01-BASIC RUN: Basic systemd setup [OK]
make: Leaving directory '/home/zbyszek/src/systemd/test/TEST-01-BASIC'
--x-- Result of TEST-01-BASIC: 0 --x--
--x-- Running TEST-02-CRYPTSETUP --x--

View File

@ -1,9 +1,6 @@
BUILD_DIR=$(shell ../../tools/find-build-dir.sh)
all setup run:
all setup run clean clean-again:
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@
clean clean-again:
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --clean
.PHONY: all setup run clean clean-again

View File

@ -1,34 +1,25 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="Basic systemd setup"
IMAGE_NAME="basic"
RUN_IN_UNPRIVILEGED_CONTAINER=${RUN_IN_UNPRIVILEGED_CONTAINER:-yes}
TEST_REQUIRE_INSTALL_TESTS=0
. $TEST_BASE_DIR/test-functions
test_setup() {
test_create_image() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=multi-user.target
[Service]
ExecStart=/bin/sh -e -x -c 'systemctl --state=failed --no-legend --no-pager > /failed ; systemctl daemon-reload ; echo OK > /testok'
Type=oneshot
EOF
setup_testsuite
# install tests manually so the test is functional even when -Dinstall-tests=false
mkdir -p $initdir/usr/lib/systemd/tests/testdata/units/
cp -v $(dirname $0)/../units/{testsuite-01,end}.service $initdir/usr/lib/systemd/tests/testdata/units/
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 01

View File

@ -1,21 +1,22 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="cryptsetup systemd setup"
IMAGE_NAME="cryptsetup"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
check_result_qemu() {
ret=1
mkdir -p $initdir
mount ${LOOPDEV}p1 $initdir
mount_initdir
[[ -e $initdir/testok ]] && ret=0
[[ -f $initdir/failed ]] && cp -a $initdir/failed $TESTDIR
cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
mount /dev/mapper/varcrypt $initdir/var
cp -a $initdir/var/log/journal $TESTDIR
umount $initdir/var
umount $initdir
rm -r $initdir/var/log/journal/*
_umount_dir $initdir/var
_umount_dir $initdir
cryptsetup luksClose /dev/mapper/varcrypt
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
ls -l $TESTDIR/journal/*/*.journal
@ -23,8 +24,7 @@ check_result_qemu() {
return $ret
}
test_setup() {
test_create_image() {
create_empty_image_rootdir
echo -n test >$TESTDIR/keyfile
cryptsetup -q luksFormat --pbkdf pbkdf2 --pbkdf-force-iterations 1000 ${LOOPDEV}p2 $TESTDIR/keyfile
@ -42,25 +42,12 @@ test_setup() {
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=multi-user.target
[Service]
ExecStart=/bin/sh -x -c 'systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok'
Type=oneshot
EOF
setup_testsuite
install_dmevent
generate_module_dependencies
cat >$initdir/etc/crypttab <<EOF
$DM_NAME UUID=$ID_FS_UUID /etc/varkey
EOF
echo -n test > $initdir/etc/varkey
echo -n test >$initdir/etc/varkey
cat $initdir/etc/crypttab | ddebug
cat >>$initdir/etc/fstab <<EOF
@ -82,8 +69,8 @@ test_cleanup() {
}
test_setup_cleanup() {
cleanup_root_var
_test_setup_cleanup
cleanup_root_var || :
cleanup_initdir
}
do_test "$@"
do_test "$@" 02

View File

@ -5,36 +5,4 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=multi-user.target
[Service]
ExecStart=/test-jobs.sh
Type=oneshot
EOF
# copy the units used by this test
cp $TEST_BASE_DIR/{hello.service,sleep.service,hello-after-sleep.target,unstoppable.service} \
$initdir/etc/systemd/system
cp test-jobs.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 03

View File

@ -4,41 +4,4 @@ TEST_DESCRIPTION="Journal-related tests"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-journal.sh
Type=oneshot
EOF
cat >$initdir/etc/systemd/system/forever-print-hola.service <<EOF
[Unit]
Description=ForeverPrintHola service
[Service]
Type=simple
ExecStart=/bin/sh -x -c 'while :; do printf "Hola\n" || touch /i-lose-my-logs; sleep 1; done'
EOF
cp test-journal.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 04

View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
set -x
set -e
set -o pipefail
[[ "$(systemctl show -p DefaultLimitNOFILESoft)" = "DefaultLimitNOFILESoft=10000" ]]
[[ "$(systemctl show -p DefaultLimitNOFILE)" = "DefaultLimitNOFILE=16384" ]]
[[ "$(systemctl show -p LimitNOFILESoft testsuite.service)" = "LimitNOFILESoft=10000" ]]
[[ "$(systemctl show -p LimitNOFILE testsuite.service)" = "LimitNOFILE=16384" ]]
[[ "$(ulimit -n -S)" = "10000" ]]
[[ "$(ulimit -n -H)" = "16384" ]]
touch /testok

View File

@ -4,37 +4,4 @@ TEST_DESCRIPTION="Resource limits-related tests"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
cat >$initdir/etc/systemd/system.conf <<EOF
[Manager]
DefaultLimitNOFILE=10000:16384
EOF
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-rlimits.sh
Type=oneshot
EOF
cp test-rlimits.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 05

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="SELinux tests"
IMAGE_NAME="selinux"
TEST_NO_NSPAWN=1
# Requirements:
@ -15,60 +16,16 @@ test -f /usr/share/selinux/devel/include/system/systemd.if || exit 0
SETUP_SELINUX=yes
KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux"
test_setup() {
test_create_image() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat <<EOF >$initdir/etc/systemd/system/testsuite.service
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-selinux-checks.sh
Type=oneshot
EOF
cat <<EOF >$initdir/etc/systemd/system/hola.service
[Service]
Type=oneshot
ExecStart=/bin/echo Start Hola
ExecReload=/bin/echo Reload Hola
ExecStop=/bin/echo Stop Hola
RemainAfterExit=yes
EOF
setup_testsuite
cat <<EOF >$initdir/etc/systemd/system/load-systemd-test-module.service
[Unit]
Description=Load systemd-test module
DefaultDependencies=no
Requires=local-fs.target
Conflicts=shutdown.target
After=local-fs.target
Before=sysinit.target shutdown.target autorelabel.service
ConditionSecurity=selinux
ConditionPathExists=|/.load-systemd-test-module
[Service]
ExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && cd /systemd-test-module && make -f /usr/share/selinux/devel/Makefile load && rm /.load-systemd-test-module'
Type=oneshot
TimeoutSec=0
RemainAfterExit=yes
EOF
touch $initdir/.load-systemd-test-module
mkdir -p $initdir/etc/systemd/system/basic.target.wants
ln -fs load-systemd-test-module.service $initdir/etc/systemd/system/basic.target.wants/load-systemd-test-module.service
local _modules_dir=/var/lib/selinux
rm -rf $initdir/$_modules_dir
if ! cp -ar $_modules_dir $initdir/$_modules_dir; then
@ -87,11 +44,10 @@ EOF
mkdir $initdir/systemd-test-module
cp systemd_test.te $initdir/systemd-test-module
cp systemd_test.if $initdir/systemd-test-module
cp test-selinux-checks.sh $initdir
dracut_install -o sesearch
dracut_install runcon
dracut_install checkmodule semodule semodule_package m4 make /usr/libexec/selinux/hll/pp load_policy sefcontext_compile
)
}
do_test "$@"
do_test "$@" 06

View File

@ -7,32 +7,4 @@ TEST_NO_QEMU=1
NSPAWN_TIMEOUT=30
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-segfault.sh
Type=oneshot
EOF
cp test-segfault.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 07

View File

@ -1,70 +1,22 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2730"
IMAGE_NAME="test08"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
FSTYPE=ext4
test_setup() {
test_create_image() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/sh -x -c 'mount -o remount,rw /dev/sda1 && echo OK > /testok; systemctl poweroff'
Type=oneshot
EOF
rm $initdir/etc/fstab
cat >$initdir/etc/systemd/system/-.mount <<EOF
[Unit]
Before=local-fs.target
[Mount]
What=/dev/sda1
Where=/
Type=ext4
Options=errors=remount-ro,noatime
[Install]
WantedBy=local-fs.target
Alias=root.mount
EOF
cat >$initdir/etc/systemd/system/systemd-remount-fs.service <<EOF
[Unit]
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-fsck-root.service
Before=local-fs-pre.target local-fs.target shutdown.target
Wants=local-fs-pre.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/systemctl reload /
EOF
setup_testsuite
)
ln -s /etc/systemd/system/-.mount $initdir/etc/systemd/system/root.mount
mkdir -p $initdir/etc/systemd/system/local-fs.target.wants
ln -s /etc/systemd/system/-.mount $initdir/etc/systemd/system/local-fs.target.wants/-.mount
mask_supporting_services
}
do_test "$@"
do_test "$@" 08

View File

@ -6,32 +6,4 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<'EOF'
[Unit]
Description=Testsuite service
[Service]
Type=oneshot
ExecStart=/bin/sh -c '>/testok'
RemainAfterExit=yes
ExecStop=/bin/sh -c 'kill -SEGV $$$$'
TimeoutStopSec=270s
EOF
setup_testsuite
)
}
do_test "$@"
do_test "$@" 09

View File

@ -4,45 +4,4 @@ TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install true rm socat
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<'EOF'
[Unit]
Description=Testsuite service
[Service]
Type=oneshot
ExecStart=/bin/sh -e -x -c 'rm -f /tmp/nonexistent; systemctl start test.socket; printf x > test.file; socat -t20 OPEN:test.file UNIX-CONNECT:/run/test.ctl; >/testok'
EOF
cat >$initdir/etc/systemd/system/test.socket <<'EOF'
[Socket]
ListenStream=/run/test.ctl
EOF
cat > $initdir/etc/systemd/system/test.service <<'EOF'
[Unit]
Requires=test.socket
ConditionPathExistsGlob=/tmp/nonexistent
[Service]
ExecStart=/bin/true
EOF
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 10

View File

@ -5,58 +5,4 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install false touch
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-fail-on-restart.sh
Type=oneshot
EOF
cat >$initdir/etc/systemd/system/fail-on-restart.service <<EOF
[Unit]
Description=Fail on restart
StartLimitIntervalSec=1m
StartLimitBurst=3
[Service]
Type=simple
ExecStart=/bin/false
Restart=always
EOF
cat >$initdir/test-fail-on-restart.sh <<'EOF'
#!/usr/bin/env bash
set -x
systemctl start fail-on-restart.service
active_state=$(systemctl show --property ActiveState fail-on-restart.service)
while [[ "$active_state" == "ActiveState=activating" || "$active_state" == "ActiveState=active" ]]; do
sleep 1
active_state=$(systemctl show --property ActiveState fail-on-restart.service)
done
systemctl is-failed fail-on-restart.service || exit 1
touch /testok
EOF
chmod 0755 $initdir/test-fail-on-restart.sh
setup_testsuite
)
}
do_test "$@"
do_test "$@" 11

View File

@ -5,85 +5,4 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install cat mv stat nc
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=multi-user.target
[Service]
ExecStart=/test-socket-group.sh
Type=oneshot
EOF
cat >$initdir/test-socket-group.sh <<'EOF'
#!/usr/bin/env bash
set -x
set -e
set -o pipefail
U=/run/systemd/system/test.socket
cat <<'EOL' >$U
[Unit]
Description=Test socket
[Socket]
Accept=yes
ListenStream=/run/test.socket
SocketGroup=adm
SocketMode=0660
EOL
cat <<'EOL' > /run/systemd/system/test@.service
[Unit]
Description=Test service
[Service]
StandardInput=socket
ExecStart=/bin/sh -x -c cat
EOL
systemctl start test.socket
systemctl is-active test.socket
[[ "$(stat --format='%G' /run/test.socket)" == adm ]]
echo A | nc -w1 -U /run/test.socket
mv $U ${U}.disabled
systemctl daemon-reload
systemctl is-active test.socket
[[ "$(stat --format='%G' /run/test.socket)" == adm ]]
echo B | nc -w1 -U /run/test.socket && exit 1
mv ${U}.disabled $U
systemctl daemon-reload
systemctl is-active test.socket
echo C | nc -w1 -U /run/test.socket && exit 1
[[ "$(stat --format='%G' /run/test.socket)" == adm ]]
systemctl restart test.socket
systemctl is-active test.socket
echo D | nc -w1 -U /run/test.socket
[[ "$(stat --format='%G' /run/test.socket)" == adm ]]
touch /testok
EOF
chmod 0755 $initdir/test-socket-group.sh
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 12

View File

@ -1,10 +0,0 @@
BUILD_DIR=$(shell ../../tools/find-build-dir.sh)
all setup run:
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@
clean clean-again:
@basedir=../.. TEST_BASE_DIR=../ ./test.sh --clean
@rm -f has-overflow
.PHONY: all setup run clean clean-again

View File

@ -0,0 +1 @@
../TEST-01-BASIC/Makefile

View File

@ -1,193 +1,23 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="systemd-nspawn smoke test"
IMAGE_NAME=nspawn
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
test_setup() {
test_create_image() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install busybox chmod rmdir unshare ip sysctl
cp create-busybox-container $initdir/
./create-busybox-container $initdir/nc-container
../create-busybox-container $initdir/nc-container
initdir="$initdir/nc-container" dracut_install nc ip
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-nspawn.sh
Type=oneshot
EOF
cat >$initdir/test-nspawn.sh <<'EOF'
#!/usr/bin/env bash
set -x
set -e
set -u
set -o pipefail
export SYSTEMD_LOG_LEVEL=debug
# check cgroup-v2
is_v2_supported=no
mkdir -p /tmp/cgroup2
if mount -t cgroup2 cgroup2 /tmp/cgroup2; then
is_v2_supported=yes
umount /tmp/cgroup2
fi
rmdir /tmp/cgroup2
# check cgroup namespaces
is_cgns_supported=no
if [[ -f /proc/1/ns/cgroup ]]; then
is_cgns_supported=yes
fi
is_user_ns_supported=no
# On some systems (e.g. CentOS 7) the default limit for user namespaces
# is set to 0, which causes the following unshare syscall to fail, even
# with enabled user namespaces support. By setting this value explicitly
# we can ensure the user namespaces support to be detected correctly.
sysctl -w user.max_user_namespaces=10000
if unshare -U sh -c :; then
is_user_ns_supported=yes
fi
function check_bind_tmp_path {
# https://github.com/systemd/systemd/issues/4789
local _root="/var/lib/machines/bind-tmp-path"
/create-busybox-container "$_root"
>/tmp/bind
systemd-nspawn --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind'
}
function check_norbind {
# https://github.com/systemd/systemd/issues/13170
local _root="/var/lib/machines/norbind-path"
mkdir -p /tmp/binddir/subdir
echo -n "outer" > /tmp/binddir/subdir/file
mount -t tmpfs tmpfs /tmp/binddir/subdir
echo -n "inner" > /tmp/binddir/subdir/file
/create-busybox-container "$_root"
systemd-nspawn --register=no -D "$_root" --bind=/tmp/binddir:/mnt:norbind /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi'
}
function check_notification_socket {
# https://github.com/systemd/systemd/issues/4944
local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/systemd/nspawn/notify'
systemd-nspawn --register=no -D /nc-container /bin/sh -x -c "$_cmd"
systemd-nspawn --register=no -D /nc-container -U /bin/sh -x -c "$_cmd"
}
function run {
if [[ "$1" = "yes" && "$is_v2_supported" = "no" ]]; then
printf "Unified cgroup hierarchy is not supported. Skipping.\n" >&2
return 0
fi
if [[ "$2" = "yes" && "$is_cgns_supported" = "no" ]]; then
printf "CGroup namespaces are not supported. Skipping.\n" >&2
return 0
fi
local _root="/var/lib/machines/unified-$1-cgns-$2-api-vfs-writable-$3"
/create-busybox-container "$_root"
SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b
SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -b
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -U -b; then
[[ "$is_user_ns_supported" = "yes" && "$3" = "network" ]] && return 1
else
[[ "$is_user_ns_supported" = "no" && "$3" = "network" ]] && return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -U -b; then
[[ "$is_user_ns_supported" = "yes" && "$3" = "yes" ]] && return 1
else
[[ "$is_user_ns_supported" = "no" && "$3" = "yes" ]] && return 1
fi
local _netns_opt="--network-namespace-path=/proc/self/ns/net"
# --network-namespace-path and network-related options cannot be used together
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-interface=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-macvlan=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-ipvlan=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-veth -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-veth-extra=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-bridge=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-zone=zone -b; then
return 1
fi
# allow combination of --network-namespace-path and --private-network
if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --private-network -b; then
return 1
fi
# test --network-namespace-path works with a network namespace created by "ip netns"
ip netns add nspawn_test
_netns_opt="--network-namespace-path=/run/netns/nspawn_test"
SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" /bin/ip a | grep -v -E '^1: lo.*UP'
local r=$?
ip netns del nspawn_test
if [ $r -ne 0 ]; then
return 1
fi
return 0
}
check_bind_tmp_path
check_norbind
check_notification_socket
for api_vfs_writable in yes no network; do
run no no $api_vfs_writable
run yes no $api_vfs_writable
run no yes $api_vfs_writable
run yes yes $api_vfs_writable
done
touch /testok
EOF
chmod 0755 $initdir/test-nspawn.sh
setup_testsuite
)
}
do_test "$@"
do_test "$@" 13

View File

@ -1,78 +1,21 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="/etc/machine-id testing"
IMAGE_NAME=badid
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
test_setup() {
test_create_image() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$initdir/etc/machine-id
dracut_install mount cmp
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/sh -e -x -c '/test-machine-id-setup.sh; systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok'
Type=oneshot
EOF
cat >$initdir/test-machine-id-setup.sh <<'EOF'
#!/usr/bin/env bash
set -e
set -x
function setup_root {
local _root="$1"
mkdir -p "$_root"
mount -t tmpfs tmpfs "$_root"
mkdir -p "$_root/etc" "$_root/run"
}
function check {
printf "Expected\n"
cat "$1"
printf "\nGot\n"
cat "$2"
cmp "$1" "$2"
}
r="$(pwd)/overwrite-broken-machine-id"
setup_root "$r"
systemd-machine-id-setup --print --root "$r"
echo abc >>"$r/etc/machine-id"
id=$(systemd-machine-id-setup --print --root "$r")
echo $id >expected
check expected "$r/etc/machine-id"
r="$(pwd)/transient-machine-id"
setup_root "$r"
systemd-machine-id-setup --print --root "$r"
echo abc >>"$r/etc/machine-id"
mount -o remount,ro "$r"
mount -t tmpfs tmpfs "$r/run"
transient_id=$(systemd-machine-id-setup --print --root "$r")
mount -o remount,rw "$r"
commited_id=$(systemd-machine-id-setup --print --commit --root "$r")
[[ "$transient_id" = "$commited_id" ]]
check "$r/etc/machine-id" "$r/run/machine-id"
EOF
chmod +x $initdir/test-machine-id-setup.sh
setup_testsuite
)
}
do_test "$@"
do_test "$@" 14

View File

@ -5,18 +5,4 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
test_setup() {
# create the basic filesystem layout
setup_basic_environment
mask_supporting_services
# import the test scripts in the rootfs and plug them in systemd
cp testsuite.service $initdir/etc/systemd/system/
cp test-dropin.sh $initdir/
setup_testsuite
# create dedicated rootfs for nspawn (located in $TESTDIR/nspawn-root)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 15

View File

@ -1,6 +0,0 @@
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-dropin.sh
Type=oneshot

View File

@ -6,30 +6,4 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image
# Create what will eventually be our root filesystem onto an overlay
(
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
for s in success-all success-start success-stop success-runtime \
fail-start fail-stop fail-runtime
do
cp testsuite-${s}.service ${initdir}/etc/systemd/system
done
cp testsuite.service ${initdir}/etc/systemd/system
cp extend_timeout_test_service.sh ${initdir}/
cp assess.sh ${initdir}/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 16

View File

@ -1,18 +0,0 @@
[Unit]
Description=Testsuite: Assess all other testsuite-*.services worked as expected
Wants=testsuite-success-all.service
Wants=testsuite-success-start.service
Wants=testsuite-success-runtime.service
Wants=testsuite-success-stop.service
Wants=testsuite-fail-start.service
Wants=testsuite-fail-stop.service
Wants=testsuite-fail-runtime.service
StopWhenUnneeded=yes
[Service]
Type=simple
TimeoutStartSec=infinity
ExecStartPre=/assess.sh
ExecStart=/bin/true

View File

@ -6,29 +6,4 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
}
do_test "$@"
do_test "$@" 17

View File

@ -5,31 +5,4 @@ TEST_DESCRIPTION="FailureAction= operation"
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=600
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 18

View File

@ -7,29 +7,4 @@ TEST_NO_NSPAWN=1
QEMU_TIMEOUT=600
UNIFIED_CGROUP_HIERARCHY=yes
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
}
do_test "$@"
do_test "$@" 19

View File

@ -4,34 +4,4 @@ TEST_DESCRIPTION="test changing main PID"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
Before=getty-pre.target
Wants=getty-pre.target
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
NotifyAccess=all
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 20

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="Sysuser-related tests"
IMAGE_NAME=sysusers
. $TEST_BASE_DIR/test-functions
test_setup() {

View File

@ -2,30 +2,6 @@
set -e
TEST_DESCRIPTION="Tmpfiles related tests"
TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
test_setup() {
# create the basic filesystem layout
setup_basic_environment
mask_supporting_services
inst_binary mv
inst_binary stat
inst_binary seq
inst_binary xargs
inst_binary mkfifo
inst_binary readlink
# setup the testsuite service
cp testsuite.service $initdir/etc/systemd/system/
setup_testsuite
mkdir -p $initdir/testsuite
cp run-tmpfiles-tests.sh $initdir/testsuite/
cp test-*.sh $initdir/testsuite/
# create dedicated rootfs for nspawn (located in $TESTDIR/nspawn-root)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 22

View File

@ -1,33 +1,6 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="test Type=exec"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 23

View File

@ -3,34 +3,43 @@ set -e
TEST_DESCRIPTION="Run unit tests under containers"
RUN_IN_UNPRIVILEGED_CONTAINER=yes
# embed some newlines in the kernel command line to stress our test suite
KERNEL_APPEND="
frobnicate!
$KERNEL_APPEND
"
. $TEST_BASE_DIR/test-functions
check_result_nspawn() {
local _ret=1
[[ -e $TESTDIR/$1/testok ]] && _ret=0
if [[ -s $TESTDIR/$1/failed ]]; then
[[ -e $1/testok ]] && _ret=0
if [[ -s $1/failed ]]; then
_ret=$(($_ret+1))
echo "=== Failed test log ==="
cat $TESTDIR/$1/failed
cat $1/failed
else
if [[ -s $TESTDIR/$1/skipped ]]; then
if [[ -s $1/skipped ]]; then
echo "=== Skipped test log =="
cat $TESTDIR/$1/skipped
cat $1/skipped
fi
if [[ -s $TESTDIR/$1/testok ]]; then
if [[ -s $1/testok ]]; then
echo "=== Passed tests ==="
cat $TESTDIR/$1/testok
cat $1/testok
fi
fi
cp -a $TESTDIR/$1/var/log/journal $TESTDIR
cp -a $1/var/log/journal $TESTDIR
rm -r $1/var/log/journal/*
_umount_dir $initdir
[[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
return $_ret
}
check_result_qemu() {
local _ret=1
mkdir -p $initdir
mount ${LOOPDEV}p1 $initdir
mount_initdir
[[ -e $initdir/testok ]] && _ret=0
if [[ -s $initdir/failed ]]; then
_ret=$(($_ret+1))
@ -47,55 +56,10 @@ check_result_qemu() {
fi
fi
cp -a $initdir/var/log/journal $TESTDIR
umount $initdir
rm -r $initdir/var/log/journal/*
_umount_dir $initdir
[[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
return $_ret
}
test_setup() {
if type -P meson && [[ "$(meson configure $BUILD_DIR | grep install-tests | awk '{ print $2 }')" != "true" ]]; then
dfatal "Needs to be built with -Dinstall-tests=true"
exit 1
fi
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
for i in getfacl dirname basename capsh cut rev stat mktemp rmdir ionice unshare uname tr awk getent diff xzcat lz4cat; do
inst_binary $i
done
inst /etc/hosts
setup_basic_environment
install_keymaps yes
install_zoneinfo
# Install nproc to determine # of CPUs for correct parallelization
inst_binary nproc
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
# mask some services that we do not want to run in these tests
ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.service
ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
ln -fs /dev/null $initdir/etc/systemd/system/systemd-resolved.service
}
do_test "$@"
do_test "$@" 24

View File

@ -4,30 +4,4 @@ TEST_DESCRIPTION="test importd"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
dracut_install dd gunzip mv tar diff
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 25

View File

@ -4,29 +4,4 @@ TEST_DESCRIPTION="test setenv"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 26

View File

@ -4,31 +4,4 @@ TEST_DESCRIPTION="test StandardOutput=file:"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
inst_binary cmp
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 27

View File

@ -5,52 +5,4 @@ RUN_IN_UNPRIVILEGED_CONTAINER=yes
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# Set up the services.
cat >$initdir/etc/systemd/system/specifier-j-wants.service << EOF
[Unit]
Description=Wants with percent-j specifier
Wants=specifier-j-depends-%j.service
After=specifier-j-depends-%j.service
[Service]
Type=oneshot
ExecStart=test -f /tmp/test-specifier-j-%j
ExecStart=/bin/sh -c 'echo OK > /testok'
EOF
cat >$initdir/etc/systemd/system/specifier-j-depends-wants.service << EOF
[Unit]
Description=Dependent service for percent-j specifier
[Service]
Type=oneshot
ExecStart=touch /tmp/test-specifier-j-wants
EOF
cat >$initdir/etc/systemd/system/testsuite.service << EOF
[Unit]
Description=Testsuite: Ensure %j Wants directives work
Wants=specifier-j-wants.service
After=specifier-j-wants.service
[Service]
Type=oneshot
ExecStart=/bin/true
EOF
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 28

View File

@ -6,29 +6,4 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
}
do_test "$@"
do_test "$@" 29

View File

@ -2,42 +2,6 @@
set -e
TEST_DESCRIPTION="test OnClockChange= + OnTimezoneChange="
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
inst_any /usr/share/zoneinfo/Europe/Kiev
inst_any /usr/share/zoneinfo/Europe/Berlin
setup_basic_environment
mask_supporting_services
# extend the watchdog
mkdir -p $initdir/etc/systemd/system/systemd-timedated.service.d
cat >$initdir/etc/systemd/system/systemd-timedated.service.d/watchdog.conf <<EOF
[Service]
WatchdogSec=10min
EOF
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
}
do_test "$@"
do_test "$@" 30

View File

@ -6,29 +6,4 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
}
do_test "$@"
do_test "$@" 31

View File

@ -2,35 +2,8 @@
set -e
TEST_DESCRIPTION="test OOM killer logic"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
UNIFIED_CGROUP_HIERARCHY=yes
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
MemoryAccounting=yes
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
}
do_test "$@"
do_test "$@" 32

View File

@ -3,33 +3,6 @@
# ex: ts=8 sw=4 sts=4 et filetype=sh
set -e
TEST_DESCRIPTION="test CleanUnit"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
) || return 1
setup_nspawn_root
}
do_test "$@"
do_test "$@" 33

View File

@ -1,33 +1,6 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="test migrating state directory from DynamicUser=1 to DynamicUser=0 and back"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 34

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -1,36 +0,0 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="network-generator tests"
. $TEST_BASE_DIR/test-functions
test_setup() {
mkdir -p $TESTDIR/run/systemd/network
}
test_run() {
local generator
if [[ -x $BUILD_DIR/systemd-network-generator ]]; then
generator=$BUILD_DIR/systemd-network-generator
elif [[ -x /usr/lib/systemd/systemd-network-generator ]]; then
generator=/usr/lib/systemd/systemd-network-generator
elif [[ -x /lib/systemd/systemd-network-generator ]]; then
generator=/lib/systemd/systemd-network-generator
else
exit 1
fi
for f in test-*.input; do
echo "*** Running $f"
rm -f $TESTDIR/run/systemd/network/*
$generator --root $TESTDIR -- $(cat $f)
if ! diff -u $TESTDIR/run/systemd/network ${f%.input}.expected; then
echo "**** Unexpected output for $f"
exit 1
fi
done
}
do_test "$@"

View File

@ -4,34 +4,6 @@ set -e
TEST_DESCRIPTION="test MUMAPolicy= and NUMAMask= options"
TEST_NO_NSPAWN=1
QEMU_OPTIONS="-numa node,nodeid=0"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install mktemp
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 36

View File

@ -3,33 +3,6 @@
# ex: ts=8 sw=4 sts=4 et filetype=sh
set -e
TEST_DESCRIPTION="test RuntimeDirectoryPreserve=yes"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
) || return 1
setup_nspawn_root
}
do_test "$@"
do_test "$@" 37

View File

@ -1,35 +1,6 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="Test ExecReload= (PR #13098)"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install mktemp
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 39

View File

@ -1,33 +1,6 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="test ExecXYZEx= service unit dbus hookups"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 40

View File

@ -3,30 +3,4 @@ set -e
TEST_DESCRIPTION="Test oneshot unit restart on failure"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 41

View File

@ -4,46 +4,4 @@ TEST_DESCRIPTION="test that ExecStopPost= is always run"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup policy for Type=dbus test
mkdir -p $initdir/etc/dbus-1/system.d
cat > $initdir/etc/dbus-1/system.d/systemd.test.ExecStopPost.conf <<EOF
<?xml version="1.0"?>
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="systemd.test.ExecStopPost"/>
</policy>
</busconfig>
EOF
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
Before=getty-pre.target
Wants=getty-pre.target
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 42

View File

@ -3,47 +3,6 @@ set -e
TEST_DESCRIPTION="Test PrivateUsers=yes on user manager"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
inst_binary stat
mask_supporting_services
# Allocate user for running test case under
mkdir -p $initdir/etc/sysusers.d
cat >$initdir/etc/sysusers.d/testuser.conf <<EOF
u testuser 4711 "Test User" /home/testuser
EOF
mkdir -p $initdir/home/testuser -m 0700
chown 4711:4711 $initdir/home/testuser
enable_user_manager testuser
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=systemd-logind.service user@4711.service
Wants=user@4711.service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
has_user_dbus_socket || exit 0
do_test "$@"
do_test "$@" 43

View File

@ -4,36 +4,4 @@ TEST_DESCRIPTION="test log namespaces"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
Before=getty-pre.target
Wants=getty-pre.target
Wants=systemd-journald@foobar.socket systemd-journald-varlink@foobar.socket
After=systemd-journald@foobar.socket systemd-journald-varlink@foobar.socket
[Service]
ExecStart=/testsuite.sh
Type=oneshot
LogTarget=foobar
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 44

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -1,37 +0,0 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="test systemd-repart"
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install truncate sfdisk grep
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
Before=getty-pre.target
Wants=getty-pre.target
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -1,120 +0,0 @@
#!/usr/bin/env bash
set -ex
# Check if repart is installed, and if it isn't bail out early instead of failing
if ! test -x /usr/bin/systemd-repart ; then
echo OK > /testok
exit 0
fi
systemd-analyze log-level debug
truncate -s 1G /tmp/zzz
SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8
systemd-repart /tmp/zzz --empty=force --dry-run=no --seed=$SEED
sfdisk -d /tmp/zzz | grep -v -e 'sector-size' -e '^$' > /tmp/empty
cmp /tmp/empty - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: /tmp/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
EOF
mkdir /tmp/definitions
cat > /tmp/definitions/root.conf <<EOF
[Partition]
Type=root
EOF
ln -s root.conf /tmp/definitions/root2.conf
cat > /tmp/definitions/home.conf <<EOF
[Partition]
Type=home
EOF
cat > /tmp/definitions/swap.conf <<EOF
[Partition]
Type=swap
SizeMaxBytes=64M
PaddingMinBytes=92M
EOF
systemd-repart /tmp/zzz --dry-run=no --seed=$SEED --definitions=/tmp/definitions
sfdisk -d /tmp/zzz | grep -v -e 'sector-size' -e '^$' > /tmp/populated
cmp /tmp/populated - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: /tmp/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
/tmp/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
/tmp/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
/tmp/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
/tmp/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
EOF
cat > /tmp/definitions/swap.conf <<EOF
[Partition]
Type=swap
SizeMaxBytes=64M
EOF
cat > /tmp/definitions/extra.conf <<EOF
[Partition]
Type=linux-generic
EOF
systemd-repart /tmp/zzz --dry-run=no --seed=$SEED --definitions=/tmp/definitions
sfdisk -d /tmp/zzz | grep -v -e 'sector-size' -e '^$' > /tmp/populated2
cmp /tmp/populated2 - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: /tmp/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
/tmp/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
/tmp/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
/tmp/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
/tmp/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
/tmp/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=03477476-06AD-44E8-9EF4-BC2BD7771289, name="linux-generic"
EOF
truncate -s 2G /tmp/zzz
systemd-repart /tmp/zzz --dry-run=no --seed=$SEED --definitions=/tmp/definitions
sfdisk -d /tmp/zzz | grep -v -e 'sector-size' -e '^$' > /tmp/populated3
cmp /tmp/populated3 - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: /tmp/zzz
unit: sectors
first-lba: 2048
last-lba: 4194270
/tmp/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
/tmp/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
/tmp/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
/tmp/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
/tmp/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=03477476-06AD-44E8-9EF4-BC2BD7771289, name="linux-generic"
EOF
systemd-analyze log-level info
echo OK > /testok
exit 0

View File

@ -5,38 +5,4 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image
mkdir -p $TESTDIR/root
mount ${LOOPDEV}p1 $TESTDIR/root
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
Before=getty-pre.target
Wants=getty-pre.target
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
NotifyAccess=all
EOF
cp testsuite.sh $initdir/
setup_testsuite
) || return 1
setup_nspawn_root
ddebug "umount $TESTDIR/root"
umount $TESTDIR/root
}
do_test "$@"
do_test "$@" 46

View File

@ -1,43 +1,6 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="Test that KillMode=mixed does not leave left over proccesses with ExecStopPost="
. $TEST_BASE_DIR/test-functions
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/testsuite.sh
Type=oneshot
EOF
cat > $initdir/etc/systemd/system/issue_14566_test.service << EOF
[Unit]
Description=Issue 14566 Repro
[Service]
ExecStart=/repro.sh
ExecStopPost=/bin/true
KillMode=mixed
EOF
cp testsuite.sh $initdir/
cp repro.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"
do_test "$@" 47

View File

@ -1 +0,0 @@
../units/basic.target

View File

@ -1 +0,0 @@
loopy.service

View File

@ -1 +0,0 @@
loopy3.service

View File

@ -1,236 +1,56 @@
# SPDX-License-Identifier: LGPL-2.1+
test_data_files = '''
a.service
a-conj.service
b.service
basic.target
c.service
d.service
daughter.service
dml.slice
dml-passthrough.slice
dml-passthrough-empty.service
dml-passthrough-set-dml.service
dml-passthrough-set-ml.service
dml-override.slice
dml-override-empty.service
dml-discard.slice
dml-discard-empty.service
dml-discard-set-ml.service
e.service
end.service
f.service
g.service
grandchild.service
h.service
hello-after-sleep.target
hello.service
hwdb.d/10-bad.hwdb
i.service
journal-data/journal-1.txt
journal-data/journal-2.txt
nomem.slice
nomemleaf.service
parent-deep.slice
parent.slice
sched_idle_bad.service
sched_idle_ok.service
sched_rr_bad.service
sched_rr_change.service
sched_rr_ok.service
shutdown.target
sleep.service
sockets.target
son.service
sysinit.target
test-execute/exec-basic.service
test-execute/exec-ambientcapabilities-merge-nfsnobody.service
test-execute/exec-ambientcapabilities-merge-nobody.service
test-execute/exec-ambientcapabilities-merge.service
test-execute/exec-ambientcapabilities-nfsnobody.service
test-execute/exec-ambientcapabilities-nobody.service
test-execute/exec-ambientcapabilities.service
test-execute/exec-bindpaths.service
test-execute/exec-capabilityboundingset-invert.service
test-execute/exec-capabilityboundingset-merge.service
test-execute/exec-capabilityboundingset-reset.service
test-execute/exec-capabilityboundingset-simple.service
test-execute/exec-condition-failed.service
test-execute/exec-condition-skip.service
test-execute/exec-cpuaffinity1.service
test-execute/exec-cpuaffinity2.service
test-execute/exec-cpuaffinity3.service
test-execute/exec-dynamicuser-fixeduser-adm.service
test-execute/exec-dynamicuser-fixeduser-games.service
test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service
test-execute/exec-dynamicuser-fixeduser.service
test-execute/exec-dynamicuser-statedir-migrate-step1.service
test-execute/exec-dynamicuser-statedir-migrate-step2.service
test-execute/exec-dynamicuser-statedir.service
test-execute/exec-dynamicuser-supplementarygroups.service
test-execute/exec-environment-no-substitute.service
test-execute/exec-environment-empty.service
test-execute/exec-environment-multiple.service
test-execute/exec-environment.service
test-execute/exec-environmentfile.service
test-execute/exec-group-nfsnobody.service
test-execute/exec-group-nobody.service
test-execute/exec-group-nogroup.service
test-execute/exec-group.service
test-execute/exec-ignoresigpipe-no.service
test-execute/exec-ignoresigpipe-yes.service
test-execute/exec-inaccessiblepaths-mount-propagation.service
test-execute/exec-inaccessiblepaths-sys.service
test-execute/exec-ioschedulingclass-best-effort.service
test-execute/exec-ioschedulingclass-idle.service
test-execute/exec-ioschedulingclass-none.service
test-execute/exec-ioschedulingclass-realtime.service
test-execute/exec-oomscoreadjust-negative.service
test-execute/exec-oomscoreadjust-positive.service
test-execute/exec-passenvironment-absent.service
test-execute/exec-passenvironment-empty.service
test-execute/exec-passenvironment-repeated.service
test-execute/exec-passenvironment.service
test-execute/exec-personality-aarch64.service
test-execute/exec-personality-ppc64.service
test-execute/exec-personality-ppc64le.service
test-execute/exec-personality-s390.service
test-execute/exec-personality-x86-64.service
test-execute/exec-personality-x86.service
test-execute/exec-privatedevices-disabled-by-prefix.service
test-execute/exec-privatedevices-no-capability-mknod.service
test-execute/exec-privatedevices-no-capability-sys-rawio.service
test-execute/exec-privatedevices-no.service
test-execute/exec-privatedevices-yes-with-group.service
test-execute/exec-privatedevices-yes-capability-mknod.service
test-execute/exec-privatedevices-yes-capability-sys-rawio.service
test-execute/exec-privatedevices-yes.service
test-execute/exec-privatenetwork-yes.service
test-execute/exec-privatetmp-no.service
test-execute/exec-privatetmp-yes.service
test-execute/exec-privatetmp-disabled-by-prefix.service
test-execute/exec-protecthome-tmpfs-vs-protectsystem-strict.service
test-execute/exec-protectkernellogs-yes-capabilities.service
test-execute/exec-protectkernellogs-no-capabilities.service
test-execute/exec-protectkernelmodules-no-capabilities.service
test-execute/exec-protectkernelmodules-yes-capabilities.service
test-execute/exec-protectkernelmodules-yes-mount-propagation.service
test-execute/exec-readonlypaths-mount-propagation.service
test-execute/exec-readonlypaths-simple.service
test-execute/exec-readonlypaths-with-bindpaths.service
test-execute/exec-readonlypaths.service
test-execute/exec-readwritepaths-mount-propagation.service
test-execute/exec-restrictnamespaces-merge-all.service
test-execute/exec-restrictnamespaces-merge-and.service
test-execute/exec-restrictnamespaces-merge-or.service
test-execute/exec-restrictnamespaces-mnt-blacklist.service
test-execute/exec-restrictnamespaces-mnt.service
test-execute/exec-restrictnamespaces-no.service
test-execute/exec-restrictnamespaces-yes.service
test-execute/exec-runtimedirectory-mode.service
test-execute/exec-runtimedirectory-owner-nfsnobody.service
test-execute/exec-runtimedirectory-owner-nobody.service
test-execute/exec-runtimedirectory-owner-nogroup.service
test-execute/exec-runtimedirectory-owner.service
test-execute/exec-runtimedirectory.service
test-execute/exec-specifier-interpolation.service
test-execute/exec-specifier.service
test-execute/exec-specifier@.service
test-execute/exec-standardinput-data.service
test-execute/exec-standardinput-file.service
test-execute/exec-standardinput-file-cat.service
test-execute/exec-standardoutput-file.service
test-execute/exec-standardoutput-append.service
test-execute/exec-supplementarygroups-multiple-groups-default-group-user.service
test-execute/exec-supplementarygroups-multiple-groups-withgid.service
test-execute/exec-supplementarygroups-multiple-groups-withuid.service
test-execute/exec-supplementarygroups-single-group-user.service
test-execute/exec-supplementarygroups-single-group.service
test-execute/exec-supplementarygroups.service
test-execute/exec-systemcallerrornumber-name.service
test-execute/exec-systemcallerrornumber-number.service
test-execute/exec-systemcallfilter-failing.service
test-execute/exec-systemcallfilter-failing2.service
test-execute/exec-systemcallfilter-not-failing.service
test-execute/exec-systemcallfilter-not-failing2.service
test-execute/exec-systemcallfilter-system-user-nfsnobody.service
test-execute/exec-systemcallfilter-system-user-nobody.service
test-execute/exec-systemcallfilter-system-user.service
test-execute/exec-systemcallfilter-with-errno-multi.service
test-execute/exec-systemcallfilter-with-errno-name.service
test-execute/exec-systemcallfilter-with-errno-number.service
test-execute/exec-temporaryfilesystem-options.service
test-execute/exec-temporaryfilesystem-ro.service
test-execute/exec-temporaryfilesystem-rw.service
test-execute/exec-temporaryfilesystem-usr.service
test-execute/exec-umask-0177.service
test-execute/exec-umask-default.service
test-execute/exec-unsetenvironment.service
test-execute/exec-user-nfsnobody.service
test-execute/exec-user-nobody.service
test-execute/exec-user.service
test-execute/exec-workingdirectory.service
test-execute/exec-workingdirectory-trailing-dot.service
test-path/basic.target
test-path/path-changed.path
test-path/path-changed.service
test-path/path-directorynotempty.path
test-path/path-directorynotempty.service
test-path/path-exists.path
test-path/path-exists.service
test-path/path-existsglob.path
test-path/path-existsglob.service
test-path/path-makedirectory.path
test-path/path-makedirectory.service
test-path/path-modified.path
test-path/path-modified.service
test-path/path-mycustomunit.service
test-path/path-service.service
test-path/path-unit.path
test-path/paths.target
test-path/sysinit.target
test-umount/empty.mountinfo
test-umount/example.swaps
test-umount/garbled.mountinfo
test-umount/rhbug-1554943.mountinfo
testsuite.target
timers.target
unit-with-.service.d/20-override.conf
unit-with-multiple-.service.d/20-override.conf
unit-with-multiple-.service.d/30-override.conf
unit-with-multiple-dashes.service
unit-with-multiple-dashes.service.d/10-override.conf
unstoppable.service
'''.split()
testdata_dir = testsdir + '/testdata/'
install_subdir('journal-data',
install_dir : testdata_dir)
install_subdir('units',
install_dir : testdata_dir)
install_subdir('test-execute',
install_dir : testdata_dir)
install_subdir('test-path',
install_dir : testdata_dir)
install_subdir('test-umount',
install_dir : testdata_dir)
install_subdir('test-network-generator-conversion',
install_dir : testdata_dir)
install_subdir('testsuite-04.units',
install_dir : testdata_dir)
install_subdir('testsuite-06.units',
install_dir : testdata_dir)
install_subdir('testsuite-10.units',
install_dir : testdata_dir)
install_subdir('testsuite-11.units',
install_dir : testdata_dir)
install_subdir('testsuite-16.units',
install_dir : testdata_dir)
install_subdir('testsuite-28.units',
install_dir : testdata_dir)
install_subdir('testsuite-30.units',
install_dir : testdata_dir)
testsuite08_dir = testdata_dir + '/testsuite-08.units'
install_data('testsuite-08.units/-.mount',
install_dir : testsuite08_dir)
install_data('testsuite-08.units/systemd-remount-fs.service',
install_dir : testsuite08_dir)
meson.add_install_script(meson_make_symlink,
'./-.mount',
testsuite08_dir + '/root.mount')
meson.add_install_script(meson_make_symlink,
'../-.mount',
testsuite08_dir + '/local-fs.target.wants/-.mount')
if conf.get('ENABLE_RESOLVE') == 1
test_data_files += '''
test-resolve/_openpgpkey.fedoraproject.org.pkts
test-resolve/fedoraproject.org.pkts
test-resolve/gandi.net.pkts
test-resolve/google.com.pkts
test-resolve/root.pkts
test-resolve/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts
test-resolve/teamits.com.pkts
test-resolve/zbyszek@fedoraproject.org.pkts
test-resolve/_443._tcp.fedoraproject.org.pkts
test-resolve/kyhwana.org.pkts
test-resolve/fake-caa.pkts
'''.split()
install_subdir('test-resolve',
install_dir : testdata_dir)
endif
if install_tests
foreach file : test_data_files
subdir = file.split('/')[0]
if subdir == file
subdir = ''
endif
install_data('create-busybox-container',
install_mode : 'rwxr-xr-x',
install_dir : testdata_dir)
install_data(file,
install_dir : testsdir + '/testdata/' + subdir)
endforeach
endif
test_network_generator_conversion_sh = find_program('test-network-generator-conversion.sh')
############################################################
@ -257,6 +77,9 @@ if install_tests
install_data('run-unit-tests.py',
install_mode : 'rwxr-xr-x',
install_dir : testsdir)
install_data('test-network-generator-conversion.sh',
install_mode : 'rwxr-xr-x',
install_dir : testsdir)
endif
############################################################

View File

@ -4,8 +4,10 @@ set -e
BUILD_DIR="$($(dirname "$0")/../tools/find-build-dir.sh)"
if [ $# -gt 0 ]; then
args="$@"
do_clean=0
else
args="clean setup run clean-again"
args="setup run clean-again"
do_clean=1
fi
ninja -C "$BUILD_DIR"
@ -16,6 +18,13 @@ COUNT=0
FAILURES=0
cd "$(dirname "$0")"
if [ $do_clean = 1 ]; then
for TEST in TEST-??-* ; do
( set -x ; make -C "$TEST" "BUILD_DIR=$BUILD_DIR" clean )
done
fi
for TEST in TEST-??-* ; do
COUNT=$(($COUNT+1))
@ -31,6 +40,12 @@ for TEST in TEST-??-* ; do
[ "$RESULT" -ne "0" ] && FAILURES=$(($FAILURES+1))
done
if [ $FAILURES -eq 0 -a $do_clean = 1 ]; then
for TEST in TEST-??-* ; do
( set -x ; make -C "$TEST" "BUILD_DIR=$BUILD_DIR" clean-again )
done
fi
echo ""
for TEST in ${!results[@]}; do

View File

@ -1 +0,0 @@
../units/shutdown.target

View File

@ -1 +0,0 @@
../units/sockets.target

View File

@ -1 +0,0 @@
../units/sysinit.target

View File

@ -14,8 +14,11 @@ NSPAWN_TIMEOUT="${NSPAWN_TIMEOUT:-infinity}"
TIMED_OUT= # will be 1 after run_* if *_TIMEOUT is set and test timed out
[[ "$LOOKS_LIKE_SUSE" ]] && FSTYPE="${FSTYPE:-btrfs}" || FSTYPE="${FSTYPE:-ext4}"
UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}"
EFI_MOUNT="$(bootctl -x 2>/dev/null || echo /boot)"
EFI_MOUNT="${EFI_MOUNT:-$(bootctl -x 2>/dev/null || echo /boot)}"
QEMU_MEM="${QEMU_MEM:-512M}"
IMAGE_NAME=${IMAGE_NAME:-default}
TEST_REQUIRE_INSTALL_TESTS="${TEST_REQUIRE_INSTALL_TESTS:-1}"
LOOPDEV=
# Decide if we can (and want to) run QEMU with KVM acceleration.
# Check if nested KVM is explicitly enabled (TEST_NESTED_KVM). If not,
@ -39,11 +42,104 @@ PATH_TO_INIT=$ROOTLIBDIR/systemd
[ "$SYSTEMD_NSPAWN" ] || SYSTEMD_NSPAWN=$(which -a $BUILD_DIR/systemd-nspawn systemd-nspawn 2>/dev/null | grep '^/' -m1)
[ "$JOURNALCTL" ] || JOURNALCTL=$(which -a $BUILD_DIR/journalctl journalctl 2>/dev/null | grep '^/' -m1)
BASICTOOLS="test env sh bash setsid loadkeys setfont login sulogin gzip sleep echo head tail cat mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs"
DEBUGTOOLS="df free ls stty ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find vi mv"
BASICTOOLS=(
awk
basename
bash
busybox
capsh
cat
chmod
chown
cmp
cryptsetup
cut
date
dd
diff
dirname
dmsetup
echo
env
false
getent
getfacl
grep
gunzip
gzip
head
ionice
ip
ln
loadkeys
login
lz4cat
mkfifo
mktemp
modprobe
mount
mv
nc
nproc
readlink
rev
rm
rmdir
sed
seq
setfont
setsid
sfdisk
sh
sleep
socat
stat
su
sulogin
sysctl
tail
tar
tee
test
touch
tr
true
truncate
umount
uname
unshare
xargs
xzcat
)
DEBUGTOOLS=(
cp
df
dhclient
dmesg
du
find
free
grep
hostname
id
less
ln
ls
mkdir
ping
ps
route
sort
strace
stty
tty
vi
)
STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"
STATEFILE="$STATEDIR/.testdir"
IMAGESTATEDIR="$STATEDIR/.."
TESTLOG="$STATEDIR/test.log"
is_built_with_asan() {
@ -138,6 +234,10 @@ run_qemu() {
CONSOLE=ttyS0
# make sure the initdir is not mounted to avoid concurrent access
cleanup_initdir
umount_loopback
if [[ ! "$KERNEL_BIN" ]]; then
if [[ "$LOOKS_LIKE_ARCH" ]]; then
KERNEL_BIN=/boot/vmlinuz-linux
@ -184,6 +284,9 @@ run_qemu() {
find_qemu_bin || return 1
# Umount initdir to avoid concurrent access to the filesystem
_umount_dir $initdir
local _cgroup_args
if [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" ]]; then
_cgroup_args="systemd.unified_cgroup_hierarchy=yes"
@ -198,14 +301,18 @@ run_qemu() {
if [[ "$LOOKS_LIKE_SUSE" ]]; then
PARAMS+="rd.hostonly=0"
elif [[ "$LOOKS_LIKE_ARCH" ]]; then
PARAMS+="rw"
fi
local _end
if [[ ! "$INTERACTIVE_DEBUG" ]]; then
_end="systemd.wants=end.service"
else
PARAMS+="ro"
_end=""
fi
KERNEL_APPEND="$PARAMS \
root=/dev/sda1 \
rw \
raid=noautodetect \
rd.luks=0 \
loglevel=2 \
@ -213,6 +320,9 @@ init=$PATH_TO_INIT \
console=$CONSOLE \
selinux=0 \
$_cgroup_args \
SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/testsuite-$1.units:/usr/lib/systemd/tests/testdata/units: \
systemd.unit=testsuite.target \
systemd.wants=testsuite-$1.service ${_end} \
$KERNEL_APPEND \
"
@ -221,7 +331,7 @@ $KERNEL_APPEND \
-m $QEMU_MEM \
-nographic \
-kernel $KERNEL_BIN \
-drive format=raw,cache=unsafe,file=${TESTDIR}/rootdisk.img \
-drive format=raw,cache=unsafe,file=${IMAGESTATEDIR}/${IMAGE_NAME}.img \
$QEMU_OPTIONS \
"
@ -253,24 +363,41 @@ $QEMU_OPTIONS \
run_nspawn() {
[[ -d /run/systemd/system ]] || return 1
local _nspawn_cmd="$SYSTEMD_NSPAWN $NSPAWN_ARGUMENTS --register=no --kill-signal=SIGKILL --directory=$TESTDIR/$1 $PATH_TO_INIT $KERNEL_APPEND"
local _nspawn_cmd=(
--register=no
--kill-signal=SIGKILL
--directory=$1
--setenv=SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/testsuite-$2.units:/usr/lib/systemd/tests/testdata/units:
$PATH_TO_INIT
$KERNEL_APPEND
systemd.unit=testsuite.target
systemd.wants=testsuite-$2.service
)
if [[ ! "$INTERACTIVE_DEBUG" ]]; then
_nspawn_cmd+=( systemd.wants=end.service )
fi
local _nspawn_pre
if [[ "$NSPAWN_TIMEOUT" != "infinity" ]]; then
_nspawn_cmd="timeout --foreground $NSPAWN_TIMEOUT $_nspawn_cmd"
_nspawn_pre=(timeout --foreground $NSPAWN_TIMEOUT)
else
_nspawn_pre=()
fi
if [[ "$UNIFIED_CGROUP_HIERARCHY" = "hybrid" ]]; then
dwarn "nspawn doesn't support SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=hybrid, skipping"
exit
elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" || "$UNIFIED_CGROUP_HIERARCHY" = "no" ]]; then
_nspawn_cmd="env SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY $_nspawn_cmd"
_nspawn_pre=("${nspawn_pre[@]}" env SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY)
elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "default" ]]; then
_nspawn_cmd="env --unset=UNIFIED_CGROUP_HIERARCHY --unset=SYSTEMD_NSPAWN_UNIFIED_HIERARCHY $_nspawn_cmd"
_nspawn_pre=("${nspawn_pre[@]}" env --unset=UNIFIED_CGROUP_HIERARCHY --unset=SYSTEMD_NSPAWN_UNIFIED_HIERARCHY)
else
dfatal "Unknown UNIFIED_CGROUP_HIERARCHY. Got $UNIFIED_CGROUP_HIERARCHY, expected [yes|no|hybrid|default]"
exit 1
fi
(set -x; $_nspawn_cmd)
(set -x; "${_nspawn_pre[@]}" "$SYSTEMD_NSPAWN" $NSPAWN_ARGUMENTS "${_nspawn_cmd[@]}")
rc=$?
if [ "$rc" = 124 ] && [ "$NSPAWN_TIMEOUT" != "infinity" ]; then
derror "test timed out after $NSPAWN_TIMEOUT s"
@ -288,6 +415,7 @@ setup_basic_environment() {
install_systemd
install_missing_libraries
install_config_files
install_zoneinfo
create_rc_local
install_basic_tools
install_libnss
@ -301,6 +429,8 @@ setup_basic_environment() {
install_plymouth
install_debug_tools
install_ld_so_conf
install_testuser
has_user_dbus_socket && install_user_dbus
setup_selinux
strip_binaries
install_depmod_files
@ -326,27 +456,9 @@ setup_selinux() {
exit 1
fi
cat <<EOF >$initdir/etc/systemd/system/autorelabel.service
[Unit]
Description=Relabel all filesystems
DefaultDependencies=no
Requires=local-fs.target
Conflicts=shutdown.target
After=local-fs.target
Before=sysinit.target shutdown.target
ConditionSecurity=selinux
ConditionPathExists=|/.autorelabel
[Service]
ExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && fixfiles -f -F relabel && rm /.autorelabel && systemctl --force reboot'
Type=oneshot
TimeoutSec=0
RemainAfterExit=yes
EOF
touch $initdir/.autorelabel
mkdir -p $initdir/etc/systemd/system/basic.target.wants
ln -fs autorelabel.service $initdir/etc/systemd/system/basic.target.wants/autorelabel.service
mkdir -p $initdir/usr/lib/systemd/tests/testdata/units/basic.target.wants
ln -sf ../autorelabel.service $initdir/usr/lib/systemd/tests/testdata/units/basic.target.wants/
dracut_install $_fixfiles_tools
dracut_install fixfiles
@ -475,7 +587,7 @@ unset_ld_preload() {
}
unset_ld_preload systemd-remount-fs
unset_ld_preload testsuite
unset_ld_preload testsuite-
export ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd.asan.log UBSAN_OPTIONS=\$DEFAULT_UBSAN_OPTIONS
exec $ROOTLIBDIR/systemd "\$@"
@ -530,7 +642,7 @@ install_systemd() {
# and it could fill the available space
strip_binaries
[[ "$LOOKS_LIKE_SUSE" ]] && setup_suse
[[ "$LOOKS_LIKE_SUSE" ]] && setup_suse
# enable debug logging in PID1
echo LogLevel=debug >> $initdir/etc/systemd/system.conf
@ -556,17 +668,37 @@ install_missing_libraries() {
done
}
cleanup_loopdev() {
if [ -n "${LOOPDEV}" ]; then
ddebug "losetup -d $LOOPDEV"
losetup -d "${LOOPDEV}"
fi
}
trap cleanup_loopdev EXIT
create_empty_image() {
if [ -z "$IMAGE_NAME" ]; then
echo "create_empty_image: \$IMAGE_NAME not set"
exit 1
fi
local _size=500
if [[ "$STRIP_BINARIES" = "no" ]]; then
_size=$((4*_size))
fi
rm -f "$TESTDIR/rootdisk.img"
image="${TESTDIR}/${IMAGE_NAME}.img"
public="$IMAGESTATEDIR/${IMAGE_NAME}.img"
echo "Setting up $public (${_size} MB)"
rm -f "$image" "$public"
# Create the blank file to use as a root filesystem
truncate -s "${_size}M" "$TESTDIR/rootdisk.img"
LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
truncate -s "${_size}M" "$image"
ln -vs "$(realpath $image)" "$public"
LOOPDEV=$(losetup --show -P -f "$public")
[ -b "$LOOPDEV" ] || return 1
echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
sfdisk "$LOOPDEV" <<EOF
,$((_size-50))M
,
@ -574,20 +706,50 @@ EOF
udevadm settle
local _label="-L systemd"
local _label="-L systemd.${name}"
# mkfs.reiserfs doesn't know -L. so, use --label instead
[[ "$FSTYPE" == "reiserfs" ]] && _label="--label systemd"
if ! mkfs -t "${FSTYPE}" ${_label} "${LOOPDEV}p1" -q; then
[[ "$FSTYPE" == "reiserfs" ]] && _label="--label systemd.${name}"
mkfs -t "${FSTYPE}" ${_label} "${LOOPDEV}p1" -q; ret=$?
if [ $ret -ne 0 ] ; then
dfatal "Failed to mkfs -t ${FSTYPE}"
exit 1
fi
}
mount_initdir() {
if [ -z "${LOOPDEV}" ]; then
image="${IMAGESTATEDIR}/${IMAGE_NAME}.img"
LOOPDEV=$(losetup --show -P -f "$image")
[ -b "$LOOPDEV" ] || return 1
udevadm settle
fi
if ! mountpoint -q $initdir; then
mkdir -p $initdir
mount ${LOOPDEV}p1 $initdir
TEST_SETUP_CLEANUP_ROOTDIR=1
fi
}
cleanup_initdir() {
# only umount if create_empty_image_rootdir() was called to mount it
[[ -z $TEST_SETUP_CLEANUP_ROOTDIR ]] || _umount_dir $initdir
}
umount_loopback() {
# unmount the loopback device from all places. Otherwise we risk file
# system corruption.
image="${IMAGESTATEDIR}/${IMAGE_NAME}.img"
for device in $(losetup -l | awk '$6=="'"$image"'" {print $1}'); do
ddebug "Unmounting all uses of $device"
mount | awk '/^'"${device}"'p/{print $1}' | xargs --no-run-if-empty umount -v
done
}
create_empty_image_rootdir() {
create_empty_image
mkdir -p $initdir
mount ${LOOPDEV}p1 $initdir
TEST_SETUP_CLEANUP_ROOTDIR=1
mount_initdir
}
check_asan_reports() {
@ -632,27 +794,29 @@ check_result_nspawn() {
local ret=1
local journald_report=""
local pids=""
[[ -e $TESTDIR/$1/testok ]] && ret=0
[[ -f $TESTDIR/$1/failed ]] && cp -a $TESTDIR/$1/failed $TESTDIR
cp -a $TESTDIR/$1/var/log/journal $TESTDIR
[[ -e $1/testok ]] && ret=0
[[ -f $1/failed ]] && cp -a $1/failed $TESTDIR
cp -a $1/var/log/journal $TESTDIR
rm -r $1/var/log/journal/*
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
ls -l $TESTDIR/journal/*/*.journal
test -s $TESTDIR/failed && ret=$(($ret+1))
[ -n "$TIMED_OUT" ] && ret=$(($ret+1))
check_asan_reports "$TESTDIR/$1" || ret=$(($ret+1))
check_asan_reports "$1" || ret=$(($ret+1))
_umount_dir $initdir
return $ret
}
# can be overridden in specific test
check_result_qemu() {
local ret=1
mkdir -p $initdir
mount ${LOOPDEV}p1 $initdir
mount_initdir
[[ -e $initdir/testok ]] && ret=0
[[ -f $initdir/failed ]] && cp -a $initdir/failed $TESTDIR
cp -a $initdir/var/log/journal $TESTDIR
rm -r $initdir/var/log/journal/*
check_asan_reports "$initdir" || ret=$(($ret+1))
umount $initdir
_umount_dir $initdir
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
ls -l $TESTDIR/journal/*/*.journal
test -s $TESTDIR/failed && ret=$(($ret+1))
@ -727,6 +891,17 @@ install_ld_so_conf() {
ldconfig -r "$initdir"
}
install_testuser() {
# create unprivileged user for user manager tests
mkdir -p $initdir/etc/sysusers.d
cat >$initdir/etc/sysusers.d/testuser.conf <<EOF
u testuser 4711 "Test User" /home/testuser
EOF
mkdir -p $initdir/home/testuser -m 0700
chown 4711:4711 $initdir/home/testuser
}
install_config_files() {
inst /etc/sysconfig/init || :
inst /etc/passwd
@ -741,29 +916,20 @@ install_config_files() {
# we want an empty environment
> $initdir/etc/environment
> $initdir/etc/machine-id
# set the hostname
echo systemd-testsuite > $initdir/etc/hostname
# fstab
if [[ "$LOOKS_LIKE_SUSE" ]]; then
ROOTMOUNT="/dev/sda1 / ${FSTYPE} rw 0 1"
else
ROOTMOUNT="LABEL=systemd / ${FSTYPE} rw 0 1"
fi
cat >$initdir/etc/fstab <<EOF
$ROOTMOUNT
EOF
}
install_basic_tools() {
[[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
dracut_install "${BASICTOOLS[@]}"
dracut_install -o sushell
# in Debian ldconfig is just a shell script wrapper around ldconfig.real
dracut_install -o ldconfig.real
}
install_debug_tools() {
[[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
dracut_install "${DEBUGTOOLS[@]}"
if [[ $INTERACTIVE_DEBUG ]]; then
# Set default TERM from vt220 to linux, so at least basic key shortcuts work
@ -810,6 +976,19 @@ install_dbus() {
| while read file; do
inst $file
done
# setup policy for Type=dbus test
mkdir -p $initdir/etc/dbus-1/system.d
cat > $initdir/etc/dbus-1/system.d/systemd.test.ExecStopPost.conf <<EOF
<?xml version="1.0"?>
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="systemd.test.ExecStopPost"/>
</policy>
</busconfig>
EOF
}
install_user_dbus() {
@ -885,10 +1064,16 @@ install_keymaps() {
}
install_zoneinfo() {
for i in /usr/share/zoneinfo/{,*/,*/*/}*; do
[[ -f $i ]] || continue
inst $i
done
inst_any /usr/share/zoneinfo/Asia/Seoul
inst_any /usr/share/zoneinfo/Asia/Vladivostok
inst_any /usr/share/zoneinfo/Australia/Sydney
inst_any /usr/share/zoneinfo/Europe/Berlin
inst_any /usr/share/zoneinfo/Europe/Kiev
inst_any /usr/share/zoneinfo/Pacific/Auckland
inst_any /usr/share/zoneinfo/Pacific/Honolulu
inst_any /usr/share/zoneinfo/CET
inst_any /usr/share/zoneinfo/EET
inst_any /usr/share/zoneinfo/UTC
}
install_fonts() {
@ -916,40 +1101,17 @@ has_user_dbus_socket() {
fi
}
enable_user_manager() {
has_user_dbus_socket || return 0
local _userid
[[ $# -gt 0 ]] || set -- nobody
mkdir -p "$initdir/var/lib/systemd/linger"
for _userid; do
touch "$initdir/var/lib/systemd/linger/$_userid"
done
dracut_install su
install_user_dbus
}
setup_testsuite() {
cp $TEST_BASE_DIR/testsuite.target $initdir/etc/systemd/system/
cp $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/
mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
# Don't shutdown the machine after running the test when INTERACTIVE_DEBUG is set
[[ -z $INTERACTIVE_DEBUG ]] && ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
# make the testsuite the default target
ln -fs testsuite.target $initdir/etc/systemd/system/default.target
}
setup_nspawn_root() {
rm -fr $TESTDIR/nspawn-root
ddebug "cp -ar $initdir $TESTDIR/nspawn-root"
cp -ar $initdir $TESTDIR/nspawn-root
# we don't mount in the nspawn root
rm -f $TESTDIR/nspawn-root/etc/fstab
if [ -z "${initdir}" ]; then
dfatal "\$initdir not defined"
exit 1
fi
rm -rf "$TESTDIR/unprivileged-nspawn-root"
if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then
cp -ar $TESTDIR/nspawn-root $TESTDIR/unprivileged-nspawn-root
ddebug "cp -ar $initdir $TESTDIR/unprivileged-nspawn-root"
cp -ar $initdir $TESTDIR/unprivileged-nspawn-root
fi
}
@ -1005,7 +1167,10 @@ inst_libs() {
}
import_testdir() {
# make sure we don't get a stale LOOPDEV value from old times
__LOOPDEV=$LOOPDEV
[[ -e $STATEFILE ]] && . $STATEFILE
LOOPDEV=$__LOOPDEV
if [[ ! -d "$TESTDIR" ]]; then
if [[ -z "$TESTDIR" ]]; then
TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
@ -1013,7 +1178,9 @@ import_testdir() {
mkdir -p "$TESTDIR"
fi
echo "TESTDIR=\"$TESTDIR\"" > $STATEFILE
cat >$STATEFILE<<EOF
TESTDIR="$TESTDIR"
EOF
export TESTDIR
fi
}
@ -1755,14 +1922,9 @@ _umount_dir() {
fi
}
_test_setup_cleanup() {
# only umount if create_empty_image_rootdir() was called to mount it
[[ -z $TEST_SETUP_CLEANUP_ROOTDIR ]] || _umount_dir $initdir
}
# can be overridden in specific test
test_setup_cleanup() {
_test_setup_cleanup
cleanup_initdir
}
_test_cleanup() {
@ -1770,12 +1932,9 @@ _test_cleanup() {
(
set +e
_umount_dir $initdir
if [[ $LOOPDEV && -b $LOOPDEV ]]; then
ddebug "losetup -d $LOOPDEV"
losetup -d $LOOPDEV
fi
rm -fr "$TESTDIR"
rm -f "$STATEFILE"
rm -vf "${IMAGESTATEDIR}/${IMAGE_NAME}.img"
rm -vfr "$TESTDIR"
rm -vf "$STATEFILE"
) || :
}
@ -1784,24 +1943,70 @@ test_cleanup() {
_test_cleanup
}
test_cleanup_again() {
[ -n "$TESTDIR" ] || return
rm -rf "$TESTDIR/unprivileged-nspawn-root"
_umount_dir $initdir
}
test_create_image() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
setup_basic_environment
mask_supporting_services
)
}
test_setup() {
if [ ${TEST_REQUIRE_INSTALL_TESTS} -ne 0 ] && \
type -P meson >/dev/null && \
[[ "$(meson configure $BUILD_DIR | grep install-tests | awk '{ print $2 }')" != "true" ]]; then
dfatal "Needs to be built with -Dinstall-tests=true"
exit 1
fi
image="${TESTDIR}/${IMAGE_NAME}.img"
public="${IMAGESTATEDIR}/${IMAGE_NAME}.img"
if [ -e "$image" ]; then
echo "Reusing existing image $PWD/$image → $(realpath $image)"
mount_initdir
elif [ -e "$public" ]; then
echo "Reusing existing cached image $PWD/$public → $(realpath $public)"
ln -s "$(realpath $public)" "$image"
mount_initdir
else
test_create_image
fi
setup_nspawn_root
}
test_run() {
mount_initdir
rm -f "$initdir"/{testok,failed,skipped}
if [ -z "$TEST_NO_QEMU" ]; then
if run_qemu; then
check_result_qemu || return 1
if run_qemu "$1"; then
check_result_qemu || { echo "QEMU test failed"; return 1; }
else
dwarn "can't run QEMU, skipping"
fi
fi
if [ -z "$TEST_NO_NSPAWN" ]; then
if run_nspawn "nspawn-root"; then
check_result_nspawn "nspawn-root" || return 1
mount_initdir
if run_nspawn "$initdir" "$1"; then
check_result_nspawn "$initdir" || { echo "nspawn-root test failed"; return 1; }
else
dwarn "can't run systemd-nspawn, skipping"
fi
if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then
if NSPAWN_ARGUMENTS="-U --private-network $NSPAWN_ARGUMENTS" run_nspawn "unprivileged-nspawn-root"; then
check_result_nspawn "unprivileged-nspawn-root" || return 1
dir="$TESTDIR/unprivileged-nspawn-root"
if NSPAWN_ARGUMENTS="-U --private-network $NSPAWN_ARGUMENTS" run_nspawn "$dir" "$1"; then
check_result_nspawn "$dir" || { echo "unprivileged-nspawn-root test failed"; return 1; }
else
dwarn "can't run systemd-nspawn, skipping"
fi
@ -1830,34 +2035,40 @@ do_test() {
import_testdir
import_initdir
testname="$(basename $PWD)"
while (($# > 0)); do
case $1 in
--run)
echo "TEST RUN: $TEST_DESCRIPTION"
test_run
echo "${testname} RUN: $TEST_DESCRIPTION"
test_run "$2"
ret=$?
if (( $ret == 0 )); then
echo "TEST RUN: $TEST_DESCRIPTION [OK]"
echo "${testname} RUN: $TEST_DESCRIPTION [OK]"
else
echo "TEST RUN: $TEST_DESCRIPTION [FAILED]"
echo "${testname} RUN: $TEST_DESCRIPTION [FAILED]"
fi
exit $ret;;
--setup)
echo "TEST SETUP: $TEST_DESCRIPTION"
echo "${testname} SETUP: $TEST_DESCRIPTION"
test_setup
test_setup_cleanup
;;
--clean)
echo "TEST CLEANUP: $TEST_DESCRIPTION"
echo "${testname} CLEANUP: $TEST_DESCRIPTION"
test_cleanup
;;
--clean-again)
echo "${testname} CLEANUP AGAIN: $TEST_DESCRIPTION"
test_cleanup_again
;;
--all)
ret=0
echo -n "TEST: $TEST_DESCRIPTION "
echo -n "${testname}: $TEST_DESCRIPTION "
(
test_setup
test_setup_cleanup
test_run
test_run "$2"
) </dev/null >"$TESTLOG" 2>&1 || ret=$?
test_cleanup
if [ $ret -eq 0 ]; then

View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -ex
if [[ -n "$1" ]]; then
generator=$1
elif [[ -x /usr/lib/systemd/systemd-network-generator ]]; then
generator=/usr/lib/systemd/systemd-network-generator
elif [[ -x /lib/systemd/systemd-network-generator ]]; then
generator=/lib/systemd/systemd-network-generator
else
exit 1
fi
src="$(dirname "$0")/testdata/test-network-generator-conversion"
for f in "$src"/test-*.input; do
echo "*** Running $f"
(
out=$(mktemp --directory)
trap "rm -rf '$out'" EXIT INT QUIT PIPE
$generator --root "$out" -- $(cat $f)
if ! diff -u "$out"/run/systemd/network ${f%.input}.expected; then
echo "**** Unexpected output for $f"
exit 1
fi
) || exit 1
done

View File

@ -1 +0,0 @@
../../units/basic.target

View File

@ -0,0 +1,22 @@
# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Basic System
Documentation=man:systemd.special(7)
Requires=sysinit.target
Wants=sockets.target timers.target paths.target slices.target
After=sysinit.target sockets.target paths.target slices.target tmp.mount
# We support /var, /tmp, /var/tmp, being on NFS, but we don't pull in
# remote-fs.target by default, hence pull them in explicitly here. Note that we
# require /var and /var/tmp, but only add a Wants= type dependency on /tmp, as
# we support that unit being masked, and this should not be considered an error.
RequiresMountsFor=/var /var/tmp
Wants=tmp.mount

View File

@ -1 +0,0 @@
path-service.service

View File

@ -0,0 +1,6 @@
[Unit]
Description=Service Test for Path units
[Service]
ExecStart=/bin/true
Type=oneshot

View File

@ -1 +0,0 @@
path-service.service

View File

@ -0,0 +1,6 @@
[Unit]
Description=Service Test for Path units
[Service]
ExecStart=/bin/true
Type=oneshot

Some files were not shown because too many files have changed in this diff Show More