diff options
author | Jan Janssen <medhefgo@web.de> | 2022-03-14 10:37:27 +0100 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2022-03-16 14:50:12 +0100 |
commit | 68da8adf54d7ab88610c161a1c7dd2819eb96886 (patch) | |
tree | 0a1f175eb14cb1e984c63f309641cf17df416e66 /src/libsystemd-network | |
parent | update TODO (diff) | |
download | systemd-68da8adf54d7ab88610c161a1c7dd2819eb96886.tar.xz systemd-68da8adf54d7ab88610c161a1c7dd2819eb96886.zip |
test: Use TEST macros in more places
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r-- | src/libsystemd-network/test-dhcp6-client.c | 37 | ||||
-rw-r--r-- | src/libsystemd-network/test-ndisc-ra.c | 24 | ||||
-rw-r--r-- | src/libsystemd-network/test-ndisc-rs.c | 20 | ||||
-rw-r--r-- | src/libsystemd-network/test-sd-dhcp-lease.c | 23 |
4 files changed, 22 insertions, 82 deletions
diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c index f53e093d77..dfd9042c29 100644 --- a/src/libsystemd-network/test-dhcp6-client.c +++ b/src/libsystemd-network/test-dhcp6-client.c @@ -78,12 +78,10 @@ static int test_ifindex = 42; static unsigned test_client_sent_message_count = 0; static sd_dhcp6_client *client_ref = NULL; -static void test_client_basic(void) { +TEST(client_basic) { _cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL; int v; - log_debug("/* %s */", __func__); - assert_se(sd_dhcp6_client_new(&client) >= 0); assert_se(client); @@ -144,13 +142,11 @@ static void test_client_basic(void) { assert_se(sd_dhcp6_client_detach_event(client) >= 0); } -static void test_parse_domain(void) { +TEST(parse_domain) { _cleanup_free_ char *domain = NULL; _cleanup_strv_free_ char **list = NULL; uint8_t *data; - log_debug("/* %s */", __func__); - data = (uint8_t []) { 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0 }; assert_se(dhcp6_option_parse_domainname(data, 13, &domain) >= 0); assert_se(domain); @@ -182,7 +178,7 @@ static void test_parse_domain(void) { assert_se(dhcp6_option_parse_domainname_list(data, 2, &list) < 0); } -static void test_option(void) { +TEST(option) { uint8_t packet[] = { 'F', 'O', 'O', 'H', 'O', 'G', 'E', 0x00, SD_DHCP6_OPTION_ORO, 0x00, 0x07, @@ -204,8 +200,6 @@ static void test_option(void) { uint16_t optcode; uint8_t *out; - log_debug("/* %s */", __func__); - assert_se(sizeof(packet) == sizeof(result)); offset = 0; @@ -258,7 +252,7 @@ static void test_option(void) { assert_se(memcmp(packet, result, sizeof(packet)) == 0); } -static void test_option_status(void) { +TEST(option_status) { uint8_t option1[] = { /* IA NA */ 0x00, 0x03, 0x00, 0x12, 0x1a, 0x1d, 0x1a, 0x1d, @@ -330,8 +324,6 @@ static void test_option_status(void) { be32_t iaid; int r; - log_debug("/* %s */", __func__); - memcpy(&iaid, option1 + 4, sizeof(iaid)); option = (DHCP6Option*) option1; @@ -384,7 +376,7 @@ static void test_option_status(void) { ia = dhcp6_ia_free(ia); } -static void test_client_parse_message_issue_22099(void) { +TEST(client_parse_message_issue_22099) { static const uint8_t msg[] = { /* Message type */ DHCP6_MESSAGE_REPLY, @@ -444,8 +436,6 @@ static void test_client_parse_message_issue_22099(void) { _cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL; _cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL; - log_debug("/* %s */", __func__); - assert_se(sd_dhcp6_client_new(&client) >= 0); assert_se(sd_dhcp6_client_set_iaid(client, 0xcc59117b) >= 0); assert_se(sd_dhcp6_client_set_duid(client, 2, duid, sizeof(duid)) >= 0); @@ -970,12 +960,10 @@ int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *a) { return TAKE_FD(test_fd[0]); } -static void test_dhcp6_client(void) { +TEST(dhcp6_client) { _cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL; _cleanup_(sd_event_unrefp) sd_event *e = NULL; - log_debug("/* %s */", __func__); - assert_se(sd_event_new(&e) >= 0); assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), 2 * USEC_PER_SEC, 0, @@ -1006,15 +994,4 @@ static void test_dhcp6_client(void) { test_fd[1] = safe_close(test_fd[1]); } -int main(int argc, char *argv[]) { - test_setup_logging(LOG_DEBUG); - - test_client_basic(); - test_parse_domain(); - test_option(); - test_option_status(); - test_client_parse_message_issue_22099(); - test_dhcp6_client(); - - return 0; -} +DEFINE_TEST_MAIN(LOG_DEBUG); diff --git a/src/libsystemd-network/test-ndisc-ra.c b/src/libsystemd-network/test-ndisc-ra.c index 83186a97bb..cbf065d4fb 100644 --- a/src/libsystemd-network/test-ndisc-ra.c +++ b/src/libsystemd-network/test-ndisc-ra.c @@ -100,11 +100,9 @@ static const struct in6_addr test_rdnss = { { { 0x20, 0x01, 0x0d, 0xb8, static const char *test_dnssl[] = { "lab.intra", NULL }; -static void test_radv_prefix(void) { +TEST(radv_prefix) { sd_radv_prefix *p; - printf("* %s\n", __func__); - assert_se(sd_radv_prefix_new(&p) >= 0); assert_se(sd_radv_prefix_set_onlink(NULL, true) < 0); @@ -142,11 +140,9 @@ static void test_radv_prefix(void) { assert_se(!p); } -static void test_radv(void) { +TEST(radv) { sd_radv *ra; - printf("* %s\n", __func__); - assert_se(sd_radv_new(&ra) >= 0); assert_se(ra); @@ -284,13 +280,11 @@ static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdat return 0; } -static void test_ra(void) { +TEST(ra) { sd_event *e; sd_radv *ra; unsigned i; - printf("* %s\n", __func__); - assert_se(socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) >= 0); assert_se(sd_event_new(&e) >= 0); @@ -349,14 +343,4 @@ static void test_ra(void) { sd_event_unref(e); } -int main(int argc, char *argv[]) { - - test_setup_logging(LOG_DEBUG); - - test_radv_prefix(); - test_radv(); - test_ra(); - - printf("* done\n"); - return 0; -} +DEFINE_TEST_MAIN(LOG_DEBUG); diff --git a/src/libsystemd-network/test-ndisc-rs.c b/src/libsystemd-network/test-ndisc-rs.c index 10915e1d4c..2c27d12b09 100644 --- a/src/libsystemd-network/test-ndisc-rs.c +++ b/src/libsystemd-network/test-ndisc-rs.c @@ -257,13 +257,10 @@ static void test_callback(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router sd_event_exit(e, 0); } -static void test_rs(void) { +TEST(rs) { sd_event *e; sd_ndisc *nd; - if (verbose) - printf("* %s\n", __func__); - send_ra_function = send_ra; assert_se(sd_event_new(&e) >= 0); @@ -347,13 +344,10 @@ static int test_timeout_value(uint8_t flags) { return 0; } -static void test_timeout(void) { +TEST(timeout) { sd_event *e; sd_ndisc *nd; - if (verbose) - printf("* %s\n", __func__); - send_ra_function = test_timeout_value; assert_se(sd_event_new(&e) >= 0); @@ -381,12 +375,4 @@ static void test_timeout(void) { sd_event_unref(e); } -int main(int argc, char *argv[]) { - - test_setup_logging(LOG_DEBUG); - - test_rs(); - test_timeout(); - - return 0; -} +DEFINE_TEST_MAIN(LOG_DEBUG); diff --git a/src/libsystemd-network/test-sd-dhcp-lease.c b/src/libsystemd-network/test-sd-dhcp-lease.c index 9f13226889..3eea1b0d9b 100644 --- a/src/libsystemd-network/test-sd-dhcp-lease.c +++ b/src/libsystemd-network/test-sd-dhcp-lease.c @@ -6,13 +6,14 @@ #include "macro.h" #include "string-util.h" #include "strv.h" +#include "tests.h" /* According to RFC1035 section 4.1.4, a domain name in a message can be either: * - a sequence of labels ending in a zero octet * - a pointer * - a sequence of labels ending with a pointer */ -static void test_dhcp_lease_parse_search_domains_basic(void) { +TEST(dhcp_lease_parse_search_domains_basic) { int r; _cleanup_strv_free_ char **domains = NULL; static const uint8_t optionbuf[] = { @@ -26,7 +27,7 @@ static void test_dhcp_lease_parse_search_domains_basic(void) { assert_se(streq(domains[1], "ABCD.EFG")); } -static void test_dhcp_lease_parse_search_domains_ptr(void) { +TEST(dhcp_lease_parse_search_domains_ptr) { int r; _cleanup_strv_free_ char **domains = NULL; static const uint8_t optionbuf[] = { @@ -39,7 +40,7 @@ static void test_dhcp_lease_parse_search_domains_ptr(void) { assert_se(streq(domains[1], "FOO")); } -static void test_dhcp_lease_parse_search_domains_labels_and_ptr(void) { +TEST(dhcp_lease_parse_search_domains_labels_and_ptr) { int r; _cleanup_strv_free_ char **domains = NULL; static const uint8_t optionbuf[] = { @@ -55,7 +56,7 @@ static void test_dhcp_lease_parse_search_domains_labels_and_ptr(void) { /* Tests for exceptions. */ -static void test_dhcp_lease_parse_search_domains_no_data(void) { +TEST(dhcp_lease_parse_search_domains_no_data) { _cleanup_strv_free_ char **domains = NULL; static const uint8_t optionbuf[3] = {0, 0, 0}; @@ -63,7 +64,7 @@ static void test_dhcp_lease_parse_search_domains_no_data(void) { assert_se(dhcp_lease_parse_search_domains(optionbuf, 0, &domains) == -ENODATA); } -static void test_dhcp_lease_parse_search_domains_loops(void) { +TEST(dhcp_lease_parse_search_domains_loops) { _cleanup_strv_free_ char **domains = NULL; static const uint8_t optionbuf[] = { 0x03, 'F', 'O', 'O', 0x00, 0x03, 'B', 'A', 'R', 0xC0, 0x06, @@ -72,7 +73,7 @@ static void test_dhcp_lease_parse_search_domains_loops(void) { assert_se(dhcp_lease_parse_search_domains(optionbuf, sizeof(optionbuf), &domains) == -EBADMSG); } -static void test_dhcp_lease_parse_search_domains_wrong_len(void) { +TEST(dhcp_lease_parse_search_domains_wrong_len) { _cleanup_strv_free_ char **domains = NULL; static const uint8_t optionbuf[] = { 0x03, 'F', 'O', 'O', 0x03, 'B', 'A', 'R', 0x00, @@ -82,12 +83,4 @@ static void test_dhcp_lease_parse_search_domains_wrong_len(void) { assert_se(dhcp_lease_parse_search_domains(optionbuf, sizeof(optionbuf) - 5, &domains) == -EBADMSG); } -int main(int argc, char *argv[]) { - test_dhcp_lease_parse_search_domains_basic(); - test_dhcp_lease_parse_search_domains_ptr(); - test_dhcp_lease_parse_search_domains_labels_and_ptr(); - test_dhcp_lease_parse_search_domains_no_data(); - test_dhcp_lease_parse_search_domains_loops(); - test_dhcp_lease_parse_search_domains_wrong_len(); - return 0; -} +DEFINE_TEST_MAIN(LOG_INFO); |