summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2014-04-23 18:21:06 +0200
committerMichael Brown2014-04-24 14:01:33 +0200
commit5c6aa56f28d45a34521a9fc357236a9b4d81d04d (patch)
treea9b2f77682e2a1c28fbf3e4981e868347bb878c7
parent[serial] Enable UART FIFOs (diff)
downloadipxe-5c6aa56f28d45a34521a9fc357236a9b4d81d04d.tar.gz
ipxe-5c6aa56f28d45a34521a9fc357236a9b4d81d04d.tar.xz
ipxe-5c6aa56f28d45a34521a9fc357236a9b4d81d04d.zip
[test] Rewrite TCP/IP tests using okx()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/tests/tcpip_test.c91
1 files changed, 53 insertions, 38 deletions
diff --git a/src/tests/tcpip_test.c b/src/tests/tcpip_test.c
index 13423c39..4ff23e3f 100644
--- a/src/tests/tcpip_test.c
+++ b/src/tests/tcpip_test.c
@@ -142,51 +142,66 @@ static uint16_t rfc_tcpip_chksum ( const void *data, size_t len ) {
* Report TCP/IP fixed-data test result
*
* @v test TCP/IP test
+ * @v file Test code file
+ * @v line Test code line
*/
-#define tcpip_ok( test ) do { \
- uint16_t expected; \
- uint16_t generic_sum; \
- uint16_t sum; \
- expected = rfc_tcpip_chksum ( (test)->data, (test)->len ); \
- generic_sum = generic_tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, \
- (test)->data, \
- (test)->len ); \
- ok ( generic_sum == expected ); \
- sum = tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, (test)->data, \
- (test)->len ); \
- ok ( sum == expected ); \
- } while ( 0 )
+static void tcpip_okx ( struct tcpip_test *test, const char *file,
+ unsigned int line ) {
+ uint16_t expected;
+ uint16_t generic_sum;
+ uint16_t sum;
+
+ /* Verify generic_tcpip_continue_chksum() result */
+ expected = rfc_tcpip_chksum ( test->data, test->len );
+ generic_sum = generic_tcpip_continue_chksum ( TCPIP_EMPTY_CSUM,
+ test->data, test->len );
+ okx ( generic_sum == expected, file, line );
+
+ /* Verify optimised tcpip_continue_chksum() result */
+ sum = tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, test->data, test->len );
+ okx ( sum == expected, file, line );
+}
+#define tcpip_ok( test ) tcpip_okx ( test, __FILE__, __LINE__ )
/**
* Report TCP/IP pseudorandom-data test result
*
* @v test TCP/IP test
+ * @v file Test code file
+ * @v line Test code line
*/
-#define tcpip_random_ok( test ) do { \
- uint8_t *data = ( tcpip_data + (test)->offset ); \
- uint16_t expected; \
- uint16_t generic_sum; \
- uint16_t sum; \
- unsigned long elapsed; \
- unsigned int i; \
- assert ( ( (test)->len + (test)->offset ) <= \
- sizeof ( tcpip_data ) ); \
- srandom ( (test)->seed ); \
- for ( i = 0 ; i < (test)->len ; i++ ) \
- data[i] = random(); \
- expected = rfc_tcpip_chksum ( data, (test)->len ); \
- generic_sum = generic_tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, \
- data, \
- (test)->len ); \
- ok ( generic_sum == expected ); \
- simple_profile(); \
- sum = tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, data, \
- (test)->len ); \
- elapsed = simple_profile(); \
- ok ( sum == expected ); \
- DBG ( "TCPIP checksummed %zd bytes (+%zd) in %ld ticks\n", \
- (test)->len, (test)->offset, elapsed ); \
- } while ( 0 )
+static void tcpip_random_okx ( struct tcpip_random_test *test,
+ const char *file, unsigned int line ) {
+ uint8_t *data = ( tcpip_data + test->offset );
+ uint16_t expected;
+ uint16_t generic_sum;
+ uint16_t sum;
+ unsigned long elapsed;
+ unsigned int i;
+
+ /* Sanity check */
+ assert ( ( test->len + test->offset ) <= sizeof ( tcpip_data ) );
+
+ /* Generate random data */
+ srandom ( test->seed );
+ for ( i = 0 ; i < test->len ; i++ )
+ data[i] = random();
+
+ /* Verify generic_tcpip_continue_chksum() result */
+ expected = rfc_tcpip_chksum ( data, test->len );
+ generic_sum = generic_tcpip_continue_chksum ( TCPIP_EMPTY_CSUM,
+ data, test->len );
+ okx ( generic_sum == expected, file, line );
+
+ /* Verify optimised tcpip_continue_chksum() result */
+ simple_profile();
+ sum = tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, data, test->len );
+ elapsed = simple_profile();
+ okx ( sum == expected, file, line );
+ DBG ( "TCPIP checksummed %zd bytes (+%zd) in %ld ticks\n",
+ test->len, test->offset, elapsed );
+}
+#define tcpip_random_ok( test ) tcpip_random_okx ( test, __FILE__, __LINE__ )
/**
* Perform TCP/IP self-tests