fixed unit tests after changing ip_addr_t

This commit is contained in:
goldsimon 2015-04-10 08:51:06 +02:00
parent 2e649e1843
commit cf180b651b
5 changed files with 94 additions and 87 deletions

View File

@ -420,9 +420,9 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
*/
START_TEST(test_dhcp)
{
struct ip_addr addr;
struct ip_addr netmask;
struct ip_addr gw;
ip4_addr_t addr;
ip4_addr_t netmask;
ip4_addr_t gw;
int i;
u32_t xid;
LWIP_UNUSED_ARG(_i);
@ -445,9 +445,9 @@ START_TEST(test_dhcp)
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
/* IP addresses should be zero */
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(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
fail_unless(txpacket == 1, "TX %d packets, expected 1", txpacket); /* Nothing more sent */
xid = htonl(net_test.dhcp->xid);
@ -476,9 +476,9 @@ START_TEST(test_dhcp)
IP4_ADDR(&addr, 195, 170, 189, 200);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 195, 170, 189, 171);
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(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
netif_remove(&net_test);
}
@ -490,9 +490,9 @@ END_TEST
*/
START_TEST(test_dhcp_nak)
{
struct ip_addr addr;
struct ip_addr netmask;
struct ip_addr gw;
ip4_addr_t addr;
ip4_addr_t netmask;
ip4_addr_t gw;
u32_t xid;
LWIP_UNUSED_ARG(_i);
@ -514,9 +514,9 @@ START_TEST(test_dhcp_nak)
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
/* IP addresses should be zero */
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(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
fail_unless(txpacket == 1); /* Nothing more sent */
xid = htonl(net_test.dhcp->xid);
@ -707,9 +707,9 @@ START_TEST(test_dhcp_relayed)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
struct ip_addr addr;
struct ip_addr netmask;
struct ip_addr gw;
ip4_addr_t addr;
ip4_addr_t netmask;
ip4_addr_t gw;
int i;
u32_t xid;
LWIP_UNUSED_ARG(_i);
@ -729,9 +729,9 @@ START_TEST(test_dhcp_relayed)
fail_unless(txpacket == 1); /* DHCP discover sent */
/* IP addresses should be zero */
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(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
fail_unless(txpacket == 1); /* Nothing more sent */
xid = htonl(net_test.dhcp->xid);
@ -756,9 +756,9 @@ START_TEST(test_dhcp_relayed)
IP4_ADDR(&addr, 79, 138, 51, 5);
IP4_ADDR(&netmask, 255, 255, 254, 0);
IP4_ADDR(&gw, 79, 138, 50, 1);
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(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
fail_unless(txpacket == 5, "txpacket = %d", txpacket);
@ -793,9 +793,9 @@ END_TEST
START_TEST(test_dhcp_nak_no_endmarker)
{
struct ip_addr addr;
struct ip_addr netmask;
struct ip_addr gw;
ip4_addr_t addr;
ip4_addr_t netmask;
ip4_addr_t gw;
u8_t dhcp_nack_no_endmarker[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x54, 0x75,
@ -870,9 +870,9 @@ START_TEST(test_dhcp_nak_no_endmarker)
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
/* IP addresses should be zero */
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(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
fail_unless(txpacket == 1); /* Nothing more sent */
xid = htonl(net_test.dhcp->xid);

View File

@ -12,7 +12,7 @@
#endif
static struct netif test_netif;
static ip_addr_t test_ipaddr, test_netmask, test_gw;
static ip4_addr_t test_ipaddr, test_netmask, test_gw;
struct eth_addr test_ethaddr = {1,1,1,1,1,1};
struct eth_addr test_ethaddr2 = {1,1,1,1,1,2};
struct eth_addr test_ethaddr3 = {1,1,1,1,1,3};
@ -72,7 +72,7 @@ default_netif_remove(void)
}
static void
create_arp_response(ip_addr_t *adr)
create_arp_response(ip4_addr_t *adr)
{
int k;
struct eth_hdr *ethhdr;
@ -91,11 +91,11 @@ create_arp_response(ip_addr_t *adr)
etharphdr->hwtype = htons(/*HWTYPE_ETHERNET*/ 1);
etharphdr->proto = htons(ETHTYPE_IP);
etharphdr->hwlen = ETHARP_HWADDR_LEN;
etharphdr->protolen = sizeof(ip_addr_t);
etharphdr->protolen = sizeof(ip4_addr_t);
etharphdr->opcode = htons(ARP_REPLY);
SMEMCPY(&etharphdr->sipaddr, adr, sizeof(ip_addr_t));
SMEMCPY(&etharphdr->dipaddr, &test_ipaddr, sizeof(ip_addr_t));
SMEMCPY(&etharphdr->sipaddr, adr, sizeof(ip4_addr_t));
SMEMCPY(&etharphdr->dipaddr, &test_ipaddr, sizeof(ip4_addr_t));
k = 6;
while(k > 0) {
@ -136,7 +136,7 @@ START_TEST(test_etharp_table)
err_t err;
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
s8_t idx;
ip_addr_t *unused_ipaddr;
ip4_addr_t *unused_ipaddr;
struct eth_addr *unused_ethaddr;
struct udp_pcb* pcb;
LWIP_UNUSED_ARG(_i);
@ -150,7 +150,7 @@ START_TEST(test_etharp_table)
pcb = udp_new();
fail_unless(pcb != NULL);
if (pcb != NULL) {
ip_addr_t adrs[ARP_TABLE_SIZE + 2];
ip4_addr_t adrs[ARP_TABLE_SIZE + 2];
int i;
for(i = 0; i < ARP_TABLE_SIZE + 2; i++) {
IP4_ADDR(&adrs[i], 192,168,0,i+2);
@ -160,7 +160,10 @@ START_TEST(test_etharp_table)
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 10, PBUF_RAM);
fail_unless(p != NULL);
if (p != NULL) {
err_t err = udp_sendto(pcb, p, &adrs[i], 123);
err_t err;
ip_addr_t dst;
ip_addr_copy_from_ip4(dst, adrs[i]);
err = udp_sendto(pcb, p, &dst, 123);
fail_unless(err == ERR_OK);
/* etharp request sent? */
fail_unless(linkoutput_ctr == (2*i) + 1);
@ -192,7 +195,10 @@ START_TEST(test_etharp_table)
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 10, PBUF_RAM);
fail_unless(p != NULL);
if (p != NULL) {
err_t err = udp_sendto(pcb, p, &adrs[i], 123);
err_t err;
ip_addr_t dst;
ip_addr_copy_from_ip4(dst, adrs[i]);
err = udp_sendto(pcb, p, &dst, 123);
fail_unless(err == ERR_OK);
/* etharp request sent? */
fail_unless(linkoutput_ctr == (2*i) + 1);

View File

@ -4,6 +4,7 @@
#include "lwip/stats.h"
#include "lwip/pbuf.h"
#include "lwip/inet_chksum.h"
#include "lwip/ip_addr.h"
#if !LWIP_STATS || !TCP_STATS || !MEMP_STATS
#error "This tests needs TCP- and MEMP-statistics enabled"
@ -62,8 +63,8 @@ tcp_create_segment_wnd(ip_addr_t* src_ip, ip_addr_t* dst_ip,
iphdr = p->payload;
/* fill IP header */
iphdr->dest.addr = dst_ip->addr;
iphdr->src.addr = src_ip->addr;
iphdr->dest.addr = ip_2_ip4(dst_ip)->addr;
iphdr->src.addr = ip_2_ip4(src_ip)->addr;
IPH_VHL_SET(iphdr, 4, IP_HLEN / 4);
IPH_TOS_SET(iphdr, 0);
IPH_LEN_SET(iphdr, htons(p->tot_len));
@ -92,7 +93,7 @@ tcp_create_segment_wnd(ip_addr_t* src_ip, ip_addr_t* dst_ip,
/* calculate checksum */
tcphdr->chksum = inet_chksum_pseudo(p,
tcphdr->chksum = ip_chksum_pseudo(p,
IP_PROTO_TCP, p->tot_len, src_ip, dst_ip);
pbuf_header(p, sizeof(struct ip_hdr));
@ -239,24 +240,24 @@ void test_tcp_input(struct pbuf *p, struct netif *inp)
{
struct ip_hdr *iphdr = (struct ip_hdr*)p->payload;
/* these lines are a hack, don't use them as an example :-) */
ip_addr_copy(*ipX_current_dest_addr(), iphdr->dest);
ip_addr_copy(*ipX_current_src_addr(), iphdr->src);
ip_addr_copy_from_ip4(*ip_current_dest_addr(), iphdr->dest);
ip_addr_copy_from_ip4(*ip_current_src_addr(), iphdr->src);
ip_current_netif() = inp;
ip_current_header() = iphdr;
ip4_current_header() = iphdr;
/* since adding IPv6, p->payload must point to tcp header, not ip header */
pbuf_header(p, -(s16_t)sizeof(struct ip_hdr));
tcp_input(p, inp);
ipX_current_dest_addr()->addr = 0;
ipX_current_src_addr()->addr = 0;
ip_addr_set_zero(ip_current_dest_addr());
ip_addr_set_zero(ip_current_src_addr());
ip_current_netif() = NULL;
ip_current_header() = NULL;
ip4_current_header() = NULL;
}
static err_t test_tcp_netif_output(struct netif *netif, struct pbuf *p,
const ip_addr_t *ipaddr)
const ip4_addr_t *ipaddr)
{
struct test_tcp_txcounters *txcounters = (struct test_tcp_txcounters*)netif->state;
LWIP_UNUSED_ARG(ipaddr);
@ -291,8 +292,8 @@ void test_tcp_init_netif(struct netif *netif, struct test_tcp_txcounters *txcoun
}
netif->output = test_tcp_netif_output;
netif->flags |= NETIF_FLAG_UP | NETIF_FLAG_LINK_UP;
ip_addr_copy(netif->netmask, *netmask);
ip_addr_copy(netif->ip_addr, *ip_addr);
ip4_addr_copy(netif->netmask, *ip_2_ip4(netmask));
ip4_addr_copy(netif->ip_addr, *ip_2_ip4(ip_addr));
for (n = netif_list; n != NULL; n = n->next) {
if (n == netif) {
return;

View File

@ -87,9 +87,9 @@ START_TEST(test_tcp_recv_inseq)
/* initialize local vars */
memset(&netif, 0, sizeof(netif));
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, &txcounters, &local_ip, &netmask);
data_len = sizeof(data);
/* initialize counter struct */
@ -143,9 +143,9 @@ START_TEST(test_tcp_fast_retx_recover)
LWIP_UNUSED_ARG(_i);
/* initialize local vars */
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, &txcounters, &local_ip, &netmask);
memset(&counters, 0, sizeof(counters));
@ -338,9 +338,9 @@ START_TEST(test_tcp_fast_rexmit_wraparound)
}
/* initialize local vars */
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, &txcounters, &local_ip, &netmask);
memset(&counters, 0, sizeof(counters));
@ -435,9 +435,9 @@ START_TEST(test_tcp_rto_rexmit_wraparound)
}
/* initialize local vars */
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, &txcounters, &local_ip, &netmask);
memset(&counters, 0, sizeof(counters));
@ -525,9 +525,9 @@ static void test_tcp_tx_full_window_lost(u8_t zero_window_probe_from_unsent)
}
/* initialize local vars */
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, &txcounters, &local_ip, &netmask);
memset(&counters, 0, sizeof(counters));
memset(&txcounters, 0, sizeof(txcounters));

View File

@ -156,9 +156,9 @@ START_TEST(test_tcp_recv_ooseq_FIN_OOSEQ)
/* initialize local vars */
memset(&netif, 0, sizeof(netif));
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
data_len = sizeof(data);
/* initialize counter struct */
@ -298,9 +298,9 @@ START_TEST(test_tcp_recv_ooseq_FIN_INSEQ)
/* initialize local vars */
memset(&netif, 0, sizeof(netif));
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
data_len = sizeof(data);
/* initialize counter struct */
@ -475,9 +475,9 @@ START_TEST(test_tcp_recv_ooseq_overrun_rxwin)
/* initialize local vars */
memset(&netif, 0, sizeof(netif));
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
/* initialize counter struct */
memset(&counters, 0, sizeof(counters));
@ -568,9 +568,9 @@ START_TEST(test_tcp_recv_ooseq_overrun_rxwin_edge)
/* initialize local vars */
memset(&netif, 0, sizeof(netif));
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
/* initialize counter struct */
memset(&counters, 0, sizeof(counters));
@ -660,9 +660,9 @@ START_TEST(test_tcp_recv_ooseq_max_bytes)
/* initialize local vars */
memset(&netif, 0, sizeof(netif));
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
/* initialize counter struct */
memset(&counters, 0, sizeof(counters));
@ -741,9 +741,9 @@ START_TEST(test_tcp_recv_ooseq_max_pbufs)
/* initialize local vars */
memset(&netif, 0, sizeof(netif));
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
/* initialize counter struct */
memset(&counters, 0, sizeof(counters));
@ -845,9 +845,9 @@ static void test_tcp_recv_ooseq_double_FINs(int delay_packet)
/* initialize local vars */
memset(&netif, 0, sizeof(netif));
IP4_ADDR(&local_ip, 192, 168, 1, 1);
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP_ADDR4(&local_ip, 192, 168, 1, 1);
IP_ADDR4(&remote_ip, 192, 168, 1, 2);
IP_ADDR4(&netmask, 255, 255, 255, 0);
test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
/* initialize counter struct */
memset(&counters, 0, sizeof(counters));