Start implementing unit tests for timers

This commit is contained in:
Dirk Ziegelmeier
2018-01-04 13:37:05 +01:00
parent 40fecab313
commit 756b7431a7
9 changed files with 116 additions and 7 deletions

View File

@@ -36,6 +36,7 @@ TESTFILES=$(TESTDIR)/lwip_unittests.c \
$(TESTDIR)/core/test_def.c \
$(TESTDIR)/core/test_mem.c \
$(TESTDIR)/core/test_pbuf.c \
$(TESTDIR)/core/test_timers.c \
$(TESTDIR)/dhcp/test_dhcp.c \
$(TESTDIR)/etharp/test_etharp.c \
$(TESTDIR)/ip4/test_ip4.c \

View File

@@ -42,14 +42,16 @@
#include <string.h>
u32_t lwip_sys_now;
u32_t sys_jiffies(void)
{
return (u32_t)0; /* todo */
return lwip_sys_now;
}
u32_t sys_now(void)
{
return (u32_t)0; /* todo */
return lwip_sys_now;
}
void sys_init(void)

View File

@@ -65,5 +65,8 @@ typedef u32_t sys_thread_t;
typedef int (*test_sys_arch_waiting_fn)(sys_sem_t* wait_sem, sys_mbox_t* wait_mbox);
void test_sys_arch_wait_callback(test_sys_arch_waiting_fn waiting_fn);
/* current time */
extern u32_t lwip_sys_now;
#endif /* LWIP_HDR_TEST_SYS_ARCH_H */

View File

@@ -0,0 +1,79 @@
#include "test_timers.h"
#include "lwip/def.h"
#include "lwip/timeouts.h"
#include "arch/sys_arch.h"
/* Setups/teardown functions */
static struct sys_timeo* old_list_head;
static void
timers_setup(void)
{
struct sys_timeo** list_head = lwip_sys_timers_get_next_timout();
old_list_head = *list_head;
*list_head = NULL;
}
static void
timers_teardown(void)
{
struct sys_timeo** list_head = lwip_sys_timers_get_next_timout();
*list_head = old_list_head;
lwip_sys_now = 0;
}
static void dummy_handler(void* arg)
{
LWIP_UNUSED_ARG(arg);
}
static void test_timers(void)
{
struct sys_timeo** list_head = lwip_sys_timers_get_next_timout();
lwip_sys_now = 100;
sys_timeout(10, dummy_handler, NULL);
fail_unless(sys_timeouts_sleeptime() == 10);
sys_timeout(20, dummy_handler, NULL);
fail_unless(sys_timeouts_sleeptime() == 10);
sys_timeout( 5, dummy_handler, NULL);
fail_unless(sys_timeouts_sleeptime() == 5);
sys_untimeout(dummy_handler, NULL);
sys_untimeout(dummy_handler, NULL);
sys_untimeout(dummy_handler, NULL);
lwip_sys_now = 0xfffffff0;
sys_timeout(10, dummy_handler, NULL);
fail_unless(sys_timeouts_sleeptime() == 10);
sys_timeout(20, dummy_handler, NULL);
fail_unless(sys_timeouts_sleeptime() == 10);
sys_timeout( 5, dummy_handler, NULL);
fail_unless(sys_timeouts_sleeptime() == 5);
sys_untimeout(dummy_handler, NULL);
sys_untimeout(dummy_handler, NULL);
sys_untimeout(dummy_handler, NULL);
}
START_TEST(test_lwip_timers)
{
LWIP_UNUSED_ARG(_i);
test_timers();
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
timers_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_lwip_timers)
};
return create_suite("TIMERS", tests, LWIP_ARRAYSIZE(tests), timers_setup, timers_teardown);
}

View File

@@ -0,0 +1,8 @@
#ifndef LWIP_HDR_TEST_TIMERS_H
#define LWIP_HDR_TEST_TIMERS_H
#include "../lwip_check.h"
Suite *timers_suite(void);
#endif

View File

@@ -7,6 +7,7 @@
#include "core/test_def.h"
#include "core/test_mem.h"
#include "core/test_pbuf.h"
#include "core/test_timers.h"
#include "etharp/test_etharp.h"
#include "dhcp/test_dhcp.h"
#include "mdns/test_mdns.h"
@@ -66,6 +67,7 @@ int main(void)
def_suite,
mem_suite,
pbuf_suite,
timers_suite,
etharp_suite,
dhcp_suite,
mdns_suite,

View File

@@ -32,6 +32,8 @@
#ifndef LWIP_HDR_LWIPOPTS_H
#define LWIP_HDR_LWIPOPTS_H
#define LWIP_TESTMODE 1
#define LWIP_IPV6 1
/* We link to special sys_arch.c (for basic non-waiting API layers unit tests) */
@@ -65,7 +67,7 @@
/* Minimal changes to opt.h required for etharp unit tests: */
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + 1)
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + 5)
/* MIB2 stats are required to check IPv4 reassembly results */
#define MIB2_STATS 1