1
0
mirror of https://github.com/systemd/systemd synced 2026-03-19 03:24:45 +01:00

Compare commits

..

13 Commits

Author SHA1 Message Date
Lennart Poettering
abfbfee36c
Merge pull request #19986 from keszybz/test-mount-util-more
Add smoke test for mount_flags_to_string()
2021-06-22 15:03:57 +02:00
Hristo Venev
2e8a32afbc networkd: Permit all-zero RoutingPolicyRule prefixes
For example this `From` address range is no longer ignored:

    [RoutingPolicyRule]
    From=0.0.0.0/8
2021-06-22 20:19:12 +09:00
Frantisek Sumsal
ffd0815171
Merge pull request #19969 from bluca/test_02_qemu
test-loop-block: run in qemu
2021-06-22 12:58:07 +02:00
simmon
d8301aef51 po: Translated using Weblate (Korean)
Currently translated at 100.0% (189 of 189 strings)

Co-authored-by: simmon <simmon@nplob.com>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/master/ko/
Translation: systemd/main
2021-06-22 12:24:35 +02:00
Zbigniew Jędrzejewski-Szmek
51bb6a103e test-mount-util: add output test for mount_flags_to_string() 2021-06-22 14:42:03 +09:00
Zbigniew Jędrzejewski-Szmek
917578880f test-mount-util: add usual print headers 2021-06-22 14:42:03 +09:00
Yu Watanabe
4bee2333cf mount-util: add one more assertion 2021-06-22 14:42:03 +09:00
Luca Boccassi
b152adbfa9 test-loop-block: run in qemu
test-loop-block needs to run in qemu, so we are currently not
testing it in the CI. Run it by itself in a separate job from
TEST-02-UNITTESTS to avoid slowing that suite down.

Fixes https://github.com/systemd/systemd/issues/19966

Disable it in the bionic-* CI for now, as it's affected by
the same uevent ordering issue as TEST-50-DISSECT which makes
it flaky.
2021-06-21 20:55:19 +01:00
Luca Boccassi
fa1fdd3099 test: move custom result checks from TEST-02-UNITTESTS to test-functions 2021-06-21 20:45:56 +01:00
Luca Boccassi
85d3f13254 test: allow to call units/testsuite-02.sh from other scripts 2021-06-21 19:47:38 +01:00
Luca Boccassi
1d5574516f test: do not fail TEST-02-UNITTESTS if they are all skipped
The return code is initialized to fail if /testok is not found, but
that also covers the case where all tests are skipped.
2021-06-21 19:47:38 +01:00
Luca Boccassi
7d3f9bf493 test: do not lose logs of late failures in TEST-02-UNITTESTS
Due to set -e, if the wait() fails (eg: because of an assert in the
waited task), report_result() never runs and logs are lost
2021-06-21 19:47:38 +01:00
Luca Boccassi
35cde9e935 test: install nls modules, required by vfat
kernel: FAT-fs (loop0p2): codepage cp437 not found
kernel: FAT-fs (loop0p2): IO charset ascii not found
2021-06-21 19:47:38 +01:00
15 changed files with 192 additions and 60 deletions

View File

@ -9,7 +9,7 @@ msgstr ""
"Project-Id-Version: systemd\n" "Project-Id-Version: systemd\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-08 17:48+0100\n" "POT-Creation-Date: 2021-01-08 17:48+0100\n"
"PO-Revision-Date: 2021-04-15 10:01+0000\n" "PO-Revision-Date: 2021-06-22 10:04+0000\n"
"Last-Translator: simmon <simmon@nplob.com>\n" "Last-Translator: simmon <simmon@nplob.com>\n"
"Language-Team: Korean <https://translate.fedoraproject.org/projects/systemd/" "Language-Team: Korean <https://translate.fedoraproject.org/projects/systemd/"
"master/ko/>\n" "master/ko/>\n"
@ -18,7 +18,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n" "Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 4.5.3\n" "X-Generator: Weblate 4.7\n"
"X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-SourceCharset: UTF-8\n"
#: src/core/org.freedesktop.systemd1.policy.in:22 #: src/core/org.freedesktop.systemd1.policy.in:22
@ -112,7 +112,7 @@ msgstr "홈 영역 암호 변경"
#: src/home/org.freedesktop.home1.policy:64 #: src/home/org.freedesktop.home1.policy:64
msgid "" msgid ""
"Authentication is required to change the password of a user's home area." "Authentication is required to change the password of a user's home area."
msgstr "사용자 홈 영역의 암호를 바꾸려면 인증이 필요합니다." msgstr "사용자 홈 영역의 비밀번호를 변경하려면 인증이 필요합니다."
#: src/hostname/org.freedesktop.hostname1.policy:20 #: src/hostname/org.freedesktop.hostname1.policy:20
msgid "Set hostname" msgid "Set hostname"

