diff --git a/Tools/NetTest_Runner/include/test.h b/Tools/NetTest_Runner/include/test.h index 6c65b42e08df234f56563a42cdd17309cdca89e9..9ad23c35cce0e3699962d978e69a9935b3d9e904 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 92acc718e4f66b77ee156e185cec294c90bbc9b7..9c6f04447eb6c32db5f268e035d68a29ef14e720 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 10e9163a611a3fb0d70d8c8087de89a8e078a15d..5aef206149e849fcc7f7b530ebea6a937ff7c6d4 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) {