From 66250a13b0607f3599999a0ab70453ef1658c20f Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Mon, 29 Dec 2014 11:04:22 +0800 Subject: [PATCH] Tools/NetTest - Move common test code --- Tools/NetTest_Runner/include/test.h | 13 +++++++++++++ Tools/NetTest_Runner/test_arp.c | 15 ++++++++------- Tools/NetTest_Runner/test_tcp.c | 21 ++++++--------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Tools/NetTest_Runner/include/test.h b/Tools/NetTest_Runner/include/test.h index 6c65b42e..9ad23c35 100644 --- a/Tools/NetTest_Runner/include/test.h +++ b/Tools/NetTest_Runner/include/test.h @@ -17,5 +17,18 @@ extern void test_assertion_fail(const char *filename, int line, const char *test extern void test_trace(const char *msg, ...); extern void test_trace_hexdump(const char *hdr, const void *data, size_t len); +// Some helpful macros +// - They require some names to be present +#define RX_HEADER \ + size_t rxlen, ofs, len; \ + do { ofs = 0; ofs = ofs; len = 0; len = len; } while(0);\ + char rxbuf[MTU] +#define TEST_HEADER \ + TEST_SETNAME(__func__);\ + RX_HEADER + +#define TEST_ASSERT_rx() TEST_ASSERT( rxlen = Net_Receive(0, sizeof(rxbuf), rxbuf, ERX_TIMEOUT) ) +#define TEST_ASSERT_no_rx() TEST_ASSERT( Net_Receive(0, sizeof(rxbuf), rxbuf, NRX_TIMEOUT) == 0 ) + #endif diff --git a/Tools/NetTest_Runner/test_arp.c b/Tools/NetTest_Runner/test_arp.c index 92acc718..9c6f0444 100644 --- a/Tools/NetTest_Runner/test_arp.c +++ b/Tools/NetTest_Runner/test_arp.c @@ -6,25 +6,26 @@ #include "stack.h" #include "arp.h" +static const int ERX_TIMEOUT = 1000; // Expect RX timeout (timeout=failure) +static const int NRX_TIMEOUT = 250; // Not expect RX timeout (timeout=success) + bool Test_ARP_Basic(void) { - TEST_SETNAME(__func__); - size_t rxlen; - char rxbuf[MTU]; + TEST_HEADER; // Request test machine's IP ARP_SendRequest(0, BLOB(TEST_IP)); - TEST_ASSERT( rxlen = Net_Receive(0, sizeof(rxbuf), rxbuf, 1000) ); + TEST_ASSERT_rx(); TEST_ASSERT( ARP_Pkt_IsResponse(rxlen, rxbuf, BLOB(TEST_IP), BLOB(TEST_MAC)) ); // Request host machine's IP ARP_SendRequest(0, BLOB(HOST_IP)); - TEST_ASSERT( Net_Receive(0, sizeof(rxbuf), rxbuf, 1000) == 0 ); + TEST_ASSERT_no_rx(); #if 0 // Ask test machine to request our IP Stack_SendCommand("arprequest "HOST_IP_STR); - TEST_ASSERT( rxlen = Net_Receive(0, sizeof(rxbuf), rxbuf, 1000) ); + TEST_ASSERT_rx(); TEST_ASSERT( ARP_Pkt_IsRequest(rxlen, rxbuf, HOST_IP) ); // Respond @@ -32,7 +33,7 @@ bool Test_ARP_Basic(void) // Ask test machine to request our IP again (expecting nothing) Stack_SendCommand("arprequest "HOST_IP_STR); - TEST_ASSERT( !Net_Receive(0, sizeof(rxbuf), rxbuf, 1000) ); + TEST_ASSERT_no_rx(); #endif return true; diff --git a/Tools/NetTest_Runner/test_tcp.c b/Tools/NetTest_Runner/test_tcp.c index 10e9163a..5aef2061 100644 --- a/Tools/NetTest_Runner/test_tcp.c +++ b/Tools/NetTest_Runner/test_tcp.c @@ -15,21 +15,12 @@ #define TEST_TIMERS 0 -#define RX_HEADER \ - size_t rxlen, ofs, len; \ - char rxbuf[MTU] -#define TEST_HEADER \ - TEST_SETNAME(__func__);\ - RX_HEADER - -#define TEST_ASSERT_rx() TEST_ASSERT( rxlen = Net_Receive(0, sizeof(rxbuf), rxbuf, ERX_TIMEOUT) ) -#define TEST_ASSERT_no_rx() TEST_ASSERT( Net_Receive(0, sizeof(rxbuf), rxbuf, NRX_TIMEOUT) == 0 ) -const int ERX_TIMEOUT = 1000; // Expect RX timeout (timeout=failure) -const int NRX_TIMEOUT = 250; // Not expect RX timeout (timeout=success) -const int RETX_TIMEOUT = 1000; // OS PARAM - Retransmit timeout -const int LOST_TIMEOUT = 1000; // OS PARAM - Time before sending an ACK -const int DACK_TIMEOUT = 500; // OS PARAM - Timeout for delayed ACKs -const size_t DACK_BYTES = 4096; // OS PARAM - Threshold for delayed ACKs +static const int ERX_TIMEOUT = 1000; // Expect RX timeout (timeout=failure) +static const int NRX_TIMEOUT = 250; // Not expect RX timeout (timeout=success) +static const int RETX_TIMEOUT = 1000; // OS PARAM - Retransmit timeout +static const int LOST_TIMEOUT = 1000; // OS PARAM - Time before sending an ACK +static const int DACK_TIMEOUT = 500; // OS PARAM - Timeout for delayed ACKs +static const size_t DACK_BYTES = 4096; // OS PARAM - Threshold for delayed ACKs bool Test_TCP_Basic(void) { -- 2.20.1