test: use assert_se() instead of assert()

This commit is contained in:
Yu Watanabe
2021-10-12 02:39:11 +09:00
parent 1c71302f70
commit f21b863eeb
44 changed files with 131 additions and 131 deletions

View File

@@ -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]) {

View File

@@ -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));
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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));

View File

@@ -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 */

View File

@@ -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_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(!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, "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"));

View File

@@ -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");

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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",

View File

@@ -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);
}
}

View File

@@ -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++) {

View File

@@ -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);
}

View File

@@ -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));
}
}

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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);

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