]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[test] Rewrite TCP/IP tests using okx()
authorMichael Brown <mcb30@ipxe.org>
Wed, 23 Apr 2014 16:21:06 +0000 (17:21 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 24 Apr 2014 12:01:33 +0000 (13:01 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/tests/tcpip_test.c

index 13423c397cf60eb6faa14aa15ac5d1770ed39f32..4ff23e3f2db9f3d383afac209c3e8974e0f006b5 100644 (file)
@@ -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