Fixed dhcp unit tests after changing netif up/down handling

This commit is contained in:
goldsimon 2015-03-06 07:38:51 +01:00
parent 89434f6a2f
commit 896535fe87

View File

@ -369,6 +369,7 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
case 3: case 3:
case 4: case 4:
case 5: case 5:
case 6:
{ {
const u8_t arpproto[] = { 0x08, 0x06 }; const u8_t arpproto[] = { 0x08, 0x06 };
@ -378,7 +379,7 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
check_pkt(p, 12, arpproto, sizeof(arpproto)); /* eth level proto: ip */ check_pkt(p, 12, arpproto, sizeof(arpproto)); /* eth level proto: ip */
break; break;
} }
case 6: case 7:
{ {
const u8_t fake_arp[6] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xab }; const u8_t fake_arp[6] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xab };
const u8_t ipproto[] = { 0x08, 0x00 }; const u8_t ipproto[] = { 0x08, 0x00 };
@ -434,6 +435,7 @@ START_TEST(test_dhcp)
IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&gw, 0, 0, 0, 0);
netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
netif_set_up(&net_test);
dhcp_start(&net_test); dhcp_start(&net_test);
@ -442,9 +444,6 @@ START_TEST(test_dhcp)
memcpy(&dhcp_offer[46], &xid, 4); memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
/* Interface down */
fail_if(netif_is_up(&net_test));
/* IP addresses should be zero */ /* IP addresses should be zero */
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr))); fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr))); fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));
@ -468,7 +467,7 @@ START_TEST(test_dhcp)
for (i = 0; i < 20; i++) { for (i = 0; i < 20; i++) {
tick_lwip(); tick_lwip();
} }
fail_unless(txpacket == 4, "TX %d packets, expected 4", txpacket); /* ARP requests sent */ fail_unless(txpacket == 5, "TX %d packets, expected 5", txpacket); /* ARP requests sent */
/* Interface up */ /* Interface up */
fail_unless(netif_is_up(&net_test)); fail_unless(netif_is_up(&net_test));
@ -505,6 +504,7 @@ START_TEST(test_dhcp_nak)
IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&gw, 0, 0, 0, 0);
netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
netif_set_up(&net_test);
dhcp_start(&net_test); dhcp_start(&net_test);
@ -513,9 +513,6 @@ START_TEST(test_dhcp_nak)
memcpy(&dhcp_offer[46], &xid, 4); memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
/* Interface down */
fail_if(netif_is_up(&net_test));
/* IP addresses should be zero */ /* IP addresses should be zero */
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr))); fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr))); fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));
@ -725,14 +722,12 @@ START_TEST(test_dhcp_relayed)
IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&gw, 0, 0, 0, 0);
netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
netif_set_up(&net_test);
dhcp_start(&net_test); dhcp_start(&net_test);
fail_unless(txpacket == 1); /* DHCP discover sent */ fail_unless(txpacket == 1); /* DHCP discover sent */
/* Interface down */
fail_if(netif_is_up(&net_test));
/* IP addresses should be zero */ /* IP addresses should be zero */
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr))); fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr))); fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));
@ -752,7 +747,7 @@ START_TEST(test_dhcp_relayed)
for (i = 0; i < 25; i++) { for (i = 0; i < 25; i++) {
tick_lwip(); tick_lwip();
} }
fail_unless(txpacket == 4, "txpkt should be 5, is %d", txpacket); /* ARP requests sent */ fail_unless(txpacket == 5, "txpkt should be 5, is %d", txpacket); /* ARP requests sent */
/* Interface up */ /* Interface up */
fail_unless(netif_is_up(&net_test)); fail_unless(netif_is_up(&net_test));
@ -765,20 +760,20 @@ START_TEST(test_dhcp_relayed)
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr))); fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(struct ip_addr))); fail_if(memcmp(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_unless(txpacket == 4, "txpacket = %d", txpacket); fail_unless(txpacket == 5, "txpacket = %d", txpacket);
for (i = 0; i < 108000 - 25; i++) { for (i = 0; i < 108000 - 25; i++) {
tick_lwip(); tick_lwip();
} }
fail_unless(netif_is_up(&net_test)); fail_unless(netif_is_up(&net_test));
fail_unless(txpacket == 5, "txpacket = %d", txpacket); fail_unless(txpacket == 6, "txpacket = %d", txpacket);
/* We need to send arp response here.. */ /* We need to send arp response here.. */
send_pkt(&net_test, arp_resp, sizeof(arp_resp)); send_pkt(&net_test, arp_resp, sizeof(arp_resp));
fail_unless(txpacket == 6, "txpacket = %d", txpacket); fail_unless(txpacket == 7, "txpacket = %d", txpacket);
fail_unless(netif_is_up(&net_test)); fail_unless(netif_is_up(&net_test));
xid = htonl(net_test.dhcp->xid); /* xid updated */ xid = htonl(net_test.dhcp->xid); /* xid updated */
@ -789,7 +784,7 @@ START_TEST(test_dhcp_relayed)
tick_lwip(); tick_lwip();
} }
fail_unless(txpacket == 6, "txpacket = %d", txpacket); fail_unless(txpacket == 7, "txpacket = %d", txpacket);
netif_remove(&net_test); netif_remove(&net_test);
@ -865,6 +860,7 @@ START_TEST(test_dhcp_nak_no_endmarker)
IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&gw, 0, 0, 0, 0);
netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
netif_set_up(&net_test);
dhcp_start(&net_test); dhcp_start(&net_test);
@ -873,9 +869,6 @@ START_TEST(test_dhcp_nak_no_endmarker)
memcpy(&dhcp_offer[46], &xid, 4); memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
/* Interface down */
fail_if(netif_is_up(&net_test));
/* IP addresses should be zero */ /* IP addresses should be zero */
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr))); fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr))); fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));