Skip to content

Commit f21b863

Browse files
committed
test: use assert_se() instead of assert()
1 parent 1c71302 commit f21b863

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+135
-135
lines changed

src/libsystemd-network/test-dhcp-option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static DHCPMessage *create_message(uint8_t *options, uint16_t optlen,
121121
}
122122

123123
static void test_ignore_opts(uint8_t *descoption, int *descpos, int *desclen) {
124-
assert(*descpos >= 0);
124+
assert_se(*descpos >= 0);
125125

126126
while (*descpos < *desclen) {
127127
switch(descoption[*descpos]) {

src/libsystemd/sd-bus/test-bus-address.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void test_one_address(sd_bus *b,
1616
r = bus_set_address_system_remote(b, host);
1717
log_info("\"%s\" → %d, \"%s\"", host, r, strna(r >= 0 ? b->address : NULL));
1818
if (result < 0 || expected) {
19-
assert(r == result);
19+
assert_se(r == result);
2020
if (r >= 0)
2121
assert_se(streq(b->address, expected));
2222
}

src/libsystemd/sd-event/test-event.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ struct inotify_context {
404404
static void maybe_exit(sd_event_source *s, struct inotify_context *c) {
405405
unsigned n;
406406

407-
assert(s);
408-
assert(c);
407+
assert_se(s);
408+
assert_se(c);
409409

410410
if (!c->delete_self_handler_called)
411411
return;

src/libsystemd/sd-journal/test-compress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ _unused_ static void test_decompress_startswith(const char *compression,
118118
compressed = compressed2 = malloc(BUFSIZE_2);
119119
assert_se(compressed2);
120120
r = compress(data, data_len, compressed, BUFSIZE_2, &csize);
121-
assert(r == 0);
121+
assert_se(r == 0);
122122
}
123123
assert_se(r == 0);
124124

src/libsystemd/sd-netlink/test-netlink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ struct test_async_object {
287287
};
288288

289289
static struct test_async_object *test_async_object_free(struct test_async_object *t) {
290-
assert(t);
290+
assert_se(t);
291291

292292
free(t->ifname);
293293
return mfree(t);
@@ -315,7 +315,7 @@ static int link_handler2(sd_netlink *rtnl, sd_netlink_message *m, void *userdata
315315
static void test_async_object_destroy(void *userdata) {
316316
struct test_async_object *t = userdata;
317317

318-
assert(userdata);
318+
assert_se(userdata);
319319

320320
log_info("%s: n_ref=%u", __func__, t->n_ref);
321321
test_async_object_unref(t);
@@ -593,8 +593,8 @@ static int genl_ctrl_match_callback(sd_netlink *genl, sd_netlink_message *m, voi
593593
uint16_t id;
594594
uint8_t cmd;
595595

596-
assert(genl);
597-
assert(m);
596+
assert_se(genl);
597+
assert_se(m);
598598

599599
assert_se(sd_genl_message_get_family_name(genl, m, &name) >= 0);
600600
assert_se(streq(name, CTRL_GENL_NAME));

src/oom/test-oomd-util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void test_oomd_cgroup_kill(void) {
5252
/* Create another cgroup below this one for the pids we forked off. We need this to be managed
5353
* by the test so that pid1 doesn't delete it before we can read the xattrs. */
5454
cgroup = path_join(cgroup_root, "oomdkilltest");
55-
assert(cgroup);
55+
assert_se(cgroup);
5656
assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, cgroup) >= 0);
5757

5858
/* If we don't have permissions to set xattrs we're likely in a userns or missing capabilities */

src/resolve/test-resolved-etc-hosts.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ static void test_parse_etc_hosts(void) {
105105
assert_se(address_equal_4(bn->addresses[2], inet_addr("1.2.3.11")));
106106
assert_se(address_equal_4(bn->addresses[3], inet_addr("1.2.3.12")));
107107

108-
assert(!hashmap_get(hosts.by_name, "within.comment"));
109-
assert(!hashmap_get(hosts.by_name, "within.comment2"));
110-
assert(!hashmap_get(hosts.by_name, "within.comment3"));
111-
assert(!hashmap_get(hosts.by_name, "#"));
112-
113-
assert(!hashmap_get(hosts.by_name, "short.address"));
114-
assert(!hashmap_get(hosts.by_name, "long.address"));
115-
assert(!hashmap_get(hosts.by_name, "multi.colon"));
108+
assert_se(!hashmap_get(hosts.by_name, "within.comment"));
109+
assert_se(!hashmap_get(hosts.by_name, "within.comment2"));
110+
assert_se(!hashmap_get(hosts.by_name, "within.comment3"));
111+
assert_se(!hashmap_get(hosts.by_name, "#"));
112+
113+
assert_se(!hashmap_get(hosts.by_name, "short.address"));
114+
assert_se(!hashmap_get(hosts.by_name, "long.address"));
115+
assert_se(!hashmap_get(hosts.by_name, "multi.colon"));
116116
assert_se(!set_contains(hosts.no_address, "short.address"));
117117
assert_se(!set_contains(hosts.no_address, "long.address"));
118118
assert_se(!set_contains(hosts.no_address, "multi.colon"));

src/test/test-boot-timestamps.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ int main(int argc, char* argv[]) {
7676
test_setup_logging(LOG_DEBUG);
7777

7878
p = test_acpi_fpdt();
79-
assert(p >= 0);
79+
assert_se(p >= 0);
8080
q = test_efi_loader();
81-
assert(q >= 0);
81+
assert_se(q >= 0);
8282
r = test_boot_timestamps();
83-
assert(r >= 0);
83+
assert_se(r >= 0);
8484

8585
if (p == 0 && q == 0 && r == 0)
8686
return log_tests_skipped("access to firmware variables not possible");

src/test/test-bpf-firewall.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ int main(int argc, char *argv[]) {
5656
assert_se(runtime_dir = setup_fake_runtime_dir());
5757

5858
r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, &p);
59-
assert(r == 0);
59+
assert_se(r == 0);
6060

6161
r = bpf_program_add_instructions(p, exit_insn, ELEMENTSOF(exit_insn));
62-
assert(r == 0);
62+
assert_se(r == 0);
6363

6464
if (getuid() != 0)
6565
return log_tests_skipped("not running as root");
@@ -76,7 +76,7 @@ int main(int argc, char *argv[]) {
7676
log_notice("BPF firewalling (though without BPF_F_ALLOW_MULTI) supported. Good.");
7777

7878
r = bpf_program_load_kernel(p, log_buf, ELEMENTSOF(log_buf));
79-
assert(r >= 0);
79+
assert_se(r >= 0);
8080

8181
if (test_custom_filter) {
8282
zero(attr);
@@ -158,8 +158,8 @@ int main(int argc, char *argv[]) {
158158
return log_tests_skipped("Kernel doesn't support the necessary bpf bits (masked out via seccomp?)");
159159
assert_se(r >= 0);
160160

161-
assert(u->ip_bpf_ingress);
162-
assert(u->ip_bpf_egress);
161+
assert_se(u->ip_bpf_ingress);
162+
assert_se(u->ip_bpf_egress);
163163

164164
r = bpf_program_load_kernel(u->ip_bpf_ingress, log_buf, ELEMENTSOF(log_buf));
165165

@@ -168,7 +168,7 @@ int main(int argc, char *argv[]) {
168168
log_notice("%s", log_buf);
169169
log_notice("-------");
170170

171-
assert(r >= 0);
171+
assert_se(r >= 0);
172172

173173
r = bpf_program_load_kernel(u->ip_bpf_egress, log_buf, ELEMENTSOF(log_buf));
174174

@@ -177,7 +177,7 @@ int main(int argc, char *argv[]) {
177177
log_notice("%s", log_buf);
178178
log_notice("-------");
179179

180-
assert(r >= 0);
180+
assert_se(r >= 0);
181181

182182
assert_se(unit_start(u) >= 0);
183183

src/test/test-bus-util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void test_destroy_callback(void) {
3030
}
3131

3232
r = sd_bus_request_name_async(bus, &slot, "org.freedesktop.systemd.test-bus-util", 0, callback, &n_called);
33-
assert(r == 1);
33+
assert_se(r == 1);
3434

3535
assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 0);
3636
assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 0);
@@ -41,9 +41,9 @@ static void test_destroy_callback(void) {
4141
assert_se(t == destroy_callback);
4242

4343
/* Force cleanup so we can look at n_called */
44-
assert(n_called == 0);
44+
assert_se(n_called == 0);
4545
sd_bus_slot_unref(slot);
46-
assert(n_called == 1);
46+
assert_se(n_called == 1);
4747
}
4848

4949
int main(int argc, char **argv) {

0 commit comments

Comments
 (0)