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
#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
// 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;
#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)
{