1 #include "lwip_check.h"
2
3 #include "ip4/test_ip4.h"
4 #include "ip6/test_ip6.h"
5 #include "udp/test_udp.h"
6 #include "tcp/test_tcp.h"
7 #include "tcp/test_tcp_oos.h"
8 #include "core/test_def.h"
9 #include "core/test_mem.h"
10 #include "core/test_netif.h"
11 #include "core/test_pbuf.h"
12 #include "core/test_timers.h"
13 #include "etharp/test_etharp.h"
14 #include "dhcp/test_dhcp.h"
15 #include "mdns/test_mdns.h"
16 #include "mqtt/test_mqtt.h"
17 #include "api/test_sockets.h"
18
19 #include "lwip/init.h"
20 #if !NO_SYS
21 #include "lwip/tcpip.h"
22 #endif
23
create_suite(const char * name,testfunc * tests,size_t num_tests,SFun setup,SFun teardown)24 Suite* create_suite(const char* name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
25 {
26 size_t i;
27 Suite *s = suite_create(name);
28
29 for(i = 0; i < num_tests; i++) {
30 TCase *tc_core = tcase_create(name);
31 if ((setup != NULL) || (teardown != NULL)) {
32 tcase_add_checked_fixture(tc_core, setup, teardown);
33 }
34 tcase_add_named_test(tc_core, tests[i]);
35 suite_add_tcase(s, tc_core);
36 }
37 return s;
38 }
39
lwip_check_ensure_no_alloc(unsigned int skip)40 void lwip_check_ensure_no_alloc(unsigned int skip)
41 {
42 int i;
43 unsigned int mask;
44
45 if (!(skip & SKIP_HEAP)) {
46 fail_unless(lwip_stats.mem.used == 0);
47 }
48 for (i = 0, mask = 1; i < MEMP_MAX; i++, mask <<= 1) {
49 if (!(skip & mask)) {
50 fail_unless(lwip_stats.memp[i]->used == 0);
51 }
52 }
53 }
54
55 #ifdef LWIP_UNITTESTS_LIB
lwip_unittests_run(void)56 int lwip_unittests_run(void)
57 #else
58 int main(void)
59 #endif
60 {
61 int number_failed;
62 SRunner *sr;
63 size_t i;
64 suite_getter_fn* suites[] = {
65 ip4_suite,
66 ip6_suite,
67 udp_suite,
68 tcp_suite,
69 tcp_oos_suite,
70 def_suite,
71 mem_suite,
72 netif_suite,
73 pbuf_suite,
74 timers_suite,
75 etharp_suite,
76 dhcp_suite,
77 mdns_suite,
78 mqtt_suite,
79 sockets_suite
80 };
81 size_t num = sizeof(suites)/sizeof(void*);
82 LWIP_ASSERT("No suites defined", num > 0);
83
84 #if NO_SYS
85 lwip_init();
86 #else
87 tcpip_init(NULL, NULL);
88 #endif
89
90 sr = srunner_create((suites[0])());
91 srunner_set_xml(sr, "lwip_unittests.xml");
92 for(i = 1; i < num; i++) {
93 srunner_add_suite(sr, ((suite_getter_fn*)suites[i])());
94 }
95
96 #ifdef LWIP_UNITTESTS_NOFORK
97 srunner_set_fork_status(sr, CK_NOFORK);
98 #endif
99 #ifdef LWIP_UNITTESTS_FORK
100 srunner_set_fork_status(sr, CK_FORK);
101 #endif
102
103 srunner_run_all(sr, CK_NORMAL);
104 number_failed = srunner_ntests_failed(sr);
105 srunner_free(sr);
106 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
107 }
108