From a80c4d147cc0caa25c61675b972ab617511ae96f Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Wed, 12 Feb 2014 21:52:21 +0100 Subject: [PATCH] Unit test patch by Erik Ekman: use macro to store correct testcase name --- test/unit/core/test_mem.c | 6 ++--- test/unit/core/test_pbuf.c | 10 ++++---- test/unit/dhcp/test_dhcp.c | 12 ++++----- test/unit/etharp/test_etharp.c | 6 ++--- test/unit/lwip_check.h | 18 ++++++++++--- test/unit/tcp/test_tcp.c | 18 ++++++------- test/unit/tcp/test_tcp_oos.c | 46 +++++++++++++++++----------------- test/unit/udp/test_udp.c | 6 ++--- 8 files changed, 66 insertions(+), 56 deletions(-) diff --git a/test/unit/core/test_mem.c b/test/unit/core/test_mem.c index d3a5d540..af7276d0 100644 --- a/test/unit/core/test_mem.c +++ b/test/unit/core/test_mem.c @@ -66,8 +66,8 @@ END_TEST Suite * mem_suite(void) { - TFun tests[] = { - test_mem_one + testfunc tests[] = { + TESTFUNC(test_mem_one) }; - return create_suite("MEM", tests, sizeof(tests)/sizeof(TFun), mem_setup, mem_teardown); + return create_suite("MEM", tests, sizeof(tests)/sizeof(testfunc), mem_setup, mem_teardown); } diff --git a/test/unit/core/test_pbuf.c b/test/unit/core/test_pbuf.c index 2cb2a516..211465ec 100644 --- a/test/unit/core/test_pbuf.c +++ b/test/unit/core/test_pbuf.c @@ -143,10 +143,10 @@ END_TEST Suite * pbuf_suite(void) { - TFun tests[] = { - test_pbuf_copy_zero_pbuf, - test_pbuf_split_64k_on_small_pbufs, - test_pbuf_queueing_bigger_than_64k + testfunc tests[] = { + TESTFUNC(test_pbuf_copy_zero_pbuf), + TESTFUNC(test_pbuf_split_64k_on_small_pbufs), + TESTFUNC(test_pbuf_queueing_bigger_than_64k) }; - return create_suite("PBUF", tests, sizeof(tests)/sizeof(TFun), pbuf_setup, pbuf_teardown); + return create_suite("PBUF", tests, sizeof(tests)/sizeof(testfunc), pbuf_setup, pbuf_teardown); } diff --git a/test/unit/dhcp/test_dhcp.c b/test/unit/dhcp/test_dhcp.c index 8addfa14..0055b492 100644 --- a/test/unit/dhcp/test_dhcp.c +++ b/test/unit/dhcp/test_dhcp.c @@ -906,11 +906,11 @@ END_TEST Suite * dhcp_suite(void) { - TFun tests[] = { - test_dhcp, - test_dhcp_nak, - test_dhcp_relayed, - test_dhcp_nak_no_endmarker + testfunc tests[] = { + TESTFUNC(test_dhcp), + TESTFUNC(test_dhcp_nak), + TESTFUNC(test_dhcp_relayed), + TESTFUNC(test_dhcp_nak_no_endmarker) }; - return create_suite("DHCP", tests, sizeof(tests)/sizeof(TFun), dhcp_setup, dhcp_teardown); + return create_suite("DHCP", tests, sizeof(tests)/sizeof(testfunc), dhcp_setup, dhcp_teardown); } diff --git a/test/unit/etharp/test_etharp.c b/test/unit/etharp/test_etharp.c index cbbc9502..9c21a4b4 100644 --- a/test/unit/etharp/test_etharp.c +++ b/test/unit/etharp/test_etharp.c @@ -255,8 +255,8 @@ END_TEST Suite * etharp_suite(void) { - TFun tests[] = { - test_etharp_table + testfunc tests[] = { + TESTFUNC(test_etharp_table) }; - return create_suite("ETHARP", tests, sizeof(tests)/sizeof(TFun), etharp_setup, etharp_teardown); + return create_suite("ETHARP", tests, sizeof(tests)/sizeof(testfunc), etharp_setup, etharp_teardown); } diff --git a/test/unit/lwip_check.h b/test/unit/lwip_check.h index e27f55ae..09f8cfe9 100644 --- a/test/unit/lwip_check.h +++ b/test/unit/lwip_check.h @@ -13,22 +13,32 @@ #define EXPECT_RETX(x, y) do { fail_unless(x); if(!(x)) { return y; }} while(0) #define EXPECT_RETNULL(x) EXPECT_RETX(x, NULL) +typedef struct { + TFun func; + const char *name; +} testfunc; + +#define TESTFUNC(x) {(x), "" # x "" } + +/* Modified function from check.h, supplying function name */ +#define tcase_add_named_test(tc,tf) \ + _tcase_add_test((tc),(tf).func,(tf).name,0, 0, 0, 1) + /** typedef for a function returning a test suite */ typedef Suite* (suite_getter_fn)(void); /** Create a test suite */ -static Suite* create_suite(const char* name, TFun *tests, size_t num_tests, SFun setup, SFun teardown) +static Suite* create_suite(const char* name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown) { size_t i; Suite *s = suite_create(name); for(i = 0; i < num_tests; i++) { - /* Core test case */ - TCase *tc_core = tcase_create("Core"); + TCase *tc_core = tcase_create(name); if ((setup != NULL) || (teardown != NULL)) { tcase_add_checked_fixture(tc_core, setup, teardown); } - tcase_add_test(tc_core, tests[i]); + tcase_add_named_test(tc_core, tests[i]); suite_add_tcase(s, tc_core); } return s; diff --git a/test/unit/tcp/test_tcp.c b/test/unit/tcp/test_tcp.c index 81720984..9982ef45 100644 --- a/test/unit/tcp/test_tcp.c +++ b/test/unit/tcp/test_tcp.c @@ -658,14 +658,14 @@ END_TEST Suite * tcp_suite(void) { - TFun tests[] = { - test_tcp_new_abort, - test_tcp_recv_inseq, - test_tcp_fast_retx_recover, - test_tcp_fast_rexmit_wraparound, - test_tcp_rto_rexmit_wraparound, - test_tcp_tx_full_window_lost_from_unacked, - test_tcp_tx_full_window_lost_from_unsent + testfunc tests[] = { + TESTFUNC(test_tcp_new_abort), + TESTFUNC(test_tcp_recv_inseq), + TESTFUNC(test_tcp_fast_retx_recover), + TESTFUNC(test_tcp_fast_rexmit_wraparound), + TESTFUNC(test_tcp_rto_rexmit_wraparound), + TESTFUNC(test_tcp_tx_full_window_lost_from_unacked), + TESTFUNC(test_tcp_tx_full_window_lost_from_unsent) }; - return create_suite("TCP", tests, sizeof(tests)/sizeof(TFun), tcp_setup, tcp_teardown); + return create_suite("TCP", tests, sizeof(tests)/sizeof(testfunc), tcp_setup, tcp_teardown); } diff --git a/test/unit/tcp/test_tcp_oos.c b/test/unit/tcp/test_tcp_oos.c index 612c4680..59d2514b 100644 --- a/test/unit/tcp/test_tcp_oos.c +++ b/test/unit/tcp/test_tcp_oos.c @@ -931,28 +931,28 @@ FIN_TEST(test_tcp_recv_ooseq_double_FIN_15, 15) Suite * tcp_oos_suite(void) { - TFun tests[] = { - test_tcp_recv_ooseq_FIN_OOSEQ, - test_tcp_recv_ooseq_FIN_INSEQ, - test_tcp_recv_ooseq_overrun_rxwin, - test_tcp_recv_ooseq_max_bytes, - test_tcp_recv_ooseq_max_pbufs, - test_tcp_recv_ooseq_double_FIN_0, - test_tcp_recv_ooseq_double_FIN_1, - test_tcp_recv_ooseq_double_FIN_2, - test_tcp_recv_ooseq_double_FIN_3, - test_tcp_recv_ooseq_double_FIN_4, - test_tcp_recv_ooseq_double_FIN_5, - test_tcp_recv_ooseq_double_FIN_6, - test_tcp_recv_ooseq_double_FIN_7, - test_tcp_recv_ooseq_double_FIN_8, - test_tcp_recv_ooseq_double_FIN_9, - test_tcp_recv_ooseq_double_FIN_10, - test_tcp_recv_ooseq_double_FIN_11, - test_tcp_recv_ooseq_double_FIN_12, - test_tcp_recv_ooseq_double_FIN_13, - test_tcp_recv_ooseq_double_FIN_14, - test_tcp_recv_ooseq_double_FIN_15 + testfunc tests[] = { + TESTFUNC(test_tcp_recv_ooseq_FIN_OOSEQ), + TESTFUNC(test_tcp_recv_ooseq_FIN_INSEQ), + TESTFUNC(test_tcp_recv_ooseq_overrun_rxwin), + TESTFUNC(test_tcp_recv_ooseq_max_bytes), + TESTFUNC(test_tcp_recv_ooseq_max_pbufs), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_0), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_1), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_2), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_3), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_4), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_5), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_6), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_7), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_8), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_9), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_10), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_11), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_12), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_13), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_14), + TESTFUNC(test_tcp_recv_ooseq_double_FIN_15) }; - return create_suite("TCP_OOS", tests, sizeof(tests)/sizeof(TFun), tcp_oos_setup, tcp_oos_teardown); + return create_suite("TCP_OOS", tests, sizeof(tests)/sizeof(testfunc), tcp_oos_setup, tcp_oos_teardown); } diff --git a/test/unit/udp/test_udp.c b/test/unit/udp/test_udp.c index a2f02af0..7de97851 100644 --- a/test/unit/udp/test_udp.c +++ b/test/unit/udp/test_udp.c @@ -61,8 +61,8 @@ END_TEST Suite * udp_suite(void) { - TFun tests[] = { - test_udp_new_remove, + testfunc tests[] = { + TESTFUNC(test_udp_new_remove), }; - return create_suite("UDP", tests, sizeof(tests)/sizeof(TFun), udp_setup, udp_teardown); + return create_suite("UDP", tests, sizeof(tests)/sizeof(testfunc), udp_setup, udp_teardown); }