2009-11-27 08:03:53 +00:00
|
|
|
#include "lwip_check.h"
|
|
|
|
|
2017-08-02 19:11:53 +00:00
|
|
|
#include "ip4/test_ip4.h"
|
2018-06-08 20:18:50 +00:00
|
|
|
#include "ip6/test_ip6.h"
|
2009-11-27 08:03:53 +00:00
|
|
|
#include "udp/test_udp.h"
|
|
|
|
#include "tcp/test_tcp.h"
|
|
|
|
#include "tcp/test_tcp_oos.h"
|
2017-12-23 19:35:18 +00:00
|
|
|
#include "core/test_def.h"
|
2020-07-04 16:31:36 +00:00
|
|
|
#include "core/test_dns.h"
|
2010-01-18 17:45:41 +00:00
|
|
|
#include "core/test_mem.h"
|
2018-01-12 21:27:15 +00:00
|
|
|
#include "core/test_netif.h"
|
2012-05-03 18:11:23 +00:00
|
|
|
#include "core/test_pbuf.h"
|
2018-01-04 12:37:05 +00:00
|
|
|
#include "core/test_timers.h"
|
2010-03-20 11:45:25 +00:00
|
|
|
#include "etharp/test_etharp.h"
|
2012-03-22 09:52:05 +00:00
|
|
|
#include "dhcp/test_dhcp.h"
|
2016-08-14 13:02:15 +00:00
|
|
|
#include "mdns/test_mdns.h"
|
2017-04-12 19:54:42 +00:00
|
|
|
#include "mqtt/test_mqtt.h"
|
2017-03-16 20:52:30 +00:00
|
|
|
#include "api/test_sockets.h"
|
2009-11-27 08:03:53 +00:00
|
|
|
|
|
|
|
#include "lwip/init.h"
|
2017-03-17 08:05:36 +00:00
|
|
|
#if !NO_SYS
|
|
|
|
#include "lwip/tcpip.h"
|
|
|
|
#endif
|
2009-11-27 08:03:53 +00:00
|
|
|
|
2019-01-30 13:53:41 +00:00
|
|
|
/* This function is used for LWIP_RAND by some ports... */
|
|
|
|
unsigned int
|
|
|
|
lwip_port_rand(void)
|
|
|
|
{
|
2021-11-22 07:41:03 +00:00
|
|
|
return (unsigned int)rand();
|
2019-01-30 13:53:41 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 19:15:41 +00:00
|
|
|
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++) {
|
|
|
|
TCase *tc_core = tcase_create(name);
|
|
|
|
if ((setup != NULL) || (teardown != NULL)) {
|
|
|
|
tcase_add_checked_fixture(tc_core, setup, teardown);
|
|
|
|
}
|
|
|
|
tcase_add_named_test(tc_core, tests[i]);
|
|
|
|
suite_add_tcase(s, tc_core);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
2009-11-27 08:03:53 +00:00
|
|
|
|
2017-08-04 04:17:21 +00:00
|
|
|
void lwip_check_ensure_no_alloc(unsigned int skip)
|
2017-08-03 20:25:33 +00:00
|
|
|
{
|
|
|
|
int i;
|
2017-08-04 04:17:21 +00:00
|
|
|
unsigned int mask;
|
2017-08-03 20:25:33 +00:00
|
|
|
|
|
|
|
if (!(skip & SKIP_HEAP)) {
|
2020-06-23 18:47:05 +00:00
|
|
|
fail_unless(lwip_stats.mem.used == 0,
|
|
|
|
"mem heap still has %d bytes allocated", lwip_stats.mem.used);
|
2017-08-03 20:25:33 +00:00
|
|
|
}
|
|
|
|
for (i = 0, mask = 1; i < MEMP_MAX; i++, mask <<= 1) {
|
|
|
|
if (!(skip & mask)) {
|
2020-06-21 22:51:09 +00:00
|
|
|
fail_unless(lwip_stats.memp[i]->used == 0,
|
|
|
|
"memp pool '%s' still has %d entries allocated",
|
|
|
|
lwip_stats.memp[i]->name, lwip_stats.memp[i]->used);
|
2017-08-03 20:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-05 19:15:41 +00:00
|
|
|
#ifdef LWIP_UNITTESTS_LIB
|
|
|
|
int lwip_unittests_run(void)
|
|
|
|
#else
|
|
|
|
int main(void)
|
|
|
|
#endif
|
2009-11-27 08:03:53 +00:00
|
|
|
{
|
|
|
|
int number_failed;
|
|
|
|
SRunner *sr;
|
|
|
|
size_t i;
|
|
|
|
suite_getter_fn* suites[] = {
|
2017-08-02 19:11:53 +00:00
|
|
|
ip4_suite,
|
2018-06-08 20:18:50 +00:00
|
|
|
ip6_suite,
|
2009-11-27 08:03:53 +00:00
|
|
|
udp_suite,
|
|
|
|
tcp_suite,
|
|
|
|
tcp_oos_suite,
|
2017-12-23 19:35:18 +00:00
|
|
|
def_suite,
|
2020-07-04 16:31:36 +00:00
|
|
|
dns_suite,
|
2010-01-18 17:45:41 +00:00
|
|
|
mem_suite,
|
2018-01-12 21:27:15 +00:00
|
|
|
netif_suite,
|
2012-05-03 18:11:23 +00:00
|
|
|
pbuf_suite,
|
2018-01-04 12:37:05 +00:00
|
|
|
timers_suite,
|
2012-03-22 09:52:05 +00:00
|
|
|
etharp_suite,
|
2016-08-14 13:02:15 +00:00
|
|
|
dhcp_suite,
|
2017-03-16 20:52:30 +00:00
|
|
|
mdns_suite,
|
2017-04-12 19:54:42 +00:00
|
|
|
mqtt_suite,
|
2017-03-16 20:52:30 +00:00
|
|
|
sockets_suite
|
2009-11-27 08:03:53 +00:00
|
|
|
};
|
|
|
|
size_t num = sizeof(suites)/sizeof(void*);
|
|
|
|
LWIP_ASSERT("No suites defined", num > 0);
|
|
|
|
|
2017-03-17 08:05:36 +00:00
|
|
|
#if NO_SYS
|
2009-11-27 08:03:53 +00:00
|
|
|
lwip_init();
|
2017-03-17 08:05:36 +00:00
|
|
|
#else
|
|
|
|
tcpip_init(NULL, NULL);
|
|
|
|
#endif
|
2009-11-27 08:03:53 +00:00
|
|
|
|
|
|
|
sr = srunner_create((suites[0])());
|
2018-03-04 08:38:55 +00:00
|
|
|
srunner_set_xml(sr, "lwip_unittests.xml");
|
2009-11-27 08:03:53 +00:00
|
|
|
for(i = 1; i < num; i++) {
|
|
|
|
srunner_add_suite(sr, ((suite_getter_fn*)suites[i])());
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef LWIP_UNITTESTS_NOFORK
|
|
|
|
srunner_set_fork_status(sr, CK_NOFORK);
|
|
|
|
#endif
|
|
|
|
#ifdef LWIP_UNITTESTS_FORK
|
|
|
|
srunner_set_fork_status(sr, CK_FORK);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
srunner_run_all(sr, CK_NORMAL);
|
|
|
|
number_failed = srunner_ntests_failed(sr);
|
|
|
|
srunner_free(sr);
|
|
|
|
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|