View File

@ -402,7 +402,7 @@ static int routing_policy_rule_set_netlink_message(const RoutingPolicyRule *rule
/* link may be NULL. */ /* link may be NULL. */
if (in_addr_is_set(rule->family, &rule->from)) { if (rule->from_prefixlen > 0) {
r = netlink_message_append_in_addr_union(m, FRA_SRC, rule->family, &rule->from); r = netlink_message_append_in_addr_union(m, FRA_SRC, rule->family, &rule->from);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Could not append FRA_SRC attribute: %m"); return log_link_error_errno(link, r, "Could not append FRA_SRC attribute: %m");
@ -412,7 +412,7 @@ static int routing_policy_rule_set_netlink_message(const RoutingPolicyRule *rule
return log_link_error_errno(link, r, "Could not set source prefix length: %m"); return log_link_error_errno(link, r, "Could not set source prefix length: %m");
} }
if (in_addr_is_set(rule->family, &rule->to)) { if (rule->to_prefixlen > 0) {
r = netlink_message_append_in_addr_union(m, FRA_DST, rule->family, &rule->to); r = netlink_message_append_in_addr_union(m, FRA_DST, rule->family, &rule->to);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Could not append FRA_DST attribute: %m"); return log_link_error_errno(link, r, "Could not append FRA_DST attribute: %m");

View File

@ -531,7 +531,7 @@ int mode_to_inaccessible_node(
return 0; return 0;
} }
static int mount_flags_to_string(long unsigned flags, char **ret) { int mount_flags_to_string(long unsigned flags, char **ret) {
static const struct { static const struct {
long unsigned flag; long unsigned flag;
const char *name; const char *name;
@ -564,6 +564,8 @@ static int mount_flags_to_string(long unsigned flags, char **ret) {
}; };
_cleanup_free_ char *str = NULL; _cleanup_free_ char *str = NULL;
assert(ret);
for (size_t i = 0; i < ELEMENTSOF(map); i++) for (size_t i = 0; i < ELEMENTSOF(map); i++)
if (flags & map[i].flag) { if (flags & map[i].flag) {
if (!strextend_with_separator(&str, "|", map[i].name)) if (!strextend_with_separator(&str, "|", map[i].name))

View File

@ -89,6 +89,7 @@ int mount_option_mangle(
char **ret_remaining_options); char **ret_remaining_options);
int mode_to_inaccessible_node(const char *runtime_dir, mode_t mode, char **dest); int mode_to_inaccessible_node(const char *runtime_dir, mode_t mode, char **dest);
int mount_flags_to_string(long unsigned flags, char **ret);
/* Useful for usage with _cleanup_(), unmounts, removes a directory and frees the pointer */ /* Useful for usage with _cleanup_(), unmounts, removes a directory and frees the pointer */
static inline char* umount_and_rmdir_and_free(char *p) { static inline char* umount_and_rmdir_and_free(char *p) {

View File

@ -7,6 +7,7 @@
#include "capability-util.h" #include "capability-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h" #include "fileio.h"
#include "missing_mount.h"
#include "mount-util.h" #include "mount-util.h"
#include "namespace-util.h" #include "namespace-util.h"
#include "path-util.h" #include "path-util.h"
@ -21,6 +22,8 @@ static void test_mount_option_mangle(void) {
char *opts = NULL; char *opts = NULL;
unsigned long f; unsigned long f;
log_info("/* %s */", __func__);
assert_se(mount_option_mangle(NULL, MS_RDONLY|MS_NOSUID, &f, &opts) == 0); assert_se(mount_option_mangle(NULL, MS_RDONLY|MS_NOSUID, &f, &opts) == 0);
assert_se(f == (MS_RDONLY|MS_NOSUID)); assert_se(f == (MS_RDONLY|MS_NOSUID));
assert_se(opts == NULL); assert_se(opts == NULL);
@ -76,11 +79,61 @@ static void test_mount_option_mangle(void) {
opts = mfree(opts); opts = mfree(opts);
} }
static void test_mount_flags_to_string_one(unsigned long flags, const char *expected) {
_cleanup_free_ char *x = NULL;
int r;
r = mount_flags_to_string(flags, &x);
log_info("flags: %#lX → %d/\"%s\"", flags, r, strnull(x));
assert_se(r >= 0);
assert_se(streq(x, expected));
}
static void test_mount_flags_to_string(void) {
log_info("/* %s */", __func__);
test_mount_flags_to_string_one(0, "0");
test_mount_flags_to_string_one(MS_RDONLY, "MS_RDONLY");
test_mount_flags_to_string_one(MS_NOSUID, "MS_NOSUID");
test_mount_flags_to_string_one(MS_NODEV, "MS_NODEV");
test_mount_flags_to_string_one(MS_NOEXEC, "MS_NOEXEC");
test_mount_flags_to_string_one(MS_SYNCHRONOUS, "MS_SYNCHRONOUS");
test_mount_flags_to_string_one(MS_REMOUNT, "MS_REMOUNT");
test_mount_flags_to_string_one(MS_MANDLOCK, "MS_MANDLOCK");
test_mount_flags_to_string_one(MS_DIRSYNC, "MS_DIRSYNC");
test_mount_flags_to_string_one(MS_NOSYMFOLLOW, "MS_NOSYMFOLLOW");
test_mount_flags_to_string_one(MS_NOATIME, "MS_NOATIME");
test_mount_flags_to_string_one(MS_NODIRATIME, "MS_NODIRATIME");
test_mount_flags_to_string_one(MS_BIND, "MS_BIND");
test_mount_flags_to_string_one(MS_MOVE, "MS_MOVE");
test_mount_flags_to_string_one(MS_REC, "MS_REC");
test_mount_flags_to_string_one(MS_SILENT, "MS_SILENT");
test_mount_flags_to_string_one(MS_POSIXACL, "MS_POSIXACL");
test_mount_flags_to_string_one(MS_UNBINDABLE, "MS_UNBINDABLE");
test_mount_flags_to_string_one(MS_PRIVATE, "MS_PRIVATE");
test_mount_flags_to_string_one(MS_SLAVE, "MS_SLAVE");
test_mount_flags_to_string_one(MS_SHARED, "MS_SHARED");
test_mount_flags_to_string_one(MS_RELATIME, "MS_RELATIME");
test_mount_flags_to_string_one(MS_KERNMOUNT, "MS_KERNMOUNT");
test_mount_flags_to_string_one(MS_I_VERSION, "MS_I_VERSION");
test_mount_flags_to_string_one(MS_STRICTATIME, "MS_STRICTATIME");
test_mount_flags_to_string_one(MS_LAZYTIME, "MS_LAZYTIME");
test_mount_flags_to_string_one(MS_LAZYTIME|MS_STRICTATIME, "MS_STRICTATIME|MS_LAZYTIME");
test_mount_flags_to_string_one(UINT_MAX,
"MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS|MS_REMOUNT|"
"MS_MANDLOCK|MS_DIRSYNC|MS_NOSYMFOLLOW|MS_NOATIME|MS_NODIRATIME|"
"MS_BIND|MS_MOVE|MS_REC|MS_SILENT|MS_POSIXACL|MS_UNBINDABLE|"
"MS_PRIVATE|MS_SLAVE|MS_SHARED|MS_RELATIME|MS_KERNMOUNT|"
"MS_I_VERSION|MS_STRICTATIME|MS_LAZYTIME|fc000200");
}
static void test_bind_remount_recursive(void) { static void test_bind_remount_recursive(void) {
_cleanup_(rm_rf_physical_and_freep) char *tmp = NULL; _cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
_cleanup_free_ char *subdir = NULL; _cleanup_free_ char *subdir = NULL;
const char *p; const char *p;
log_info("/* %s */", __func__);
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) { if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
(void) log_tests_skipped("not running privileged"); (void) log_tests_skipped("not running privileged");
return; return;
@ -134,6 +187,8 @@ static void test_bind_remount_recursive(void) {
static void test_bind_remount_one(void) { static void test_bind_remount_one(void) {
pid_t pid; pid_t pid;
log_info("/* %s */", __func__);
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) { if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
(void) log_tests_skipped("not running privileged"); (void) log_tests_skipped("not running privileged");
return; return;
@ -166,6 +221,7 @@ int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG); test_setup_logging(LOG_DEBUG);
test_mount_option_mangle(); test_mount_option_mangle();
test_mount_flags_to_string();
test_bind_remount_recursive(); test_bind_remount_recursive();
test_bind_remount_one(); test_bind_remount_one();

View File

@ -16,59 +16,11 @@ $KERNEL_APPEND
. "${TEST_BASE_DIR:?}/test-functions" . "${TEST_BASE_DIR:?}/test-functions"
check_result_nspawn() { check_result_nspawn() {
local workspace="${1:?}" check_result_nspawn_unittests "${1}"
local ret=1
[[ -e "$workspace/testok" ]] && ret=0
if [[ -s "$workspace/failed" ]]; then
ret=$((ret + 1))
echo "=== Failed test log ==="
cat "$workspace/failed"
else
if [[ -s "$workspace/skipped" ]]; then
echo "=== Skipped test log =="
cat "$workspace/skipped"
fi
if [[ -s "$workspace/testok" ]]; then
echo "=== Passed tests ==="
cat "$workspace/testok"
fi
fi
save_journal "$workspace/var/log/journal"
_umount_dir "${initdir:?}"
[[ -n "${TIMED_OUT:=}" ]] && ret=1
return $ret
} }
check_result_qemu() { check_result_qemu() {
local ret=1 check_result_qemu_unittests
mount_initdir
[[ -e "${initdir:?}/testok" ]] && ret=0
if [[ -s "$initdir/failed" ]]; then
ret=$((ret + 1))
echo "=== Failed test log ==="
cat "$initdir/failed"
else
if [[ -s "$initdir/skipped" ]]; then
echo "=== Skipped test log =="
cat "$initdir/skipped"
fi
if [[ -s "$initdir/testok" ]]; then
echo "=== Passed tests ==="
cat "$initdir/testok"
fi
fi
save_journal "$initdir/var/log/journal"
_umount_dir "$initdir"
[[ -n "${TIMED_OUT:=}" ]] && ret=1
return $ret
} }
do_test "$@" do_test "$@"

View File

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

View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="Run unit tests under qemu"
# this subset of unit tests requires qemu, so they are ran here to avoid slowing down TEST-02
TEST_NO_NSPAWN=1
# embed some newlines in the kernel command line to stress our test suite
KERNEL_APPEND="
frobnicate!
$KERNEL_APPEND
"
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
check_result_nspawn() {
check_result_nspawn_unittests "${1}"
}
check_result_qemu() {
check_result_qemu_unittests
}
do_test "$@"

View File

@ -864,6 +864,7 @@ install_modules() {
instmods loop instmods loop
instmods vfat instmods vfat
instmods nls_ascii =nls
instmods dummy instmods dummy
if [[ "$LOOKS_LIKE_SUSE" ]]; then if [[ "$LOOKS_LIKE_SUSE" ]]; then
@ -1228,6 +1229,66 @@ check_result_qemu() {
return $ret return $ret
} }
check_result_nspawn_unittests() {
local workspace="${1:?}"
local ret=1
[[ -e "$workspace/testok" ]] && ret=0
if [[ -s "$workspace/failed" ]]; then
ret=$((ret + 1))
echo "=== Failed test log ==="
cat "$workspace/failed"
else
if [[ -s "$workspace/skipped" ]]; then
echo "=== Skipped test log =="
cat "$workspace/skipped"
# We might have only skipped tests - that should not fail the job
ret=0
fi
if [[ -s "$workspace/testok" ]]; then
echo "=== Passed tests ==="
cat "$workspace/testok"
fi
fi
save_journal "$workspace/var/log/journal"
_umount_dir "${initdir:?}"
[[ -n "${TIMED_OUT:=}" ]] && ret=1
return $ret
}
check_result_qemu_unittests() {
local ret=1
mount_initdir
[[ -e "${initdir:?}/testok" ]] && ret=0
if [[ -s "$initdir/failed" ]]; then
ret=$((ret + 1))
echo "=== Failed test log ==="
cat "$initdir/failed"
else
if [[ -s "$initdir/skipped" ]]; then
echo "=== Skipped test log =="
cat "$initdir/skipped"
# We might have only skipped tests - that should not fail the job
ret=0
fi
if [[ -s "$initdir/testok" ]]; then
echo "=== Passed tests ==="
cat "$initdir/testok"
fi
fi
save_journal "$initdir/var/log/journal"
_umount_dir "$initdir"
[[ -n "${TIMED_OUT:=}" ]] && ret=1
return $ret
}
strip_binaries() { strip_binaries() {
dinfo "Strip binaries" dinfo "Strip binaries"
if [[ "$STRIP_BINARIES" = "no" ]]; then if [[ "$STRIP_BINARIES" = "no" ]]; then

View File

@ -14,6 +14,7 @@ OutgoingInterface=test1
[RoutingPolicyRule] [RoutingPolicyRule]
IncomingInterface=test1 IncomingInterface=test1
From=::/0
Table=8 Table=8
Priority=100 Priority=100
Family=ipv6 Family=ipv6
@ -23,3 +24,9 @@ IncomingInterface=test1
Table=9 Table=9
Priority=101 Priority=101
Family=both Family=both
[RoutingPolicyRule]
IncomingInterface=test1
From=0.0.0.0/8
Table=10
Priority=102

View File

@ -1858,7 +1858,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
'routing-policy-rule-reconfigure2.network', 'routing-policy-rule-reconfigure2.network',
] ]
routing_policy_rule_tables = ['7', '8', '9', '1011'] routing_policy_rule_tables = ['7', '8', '9', '10', '1011']
routes = [['blackhole', '202.54.1.2'], ['unreachable', '202.54.1.3'], ['prohibit', '202.54.1.4']] routes = [['blackhole', '202.54.1.2'], ['unreachable', '202.54.1.3'], ['prohibit', '202.54.1.4']]
def setUp(self): def setUp(self):
@ -2108,6 +2108,13 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
self.assertRegex(output, 'iif test1') self.assertRegex(output, 'iif test1')
self.assertRegex(output, 'lookup 8') self.assertRegex(output, 'lookup 8')
output = check_output('ip rule list iif test1 priority 102')
print(output)
self.assertRegex(output, '102:')
self.assertRegex(output, 'from 0.0.0.0/8')
self.assertRegex(output, 'iif test1')
self.assertRegex(output, 'lookup 10')
def test_routing_policy_rule_issue_11280(self): def test_routing_policy_rule_issue_11280(self):
copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev', copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev',
'routing-policy-rule-dummy98.network', '12-dummy.netdev') 'routing-policy-rule-dummy98.network', '12-dummy.netdev')

View File

@ -4,7 +4,8 @@ set -o pipefail
NPROC=$(nproc) NPROC=$(nproc)
MAX_QUEUE_SIZE=${NPROC:-2} MAX_QUEUE_SIZE=${NPROC:-2}
mapfile -t TEST_LIST < <(find /usr/lib/systemd/tests/ -maxdepth 1 -type f -name "test-*") TESTS_GLOB=${TESTS_GLOB:-test-*}
mapfile -t TEST_LIST < <(find /usr/lib/systemd/tests/ -maxdepth 1 -type f -name "${TESTS_GLOB}")
# reset state # reset state
rm -fv /failed-tests /skipped-tests /skipped rm -fv /failed-tests /skipped-tests /skipped
@ -78,10 +79,12 @@ done
# Wait for remaining running tasks # Wait for remaining running tasks
for key in "${!running[@]}"; do for key in "${!running[@]}"; do
wait ${running[$key]} wait ${running[$key]} && ec=0 || ec=$?
ec=$?
report_result "$key" $ec report_result "$key" $ec
unset running["$key"] unset running["$key"]
done done
# Test logs are sometimes lost, as the system shuts down immediately after
journalctl --sync
exit 0 exit 0

View File

@ -0,0 +1,7 @@
[Unit]
Description=TEST-61-UNITTESTS-QEMU
[Service]
ExecStartPre=rm -f /failed /testok
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
Type=oneshot

8
test/units/testsuite-61.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -eux
set -o pipefail
TESTS_GLOB="test-loop-block"
. $(dirname $0)/testsuite-02.sh
exit 0