diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-10-11 19:39:11 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-10-12 08:20:28 +0200 |
commit | f21b863eebbd54e481dd62192dec5ec9e3aa12d9 (patch) | |
tree | bc875e9d2e3500bdb759fd1472a4a24a8bc08130 /src | |
parent | ci: use the system llvm-11 package on Focal (diff) | |
download | systemd-f21b863eebbd54e481dd62192dec5ec9e3aa12d9.tar.xz systemd-f21b863eebbd54e481dd62192dec5ec9e3aa12d9.zip |
test: use assert_se() instead of assert()
Diffstat (limited to 'src')
44 files changed, 135 insertions, 135 deletions
diff --git a/src/libsystemd-network/test-dhcp-option.c b/src/libsystemd-network/test-dhcp-option.c index d152e7925d..c4a0d4ccb2 100644 --- a/src/libsystemd-network/test-dhcp-option.c +++ b/src/libsystemd-network/test-dhcp-option.c @@ -121,7 +121,7 @@ static DHCPMessage *create_message(uint8_t *options, uint16_t optlen, } static void test_ignore_opts(uint8_t *descoption, int *descpos, int *desclen) { - assert(*descpos >= 0); + assert_se(*descpos >= 0); while (*descpos < *desclen) { switch(descoption[*descpos]) { diff --git a/src/libsystemd/sd-bus/test-bus-address.c b/src/libsystemd/sd-bus/test-bus-address.c index b92558fea9..59421094c5 100644 --- a/src/libsystemd/sd-bus/test-bus-address.c +++ b/src/libsystemd/sd-bus/test-bus-address.c @@ -16,7 +16,7 @@ static void test_one_address(sd_bus *b, r = bus_set_address_system_remote(b, host); log_info("\"%s\" → %d, \"%s\"", host, r, strna(r >= 0 ? b->address : NULL)); if (result < 0 || expected) { - assert(r == result); + assert_se(r == result); if (r >= 0) assert_se(streq(b->address, expected)); } diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c index e28885b5e0..406d10d92b 100644 --- a/src/libsystemd/sd-event/test-event.c +++ b/src/libsystemd/sd-event/test-event.c @@ -404,8 +404,8 @@ struct inotify_context { static void maybe_exit(sd_event_source *s, struct inotify_context *c) { unsigned n; - assert(s); - assert(c); + assert_se(s); + assert_se(c); if (!c->delete_self_handler_called) return; diff --git a/src/libsystemd/sd-journal/test-compress.c b/src/libsystemd/sd-journal/test-compress.c index 54e0e738b3..615bbb2934 100644 --- a/src/libsystemd/sd-journal/test-compress.c +++ b/src/libsystemd/sd-journal/test-compress.c @@ -118,7 +118,7 @@ _unused_ static void test_decompress_startswith(const char *compression, compressed = compressed2 = malloc(BUFSIZE_2); assert_se(compressed2); r = compress(data, data_len, compressed, BUFSIZE_2, &csize); - assert(r == 0); + assert_se(r == 0); } assert_se(r == 0); diff --git a/src/libsystemd/sd-netlink/test-netlink.c b/src/libsystemd/sd-netlink/test-netlink.c index c5a5e512a2..fbc3ef0609 100644 --- a/src/libsystemd/sd-netlink/test-netlink.c +++ b/src/libsystemd/sd-netlink/test-netlink.c @@ -287,7 +287,7 @@ struct test_async_object { }; static struct test_async_object *test_async_object_free(struct test_async_object *t) { - assert(t); + assert_se(t); free(t->ifname); return mfree(t); @@ -315,7 +315,7 @@ static int link_handler2(sd_netlink *rtnl, sd_netlink_message *m, void *userdata static void test_async_object_destroy(void *userdata) { struct test_async_object *t = userdata; - assert(userdata); + assert_se(userdata); log_info("%s: n_ref=%u", __func__, t->n_ref); test_async_object_unref(t); @@ -593,8 +593,8 @@ static int genl_ctrl_match_callback(sd_netlink *genl, sd_netlink_message *m, voi uint16_t id; uint8_t cmd; - assert(genl); - assert(m); + assert_se(genl); + assert_se(m); assert_se(sd_genl_message_get_family_name(genl, m, &name) >= 0); assert_se(streq(name, CTRL_GENL_NAME)); diff --git a/src/oom/test-oomd-util.c b/src/oom/test-oomd-util.c index 29f2c54ab1..265e77c0a2 100644 --- a/src/oom/test-oomd-util.c +++ b/src/oom/test-oomd-util.c @@ -52,7 +52,7 @@ static void test_oomd_cgroup_kill(void) { /* Create another cgroup below this one for the pids we forked off. We need this to be managed * by the test so that pid1 doesn't delete it before we can read the xattrs. */ cgroup = path_join(cgroup_root, "oomdkilltest"); - assert(cgroup); + assert_se(cgroup); assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, cgroup) >= 0); /* If we don't have permissions to set xattrs we're likely in a userns or missing capabilities */ diff --git a/src/resolve/test-resolved-etc-hosts.c b/src/resolve/test-resolved-etc-hosts.c index 6706885ebd..cc55a980ad 100644 --- a/src/resolve/test-resolved-etc-hosts.c +++ b/src/resolve/test-resolved-etc-hosts.c @@ -105,14 +105,14 @@ static void test_parse_etc_hosts(void) { assert_se(address_equal_4(bn->addresses[2], inet_addr("1.2.3.11"))); assert_se(address_equal_4(bn->addresses[3], inet_addr("1.2.3.12"))); - assert(!hashmap_get(hosts.by_name, "within.comment")); - assert(!hashmap_get(hosts.by_name, "within.comment2")); - assert(!hashmap_get(hosts.by_name, "within.comment3")); - assert(!hashmap_get(hosts.by_name, "#")); - - assert(!hashmap_get(hosts.by_name, "short.address")); - assert(!hashmap_get(hosts.by_name, "long.address")); - assert(!hashmap_get(hosts.by_name, "multi.colon")); + assert_se(!hashmap_get(hosts.by_name, "within.comment")); + assert_se(!hashmap_get(hosts.by_name, "within.comment2")); + assert_se(!hashmap_get(hosts.by_name, "within.comment3")); + assert_se(!hashmap_get(hosts.by_name, "#")); + + assert_se(!hashmap_get(hosts.by_name, "short.address")); + assert_se(!hashmap_get(hosts.by_name, "long.address")); + assert_se(!hashmap_get(hosts.by_name, "multi.colon")); assert_se(!set_contains(hosts.no_address, "short.address")); assert_se(!set_contains(hosts.no_address, "long.address")); assert_se(!set_contains(hosts.no_address, "multi.colon")); diff --git a/src/test/test-boot-timestamps.c b/src/test/test-boot-timestamps.c index 23155b2d98..2bee2d5c1d 100644 --- a/src/test/test-boot-timestamps.c +++ b/src/test/test-boot-timestamps.c @@ -76,11 +76,11 @@ int main(int argc, char* argv[]) { test_setup_logging(LOG_DEBUG); p = test_acpi_fpdt(); - assert(p >= 0); + assert_se(p >= 0); q = test_efi_loader(); - assert(q >= 0); + assert_se(q >= 0); r = test_boot_timestamps(); - assert(r >= 0); + assert_se(r >= 0); if (p == 0 && q == 0 && r == 0) return log_tests_skipped("access to firmware variables not possible"); diff --git a/src/test/test-bpf-firewall.c b/src/test/test-bpf-firewall.c index 1e0ad177b9..732350fae4 100644 --- a/src/test/test-bpf-firewall.c +++ b/src/test/test-bpf-firewall.c @@ -56,10 +56,10 @@ int main(int argc, char *argv[]) { assert_se(runtime_dir = setup_fake_runtime_dir()); r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, &p); - assert(r == 0); + assert_se(r == 0); r = bpf_program_add_instructions(p, exit_insn, ELEMENTSOF(exit_insn)); - assert(r == 0); + assert_se(r == 0); if (getuid() != 0) return log_tests_skipped("not running as root"); @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) { log_notice("BPF firewalling (though without BPF_F_ALLOW_MULTI) supported. Good."); r = bpf_program_load_kernel(p, log_buf, ELEMENTSOF(log_buf)); - assert(r >= 0); + assert_se(r >= 0); if (test_custom_filter) { zero(attr); @@ -158,8 +158,8 @@ int main(int argc, char *argv[]) { return log_tests_skipped("Kernel doesn't support the necessary bpf bits (masked out via seccomp?)"); assert_se(r >= 0); - assert(u->ip_bpf_ingress); - assert(u->ip_bpf_egress); + assert_se(u->ip_bpf_ingress); + assert_se(u->ip_bpf_egress); r = bpf_program_load_kernel(u->ip_bpf_ingress, log_buf, ELEMENTSOF(log_buf)); @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) { log_notice("%s", log_buf); log_notice("-------"); - assert(r >= 0); + assert_se(r >= 0); r = bpf_program_load_kernel(u->ip_bpf_egress, log_buf, ELEMENTSOF(log_buf)); @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) { log_notice("%s", log_buf); log_notice("-------"); - assert(r >= 0); + assert_se(r >= 0); assert_se(unit_start(u) >= 0); diff --git a/src/test/test-bus-util.c b/src/test/test-bus-util.c index 0381ba1ee4..5aa1bfac0e 100644 --- a/src/test/test-bus-util.c +++ b/src/test/test-bus-util.c @@ -30,7 +30,7 @@ static void test_destroy_callback(void) { } r = sd_bus_request_name_async(bus, &slot, "org.freedesktop.systemd.test-bus-util", 0, callback, &n_called); - assert(r == 1); + assert_se(r == 1); assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 0); assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 0); @@ -41,9 +41,9 @@ static void test_destroy_callback(void) { assert_se(t == destroy_callback); /* Force cleanup so we can look at n_called */ - assert(n_called == 0); + assert_se(n_called == 0); sd_bus_slot_unref(slot); - assert(n_called == 1); + assert_se(n_called == 1); } int main(int argc, char **argv) { diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c index 5d680f9b9a..fe76d27752 100644 --- a/src/test/test-calendarspec.c +++ b/src/test/test-calendarspec.c @@ -58,7 +58,7 @@ static void _test_next(int line, const char *input, const char *new_tz, usec_t a if (expect != USEC_INFINITY) assert_se(r >= 0 && u == expect); else - assert(r == -ENOENT); + assert_se(r == -ENOENT); calendar_spec_free(c); diff --git a/src/test/test-capability.c b/src/test/test-capability.c index 94f15bfb21..c5596bb6c3 100644 --- a/src/test/test-capability.c +++ b/src/test/test-capability.c @@ -194,7 +194,7 @@ static void test_update_inherited_set(void) { assert_se(!capability_update_inherited_set(caps, set)); assert_se(!cap_get_flag(caps, CAP_CHOWN, CAP_INHERITABLE, &fv)); - assert(fv == CAP_SET); + assert_se(fv == CAP_SET); cap_free(caps); } diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index c2adfa07ce..bc5eda61f8 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -395,12 +395,12 @@ static void test_cg_get_keyed_attribute(void) { assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "no_such_attr"), vals3) == -ENXIO); assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "no_such_attr"), vals3) == 1); - assert(vals3[0] && !vals3[1]); + assert_se(vals3[0] && !vals3[1]); free(vals3[0]); assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "usage_usec"), vals3) == -ENXIO); assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "usage_usec"), vals3) == 1); - assert(vals3[0] && !vals3[1]); + assert_se(vals3[0] && !vals3[1]); free(vals3[0]); assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", diff --git a/src/test/test-chase-symlinks.c b/src/test/test-chase-symlinks.c index 5f53eba101..9e50c5c749 100644 --- a/src/test/test-chase-symlinks.c +++ b/src/test/test-chase-symlinks.c @@ -34,8 +34,8 @@ static int parse_argv(int argc, char *argv[]) { int c; - assert(argc >= 0); - assert(argv); + assert_se(argc >= 0); + assert_se(argv); while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0) switch (c) { @@ -103,9 +103,9 @@ static int run(int argc, char **argv) { else { log_info("→ %s", p); if (arg_open) - assert(fd >= 0); + assert_se(fd >= 0); else - assert(fd == -1); + assert_se(fd == -1); } } diff --git a/src/test/test-condition.c b/src/test/test-condition.c index 62776086c2..d7cd63da81 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -689,12 +689,12 @@ static void test_condition_test_group(void) { free(gid); ngroups_max = sysconf(_SC_NGROUPS_MAX); - assert(ngroups_max > 0); + assert_se(ngroups_max > 0); gids = newa(gid_t, ngroups_max); ngroups = getgroups(ngroups_max, gids); - assert(ngroups >= 0); + assert_se(ngroups >= 0); max_gid = getgid(); for (i = 0; i < ngroups; i++) { diff --git a/src/test/test-cpu-set-util.c b/src/test/test-cpu-set-util.c index 0cfc883d66..c07b939506 100644 --- a/src/test/test-cpu-set-util.c +++ b/src/test/test-cpu-set-util.c @@ -256,7 +256,7 @@ static void test_cpu_set_to_from_dbus(void) { assert_se(allocated <= sizeof expected); assert_se(allocated >= DIV_ROUND_UP(201u, 8u)); /* We need at least 201 bits for our mask */ - assert(memcmp(array, expected, allocated) == 0); + assert_se(memcmp(array, expected, allocated) == 0); assert_se(cpu_set_from_dbus(array, allocated, &c2) == 0); assert_se(c2.set); @@ -268,7 +268,7 @@ static void test_cpus_in_affinity_mask(void) { int r; r = cpus_in_affinity_mask(); - assert(r > 0); + assert_se(r > 0); log_info("cpus_in_affinity_mask: %d", r); } diff --git a/src/test/test-escape.c b/src/test/test-escape.c index 413e8cd860..3fd318653c 100644 --- a/src/test/test-escape.c +++ b/src/test/test-escape.c @@ -58,8 +58,8 @@ static void test_xescape_full(bool eight_bits) { log_info("%02d: <%s>", i, q); if (i > 0) assert_se(endswith(q, ".")); - assert(strlen(q) <= i); - assert(strlen(q) + 3 >= strlen(t)); + assert_se(strlen(q) <= i); + assert_se(strlen(q) + 3 >= strlen(t)); } } diff --git a/src/test/test-exec-util.c b/src/test/test-exec-util.c index 4c11f54cef..ae740218b2 100644 --- a/src/test/test-exec-util.c +++ b/src/test/test-exec-util.c @@ -26,22 +26,22 @@ static void *ignore_stdout_args[] = { &here, &here2, &here3 }; /* noop handlers, just check that arguments are passed correctly */ static int ignore_stdout_func(int fd, void *arg) { - assert(fd >= 0); - assert(arg == &here); + assert_se(fd >= 0); + assert_se(arg == &here); safe_close(fd); return 0; } static int ignore_stdout_func2(int fd, void *arg) { - assert(fd >= 0); - assert(arg == &here2); + assert_se(fd >= 0); + assert_se(arg == &here2); safe_close(fd); return 0; } static int ignore_stdout_func3(int fd, void *arg) { - assert(fd >= 0); - assert(arg == &here3); + assert_se(fd >= 0); + assert_se(arg == &here3); safe_close(fd); return 0; diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 98989f405a..b9c1dc72c2 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -174,7 +174,7 @@ static bool check_user_has_group_with_same_name(const char *name) { struct passwd *p; struct group *g; - assert(name); + assert_se(name); p = getpwnam(name); if (!p || @@ -510,8 +510,8 @@ static int on_spawn_io(sd_event_source *s, int fd, uint32_t revents, void *userd char buf[4096]; ssize_t l; - assert(s); - assert(fd >= 0); + assert_se(s); + assert_se(fd >= 0); l = read(fd, buf, sizeof(buf) - 1); if (l < 0) { @@ -538,7 +538,7 @@ reenable: static int on_spawn_timeout(sd_event_source *s, uint64_t usec, void *userdata) { pid_t *pid = userdata; - assert(pid); + assert_se(pid); (void) kill(*pid, SIGKILL); @@ -548,7 +548,7 @@ static int on_spawn_timeout(sd_event_source *s, uint64_t usec, void *userdata) { static int on_spawn_sigchld(sd_event_source *s, const siginfo_t *si, void *userdata) { int ret = -EIO; - assert(si); + assert_se(si); if (si->si_code == CLD_EXITED) ret = si->si_status; @@ -568,8 +568,8 @@ static int find_libraries(const char *exec, char ***ret) { pid_t pid; int r; - assert(exec); - assert(ret); + assert_se(exec); + assert_se(ret); assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, -1) >= 0); @@ -653,7 +653,7 @@ static void test_exec_mount_apivfs(Manager *m) { _cleanup_strv_free_ char **libraries = NULL, **libraries_test = NULL; int r; - assert(user_runtime_unit_dir); + assert_se(user_runtime_unit_dir); r = find_executable("touch", &fullpath_touch); if (r < 0) { diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index fa8a66df04..5c266c0c9a 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -241,7 +241,7 @@ static void test_merge_env_file(void) { "zzzz=${foobar:-${nothing}}\n" "zzzzz=${nothing:+${nothing}}\n" , WRITE_STRING_FILE_AVOID_NEWLINE); - assert(r >= 0); + assert_se(r >= 0); r = merge_env_file(&a, NULL, t); assert_se(r >= 0); @@ -305,7 +305,7 @@ static void test_merge_env_file_invalid(void) { "#\n" "\n\n" /* empty line */ , WRITE_STRING_FILE_AVOID_NEWLINE); - assert(r >= 0); + assert_se(r >= 0); r = merge_env_file(&a, NULL, t); assert_se(r >= 0); diff --git a/src/test/test-firewall-util.c b/src/test/test-firewall-util.c index d2843cfab7..f22bc3c5bc 100644 --- a/src/test/test-firewall-util.c +++ b/src/test/test-firewall-util.c @@ -47,8 +47,8 @@ static void test_v6(FirewallContext *ctx) { } static union in_addr_union *parse_addr(const char *str, union in_addr_union *u) { - assert(str); - assert(u); + assert_se(str); + assert_se(u); assert_se(in_addr_from_string(AF_INET, str, u) >= 0); return u; } @@ -82,7 +82,7 @@ static bool test_v4(FirewallContext *ctx) { if (ignore) return false; } - assert(r >= 0); + assert_se(r >= 0); assert_se(fw_add_masquerade(&ctx, true, AF_INET, parse_addr("10.0.2.0", &u), 28) >= 0); assert_se(fw_add_masquerade(&ctx, false, AF_INET, parse_addr("10.0.2.0", &u), 28) >= 0); diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index f7bc8a7b2b..45a4755399 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -486,7 +486,7 @@ static void test_hashmap_foreach_key(void) { hashmap_put(m, key, (void*) (const char*) "my dummy val"); HASHMAP_FOREACH_KEY(s, key, m) { - assert(s); + assert_se(s); if (!key_found[0] && streq(key, "key 1")) key_found[0] = true; else if (!key_found[1] && streq(key, "key 2")) diff --git a/src/test/test-hostname-setup.c b/src/test/test-hostname-setup.c index 55996500f3..dcd61b295f 100644 --- a/src/test/test-hostname-setup.c +++ b/src/test/test-hostname-setup.c @@ -15,7 +15,7 @@ static void test_read_etc_hostname(void) { int fd; fd = mkostemp_safe(path); - assert(fd > 0); + assert_se(fd > 0); close(fd); /* simple hostname */ diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c index 30494f7fa1..ddba5e4dff 100644 --- a/src/test/test-install-root.c +++ b/src/test/test-install-root.c @@ -286,7 +286,7 @@ static void test_linked_units(const char *root) { else assert_not_reached(); } - assert(!p && !q); + assert_se(!p && !q); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -307,7 +307,7 @@ static void test_linked_units(const char *root) { else assert_not_reached(); } - assert(!p && !q); + assert_se(!p && !q); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -328,7 +328,7 @@ static void test_linked_units(const char *root) { else assert_not_reached(); } - assert(!p && !q); + assert_se(!p && !q); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -681,7 +681,7 @@ static void test_revert(const char *root) { UnitFileChange *changes = NULL; size_t n_changes = 0; - assert(root); + assert_se(root); assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "xx.service", NULL) == -ENOENT); assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "yy.service", NULL) == -ENOENT); @@ -1103,13 +1103,13 @@ static void verify_one( i->name, alias, r, expected, alias2 ? " [" : "", strempty(alias2), alias2 ? "]" : ""); - assert(r == expected); + assert_se(r == expected); /* This is test for "instance propagation". This propagation matters mostly for WantedBy= and * RequiredBy= settings, and less so for Alias=. The only case where it should happen is when we have * an Alias=alias@.service an instantiated template template@instance. In that case the instance name * should be propagated into the alias as alias@instance. */ - assert(streq_ptr(alias2, updated_name)); + assert_se(streq_ptr(alias2, updated_name)); } static void test_verify_alias(void) { diff --git a/src/test/test-log.c b/src/test/test-log.c index de8399dea8..cf438e6869 100644 --- a/src/test/test-log.c +++ b/src/test/test-log.c @@ -23,7 +23,7 @@ static void test_file(void) { log_info("RELATIVE_SOURCE_PATH: %s", RELATIVE_SOURCE_PATH); log_info("PROJECT_FILE: %s", PROJECT_FILE); - assert(startswith(__FILE__, RELATIVE_SOURCE_PATH "/")); + assert_se(startswith(__FILE__, RELATIVE_SOURCE_PATH "/")); } static void test_log_struct(void) { diff --git a/src/test/test-macro.c b/src/test/test-macro.c index 428f3b952a..4acbbfb7af 100644 --- a/src/test/test-macro.c +++ b/src/test/test-macro.c @@ -243,15 +243,15 @@ static void test_foreach_pointer(void) { k++; } - assert(k == 3); + assert_se(k == 3); FOREACH_POINTER(i, &b) { - assert(k == 3); - assert(i == &b); + assert_se(k == 3); + assert_se(i == &b); k = 4; } - assert(k == 4); + assert_se(k == 4); FOREACH_POINTER(i, NULL, &c, NULL, &b, NULL, &a, NULL) { switch (k) { @@ -292,7 +292,7 @@ static void test_foreach_pointer(void) { k++; } - assert(k == 11); + assert_se(k == 11); } static void test_align_to(void) { diff --git a/src/test/test-modhex.c b/src/test/test-modhex.c index 836460cec4..314be99879 100644 --- a/src/test/test-modhex.c +++ b/src/test/test-modhex.c @@ -8,7 +8,7 @@ static void test_normalize_recovery_key(const char *t, const char *expected) { _cleanup_free_ char *z = NULL; int r; - assert(t); + assert_se(t); r = normalize_recovery_key(t, &z); assert_se(expected ? diff --git a/src/test/test-path-lookup.c b/src/test/test-path-lookup.c index da146aac2a..f0b716a4c5 100644 --- a/src/test/test-path-lookup.c +++ b/src/test/test-path-lookup.c @@ -60,7 +60,7 @@ static void test_user_and_global_paths(void) { k++; } log_info(" %s", *p); - assert(u[k]); /* If NULL, we didn't find a matching entry */ + assert_se(u[k]); /* If NULL, we didn't find a matching entry */ k++; } STRV_FOREACH(p, u + k) diff --git a/src/test/test-psi-util.c b/src/test/test-psi-util.c index 857ecb59a4..d8d09118a6 100644 --- a/src/test/test-psi-util.c +++ b/src/test/test-psi-util.c @@ -42,7 +42,7 @@ static void test_read_mem_pressure(void) { assert_se(LOADAVG_INT_SIDE(rp.avg300) == 1); assert_se(LOADAVG_DECIMAL_SIDE(rp.avg300) == 11); assert_se(rp.total == 58761459); - assert(read_resource_pressure(path, PRESSURE_TYPE_FULL, &rp) == 0); + assert_se(read_resource_pressure(path, PRESSURE_TYPE_FULL, &rp) == 0); assert_se(LOADAVG_INT_SIDE(rp.avg10) == 0); assert_se(LOADAVG_DECIMAL_SIDE(rp.avg10) == 23); assert_se(LOADAVG_INT_SIDE(rp.avg60) == 0); @@ -62,7 +62,7 @@ static void test_read_mem_pressure(void) { assert_se(LOADAVG_INT_SIDE(rp.avg300) == 1); assert_se(LOADAVG_DECIMAL_SIDE(rp.avg300) == 11); assert_se(rp.total == 58761459); - assert(read_resource_pressure(path, PRESSURE_TYPE_FULL, &rp) == 0); + assert_se(read_resource_pressure(path, PRESSURE_TYPE_FULL, &rp) == 0); assert_se(LOADAVG_INT_SIDE(rp.avg10) == 0); assert_se(LOADAVG_DECIMAL_SIDE(rp.avg10) == 23); assert_se(LOADAVG_INT_SIDE(rp.avg60) == 0); diff --git a/src/test/test-recurse-dir.c b/src/test/test-recurse-dir.c index c3961191c4..2c2120b136 100644 --- a/src/test/test-recurse-dir.c +++ b/src/test/test-recurse-dir.c @@ -63,8 +63,8 @@ static int recurse_dir_callback( char ***l = userdata; - assert(path); - assert(de); + assert_se(path); + assert_se(de); switch (event) { diff --git a/src/test/test-sd-hwdb.c b/src/test/test-sd-hwdb.c index 7e1512a97d..7ed6907cbd 100644 --- a/src/test/test-sd-hwdb.c +++ b/src/test/test-sd-hwdb.c @@ -45,11 +45,11 @@ static void test_basic_enumerate(void) { for (;;) { r = sd_hwdb_enumerate(hwdb, &key, &value); - assert(IN_SET(r, 0, 1)); + assert_se(IN_SET(r, 0, 1)); if (r == 0) break; - assert(key); - assert(value); + assert_se(key); + assert_se(value); log_debug("A: \"%s\" → \"%s\"", key, value); len1 += strlen(key) + strlen(value); } diff --git a/src/test/test-set.c b/src/test/test-set.c index fd12021cfa..e63137192c 100644 --- a/src/test/test-set.c +++ b/src/test/test-set.c @@ -143,7 +143,7 @@ static void test_set_copy(void) { copy = set_copy(s); assert_se(copy); - assert(set_equal(s, copy)); + assert_se(set_equal(s, copy)); set_free(s); set_free_free(copy); diff --git a/src/test/test-signal-util.c b/src/test/test-signal-util.c index 0586775902..1e08b7a062 100644 --- a/src/test/test-signal-util.c +++ b/src/test/test-signal-util.c @@ -16,7 +16,7 @@ static void test_rt_signals(void) { info(SIGRTMAX); /* We use signals SIGRTMIN+0 to SIGRTMIN+24 unconditionally */ - assert(SIGRTMAX - SIGRTMIN >= 24); + assert_se(SIGRTMAX - SIGRTMIN >= 24); } static void test_signal_to_string_one(int val) { diff --git a/src/test/test-socket-netlink.c b/src/test/test-socket-netlink.c index da484a4003..c7d039af55 100644 --- a/src/test/test-socket-netlink.c +++ b/src/test/test-socket-netlink.c @@ -16,7 +16,7 @@ static void test_socket_address_parse_one(const char *in, int ret, int family, c r = socket_address_print(&a, &out); if (r < 0) log_error_errno(r, "Printing failed for \"%s\": %m", in); - assert(r >= 0); + assert_se(r >= 0); assert_se(a.type == 0); } diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index 584253c2fc..f9b22c7e11 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -26,37 +26,37 @@ assert_cc(SUN_PATH_LEN == 108); static void test_ifname_valid(void) { log_info("/* %s */", __func__); - assert( ifname_valid("foo")); - assert( ifname_valid("eth0")); - - assert(!ifname_valid("0")); - assert(!ifname_valid("99")); - assert( ifname_valid("a99")); - assert( ifname_valid("99a")); - - assert(!ifname_valid(NULL)); - assert(!ifname_valid("")); - assert(!ifname_valid(" ")); - assert(!ifname_valid(" foo")); - assert(!ifname_valid("bar\n")); - assert(!ifname_valid(".")); - assert(!ifname_valid("..")); - assert(ifname_valid("foo.bar")); - assert(!ifname_valid("x:y")); - - assert( ifname_valid_full("xxxxxxxxxxxxxxx", 0)); - assert(!ifname_valid_full("xxxxxxxxxxxxxxxx", 0)); - assert( ifname_valid_full("xxxxxxxxxxxxxxxx", IFNAME_VALID_ALTERNATIVE)); - assert( ifname_valid_full("xxxxxxxxxxxxxxxx", IFNAME_VALID_ALTERNATIVE)); - assert(!ifname_valid_full("999", IFNAME_VALID_ALTERNATIVE)); - assert( ifname_valid_full("999", IFNAME_VALID_ALTERNATIVE | IFNAME_VALID_NUMERIC)); - assert(!ifname_valid_full("0", IFNAME_VALID_ALTERNATIVE | IFNAME_VALID_NUMERIC)); + assert_se( ifname_valid("foo")); + assert_se( ifname_valid("eth0")); + + assert_se(!ifname_valid("0")); + assert_se(!ifname_valid("99")); + assert_se( ifname_valid("a99")); + assert_se( ifname_valid("99a")); + + assert_se(!ifname_valid(NULL)); + assert_se(!ifname_valid("")); + assert_se(!ifname_valid(" ")); + assert_se(!ifname_valid(" foo")); + assert_se(!ifname_valid("bar\n")); + assert_se(!ifname_valid(".")); + assert_se(!ifname_valid("..")); + assert_se(ifname_valid("foo.bar")); + assert_se(!ifname_valid("x:y")); + + assert_se( ifname_valid_full("xxxxxxxxxxxxxxx", 0)); + assert_se(!ifname_valid_full("xxxxxxxxxxxxxxxx", 0)); + assert_se( ifname_valid_full("xxxxxxxxxxxxxxxx", IFNAME_VALID_ALTERNATIVE)); + assert_se( ifname_valid_full("xxxxxxxxxxxxxxxx", IFNAME_VALID_ALTERNATIVE)); + assert_se(!ifname_valid_full("999", IFNAME_VALID_ALTERNATIVE)); + assert_se( ifname_valid_full("999", IFNAME_VALID_ALTERNATIVE | IFNAME_VALID_NUMERIC)); + assert_se(!ifname_valid_full("0", IFNAME_VALID_ALTERNATIVE | IFNAME_VALID_NUMERIC)); } static void test_socket_print_unix_one(const char *in, size_t len_in, const char *expected) { _cleanup_free_ char *out = NULL, *c = NULL; - assert(len_in <= SUN_PATH_LEN); + assert_se(len_in <= SUN_PATH_LEN); SocketAddress a = { .sockaddr = { .un = { .sun_family = AF_UNIX } }, .size = offsetof(struct sockaddr_un, sun_path) + len_in, .type = SOCK_STREAM, @@ -194,7 +194,7 @@ static void test_getpeercred_getpeergroups(void) { test_gid = getgid(); ngroups_max = sysconf(_SC_NGROUPS_MAX); - assert(ngroups_max > 0); + assert_se(ngroups_max > 0); test_gids = newa(gid_t, ngroups_max); diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c index fa167fb263..b27d26c81a 100644 --- a/src/test/test-stat-util.c +++ b/src/test/test-stat-util.c @@ -184,7 +184,7 @@ static void test_device_path_make_canonical_one(const char *path) { log_debug("> %s", path); if (stat(path, &st) < 0) { - assert(errno == ENOENT); + assert_se(errno == ENOENT); log_notice("Path %s not found, skipping test", path); return; } diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 51ad45b5ac..34f438cf9c 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -1007,7 +1007,7 @@ static void test_strv_fnmatch(void) { v = strv_new("xxx", "*\\*", "yyy"); assert_se(!strv_fnmatch_full(v, "\\", 0, NULL)); assert_se(strv_fnmatch_full(v, "\\", FNM_NOESCAPE, &pos)); - assert(pos == 1); + assert_se(pos == 1); } int main(int argc, char *argv[]) { diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c index 7079bffa7f..53f8114501 100644 --- a/src/test/test-time-util.c +++ b/src/test/test-time-util.c @@ -656,7 +656,7 @@ int main(int argc, char *argv[]) { /* Ensure TIME_T_MAX works correctly */ uintmax_t x = TIME_T_MAX; x++; - assert((time_t) x < 0); + assert_se((time_t) x < 0); return 0; } diff --git a/src/test/test-tmpfile-util.c b/src/test/test-tmpfile-util.c index 9f2e615867..39d524e2b6 100644 --- a/src/test/test-tmpfile-util.c +++ b/src/test/test-tmpfile-util.c @@ -14,7 +14,7 @@ static void test_tempfn_random_one(const char *p, const char *extra, const char r = tempfn_random(p, extra, &s); log_info_errno(r, "%s+%s → %s vs. %s (%i/%m vs. %i/%s)", p, strna(extra), strna(s), strna(expect), r, ret, strerror_safe(ret)); - assert(!s == !expect); + assert_se(!s == !expect); if (s) { const char *suffix; @@ -22,7 +22,7 @@ static void test_tempfn_random_one(const char *p, const char *extra, const char assert_se(in_charset(suffix, HEXDIGITS)); assert_se(strlen(suffix) == 16); } - assert(ret == r); + assert_se(ret == r); } static void test_tempfn_random(void) { @@ -59,14 +59,14 @@ static void test_tempfn_xxxxxx_one(const char *p, const char *extra, const char r = tempfn_xxxxxx(p, extra, &s); log_info_errno(r, "%s+%s → %s vs. %s (%i/%m vs. %i/%s)", p, strna(extra), strna(s), strna(expect), r, ret, strerror_safe(ret)); - assert(!s == !expect); + assert_se(!s == !expect); if (s) { const char *suffix; assert_se(suffix = startswith(s, expect)); assert_se(streq(suffix, "XXXXXX")); } - assert(ret == r); + assert_se(ret == r); } static void test_tempfn_xxxxxx(void) { diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index 477ae03a02..4fcd2e0efd 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -65,7 +65,7 @@ static void test_unit_file_build_name_map(char **ids) { *id, &fragment, &names); - assert(r == 0); + assert_se(r == 0); log_info("fragment: %s", fragment); log_info("names:"); SET_FOREACH(name, names) diff --git a/src/test/test-unit-serialize.c b/src/test/test-unit-serialize.c index 58a0d9dfd4..9bd634fcbd 100644 --- a/src/test/test-unit-serialize.c +++ b/src/test/test-unit-serialize.c @@ -17,7 +17,7 @@ static void test_deserialize_exec_command_one(Manager *m, const char *key, const r = service_deserialize_exec_command(u, key, line); log_debug("[%s] → %d (expected: %d)", line, r, expected); - assert(r == expected); + assert_se(r == expected); /* Note that the command doesn't match any command in the empty list of commands in 's', so it is * always rejected with "Current command vanished from the unit file", and we don't leak anything. */ diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c index 94ca3f04ba..af9537a3ab 100644 --- a/src/test/test-user-util.c +++ b/src/test/test-user-util.c @@ -374,14 +374,14 @@ static void test_make_salt(void) { assert_se(make_salt(&t) == 0); log_info("got %s", t); - assert(!streq(s, t)); + assert_se(!streq(s, t)); } static void test_in_gid(void) { - assert(in_gid(getgid()) >= 0); - assert(in_gid(getegid()) >= 0); - assert(in_gid(GID_INVALID) < 0); - assert(in_gid(TTY_GID) == 0); /* The TTY gid is for owning ttys, it would be really really weird if we were in it. */ + assert_se(in_gid(getgid()) >= 0); + assert_se(in_gid(getegid()) >= 0); + assert_se(in_gid(GID_INVALID) < 0); + assert_se(in_gid(TTY_GID) == 0); /* The TTY gid is for owning ttys, it would be really really weird if we were in it. */ } static void test_gid_lists_ops(void) { diff --git a/src/test/test-varlink.c b/src/test/test-varlink.c index 9a5fbc6c8e..a2708ecd08 100644 --- a/src/test/test-varlink.c +++ b/src/test/test-varlink.c @@ -72,8 +72,8 @@ static int reply(Varlink *link, JsonVariant *parameters, const char *error_id, V static int on_connect(VarlinkServer *s, Varlink *link, void *userdata) { uid_t uid = UID_INVALID; - assert(s); - assert(link); + assert_se(s); + assert_se(link); assert_se(varlink_get_peer_uid(link, &uid) >= 0); assert_se(getuid() == uid); diff --git a/src/tmpfiles/test-offline-passwd.c b/src/tmpfiles/test-offline-passwd.c index e509c63961..5978e69b86 100644 --- a/src/tmpfiles/test-offline-passwd.c +++ b/src/tmpfiles/test-offline-passwd.c @@ -47,8 +47,8 @@ static int parse_argv(int argc, char *argv[]) { int c; - assert(argc >= 0); - assert(argv); + assert_se(argc >= 0); + assert_se(argv); while ((c = getopt_long(argc, argv, "r:", options, NULL)) >= 0) switch(c) { |