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 "tcp/test_tcp_state.h"
9 #include "core/test_def.h"
10 #include "core/test_dns.h"
11 #include "core/test_mem.h"
12 #include "core/test_netif.h"
13 #include "core/test_pbuf.h"
14 #include "core/test_timers.h"
15 #include "etharp/test_etharp.h"
16 #include "dhcp/test_dhcp.h"
17 #include "mdns/test_mdns.h"
18 #include "mqtt/test_mqtt.h"
19 #include "api/test_sockets.h"
20 #include "ppp/test_pppos.h"
21 
22 #include "lwip/init.h"
23 #if !NO_SYS
24 #include "lwip/tcpip.h"
25 #endif
26 
27 /* This function is used for LWIP_RAND by some ports... */
28 unsigned int
lwip_port_rand(void)29 lwip_port_rand(void)
30 {
31   return (unsigned int)rand();
32 }
33 
create_suite(const char * name,testfunc * tests,size_t num_tests,SFun setup,SFun teardown)34 Suite* create_suite(const char* name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
35 {
36   size_t i;
37   Suite *s = suite_create(name);
38 
39   for(i = 0; i < num_tests; i++) {
40     TCase *tc_core = tcase_create(name);
41     if ((setup != NULL) || (teardown != NULL)) {
42       tcase_add_checked_fixture(tc_core, setup, teardown);
43     }
44     tcase_add_named_test(tc_core, tests[i]);
45     suite_add_tcase(s, tc_core);
46   }
47   return s;
48 }
49 
lwip_check_ensure_no_alloc(unsigned int skip)50 void lwip_check_ensure_no_alloc(unsigned int skip)
51 {
52   int i;
53   unsigned int mask;
54 
55   if (!(skip & SKIP_HEAP)) {
56     fail_unless(lwip_stats.mem.used == 0,
57       "mem heap still has %d bytes allocated", lwip_stats.mem.used);
58   }
59   for (i = 0, mask = 1; i < MEMP_MAX; i++, mask <<= 1) {
60     if (!(skip & mask)) {
61       fail_unless(lwip_stats.memp[i]->used == 0,
62         "memp pool '%s' still has %d entries allocated",
63         lwip_stats.memp[i]->name, lwip_stats.memp[i]->used);
64     }
65   }
66 }
67 
68 #ifdef LWIP_UNITTESTS_LIB
lwip_unittests_run(void)69 int lwip_unittests_run(void)
70 #else
71 int main(void)
72 #endif
73 {
74   int number_failed;
75   SRunner *sr;
76   size_t i;
77   suite_getter_fn* suites[] = {
78     ip4_suite,
79     ip6_suite,
80     udp_suite,
81     tcp_suite,
82     tcp_oos_suite,
83     tcp_state_suite,
84     def_suite,
85     dns_suite,
86     mem_suite,
87     netif_suite,
88     pbuf_suite,
89     timers_suite,
90     etharp_suite,
91     dhcp_suite,
92     mdns_suite,
93     mqtt_suite,
94     sockets_suite
95 #if PPP_SUPPORT && PPPOS_SUPPORT
96     , pppos_suite
97 #endif /* PPP_SUPPORT && PPPOS_SUPPORT */
98   };
99   size_t num = sizeof(suites)/sizeof(void*);
100   LWIP_ASSERT("No suites defined", num > 0);
101 
102 #if NO_SYS
103   lwip_init();
104 #else
105   tcpip_init(NULL, NULL);
106 #endif
107 
108   sr = srunner_create((suites[0])());
109   srunner_set_xml(sr, "lwip_unittests.xml");
110   for(i = 1; i < num; i++) {
111     srunner_add_suite(sr, ((suite_getter_fn*)suites[i])());
112   }
113 
114 #ifdef LWIP_UNITTESTS_NOFORK
115   srunner_set_fork_status(sr, CK_NOFORK);
116 #endif
117 #ifdef LWIP_UNITTESTS_FORK
118   srunner_set_fork_status(sr, CK_FORK);
119 #endif
120 
121   srunner_run_all(sr, CK_NORMAL);
122   number_failed = srunner_ntests_failed(sr);
123   srunner_free(sr);
124   return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
125 }
126