[test] Rewrite TCP/IP tests using okx()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
d644ad41f5
commit
5c6aa56f28
@ -142,51 +142,66 @@ static uint16_t rfc_tcpip_chksum ( const void *data, size_t len ) {
|
|||||||
* Report TCP/IP fixed-data test result
|
* Report TCP/IP fixed-data test result
|
||||||
*
|
*
|
||||||
* @v test TCP/IP test
|
* @v test TCP/IP test
|
||||||
|
* @v file Test code file
|
||||||
|
* @v line Test code line
|
||||||
*/
|
*/
|
||||||
#define tcpip_ok( test ) do { \
|
static void tcpip_okx ( struct tcpip_test *test, const char *file,
|
||||||
uint16_t expected; \
|
unsigned int line ) {
|
||||||
uint16_t generic_sum; \
|
uint16_t expected;
|
||||||
uint16_t sum; \
|
uint16_t generic_sum;
|
||||||
expected = rfc_tcpip_chksum ( (test)->data, (test)->len ); \
|
uint16_t sum;
|
||||||
generic_sum = generic_tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, \
|
|
||||||
(test)->data, \
|
/* Verify generic_tcpip_continue_chksum() result */
|
||||||
(test)->len ); \
|
expected = rfc_tcpip_chksum ( test->data, test->len );
|
||||||
ok ( generic_sum == expected ); \
|
generic_sum = generic_tcpip_continue_chksum ( TCPIP_EMPTY_CSUM,
|
||||||
sum = tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, (test)->data, \
|
test->data, test->len );
|
||||||
(test)->len ); \
|
okx ( generic_sum == expected, file, line );
|
||||||
ok ( sum == expected ); \
|
|
||||||
} while ( 0 )
|
/* 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
|
* Report TCP/IP pseudorandom-data test result
|
||||||
*
|
*
|
||||||
* @v test TCP/IP test
|
* @v test TCP/IP test
|
||||||
|
* @v file Test code file
|
||||||
|
* @v line Test code line
|
||||||
*/
|
*/
|
||||||
#define tcpip_random_ok( test ) do { \
|
static void tcpip_random_okx ( struct tcpip_random_test *test,
|
||||||
uint8_t *data = ( tcpip_data + (test)->offset ); \
|
const char *file, unsigned int line ) {
|
||||||
uint16_t expected; \
|
uint8_t *data = ( tcpip_data + test->offset );
|
||||||
uint16_t generic_sum; \
|
uint16_t expected;
|
||||||
uint16_t sum; \
|
uint16_t generic_sum;
|
||||||
unsigned long elapsed; \
|
uint16_t sum;
|
||||||
unsigned int i; \
|
unsigned long elapsed;
|
||||||
assert ( ( (test)->len + (test)->offset ) <= \
|
unsigned int i;
|
||||||
sizeof ( tcpip_data ) ); \
|
|
||||||
srandom ( (test)->seed ); \
|
/* Sanity check */
|
||||||
for ( i = 0 ; i < (test)->len ; i++ ) \
|
assert ( ( test->len + test->offset ) <= sizeof ( tcpip_data ) );
|
||||||
data[i] = random(); \
|
|
||||||
expected = rfc_tcpip_chksum ( data, (test)->len ); \
|
/* Generate random data */
|
||||||
generic_sum = generic_tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, \
|
srandom ( test->seed );
|
||||||
data, \
|
for ( i = 0 ; i < test->len ; i++ )
|
||||||
(test)->len ); \
|
data[i] = random();
|
||||||
ok ( generic_sum == expected ); \
|
|
||||||
simple_profile(); \
|
/* Verify generic_tcpip_continue_chksum() result */
|
||||||
sum = tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, data, \
|
expected = rfc_tcpip_chksum ( data, test->len );
|
||||||
(test)->len ); \
|
generic_sum = generic_tcpip_continue_chksum ( TCPIP_EMPTY_CSUM,
|
||||||
elapsed = simple_profile(); \
|
data, test->len );
|
||||||
ok ( sum == expected ); \
|
okx ( generic_sum == expected, file, line );
|
||||||
DBG ( "TCPIP checksummed %zd bytes (+%zd) in %ld ticks\n", \
|
|
||||||
(test)->len, (test)->offset, elapsed ); \
|
/* Verify optimised tcpip_continue_chksum() result */
|
||||||
} while ( 0 )
|
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
|
* Perform TCP/IP self-tests
|
||||||
|
Reference in New Issue
Block a user