2009-11-27 08:03:53 +00:00
|
|
|
#include "test_udp.h"
|
|
|
|
|
|
|
|
#include "lwip/udp.h"
|
|
|
|
#include "lwip/stats.h"
|
|
|
|
|
|
|
|
#if !LWIP_STATS || !UDP_STATS || !MEMP_STATS
|
|
|
|
#error "This tests needs UDP- and MEMP-statistics enabled"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Helper functions */
|
|
|
|
static void
|
|
|
|
udp_remove_all(void)
|
|
|
|
{
|
|
|
|
struct udp_pcb *pcb = udp_pcbs;
|
|
|
|
struct udp_pcb *pcb2;
|
|
|
|
|
|
|
|
while(pcb != NULL) {
|
|
|
|
pcb2 = pcb;
|
|
|
|
pcb = pcb->next;
|
|
|
|
udp_remove(pcb2);
|
|
|
|
}
|
2016-07-08 08:12:05 +00:00
|
|
|
fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 0);
|
2009-11-27 08:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setups/teardown functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
udp_setup(void)
|
|
|
|
{
|
|
|
|
udp_remove_all();
|
2017-08-03 20:25:33 +00:00
|
|
|
lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
|
2009-11-27 08:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
udp_teardown(void)
|
|
|
|
{
|
|
|
|
udp_remove_all();
|
2017-08-03 20:25:33 +00:00
|
|
|
lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
|
2009-11-27 08:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Test functions */
|
|
|
|
|
|
|
|
START_TEST(test_udp_new_remove)
|
|
|
|
{
|
|
|
|
struct udp_pcb* pcb;
|
|
|
|
LWIP_UNUSED_ARG(_i);
|
|
|
|
|
2016-07-08 08:12:05 +00:00
|
|
|
fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 0);
|
2009-11-27 08:03:53 +00:00
|
|
|
|
|
|
|
pcb = udp_new();
|
|
|
|
fail_unless(pcb != NULL);
|
|
|
|
if (pcb != NULL) {
|
2016-07-08 08:12:05 +00:00
|
|
|
fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 1);
|
2009-11-27 08:03:53 +00:00
|
|
|
udp_remove(pcb);
|
2016-07-08 08:12:05 +00:00
|
|
|
fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 0);
|
2009-11-27 08:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
|
|
/** Create the suite including all tests for this module */
|
|
|
|
Suite *
|
|
|
|
udp_suite(void)
|
|
|
|
{
|
2014-02-12 20:52:21 +00:00
|
|
|
testfunc tests[] = {
|
|
|
|
TESTFUNC(test_udp_new_remove),
|
2009-11-27 08:03:53 +00:00
|
|
|
};
|
2014-02-12 20:52:21 +00:00
|
|
|
return create_suite("UDP", tests, sizeof(tests)/sizeof(testfunc), udp_setup, udp_teardown);
|
2009-11-27 08:03:53 +00:00
|
|
|
}
|