Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/unit: Fix DHCP tests #53

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions test/unit/dhcp/test_dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ static void tick_lwip(void)
}
}

static u32_t get_bad_xid(const struct netif *netif)
{
return ~netif_dhcp_data(netif)->xid;
}

static void send_pkt(struct netif *netif, const u8_t *data, size_t len)
{
struct pbuf *p, *q;
Expand Down Expand Up @@ -493,7 +498,7 @@ START_TEST(test_dhcp)
dhcp_start(&net_test);

fail_unless(txpacket == 1); /* DHCP discover sent */
xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */
xid = get_bad_xid(&net_test);
memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));

Expand All @@ -508,7 +513,7 @@ START_TEST(test_dhcp)
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));

fail_unless(txpacket == 2, "TX %d packets, expected 2", txpacket); /* DHCP request sent */
xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */
xid = get_bad_xid(&net_test);
memcpy(&dhcp_ack[46], &xid, 4);
send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack));

Expand Down Expand Up @@ -568,7 +573,7 @@ START_TEST(test_dhcp_nak)
dhcp_start(&net_test);

fail_unless(txpacket == 1); /* DHCP discover sent */
xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */
xid = get_bad_xid(&net_test);
memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));

Expand All @@ -583,7 +588,7 @@ START_TEST(test_dhcp_nak)
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));

fail_unless(txpacket == 2); /* DHCP request sent */
xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */
xid = get_bad_xid(&net_test);
memcpy(&dhcp_ack[46], &xid, 4);
send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack));

Expand Down Expand Up @@ -941,7 +946,7 @@ START_TEST(test_dhcp_nak_no_endmarker)
dhcp = netif_dhcp_data(&net_test);

fail_unless(txpacket == 1); /* DHCP discover sent */
xid = dhcp->xid; /* Write bad xid, not using htonl! */
xid = get_bad_xid(&net_test);
memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));

Expand Down
Loading