summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAdrian Szyndela <adrian.s@samsung.com>2020-03-27 08:33:36 +0100
committerAdrian Szyndela <adrian.s@samsung.com>2020-03-27 08:33:36 +0100
commita70b405fa3b2c4e93db2b3bd858d70b5ef559a1e (patch)
treefbe09c89a2e6c8218b85b2ad7aeb7a2c6cd7cd01 /src/test
parent0d1510829acdb7af983a8d5b95863cff73761f55 (diff)
parente62a7fea757f259eb330da5b6d3ab4ede46400a2 (diff)
downloadsystemd-a70b405fa3b2c4e93db2b3bd858d70b5ef559a1e.tar.gz
systemd-a70b405fa3b2c4e93db2b3bd858d70b5ef559a1e.tar.bz2
systemd-a70b405fa3b2c4e93db2b3bd858d70b5ef559a1e.zip
Merge v241 into tizensandbox/adrians/upgrade-to-241
systemd 241
Diffstat (limited to 'src/test')
-rw-r--r--src/test/meson.build5
-rw-r--r--src/test/test-barrier.c17
-rw-r--r--src/test/test-bpf.c36
-rw-r--r--src/test/test-conf-parser.c22
-rw-r--r--src/test/test-execute.c3
-rw-r--r--src/test/test-fileio.c34
-rw-r--r--src/test/test-fs-util.c6
-rw-r--r--src/test/test-hexdecoct.c1
-rw-r--r--src/test/test-in-addr-util.c122
-rw-r--r--src/test/test-json.c23
-rw-r--r--src/test/test-libudev.c30
-rw-r--r--src/test/test-mountpoint-util.c1
-rw-r--r--src/test/test-path-util.c2
-rw-r--r--src/test/test-prioq.c16
-rw-r--r--src/test/test-process-util.c2
-rw-r--r--src/test/test-procfs-util.c2
-rw-r--r--src/test/test-sizeof.c11
-rw-r--r--src/test/test-stat-util.c1
-rw-r--r--src/test/test-time-util.c2
-rw-r--r--src/test/test-udev.c3
-rw-r--r--src/test/test-util.c29
21 files changed, 248 insertions, 120 deletions
diff --git a/src/test/meson.build b/src/test/meson.build
index 50d001494e..c38828315f 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -940,7 +940,8 @@ tests += [
[['src/libsystemd/sd-resolve/test-resolve.c'],
[],
- [threads]],
+ [threads],
+ '', 'timeout=120'],
[['src/libsystemd/sd-login/test-login.c'],
[],
@@ -968,7 +969,7 @@ tests += [
]
-if cxx.found()
+if cxx_cmd != ''
tests += [
[['src/libsystemd/sd-bus/test-bus-vtable-cc.cc'],
[],
diff --git a/src/test/test-barrier.c b/src/test/test-barrier.c
index 6ae84cd6fc..6469129fa4 100644
--- a/src/test/test-barrier.c
+++ b/src/test/test-barrier.c
@@ -17,6 +17,7 @@
#include "barrier.h"
#include "util.h"
#include "tests.h"
+#include "virt.h"
/* 20ms to test deadlocks; All timings use multiples of this constant as
* alarm/sleep timers. If this timeout is too small for slow machines to perform
@@ -420,11 +421,27 @@ TEST_BARRIER(test_barrier_pending_exit,
TEST_BARRIER_WAIT_SUCCESS(pid2));
int main(int argc, char *argv[]) {
+ int v;
test_setup_logging(LOG_INFO);
if (!slow_tests_enabled())
return log_tests_skipped("slow tests are disabled");
+ /*
+ * This test uses real-time alarms and sleeps to test for CPU races
+ * explicitly. This is highly fragile if your system is under load. We
+ * already increased the BASE_TIME value to make the tests more robust,
+ * but that just makes the test take significantly longer. Given the recent
+ * issues when running the test in a virtualized environments, limit it
+ * to bare metal machines only, to minimize false-positives in CIs.
+ */
+ v = detect_virtualization();
+ if (IN_SET(v, -EPERM, -EACCES))
+ return log_tests_skipped("Cannot detect virtualization");
+
+ if (v != VIRTUALIZATION_NONE)
+ return log_tests_skipped("This test requires a baremetal machine");
+
test_barrier_sync();
test_barrier_wait_next();
test_barrier_wait_next_twice();
diff --git a/src/test/test-bpf.c b/src/test/test-bpf.c
index 461f687a60..6a0bf1462f 100644
--- a/src/test/test-bpf.c
+++ b/src/test/test-bpf.c
@@ -2,6 +2,7 @@
#include <linux/bpf_insn.h>
#include <string.h>
+#include <sys/mman.h>
#include <unistd.h>
#include "bpf-firewall.h"
@@ -14,6 +15,30 @@
#include "tests.h"
#include "unit.h"
+/* We use the same limit here that PID 1 bumps RLIMIT_MEMLOCK to if it can */
+#define CAN_MEMLOCK_SIZE (64U*1024U*1024U)
+
+static bool can_memlock(void) {
+ void *p;
+ bool b;
+
+ /* Let's see if we can mlock() a larger blob of memory. BPF programs are charged against
+ * RLIMIT_MEMLOCK, hence let's first make sure we can lock memory at all, and skip the test if we
+ * cannot. Why not check RLIMIT_MEMLOCK explicitly? Because in container environments the
+ * RLIMIT_MEMLOCK value we see might not match the RLIMIT_MEMLOCK value actually in effect. */
+
+ p = mmap(NULL, CAN_MEMLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, -1, 0);
+ if (p == MAP_FAILED)
+ return false;
+
+ b = mlock(p, CAN_MEMLOCK_SIZE) >= 0;
+ if (b)
+ assert_se(munlock(p, CAN_MEMLOCK_SIZE) >= 0);
+
+ assert_se(munmap(p, CAN_MEMLOCK_SIZE) >= 0);
+ return b;
+}
+
int main(int argc, char *argv[]) {
struct bpf_insn exit_insn[] = {
BPF_MOV64_IMM(BPF_REG_0, 1),
@@ -26,10 +51,21 @@ int main(int argc, char *argv[]) {
_cleanup_(manager_freep) Manager *m = NULL;
Unit *u;
char log_buf[65535];
+ struct rlimit rl;
int r;
test_setup_logging(LOG_DEBUG);
+ if (is_run_on_travis_ci())
+ return log_tests_skipped("test-bpf fails on Travis CI: https://github.com/systemd/systemd/issues/9666");
+
+ assert_se(getrlimit(RLIMIT_MEMLOCK, &rl) >= 0);
+ rl.rlim_cur = rl.rlim_max = MAX3(rl.rlim_cur, rl.rlim_max, CAN_MEMLOCK_SIZE);
+ (void) setrlimit(RLIMIT_MEMLOCK, &rl);
+
+ if (!can_memlock())
+ return log_tests_skipped("Can't use mlock(), skipping.");
+
r = enter_cgroup_subroot();
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c
index 2921338f62..1738938fce 100644
--- a/src/test/test-conf-parser.c
+++ b/src/test/test-conf-parser.c
@@ -248,6 +248,18 @@ static const char* const config_file[] = {
"3\n",
"[Section]\n"
+ " #hogehoge\\\n" /* whitespaces before comments */
+ " setting1=1\\\n" /* whitespaces before key */
+ "2\\\n"
+ "3\n",
+
+ "[Section]\n"
+ " setting1=1\\\n" /* whitespaces before key */
+ " #hogehoge\\\n" /* commented out line prefixed with whitespaces in continuation */
+ "2\\\n"
+ "3\n",
+
+ "[Section]\n"
"setting1=1\\\n" /* continuation with extra trailing backslash at the end */
"2\\\n"
"3\\\n",
@@ -323,27 +335,27 @@ static void test_config_parse(unsigned i, const char *s) {
assert_se(streq(setting1, "1"));
break;
- case 4 ... 7:
+ case 4 ... 9:
assert_se(r == 0);
assert_se(streq(setting1, "1 2 3"));
break;
- case 8:
+ case 10:
assert_se(r == 0);
assert_se(streq(setting1, "1\\\\ \\\\2"));
break;
- case 9:
+ case 11:
assert_se(r == 0);
assert_se(streq(setting1, x1000("ABCD")));
break;
- case 10 ... 11:
+ case 12 ... 13:
assert_se(r == 0);
assert_se(streq(setting1, x1000("ABCD") " foobar"));
break;
- case 12 ... 13:
+ case 14 ... 15:
assert_se(r == -ENOBUFS);
assert_se(setting1 == NULL);
break;
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index cea68b8cfe..eb8f7c4eff 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -131,7 +131,7 @@ static bool check_user_has_group_with_same_name(const char *name) {
}
static bool is_inaccessible_available(void) {
- char *p;
+ const char *p;
FOREACH_STRING(p,
"/run/systemd/inaccessible/reg",
@@ -770,6 +770,7 @@ int main(int argc, char *argv[]) {
(void) unsetenv("USER");
(void) unsetenv("LOGNAME");
(void) unsetenv("SHELL");
+ (void) unsetenv("HOME");
can_unshare = have_namespaces();
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
index bf918c1d1e..2ddaabe7f8 100644
--- a/src/test/test-fileio.c
+++ b/src/test/test-fileio.c
@@ -26,7 +26,8 @@ static void test_parse_env_file(void) {
p[] = "/tmp/test-fileio-out-XXXXXX";
FILE *f;
_cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL,
- *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL, *ten = NULL;
+ *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL, *ten = NULL,
+ *eleven = NULL, *twelve = NULL, *thirteen = NULL;
_cleanup_strv_free_ char **a = NULL, **b = NULL;
char **i;
unsigned k;
@@ -43,7 +44,7 @@ static void test_parse_env_file(void) {
"three = \"333\n"
"xxxx\"\n"
"four = \'44\\\"44\'\n"
- "five = \'55\\\'55\' \"FIVE\" cinco \n"
+ "five = \"55\\\"55\" \"FIVE\" cinco \n"
"six = seis sechs\\\n"
" sis\n"
"seven=\"sevenval\" #nocomment\n"
@@ -51,7 +52,10 @@ static void test_parse_env_file(void) {
"export nine=nineval\n"
"ten=ignored\n"
"ten=ignored\n"
- "ten=", f);
+ "ten=\n"
+ "eleven=\\value\n"
+ "twelve=\"\\value\"\n"
+ "thirteen='\\value'", f);
fflush(f);
fclose(f);
@@ -65,14 +69,17 @@ static void test_parse_env_file(void) {
assert_se(streq_ptr(a[0], "one=BAR"));
assert_se(streq_ptr(a[1], "two=bar"));
assert_se(streq_ptr(a[2], "three=333\nxxxx"));
- assert_se(streq_ptr(a[3], "four=44\"44"));
- assert_se(streq_ptr(a[4], "five=55\'55FIVEcinco"));
+ assert_se(streq_ptr(a[3], "four=44\\\"44"));
+ assert_se(streq_ptr(a[4], "five=55\"55FIVEcinco"));
assert_se(streq_ptr(a[5], "six=seis sechs sis"));
assert_se(streq_ptr(a[6], "seven=sevenval#nocomment"));
assert_se(streq_ptr(a[7], "eight=eightval #nocomment"));
assert_se(streq_ptr(a[8], "export nine=nineval"));
assert_se(streq_ptr(a[9], "ten="));
- assert_se(a[10] == NULL);
+ assert_se(streq_ptr(a[10], "eleven=value"));
+ assert_se(streq_ptr(a[11], "twelve=\\value"));
+ assert_se(streq_ptr(a[12], "thirteen=\\value"));
+ assert_se(a[13] == NULL);
strv_env_clean(a);
@@ -93,7 +100,10 @@ static void test_parse_env_file(void) {
"seven", &seven,
"eight", &eight,
"export nine", &nine,
- "ten", &ten);
+ "ten", &ten,
+ "eleven", &eleven,
+ "twelve", &twelve,
+ "thirteen", &thirteen);
assert_se(r >= 0);
@@ -107,17 +117,23 @@ static void test_parse_env_file(void) {
log_info("eight=[%s]", strna(eight));
log_info("export nine=[%s]", strna(nine));
log_info("ten=[%s]", strna(nine));
+ log_info("eleven=[%s]", strna(eleven));
+ log_info("twelve=[%s]", strna(twelve));
+ log_info("thirteen=[%s]", strna(thirteen));
assert_se(streq(one, "BAR"));
assert_se(streq(two, "bar"));
assert_se(streq(three, "333\nxxxx"));
- assert_se(streq(four, "44\"44"));
- assert_se(streq(five, "55\'55FIVEcinco"));
+ assert_se(streq(four, "44\\\"44"));
+ assert_se(streq(five, "55\"55FIVEcinco"));
assert_se(streq(six, "seis sechs sis"));
assert_se(streq(seven, "sevenval#nocomment"));
assert_se(streq(eight, "eightval #nocomment"));
assert_se(streq(nine, "nineval"));
assert_se(ten == NULL);
+ assert_se(streq(eleven, "value"));
+ assert_se(streq(twelve, "\\value"));
+ assert_se(streq(thirteen, "\\value"));
{
/* prepare a temporary file to write the environment to */
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index b3a4b1749c..e049abc4a4 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -361,11 +361,11 @@ static void test_unlink_noerrno(void) {
{
PROTECT_ERRNO;
- errno = -42;
+ errno = 42;
assert_se(unlink_noerrno(name) >= 0);
- assert_se(errno == -42);
+ assert_se(errno == 42);
assert_se(unlink_noerrno(name) < 0);
- assert_se(errno == -42);
+ assert_se(errno == 42);
}
}
diff --git a/src/test/test-hexdecoct.c b/src/test/test-hexdecoct.c
index 6e9b94b933..52217429b1 100644
--- a/src/test/test-hexdecoct.c
+++ b/src/test/test-hexdecoct.c
@@ -234,7 +234,6 @@ static void test_unbase32hexmem(void) {
test_unbase32hexmem_one("CPNMUOJ1E8======", false, -EINVAL, NULL);
test_unbase32hexmem_one("A", false, -EINVAL, NULL);
- test_unbase32hexmem_one("A", false, -EINVAL, NULL);
test_unbase32hexmem_one("AAA", false, -EINVAL, NULL);
test_unbase32hexmem_one("AAAAAA", false, -EINVAL, NULL);
test_unbase32hexmem_one("AB", false, -EINVAL, NULL);
diff --git a/src/test/test-in-addr-util.c b/src/test/test-in-addr-util.c
index 75c3e305c3..16844e9565 100644
--- a/src/test/test-in-addr-util.c
+++ b/src/test/test-in-addr-util.c
@@ -2,83 +2,85 @@
#include <netinet/in.h>
+#include "log.h"
#include "in-addr-util.h"
-static void test_in_addr_prefix_from_string(const char *p, int family, int ret, const union in_addr_union *u, unsigned char prefixlen, bool use_default) {
+static void test_in_addr_prefix_from_string(
+ const char *p,
+ int family,
+ int ret,
+ const union in_addr_union *u,
+ unsigned char prefixlen,
+ int ret_refuse,
+ unsigned char prefixlen_refuse,
+ int ret_legacy,
+ unsigned char prefixlen_legacy) {
+
union in_addr_union q;
unsigned char l;
- int r;
+ int f, r;
- r = in_addr_prefix_from_string_internal(p, use_default, family, &q, &l);
+ r = in_addr_prefix_from_string(p, family, &q, &l);
assert_se(r == ret);
- if (r >= 0) {
- int f;
+ if (r < 0)
+ return;
+
+ assert_se(in_addr_equal(family, &q, u));
+ assert_se(l == prefixlen);
+
+ r = in_addr_prefix_from_string_auto(p, &f, &q, &l);
+ assert_se(r >= 0);
+
+ assert_se(f == family);
+ assert_se(in_addr_equal(family, &q, u));
+ assert_se(l == prefixlen);
+
+ r = in_addr_prefix_from_string_auto_internal(p, PREFIXLEN_REFUSE, &f, &q, &l);
+ assert_se(r == ret_refuse);
+ if (r >= 0) {
+ assert_se(f == family);
assert_se(in_addr_equal(family, &q, u));
- assert_se(l == prefixlen);
+ assert_se(l == prefixlen_refuse);
+ }
- r = in_addr_prefix_from_string_auto_internal(p, use_default, &f, &q, &l);
- assert_se(r >= 0);
+ r = in_addr_prefix_from_string_auto_internal(p, PREFIXLEN_LEGACY, &f, &q, &l);
+ assert_se(r == ret_legacy);
+ if (r >= 0) {
assert_se(f == family);
assert_se(in_addr_equal(family, &q, u));
- assert_se(l == prefixlen);
+ assert_se(l == prefixlen_legacy);
}
}
int main(int argc, char *argv[]) {
- test_in_addr_prefix_from_string("", AF_INET, -EINVAL, NULL, 0, false);
- test_in_addr_prefix_from_string("/", AF_INET, -EINVAL, NULL, 0, false);
- test_in_addr_prefix_from_string("/8", AF_INET, -EINVAL, NULL, 0, false);
- test_in_addr_prefix_from_string("1.2.3.4", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, false);
- test_in_addr_prefix_from_string("1.2.3.4/0", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 0, false);
- test_in_addr_prefix_from_string("1.2.3.4/1", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 1, false);
- test_in_addr_prefix_from_string("1.2.3.4/2", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 2, false);
- test_in_addr_prefix_from_string("1.2.3.4/32", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, false);
- test_in_addr_prefix_from_string("1.2.3.4/33", AF_INET, -ERANGE, NULL, 0, false);
- test_in_addr_prefix_from_string("1.2.3.4/-1", AF_INET, -ERANGE, NULL, 0, false);
- test_in_addr_prefix_from_string("::1", AF_INET, -EINVAL, NULL, 0, false);
-
- test_in_addr_prefix_from_string("", AF_INET6, -EINVAL, NULL, 0, false);
- test_in_addr_prefix_from_string("/", AF_INET6, -EINVAL, NULL, 0, false);
- test_in_addr_prefix_from_string("/8", AF_INET6, -EINVAL, NULL, 0, false);
- test_in_addr_prefix_from_string("::1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, false);
- test_in_addr_prefix_from_string("::1/0", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0, false);
- test_in_addr_prefix_from_string("::1/1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 1, false);
- test_in_addr_prefix_from_string("::1/2", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 2, false);
- test_in_addr_prefix_from_string("::1/32", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 32, false);
- test_in_addr_prefix_from_string("::1/33", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 33, false);
- test_in_addr_prefix_from_string("::1/64", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 64, false);
- test_in_addr_prefix_from_string("::1/128", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, false);
- test_in_addr_prefix_from_string("::1/129", AF_INET6, -ERANGE, NULL, 0, false);
- test_in_addr_prefix_from_string("::1/-1", AF_INET6, -ERANGE, NULL, 0, false);
-
- test_in_addr_prefix_from_string("", AF_INET, -EINVAL, NULL, 0, true);
- test_in_addr_prefix_from_string("/", AF_INET, -EINVAL, NULL, 0, true);
- test_in_addr_prefix_from_string("/8", AF_INET, -EINVAL, NULL, 0, true);
- test_in_addr_prefix_from_string("1.2.3.4", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 8, true);
- test_in_addr_prefix_from_string("1.2.3.4/0", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 0, true);
- test_in_addr_prefix_from_string("1.2.3.4/1", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 1, true);
- test_in_addr_prefix_from_string("1.2.3.4/2", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 2, true);
- test_in_addr_prefix_from_string("1.2.3.4/32", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, true);
- test_in_addr_prefix_from_string("1.2.3.4/33", AF_INET, -ERANGE, NULL, 0, true);
- test_in_addr_prefix_from_string("1.2.3.4/-1", AF_INET, -ERANGE, NULL, 0, true);
- test_in_addr_prefix_from_string("::1", AF_INET, -EINVAL, NULL, 0, true);
-
- test_in_addr_prefix_from_string("", AF_INET6, -EINVAL, NULL, 0, true);
- test_in_addr_prefix_from_string("/", AF_INET6, -EINVAL, NULL, 0, true);
- test_in_addr_prefix_from_string("/8", AF_INET6, -EINVAL, NULL, 0, true);
- test_in_addr_prefix_from_string("::1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0, true);
- test_in_addr_prefix_from_string("::1/0", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0, true);
- test_in_addr_prefix_from_string("::1/1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 1, true);
- test_in_addr_prefix_from_string("::1/2", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 2, true);
- test_in_addr_prefix_from_string("::1/32", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 32, true);
- test_in_addr_prefix_from_string("::1/33", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 33, true);
- test_in_addr_prefix_from_string("::1/64", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 64, true);
- test_in_addr_prefix_from_string("::1/128", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, true);
- test_in_addr_prefix_from_string("::1/129", AF_INET6, -ERANGE, NULL, 0, true);
- test_in_addr_prefix_from_string("::1/-1", AF_INET6, -ERANGE, NULL, 0, true);
+ test_in_addr_prefix_from_string("", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
+ test_in_addr_prefix_from_string("/", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
+ test_in_addr_prefix_from_string("/8", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
+ test_in_addr_prefix_from_string("1.2.3.4", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, -ENOANO, 0, 0, 8);
+ test_in_addr_prefix_from_string("1.2.3.4/0", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 0, 0, 0, 0, 0);
+ test_in_addr_prefix_from_string("1.2.3.4/1", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 1, 0, 1, 0, 1);
+ test_in_addr_prefix_from_string("1.2.3.4/2", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 2, 0, 2, 0, 2);
+ test_in_addr_prefix_from_string("1.2.3.4/32", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, 0, 32, 0, 32);
+ test_in_addr_prefix_from_string("1.2.3.4/33", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
+ test_in_addr_prefix_from_string("1.2.3.4/-1", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
+ test_in_addr_prefix_from_string("::1", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
+
+ test_in_addr_prefix_from_string("", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
+ test_in_addr_prefix_from_string("/", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
+ test_in_addr_prefix_from_string("/8", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
+ test_in_addr_prefix_from_string("::1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, -ENOANO, 0, 0, 0);
+ test_in_addr_prefix_from_string("::1/0", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0, 0, 0, 0, 0);
+ test_in_addr_prefix_from_string("::1/1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 1, 0, 1, 0, 1);
+ test_in_addr_prefix_from_string("::1/2", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 2, 0, 2, 0, 2);
+ test_in_addr_prefix_from_string("::1/32", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 32, 0, 32, 0, 32);
+ test_in_addr_prefix_from_string("::1/33", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 33, 0, 33, 0, 33);
+ test_in_addr_prefix_from_string("::1/64", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 64, 0, 64, 0, 64);
+ test_in_addr_prefix_from_string("::1/128", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, 0, 128, 0, 128);
+ test_in_addr_prefix_from_string("::1/129", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
+ test_in_addr_prefix_from_string("::1/-1", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
return 0;
}
diff --git a/src/test/test-json.c b/src/test/test-json.c
index 5aa4d19dbe..fdf1b4f40c 100644
--- a/src/test/test-json.c
+++ b/src/test/test-json.c
@@ -1,9 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <math.h>
-#if HAVE_VALGRIND_VALGRIND_H
-#include <valgrind/valgrind.h>
-#endif
#include "alloc-util.h"
#include "fd-util.h"
@@ -45,12 +42,13 @@ static void test_tokenizer(const char *data, ...) {
d = va_arg(ap, long double);
-#if HAVE_VALGRIND_VALGRIND_H
- if (!RUNNING_ON_VALGRIND)
-#endif
- /* Valgrind doesn't support long double calculations and automatically downgrades to 80bit:
- * http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits */
- assert_se(fabsl(d - v.real) < 0.001L);
+ /* Valgrind doesn't support long double calculations and automatically downgrades to 80bit:
+ * http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits.
+ * Some architectures might not support long double either.
+ */
+
+ assert_se(fabsl(d - v.real) < 1e-10 ||
+ fabsl((d - v.real) / v.real) < 1e-10);
} else if (t == JSON_TOKEN_INTEGER) {
intmax_t i;
@@ -211,7 +209,6 @@ static void test_2(JsonVariant *v) {
assert_se(p && json_variant_type(p) == JSON_VARIANT_REAL && fabsl(json_variant_real(p) - 1.27) < 0.001);
}
-
static void test_zeroes(JsonVariant *v) {
size_t i;
@@ -285,6 +282,7 @@ static void test_build(void) {
a = json_variant_unref(a);
b = json_variant_unref(b);
+ const char* arr_1234[] = {"one", "two", "three", "four", NULL};
assert_se(json_build(&a, JSON_BUILD_ARRAY(JSON_BUILD_OBJECT(JSON_BUILD_PAIR("x", JSON_BUILD_BOOLEAN(true)),
JSON_BUILD_PAIR("y", JSON_BUILD_OBJECT(JSON_BUILD_PAIR("this", JSON_BUILD_NULL)))),
JSON_BUILD_VARIANT(NULL),
@@ -292,8 +290,9 @@ static void test_build(void) {
JSON_BUILD_STRING(NULL),
JSON_BUILD_NULL,
JSON_BUILD_INTEGER(77),
- JSON_BUILD_ARRAY(JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("foobar")), JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("zzz"))),
- JSON_BUILD_STRV(STRV_MAKE("one", "two", "three", "four")))) >= 0);
+ JSON_BUILD_ARRAY(JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("foobar")),
+ JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("zzz"))),
+ JSON_BUILD_STRV((char**) arr_1234))) >= 0);
assert_se(json_variant_format(a, 0, &s) >= 0);
log_info("GOT: %s\n", s);
diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c
index 10bf365035..15c0f8853d 100644
--- a/src/test/test-libudev.c
+++ b/src/test/test-libudev.c
@@ -7,6 +7,7 @@
#include <unistd.h>
#include "alloc-util.h"
+#include "build.h"
#include "fd-util.h"
#include "libudev-list-internal.h"
#include "libudev-util.h"
@@ -364,16 +365,23 @@ static void test_util_replace_whitespace(void) {
test_util_replace_whitespace_one_len("hoge hoge ", 1, "h");
test_util_replace_whitespace_one_len("hoge hoge ", 0, "");
- test_util_replace_whitespace_one_len(" hoge hoge ", 9, "hoge_hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 8, "hoge_hog");
- test_util_replace_whitespace_one_len(" hoge hoge ", 7, "hoge_ho");
- test_util_replace_whitespace_one_len(" hoge hoge ", 6, "hoge_h");
- test_util_replace_whitespace_one_len(" hoge hoge ", 5, "hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 4, "hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 3, "hog");
- test_util_replace_whitespace_one_len(" hoge hoge ", 2, "ho");
- test_util_replace_whitespace_one_len(" hoge hoge ", 1, "h");
- test_util_replace_whitespace_one_len(" hoge hoge ", 0, "");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 16, "hoge_hoge");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 15, "hoge_hoge");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 14, "hoge_hog");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 13, "hoge_ho");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 12, "hoge_h");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 11, "hoge");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 10, "hoge");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 9, "hoge");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 8, "hoge");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 7, "hog");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 6, "ho");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 5, "h");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 4, "");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 3, "");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 2, "");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 1, "");
+ test_util_replace_whitespace_one_len(" hoge hoge ", 0, "");
}
static void test_util_resolve_subsys_kernel_one(const char *str, bool read_value, int retval, const char *expected) {
@@ -507,7 +515,7 @@ int main(int argc, char *argv[]) {
return EXIT_SUCCESS;
case 'V':
- printf("%s\n", PACKAGE_VERSION);
+ printf("%s\n", GIT_VERSION);
return EXIT_SUCCESS;
case 'm':
diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c
index 6d8bee0d63..8e45c0b1a7 100644
--- a/src/test/test-mountpoint-util.c
+++ b/src/test/test-mountpoint-util.c
@@ -8,7 +8,6 @@
#include "fileio.h"
#include "hashmap.h"
#include "log.h"
-#include "log.h"
#include "mountpoint-util.h"
#include "path-util.h"
#include "rm-rf.h"
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 8854a94f6c..c64ca7b016 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -531,7 +531,7 @@ static void test_hidden_or_backup_file(void) {
static void test_systemd_installation_has_version(const char *path) {
int r;
- const unsigned versions[] = {0, 231, atoi(PACKAGE_VERSION), 999};
+ const unsigned versions[] = {0, 231, PROJECT_VERSION, 999};
unsigned i;
for (i = 0; i < ELEMENTSOF(versions); i++) {
diff --git a/src/test/test-prioq.c b/src/test/test-prioq.c
index bc5fdd15b2..53c9e090a7 100644
--- a/src/test/test-prioq.c
+++ b/src/test/test-prioq.c
@@ -69,6 +69,11 @@ static void test_struct(void) {
assert_se(q = prioq_new((compare_func_t) test_compare));
assert_se(s = set_new(&test_hash_ops));
+ assert_se(prioq_peek(q) == NULL);
+ assert_se(prioq_peek_by_index(q, 0) == NULL);
+ assert_se(prioq_peek_by_index(q, 1) == NULL);
+ assert_se(prioq_peek_by_index(q, (unsigned) -1) == NULL);
+
for (i = 0; i < SET_SIZE; i++) {
assert_se(t = new0(struct test, 1));
t->value = (unsigned) rand();
@@ -79,6 +84,17 @@ static void test_struct(void) {
assert_se(set_consume(s, t) >= 0);
}
+ for (i = 0; i < SET_SIZE; i++)
+ assert_se(prioq_peek_by_index(q, i));
+ assert_se(prioq_peek_by_index(q, SET_SIZE) == NULL);
+
+ unsigned count = 0;
+ PRIOQ_FOREACH_ITEM(q, t) {
+ assert_se(t);
+ count++;
+ }
+ assert_se(count == SET_SIZE);
+
while ((t = set_steal_first(s))) {
assert_se(prioq_remove(q, t, &t->idx) == 1);
assert_se(prioq_remove(q, t, &t->idx) == 0);
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 5c87db08f5..b5ba651d89 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -70,11 +70,9 @@ static void test_get_process_comm(pid_t pid) {
assert_se(get_process_uid(pid, &u) == 0);
log_info("PID"PID_FMT" UID: "UID_FMT, pid, u);
- assert_se(u == 0 || pid != 1);
assert_se(get_process_gid(pid, &g) == 0);
log_info("PID"PID_FMT" GID: "GID_FMT, pid, g);
- assert_se(g == 0 || pid != 1);
r = get_process_environ(pid, &env);
assert_se(r >= 0 || r == -EACCES);
diff --git a/src/test/test-procfs-util.c b/src/test/test-procfs-util.c
index 08af380cc7..1d0612985b 100644
--- a/src/test/test-procfs-util.c
+++ b/src/test/test-procfs-util.c
@@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
assert_se(procfs_cpu_get_usage(&nsec) >= 0);
log_info("Current system CPU time: %s", format_timespan(buf, sizeof(buf), nsec/NSEC_PER_USEC, 1));
- assert_se(procfs_memory_get_current(&v) >= 0);
+ assert_se(procfs_memory_get_used(&v) >= 0);
log_info("Current memory usage: %s", format_bytes(buf, sizeof(buf), v));
assert_se(procfs_tasks_get_current(&v) >= 0);
diff --git a/src/test/test-sizeof.c b/src/test/test-sizeof.c
index 7a1e496ed2..35b087653e 100644
--- a/src/test/test-sizeof.c
+++ b/src/test/test-sizeof.c
@@ -13,11 +13,12 @@
#pragma GCC diagnostic ignored "-Wtype-limits"
-#define info(t) \
- printf("%s → %zu bits%s\n", STRINGIFY(t), \
- sizeof(t)*CHAR_BIT, \
- strstr(STRINGIFY(t), "signed") ? "" : \
- ((t)-1 < (t)0 ? ", signed" : ", unsigned"));
+#define info(t) \
+ printf("%s → %zu bits%s, %zu byte alignment\n", STRINGIFY(t), \
+ sizeof(t)*CHAR_BIT, \
+ strstr(STRINGIFY(t), "signed") ? "" : \
+ (t)-1 < (t)0 ? ", signed" : ", unsigned", \
+ __alignof__(t))
enum Enum {
enum_value,
diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c
index 4637a7f727..f9036a3aa7 100644
--- a/src/test/test-stat-util.c
+++ b/src/test/test-stat-util.c
@@ -62,7 +62,6 @@ static void test_path_is_fs_type(void) {
}
assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0);
assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0);
- assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0);
assert_se(path_is_fs_type("/i-dont-exist", BTRFS_SUPER_MAGIC) == -ENOENT);
}
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index 2ec2ade3f1..eb6041c152 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -212,7 +212,6 @@ static void test_format_timespan(usec_t accuracy) {
test_format_timespan_one(12345678, accuracy);
test_format_timespan_one(1200000, accuracy);
test_format_timespan_one(1230000, accuracy);
- test_format_timespan_one(1230000, accuracy);
test_format_timespan_one(1234000, accuracy);
test_format_timespan_one(1234500, accuracy);
test_format_timespan_one(1234560, accuracy);
@@ -289,7 +288,6 @@ static void test_usec_sub_signed(void) {
assert_se(usec_sub_signed(4, 4) == 0);
assert_se(usec_sub_signed(4, 5) == 0);
assert_se(usec_sub_signed(USEC_INFINITY-3, -3) == USEC_INFINITY);
- assert_se(usec_sub_signed(USEC_INFINITY-3, -3) == USEC_INFINITY);
assert_se(usec_sub_signed(USEC_INFINITY-3, -4) == USEC_INFINITY);
assert_se(usec_sub_signed(USEC_INFINITY-3, -5) == USEC_INFINITY);
assert_se(usec_sub_signed(USEC_INFINITY, 5) == USEC_INFINITY);
diff --git a/src/test/test-udev.c b/src/test/test-udev.c
index 7a4622b875..ab31f5a2f1 100644
--- a/src/test/test-udev.c
+++ b/src/test/test-udev.c
@@ -11,6 +11,7 @@
#include <sys/signalfd.h>
#include <unistd.h>
+#include "build.h"
#include "device-private.h"
#include "fs-util.h"
#include "log.h"
@@ -81,7 +82,7 @@ static int run(int argc, char *argv[]) {
return 0;
}
- log_debug("version %s", PACKAGE_VERSION);
+ log_debug("version %s", GIT_VERSION);
mac_selinux_init();
action = argv[1];
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 3c1b5f9b41..ffacd65669 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -139,11 +139,11 @@ static void test_container_of(void) {
uint64_t v1;
uint8_t pad2[2];
uint32_t v2;
- } _packed_ myval = { };
+ } myval = { };
log_info("/* %s */", __func__);
- assert_cc(sizeof(myval) == 17);
+ assert_cc(sizeof(myval) >= 17);
assert_se(container_of(&myval.v1, struct mytype, v1) == &myval);
assert_se(container_of(&myval.v2, struct mytype, v2) == &myval);
assert_se(container_of(&container_of(&myval.v2,
@@ -213,6 +213,30 @@ static void test_protect_errno(void) {
assert_se(errno == 12);
}
+static void test_unprotect_errno_inner_function(void) {
+ PROTECT_ERRNO;
+
+ errno = 2222;
+}
+
+static void test_unprotect_errno(void) {
+ log_info("/* %s */", __func__);
+
+ errno = 4711;
+
+ PROTECT_ERRNO;
+
+ errno = 815;
+
+ UNPROTECT_ERRNO;
+
+ assert_se(errno == 4711);
+
+ test_unprotect_errno_inner_function();
+
+ assert_se(errno == 4711);
+}
+
static void test_in_set(void) {
log_info("/* %s */", __func__);
@@ -383,6 +407,7 @@ int main(int argc, char *argv[]) {
test_div_round_up();
test_u64log2();
test_protect_errno();
+ test_unprotect_errno();
test_in_set();
test_log2i();
test_eqzero();