Skip to content

Commit bb76d22

Browse files
IVandeVeireMaureenHelm
authored andcommitted
test: net: igmp: Cleanup asserts
Cleanup of existing asserts in the IGMP test. Signed-off-by: Ibe Van de Veire <[email protected]>
1 parent fa07b9f commit bb76d22

File tree

1 file changed

+30
-51
lines changed

1 file changed

+30
-51
lines changed

tests/net/igmp/src/main.c

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,13 @@ static int tester_send(const struct device *dev, struct net_pkt *pkt)
183183
zassert_false(is_igmpv2_query_sent, "IGMPv3 response to IGMPv2 request");
184184

185185
#if defined(CONFIG_NET_IPV4_IGMPV3)
186-
zassert_true(ntohs(igmp_header->groups_len) == 1,
187-
"Invalid group length of IGMPv3 report (%d)", igmp_header->groups_len);
186+
zassert_equal(ntohs(igmp_header->groups_len), 1,
187+
"Invalid group length of IGMPv3 report (%d)",
188+
igmp_header->groups_len);
188189

189190
igmp_group_record = get_igmp_group_record(pkt);
190-
zassert_true(igmp_group_record->sources_len == 0,
191-
"Invalid sources length of IGMPv3 group record");
191+
zassert_equal(igmp_group_record->sources_len, 0,
192+
"Invalid sources length of IGMPv3 group record");
192193

193194
if (igmp_group_record->type == IGMPV3_CHANGE_TO_EXCLUDE_MODE) {
194195
is_join_msg_ok = true;
@@ -334,7 +335,7 @@ static void join_group(void)
334335
zassert_true(ret == 0 || ret == -EALREADY,
335336
"Cannot join IPv4 multicast group");
336337
} else {
337-
zassert_equal(ret, 0, "Cannot join IPv4 multicast group");
338+
zassert_ok(ret, "Cannot join IPv4 multicast group");
338339
}
339340

340341
/* Let the network stack to proceed */
@@ -347,7 +348,7 @@ static void leave_group(void)
347348

348349
ret = net_ipv4_igmp_leave(net_iface, &mcast_addr);
349350

350-
zassert_equal(ret, 0, "Cannot leave IPv4 multicast group");
351+
zassert_ok(ret, "Cannot leave IPv4 multicast group");
351352

352353
if (IS_ENABLED(CONFIG_NET_TC_THREAD_PREEMPTIVE)) {
353354
/* Let the network stack to proceed */
@@ -365,13 +366,9 @@ static void catch_join_group(void)
365366

366367
join_group();
367368

368-
if (k_sem_take(&wait_data, K_MSEC(WAIT_TIME))) {
369-
zassert_true(0, "Timeout while waiting join event");
370-
}
369+
zassert_ok(k_sem_take(&wait_data, K_MSEC(WAIT_TIME)), "Timeout while waiting join event");
371370

372-
if (!is_group_joined) {
373-
zassert_true(0, "Did not catch join event");
374-
}
371+
zassert_true(is_group_joined, "Did not catch join event");
375372

376373
is_group_joined = false;
377374
}
@@ -382,13 +379,9 @@ static void catch_leave_group(void)
382379

383380
leave_group();
384381

385-
if (k_sem_take(&wait_data, K_MSEC(WAIT_TIME))) {
386-
zassert_true(0, "Timeout while waiting leave event");
387-
}
382+
zassert_ok(k_sem_take(&wait_data, K_MSEC(WAIT_TIME)), "Timeout while waiting leave event");
388383

389-
if (!is_group_left) {
390-
zassert_true(0, "Did not catch leave event");
391-
}
384+
zassert_true(is_group_left, "Did not catch leave event");
392385

393386
is_group_left = false;
394387
}
@@ -401,13 +394,9 @@ static void verify_join_group(void)
401394

402395
join_group();
403396

404-
if (k_sem_take(&wait_data, K_MSEC(WAIT_TIME))) {
405-
zassert_true(0, "Timeout while waiting join event");
406-
}
397+
zassert_ok(k_sem_take(&wait_data, K_MSEC(WAIT_TIME)), "Timeout while waiting join event");
407398

408-
if (!is_join_msg_ok) {
409-
zassert_true(0, "Join msg invalid");
410-
}
399+
zassert_true(is_join_msg_ok, "Join msg invalid");
411400

412401
is_join_msg_ok = false;
413402
}
@@ -418,13 +407,9 @@ static void verify_leave_group(void)
418407

419408
leave_group();
420409

421-
if (k_sem_take(&wait_data, K_MSEC(WAIT_TIME))) {
422-
zassert_true(0, "Timeout while waiting leave event");
423-
}
410+
zassert_ok(k_sem_take(&wait_data, K_MSEC(WAIT_TIME)), "Timeout while waiting leave event");
424411

425-
if (!is_leave_msg_ok) {
426-
zassert_true(0, "Leave msg invalid");
427-
}
412+
zassert_true(is_leave_msg_ok, "Leave msg invalid");
428413

429414
is_leave_msg_ok = false;
430415
}
@@ -464,19 +449,19 @@ static void socket_group_with_address(struct in_addr *local_addr, bool do_join)
464449

465450
ret = zsock_setsockopt(fd, IPPROTO_IP, option,
466451
NULL, sizeof(mreqn));
467-
zassert_true(ret == -1 && errno == EINVAL,
468-
"Incorrect return value (%d)", -errno);
452+
zassert_equal(ret, -1, "Incorrect return value (%d)", ret);
453+
zassert_equal(errno, EINVAL, "Incorrect errno value (%d)", -errno);
469454

470455
ret = zsock_setsockopt(fd, IPPROTO_IP, option,
471456
(void *)&mreqn, 1);
472-
zassert_true(ret == -1 && errno == EINVAL,
473-
"Incorrect return value (%d)", -errno);
457+
zassert_equal(ret, -1, "Incorrect return value (%d)", ret);
458+
zassert_equal(errno, EINVAL, "Incorrect errno value (%d)", -errno);
474459

475460
/* First try with empty mreqn */
476461
ret = zsock_setsockopt(fd, IPPROTO_IP, option,
477462
(void *)&mreqn, sizeof(mreqn));
478-
zassert_true(ret == -1 && errno == EINVAL,
479-
"Incorrect return value (%d)", -errno);
463+
zassert_equal(ret, -1, "Incorrect return value (%d)", ret);
464+
zassert_equal(errno, EINVAL, "Incorrect errno value (%d)", -errno);
480465

481466
memcpy(&mreqn.imr_address, local_addr, sizeof(mreqn.imr_address));
482467
memcpy(&mreqn.imr_multiaddr, &mcast_addr, sizeof(mreqn.imr_multiaddr));
@@ -487,17 +472,15 @@ static void socket_group_with_address(struct in_addr *local_addr, bool do_join)
487472
if (do_join) {
488473
if (ignore_already) {
489474
zassert_true(ret == 0 || ret == -EALREADY,
490-
"Cannot join IPv4 multicast group (%d)",
491-
-errno);
475+
"Cannot join IPv4 multicast group (%d)", -errno);
492476
} else {
493-
zassert_equal(ret, 0,
494-
"Cannot join IPv4 multicast group (%d) "
495-
"with local addr %s",
496-
-errno, net_sprint_ipv4_addr(local_addr));
477+
zassert_ok(ret,
478+
"Cannot join IPv4 multicast group (%d) "
479+
"with local addr %s",
480+
-errno, net_sprint_ipv4_addr(local_addr));
497481
}
498482
} else {
499-
zassert_equal(ret, 0, "Cannot leave IPv4 multicast group (%d)",
500-
-errno);
483+
zassert_ok(ret, "Cannot leave IPv4 multicast group (%d)", -errno);
501484

502485
if (IS_ENABLED(CONFIG_NET_TC_THREAD_PREEMPTIVE)) {
503486
/* Let the network stack to proceed */
@@ -537,16 +520,12 @@ static void socket_group_with_index(struct in_addr *local_addr, bool do_join)
537520
if (do_join) {
538521
if (ignore_already) {
539522
zassert_true(ret == 0 || ret == -EALREADY,
540-
"Cannot join IPv4 multicast group (%d)",
541-
-errno);
523+
"Cannot join IPv4 multicast group (%d)", -errno);
542524
} else {
543-
zassert_equal(ret, 0,
544-
"Cannot join IPv4 multicast group (%d)",
545-
-errno);
525+
zassert_ok(ret, "Cannot join IPv4 multicast group (%d)", -errno);
546526
}
547527
} else {
548-
zassert_equal(ret, 0, "Cannot leave IPv4 multicast group (%d)",
549-
-errno);
528+
zassert_ok(ret, "Cannot leave IPv4 multicast group (%d)", -errno);
550529

551530
if (IS_ENABLED(CONFIG_NET_TC_THREAD_PREEMPTIVE)) {
552531
/* Let the network stack to proceed */

0 commit comments

Comments
 (0)