Commit 364235ec authored by 梁百峰's avatar 梁百峰

🎉 init:上传文件

parent 8a6303a6
fw-AC792_SDK/sdk/cpu/wl83/tools/sdk.map
fw-AC792_SDK/sdk/cpu/wl83/tools/isd_config_loader.ini
fw-AC792_SDK/sdk/cpu/wl83/tools/sdk.elf.0.0.preopt.bc
fw-AC792_SDK/sdk/cpu/wl83/tools/sdk.elf.0.2.internalize.bc
fw-AC792_SDK/sdk/cpu/wl83/tools/sdk.elf.0.4.opt.bc
fw-AC792_SDK/sdk/cpu/wl83/tools/sdk.elf.0.5.precodegen.bc
fw-AC792_SDK/sdk/cpu/wl83/tools/sdk.elf.objs.txt
fw-AC792_SDK/sdk/cpu/wl83/tools/sdk.elf.resolution.txt
fw-AC792_SDK/sdk/cpu/wl83/sdk.ld
fw-AC792_SDK/sdk/cpu/wl83/sdk.ld
fw-AC792_SDK/sdk/cpu/wl83/tools/sdk.elf.objs.txt
fw-AC792_SDK/sdk/apps/common/movable/section.txt
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmidt <goldsimon@gmx.de>
*
*/
#ifndef LWIP_HDR_FUZZ_COMMON_H
#define LWIP_HDR_FUZZ_COMMON_H
#include "lwip/opt.h"
#include "lwip/arch.h"
#ifdef __cplusplus
extern "C" {
#endif
enum lwip_fuzz_type {
LWIP_FUZZ_SINGLE = 0,
LWIP_FUZZ_MULTIPACKET = 1,
LWIP_FUZZ_MULTIPACKET_TIME = 2
};
/* bitmask of what to test: */
#define LWIP_FUZZ_DEFAULT 0x01
#define LWIP_FUZZ_STATICARP 0x02
#define LWIP_FUZZ_TCP_SERVER 0x04
#define LWIP_FUZZ_TCP_CLIENT 0x08
#define LWIP_FUZZ_UDP_SERVER 0x10
#define LWIP_FUZZ_UDP_CLIENT 0x20
int lwip_fuzztest(int argc, char **argv, enum lwip_fuzz_type type, u32_t test_apps);
#ifdef __cplusplus
}
#endif
#endif /* LWIP_HDR_FUZZ_COMMON_H */
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmidt
*
*/
#ifndef LWIP_HDR_LWIPOPTS_H__
#define LWIP_HDR_LWIPOPTS_H__
#define MEMP_NUM_SYS_TIMEOUT 17
#define LWIP_FUZZ_SYS_NOW
#define LWIP_RAND_FOR_FUZZ
/* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */
#define NO_SYS 1
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
#define SYS_LIGHTWEIGHT_PROT 0
#define LWIP_IPV6 1
#define IPV6_FRAG_COPYHEADER 1
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
/* Enable some protocols to test them */
#define LWIP_DHCP 1
#define LWIP_AUTOIP 1
#define LWIP_IGMP 1
#define LWIP_DNS 1
#define LWIP_ALTCP 1
/* Turn off checksum verification of fuzzed data */
#define CHECKSUM_CHECK_IP 0
#define CHECKSUM_CHECK_UDP 0
#define CHECKSUM_CHECK_TCP 0
#define CHECKSUM_CHECK_ICMP 0
#define CHECKSUM_CHECK_ICMP6 0
/* Minimal changes to opt.h required for tcp unit tests: */
#define MEM_SIZE 16000
#define TCP_SND_QUEUELEN 40
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
#define TCP_OVERSIZE 1
#define TCP_SND_BUF (12 * TCP_MSS)
#define TCP_WND (10 * TCP_MSS)
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define PBUF_POOL_SIZE 400 /* pbuf tests need ~200KByte */
/* Minimal changes to opt.h required for etharp unit tests: */
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#define LWIP_NUM_NETIF_CLIENT_DATA 1
#define LWIP_SNMP 1
#define MIB2_STATS 1
#define LWIP_MDNS_RESPONDER 1
#endif /* LWIP_HDR_LWIPOPTS_H__ */
/*
* Copyright (c) 2017 Simon Goldschmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmidt <goldsimon@gmx.de>
*
*/
#ifndef LWIP_HDR_TEST_SOCKETS_STRESSTEST
#define LWIP_HDR_TEST_SOCKETS_STRESSTEST
void sockets_stresstest_init_loopback(int addr_family);
void sockets_stresstest_init_server(int addr_family, u16_t server_port);
void sockets_stresstest_init_client(const char *remote_ip, u16_t remote_port);
#endif /* LWIP_HDR_TEST_SOCKETS_STRESSTEST */
#ifndef LWIP_HDR_TEST_SOCKETS_H
#define LWIP_HDR_TEST_SOCKETS_H
#include "../lwip_check.h"
Suite *sockets_suite(void);
#endif
/*
* Copyright (c) 2017 Simon Goldschmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmidt
*
*/
#ifndef LWIP_HDR_TEST_SYS_ARCH_H
#define LWIP_HDR_TEST_SYS_ARCH_H
typedef int sys_sem_t;
#define sys_sem_valid(sema) ((sema) != NULL)
typedef int sys_mutex_t;
#define sys_mutex_valid(mutex) (((mutex) != NULL)
struct lwip_mbox {
void *sem;
void **q_mem;
unsigned int head, tail;
int size;
int used;
};
typedef struct lwip_mbox sys_mbox_t;
#define SYS_MBOX_NULL NULL
#define sys_mbox_valid(mbox) ((mbox != NULL) && ((mbox)->sem != NULL) && ((mbox)->sem != (void*)-1))
#define sys_mbox_valid_val(mbox) (((mbox).sem != NULL) && ((mbox).sem != (void*)-1))
/* DWORD (thread id) is used for sys_thread_t but we won't include windows.h */
typedef u32_t sys_thread_t;
#define SYS_ARCH_DECL_PROTECT(lev)
#define SYS_ARCH_PROTECT(lev)
#define SYS_ARCH_UNPROTECT(lev)
/* to implement doing something while blocking on an mbox or semaphore:
* pass a function to test_sys_arch_wait_callback() that returns
* '0' if waiting again and
* '1' if now there should be something to do (used for asserting)
*/
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;
sys_sem_t *sys_arch_netconn_sem_get(void);
void sys_arch_netconn_sem_alloc(void);
void sys_arch_netconn_sem_free(void);
#define LWIP_NETCONN_THREAD_SEM_GET() sys_arch_netconn_sem_get()
#define LWIP_NETCONN_THREAD_SEM_ALLOC() sys_arch_netconn_sem_alloc()
#define LWIP_NETCONN_THREAD_SEM_FREE() sys_arch_netconn_sem_free()
#endif /* LWIP_HDR_TEST_SYS_ARCH_H */
#include "test_def.h"
#include "lwip/def.h"
#define MAGIC_UNTOUCHED_BYTE 0x7a
#define TEST_BUFSIZE 32
#define GUARD_SIZE 4
/* Setups/teardown functions */
static void
def_setup(void)
{
}
static void
def_teardown(void)
{
}
static void
def_check_range_untouched(const char *buf, size_t len)
{
size_t i;
for (i = 0; i < len; i++) {
fail_unless(buf[i] == (char)MAGIC_UNTOUCHED_BYTE);
}
}
static void test_def_itoa(int number, const char *expected)
{
char buf[TEST_BUFSIZE];
char *test_buf = &buf[GUARD_SIZE];
size_t exp_len = strlen(expected);
fail_unless(exp_len + 4 < (TEST_BUFSIZE - (2 * GUARD_SIZE)));
memset(buf, MAGIC_UNTOUCHED_BYTE, sizeof(buf));
lwip_itoa(test_buf, exp_len + 1, number);
def_check_range_untouched(buf, GUARD_SIZE);
fail_unless(test_buf[exp_len] == 0);
fail_unless(!memcmp(test_buf, expected, exp_len));
def_check_range_untouched(&test_buf[exp_len + 1], TEST_BUFSIZE - GUARD_SIZE - exp_len - 1);
/* check with too small buffer */
memset(buf, MAGIC_UNTOUCHED_BYTE, sizeof(buf));
lwip_itoa(test_buf, exp_len, number);
def_check_range_untouched(buf, GUARD_SIZE);
def_check_range_untouched(&test_buf[exp_len + 1], TEST_BUFSIZE - GUARD_SIZE - exp_len - 1);
/* check with too large buffer */
memset(buf, MAGIC_UNTOUCHED_BYTE, sizeof(buf));
lwip_itoa(test_buf, exp_len + 4, number);
def_check_range_untouched(buf, GUARD_SIZE);
fail_unless(test_buf[exp_len] == 0);
fail_unless(!memcmp(test_buf, expected, exp_len));
def_check_range_untouched(&test_buf[exp_len + 4], TEST_BUFSIZE - GUARD_SIZE - exp_len - 4);
}
START_TEST(test_def_lwip_itoa)
{
LWIP_UNUSED_ARG(_i);
test_def_itoa(0, "0");
test_def_itoa(1, "1");
test_def_itoa(-1, "-1");
test_def_itoa(15, "15");
test_def_itoa(-15, "-15");
test_def_itoa(156, "156");
test_def_itoa(1192, "1192");
test_def_itoa(-156, "-156");
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
def_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_def_lwip_itoa)
};
return create_suite("DEF", tests, sizeof(tests) / sizeof(testfunc), def_setup, def_teardown);
}
#ifndef LWIP_HDR_TEST_DEF_H
#define LWIP_HDR_TEST_DEF_H
#include "../lwip_check.h"
Suite *def_suite(void);
#endif
#include "test_dns.h"
#include "lwip/dns.h"
/* Setups/teardown functions */
static void
dns_setup(void)
{
}
static void
dns_teardown(void)
{
}
/* Test functions */
START_TEST(test_dns_set_get_server)
{
int n;
LWIP_UNUSED_ARG(_i);
for (n = 0; n < 256; n++) {
u8_t i = (u8_t)n;
ip_addr_t server;
/* Should return a zeroed address for any index */
fail_unless(dns_getserver(i));
fail_unless(ip_addr_isany(dns_getserver(i)));
/* Should accept setting address for any index, and ignore if out of range */
IP_ADDR4(&server, 10, 0, 0, i);
dns_setserver(i, &server);
fail_unless(dns_getserver(i));
if (i < DNS_MAX_SERVERS) {
fail_unless(ip_addr_eq(dns_getserver(i), &server) == 1);
} else {
fail_unless(ip_addr_isany(dns_getserver(i)));
}
}
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
dns_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_dns_set_get_server)
};
return create_suite("DNS", tests, sizeof(tests) / sizeof(testfunc), dns_setup, dns_teardown);
}
#ifndef LWIP_HDR_TEST_DNS_H
#define LWIP_HDR_TEST_DNS_H
#include "../lwip_check.h"
Suite *dns_suite(void);
#endif
#include "test_mem.h"
#include "lwip/mem.h"
#include "lwip/stats.h"
#if !LWIP_STATS || !MEM_STATS
#error "This tests needs MEM-statistics enabled"
#endif
/* Setups/teardown functions */
static void
mem_setup(void)
{
lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
}
static void
mem_teardown(void)
{
lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
}
/* Test functions */
/** Call mem_malloc, mem_free and mem_trim and check stats */
START_TEST(test_mem_one)
{
#define SIZE1 16
#define SIZE1_2 12
#define SIZE2 16
void *p1, *p2;
mem_size_t s1, s2;
LWIP_UNUSED_ARG(_i);
fail_unless(lwip_stats.mem.used == 0);
p1 = mem_malloc(SIZE1);
fail_unless(p1 != NULL);
fail_unless(lwip_stats.mem.used >= SIZE1);
s1 = lwip_stats.mem.used;
p2 = mem_malloc(SIZE2);
fail_unless(p2 != NULL);
fail_unless(lwip_stats.mem.used >= SIZE2 + s1);
s2 = lwip_stats.mem.used;
mem_trim(p1, SIZE1_2);
mem_free(p2);
fail_unless(lwip_stats.mem.used <= s2 - SIZE2);
mem_free(p1);
fail_unless(lwip_stats.mem.used == 0);
}
END_TEST
static void malloc_keep_x(int x, int num, int size, int freestep)
{
int i;
void *p[16];
LWIP_ASSERT("invalid size", size >= 0 && size < (mem_size_t) - 1);
memset(p, 0, sizeof(p));
for (i = 0; i < num && i < 16; i++) {
p[i] = mem_malloc((mem_size_t)size);
fail_unless(p[i] != NULL);
}
for (i = 0; i < num && i < 16; i += freestep) {
if (i == x) {
continue;
}
mem_free(p[i]);
p[i] = NULL;
}
for (i = 0; i < num && i < 16; i++) {
if (i == x) {
continue;
}
if (p[i] != NULL) {
mem_free(p[i]);
p[i] = NULL;
}
}
fail_unless(p[x] != NULL);
mem_free(p[x]);
}
START_TEST(test_mem_random)
{
const int num = 16;
int x;
int size;
int freestep;
LWIP_UNUSED_ARG(_i);
fail_unless(lwip_stats.mem.used == 0);
for (x = 0; x < num; x++) {
for (size = 1; size < 32; size++) {
for (freestep = 1; freestep <= 3; freestep++) {
fail_unless(lwip_stats.mem.used == 0);
malloc_keep_x(x, num, size, freestep);
fail_unless(lwip_stats.mem.used == 0);
}
}
}
}
END_TEST
START_TEST(test_mem_invalid_free)
{
u8_t *ptr, *ptr_low, *ptr_high;
LWIP_UNUSED_ARG(_i);
fail_unless(lwip_stats.mem.used == 0);
fail_unless(lwip_stats.mem.illegal == 0);
ptr = (u8_t *)mem_malloc(1);
fail_unless(ptr != NULL);
fail_unless(lwip_stats.mem.used != 0);
ptr_low = ptr - 0x10;
mem_free(ptr_low);
fail_unless(lwip_stats.mem.illegal == 1);
lwip_stats.mem.illegal = 0;
ptr_high = ptr + (MEM_SIZE * 2);
mem_free(ptr_high);
fail_unless(lwip_stats.mem.illegal == 1);
lwip_stats.mem.illegal = 0;
mem_free(ptr);
fail_unless(lwip_stats.mem.illegal == 0);
fail_unless(lwip_stats.mem.used == 0);
}
END_TEST
START_TEST(test_mem_double_free)
{
u8_t *ptr1b, *ptr1, *ptr2, *ptr3;
LWIP_UNUSED_ARG(_i);
fail_unless(lwip_stats.mem.used == 0);
fail_unless(lwip_stats.mem.illegal == 0);
ptr1 = (u8_t *)mem_malloc(1);
fail_unless(ptr1 != NULL);
fail_unless(lwip_stats.mem.used != 0);
ptr2 = (u8_t *)mem_malloc(1);
fail_unless(ptr2 != NULL);
fail_unless(lwip_stats.mem.used != 0);
ptr3 = (u8_t *)mem_malloc(1);
fail_unless(ptr3 != NULL);
fail_unless(lwip_stats.mem.used != 0);
/* free the middle mem */
mem_free(ptr2);
fail_unless(lwip_stats.mem.illegal == 0);
/* double-free of middle mem: should fail */
mem_free(ptr2);
fail_unless(lwip_stats.mem.illegal == 1);
lwip_stats.mem.illegal = 0;
/* free upper memory and try again */
mem_free(ptr3);
fail_unless(lwip_stats.mem.illegal == 0);
mem_free(ptr2);
fail_unless(lwip_stats.mem.illegal == 1);
lwip_stats.mem.illegal = 0;
/* free lower memory and try again */
mem_free(ptr1);
fail_unless(lwip_stats.mem.illegal == 0);
fail_unless(lwip_stats.mem.used == 0);
mem_free(ptr2);
fail_unless(lwip_stats.mem.illegal == 1);
fail_unless(lwip_stats.mem.used == 0);
lwip_stats.mem.illegal = 0;
/* reallocate lowest memory, now overlapping already freed ptr2 */
#ifndef MIN_SIZE
#define MIN_SIZE 12
#endif
ptr1b = (u8_t *)mem_malloc(MIN_SIZE * 2);
fail_unless(ptr1b != NULL);
fail_unless(lwip_stats.mem.used != 0);
mem_free(ptr2);
fail_unless(lwip_stats.mem.illegal == 1);
lwip_stats.mem.illegal = 0;
memset(ptr1b, 1, MIN_SIZE * 2);
mem_free(ptr2);
fail_unless(lwip_stats.mem.illegal == 1);
lwip_stats.mem.illegal = 0;
mem_free(ptr1b);
fail_unless(lwip_stats.mem.illegal == 0);
fail_unless(lwip_stats.mem.used == 0);
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
mem_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_mem_one),
TESTFUNC(test_mem_random),
TESTFUNC(test_mem_invalid_free),
TESTFUNC(test_mem_double_free)
};
return create_suite("MEM", tests, sizeof(tests) / sizeof(testfunc), mem_setup, mem_teardown);
}
#ifndef LWIP_HDR_TEST_MEM_H
#define LWIP_HDR_TEST_MEM_H
#include "../lwip_check.h"
Suite *mem_suite(void);
#endif
#include "test_netif.h"
#include "lwip/netif.h"
#include "lwip/stats.h"
#include "lwip/etharp.h"
#include "netif/ethernet.h"
#if !LWIP_NETIF_EXT_STATUS_CALLBACK
#error "This tests needs LWIP_NETIF_EXT_STATUS_CALLBACK enabled"
#endif
static struct netif net_test;
/* Setups/teardown functions */
static void
netif_setup(void)
{
lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
}
static void
netif_teardown(void)
{
lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
}
/* test helper functions */
static err_t
testif_tx_func(struct netif *netif, struct pbuf *p)
{
LWIP_UNUSED_ARG(netif);
LWIP_UNUSED_ARG(p);
return ERR_OK;
}
static err_t
testif_init(struct netif *netif)
{
netif->name[0] = 'c';
netif->name[1] = 'h';
netif->output = etharp_output;
netif->linkoutput = testif_tx_func;
netif->mtu = 1500;
netif->hwaddr_len = 6;
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6;
netif->hwaddr[0] = 0x02;
netif->hwaddr[1] = 0x03;
netif->hwaddr[2] = 0x04;
netif->hwaddr[3] = 0x05;
netif->hwaddr[4] = 0x06;
netif->hwaddr[5] = 0x07;
return ERR_OK;
}
#define MAX_NSC_REASON_IDX 10
static netif_nsc_reason_t expected_reasons;
static int callback_ctr;
static int dummy_active;
static void
test_netif_ext_callback_dummy(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
{
LWIP_UNUSED_ARG(netif);
LWIP_UNUSED_ARG(reason);
LWIP_UNUSED_ARG(args);
fail_unless(dummy_active);
}
static void
test_netif_ext_callback(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
{
LWIP_UNUSED_ARG(args); /* @todo */
callback_ctr++;
fail_unless(netif == &net_test);
fail_unless(expected_reasons == reason);
}
/* Test functions */
NETIF_DECLARE_EXT_CALLBACK(netif_callback_1)
NETIF_DECLARE_EXT_CALLBACK(netif_callback_2)
NETIF_DECLARE_EXT_CALLBACK(netif_callback_3)
START_TEST(test_netif_extcallbacks)
{
ip4_addr_t addr;
ip4_addr_t netmask;
ip4_addr_t gw;
LWIP_UNUSED_ARG(_i);
IP4_ADDR(&addr, 0, 0, 0, 0);
IP4_ADDR(&netmask, 0, 0, 0, 0);
IP4_ADDR(&gw, 0, 0, 0, 0);
netif_add_ext_callback(&netif_callback_3, test_netif_ext_callback_dummy);
netif_add_ext_callback(&netif_callback_2, test_netif_ext_callback);
netif_add_ext_callback(&netif_callback_1, test_netif_ext_callback_dummy);
dummy_active = 1;
/* positive tests: check that single events come as expected */
expected_reasons = LWIP_NSC_NETIF_ADDED;
callback_ctr = 0;
netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
fail_unless(callback_ctr == 1);
expected_reasons = LWIP_NSC_LINK_CHANGED;
callback_ctr = 0;
netif_set_link_up(&net_test);
fail_unless(callback_ctr == 1);
expected_reasons = LWIP_NSC_STATUS_CHANGED;
callback_ctr = 0;
netif_set_up(&net_test);
fail_unless(callback_ctr == 1);
IP4_ADDR(&addr, 1, 2, 3, 4);
expected_reasons = LWIP_NSC_IPV4_ADDRESS_CHANGED;
callback_ctr = 0;
netif_set_ipaddr(&net_test, &addr);
fail_unless(callback_ctr == 1);
IP4_ADDR(&netmask, 255, 255, 255, 0);
expected_reasons = LWIP_NSC_IPV4_NETMASK_CHANGED;
callback_ctr = 0;
netif_set_netmask(&net_test, &netmask);
fail_unless(callback_ctr == 1);
IP4_ADDR(&gw, 1, 2, 3, 254);
expected_reasons = LWIP_NSC_IPV4_GATEWAY_CHANGED;
callback_ctr = 0;
netif_set_gw(&net_test, &gw);
fail_unless(callback_ctr == 1);
IP4_ADDR(&addr, 0, 0, 0, 0);
expected_reasons = LWIP_NSC_IPV4_ADDRESS_CHANGED;
callback_ctr = 0;
netif_set_ipaddr(&net_test, &addr);
fail_unless(callback_ctr == 1);
IP4_ADDR(&netmask, 0, 0, 0, 0);
expected_reasons = LWIP_NSC_IPV4_NETMASK_CHANGED;
callback_ctr = 0;
netif_set_netmask(&net_test, &netmask);
fail_unless(callback_ctr == 1);
IP4_ADDR(&gw, 0, 0, 0, 0);
expected_reasons = LWIP_NSC_IPV4_GATEWAY_CHANGED;
callback_ctr = 0;
netif_set_gw(&net_test, &gw);
fail_unless(callback_ctr == 1);
/* check for multi-events (only one combined callback expected) */
IP4_ADDR(&addr, 1, 2, 3, 4);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 1, 2, 3, 254);
expected_reasons = (netif_nsc_reason_t)(LWIP_NSC_IPV4_ADDRESS_CHANGED | LWIP_NSC_IPV4_NETMASK_CHANGED |
LWIP_NSC_IPV4_GATEWAY_CHANGED | LWIP_NSC_IPV4_SETTINGS_CHANGED |
LWIP_NSC_IPV4_ADDR_VALID);
callback_ctr = 0;
netif_set_addr(&net_test, &addr, &netmask, &gw);
fail_unless(callback_ctr == 1);
/* check that for no-change, no callback is expected */
expected_reasons = LWIP_NSC_NONE;
callback_ctr = 0;
netif_set_ipaddr(&net_test, &addr);
fail_unless(callback_ctr == 0);
netif_set_netmask(&net_test, &netmask);
callback_ctr = 0;
fail_unless(callback_ctr == 0);
callback_ctr = 0;
netif_set_gw(&net_test, &gw);
fail_unless(callback_ctr == 0);
/* netif_set_addr() always issues at least LWIP_NSC_IPV4_ADDR_VALID */
expected_reasons = LWIP_NSC_IPV4_ADDR_VALID;
callback_ctr = 0;
netif_set_addr(&net_test, &addr, &netmask, &gw);
fail_unless(callback_ctr == 1);
/* check for single-events */
IP4_ADDR(&addr, 1, 2, 3, 5);
expected_reasons = (netif_nsc_reason_t)(LWIP_NSC_IPV4_ADDRESS_CHANGED | LWIP_NSC_IPV4_SETTINGS_CHANGED |
LWIP_NSC_IPV4_ADDR_VALID);
callback_ctr = 0;
netif_set_addr(&net_test, &addr, &netmask, &gw);
fail_unless(callback_ctr == 1);
expected_reasons = LWIP_NSC_STATUS_CHANGED;
callback_ctr = 0;
netif_set_down(&net_test);
fail_unless(callback_ctr == 1);
expected_reasons = LWIP_NSC_NETIF_REMOVED;
callback_ctr = 0;
netif_remove(&net_test);
fail_unless(callback_ctr == 1);
expected_reasons = LWIP_NSC_NONE;
netif_remove_ext_callback(&netif_callback_2);
netif_remove_ext_callback(&netif_callback_3);
netif_remove_ext_callback(&netif_callback_1);
dummy_active = 0;
}
END_TEST
START_TEST(test_netif_flag_set)
{
ip4_addr_t addr;
ip4_addr_t netmask;
ip4_addr_t gw;
LWIP_UNUSED_ARG(_i);
IP4_ADDR(&addr, 0, 0, 0, 0);
IP4_ADDR(&netmask, 0, 0, 0, 0);
IP4_ADDR(&gw, 0, 0, 0, 0);
netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
fail_if(netif_is_flag_set(&net_test, NETIF_FLAG_UP));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_BROADCAST));
fail_if(netif_is_flag_set(&net_test, NETIF_FLAG_LINK_UP));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_ETHARP));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_ETHERNET));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_IGMP));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_MLD6));
netif_remove(&net_test);
}
END_TEST
START_TEST(test_netif_find)
{
struct netif net0;
struct netif net1;
LWIP_UNUSED_ARG(_i);
/* No netifs available */
fail_unless(netif_find("ch0") == NULL);
/* Add netifs with known names */
fail_unless(netif_add_noaddr(&net0, NULL, testif_init, ethernet_input) == &net0);
net0.num = 0;
fail_unless(netif_add_noaddr(&net1, NULL, testif_init, ethernet_input) == &net1);
net1.num = 1;
fail_unless(netif_find("ch0") == &net0);
fail_unless(netif_find("CH0") == NULL);
fail_unless(netif_find("ch1") == &net1);
fail_unless(netif_find("ch3") == NULL);
/* atoi failure is not treated as zero */
fail_unless(netif_find("chX") == NULL);
fail_unless(netif_find("ab0") == NULL);
netif_remove(&net0);
netif_remove(&net1);
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
netif_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_netif_extcallbacks),
TESTFUNC(test_netif_flag_set),
TESTFUNC(test_netif_find)
};
return create_suite("NETIF", tests, sizeof(tests) / sizeof(testfunc), netif_setup, netif_teardown);
}
#ifndef LWIP_HDR_TEST_NETIF_H
#define LWIP_HDR_TEST_NETIF_H
#include "../lwip_check.h"
Suite *netif_suite(void);
#endif
#ifndef LWIP_HDR_TEST_PBUF_H
#define LWIP_HDR_TEST_PBUF_H
#include "../lwip_check.h"
Suite *pbuf_suite(void);
#endif
#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 = sys_timeouts_get_next_timeout();
old_list_head = *list_head;
*list_head = NULL;
}
static void
timers_teardown(void)
{
struct sys_timeo **list_head = sys_timeouts_get_next_timeout();
*list_head = old_list_head;
lwip_sys_now = 0;
}
static int fired[3];
static void
dummy_handler(void *arg)
{
int index = LWIP_PTR_NUMERIC_CAST(int, arg);
fired[index] = 1;
}
#define HANDLER_EXECUTION_TIME 5
static int cyclic_fired;
static void
dummy_cyclic_handler(void)
{
cyclic_fired = 1;
lwip_sys_now += HANDLER_EXECUTION_TIME;
}
struct lwip_cyclic_timer test_cyclic = {10, dummy_cyclic_handler};
static void
do_test_cyclic_timers(u32_t offset)
{
struct sys_timeo **list_head = sys_timeouts_get_next_timeout();
/* verify normal timer expiration */
lwip_sys_now = offset + 0;
sys_timeout(test_cyclic.interval_ms, lwip_cyclic_timer, &test_cyclic);
cyclic_fired = 0;
sys_check_timeouts();
fail_unless(cyclic_fired == 0);
lwip_sys_now = offset + test_cyclic.interval_ms;
sys_check_timeouts();
fail_unless(cyclic_fired == 1);
fail_unless((*list_head)->time == (u32_t)(lwip_sys_now + test_cyclic.interval_ms - HANDLER_EXECUTION_TIME));
sys_untimeout(lwip_cyclic_timer, &test_cyclic);
/* verify "overload" - next cyclic timer execution is already overdue twice */
lwip_sys_now = offset + 0;
sys_timeout(test_cyclic.interval_ms, lwip_cyclic_timer, &test_cyclic);
cyclic_fired = 0;
sys_check_timeouts();
fail_unless(cyclic_fired == 0);
lwip_sys_now = offset + 2 * test_cyclic.interval_ms;
sys_check_timeouts();
fail_unless(cyclic_fired == 1);
fail_unless((*list_head)->time == (u32_t)(lwip_sys_now + test_cyclic.interval_ms));
}
START_TEST(test_cyclic_timers)
{
LWIP_UNUSED_ARG(_i);
/* check without u32_t wraparound */
do_test_cyclic_timers(0);
/* check with u32_t wraparound */
do_test_cyclic_timers(0xfffffff0);
}
END_TEST
/* reproduce bug #52748: the bug in timeouts.c */
START_TEST(test_bug52748)
{
LWIP_UNUSED_ARG(_i);
memset(&fired, 0, sizeof(fired));
lwip_sys_now = 50;
sys_timeout(20, dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 0));
sys_timeout(5, dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 2));
lwip_sys_now = 55;
sys_check_timeouts();
fail_unless(fired[0] == 0);
fail_unless(fired[1] == 0);
fail_unless(fired[2] == 1);
lwip_sys_now = 60;
sys_timeout(10, dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 1));
sys_check_timeouts();
fail_unless(fired[0] == 0);
fail_unless(fired[1] == 0);
fail_unless(fired[2] == 1);
lwip_sys_now = 70;
sys_check_timeouts();
fail_unless(fired[0] == 1);
fail_unless(fired[1] == 1);
fail_unless(fired[2] == 1);
}
END_TEST
static void
do_test_timers(u32_t offset)
{
struct sys_timeo **list_head = sys_timeouts_get_next_timeout();
lwip_sys_now = offset + 0;
sys_timeout(10, dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 0));
fail_unless(sys_timeouts_sleeptime() == 10);
sys_timeout(20, dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 1));
fail_unless(sys_timeouts_sleeptime() == 10);
sys_timeout(5, dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 2));
fail_unless(sys_timeouts_sleeptime() == 5);
/* linked list correctly sorted? */
fail_unless((*list_head)->time == (u32_t)(lwip_sys_now + 5));
fail_unless((*list_head)->next->time == (u32_t)(lwip_sys_now + 10));
fail_unless((*list_head)->next->next->time == (u32_t)(lwip_sys_now + 20));
/* check timers expire in correct order */
memset(&fired, 0, sizeof(fired));
lwip_sys_now += 4;
sys_check_timeouts();
fail_unless(fired[2] == 0);
lwip_sys_now += 1;
sys_check_timeouts();
fail_unless(fired[2] == 1);
lwip_sys_now += 4;
sys_check_timeouts();
fail_unless(fired[0] == 0);
lwip_sys_now += 1;
sys_check_timeouts();
fail_unless(fired[0] == 1);
lwip_sys_now += 9;
sys_check_timeouts();
fail_unless(fired[1] == 0);
lwip_sys_now += 1;
sys_check_timeouts();
fail_unless(fired[1] == 1);
sys_untimeout(dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 0));
sys_untimeout(dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 1));
sys_untimeout(dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 2));
}
START_TEST(test_timers)
{
LWIP_UNUSED_ARG(_i);
/* check without u32_t wraparound */
do_test_timers(0);
/* check with u32_t wraparound */
do_test_timers(0xfffffff0);
}
END_TEST
START_TEST(test_long_timer)
{
LWIP_UNUSED_ARG(_i);
memset(&fired, 0, sizeof(fired));
lwip_sys_now = 0;
sys_timeout(LWIP_UINT32_MAX / 4, dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 0));
fail_unless(sys_timeouts_sleeptime() == LWIP_UINT32_MAX / 4);
sys_check_timeouts();
fail_unless(fired[0] == 0);
lwip_sys_now += LWIP_UINT32_MAX / 8;
sys_check_timeouts();
fail_unless(fired[0] == 0);
lwip_sys_now += LWIP_UINT32_MAX / 8;
sys_check_timeouts();
fail_unless(fired[0] == 0);
lwip_sys_now += 1;
sys_check_timeouts();
fail_unless(fired[0] == 1);
sys_untimeout(dummy_handler, LWIP_PTR_NUMERIC_CAST(void *, 0));
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
timers_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_bug52748),
TESTFUNC(test_cyclic_timers),
TESTFUNC(test_timers),
TESTFUNC(test_long_timer),
};
return create_suite("TIMERS", tests, LWIP_ARRAYSIZE(tests), timers_setup, timers_teardown);
}
#ifndef LWIP_HDR_TEST_TIMERS_H
#define LWIP_HDR_TEST_TIMERS_H
#include "../lwip_check.h"
Suite *timers_suite(void);
#endif
#ifndef LWIP_HDR_TEST_DHCP_H
#define LWIP_HDR_TEST_DHCP_H
#include "../lwip_check.h"
Suite *dhcp_suite(void);
#endif
#include "test_etharp.h"
#include "lwip/udp.h"
#include "lwip/etharp.h"
#include "lwip/inet.h"
#include "netif/ethernet.h"
#include "lwip/stats.h"
#include "lwip/prot/iana.h"
#if !LWIP_STATS || !UDP_STATS || !MEMP_STATS || !ETHARP_STATS
#error "This tests needs UDP-, MEMP- and ETHARP-statistics enabled"
#endif
#if !ETHARP_SUPPORT_STATIC_ENTRIES
#error "This test needs ETHARP_SUPPORT_STATIC_ENTRIES enabled"
#endif
static struct netif test_netif;
static ip4_addr_t test_ipaddr, test_netmask, test_gw;
struct eth_addr test_ethaddr = {{1, 1, 1, 1, 1, 1}};
struct eth_addr test_ethaddr2 = {{1, 1, 1, 1, 1, 2}};
struct eth_addr test_ethaddr3 = {{1, 1, 1, 1, 1, 3}};
struct eth_addr test_ethaddr4 = {{1, 1, 1, 1, 1, 4}};
static int linkoutput_ctr;
/* Helper functions */
static void
etharp_remove_all(void)
{
int i;
/* call etharp_tmr often enough to have all entries cleaned */
for (i = 0; i < 0xff; i++) {
etharp_tmr();
}
}
static err_t
default_netif_linkoutput(struct netif *netif, struct pbuf *p)
{
fail_unless(netif == &test_netif);
fail_unless(p != NULL);
linkoutput_ctr++;
return ERR_OK;
}
static err_t
default_netif_init(struct netif *netif)
{
fail_unless(netif != NULL);
netif->linkoutput = default_netif_linkoutput;
netif->output = etharp_output;
netif->mtu = 1500;
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
netif->hwaddr_len = ETHARP_HWADDR_LEN;
return ERR_OK;
}
static void
default_netif_add(void)
{
IP4_ADDR(&test_gw, 192, 168, 0, 1);
IP4_ADDR(&test_ipaddr, 192, 168, 0, 1);
IP4_ADDR(&test_netmask, 255, 255, 0, 0);
fail_unless(netif_default == NULL);
netif_set_default(netif_add(&test_netif, &test_ipaddr, &test_netmask,
&test_gw, NULL, default_netif_init, NULL));
netif_set_up(&test_netif);
}
static void
default_netif_remove(void)
{
fail_unless(netif_default == &test_netif);
netif_remove(&test_netif);
}
static void
create_arp_response(ip4_addr_t *adr)
{
int k;
struct eth_hdr *ethhdr;
struct etharp_hdr *etharphdr;
struct pbuf *p = pbuf_alloc(PBUF_RAW, sizeof(struct eth_hdr) + sizeof(struct etharp_hdr), PBUF_RAM);
if (p == NULL) {
FAIL_RET();
}
ethhdr = (struct eth_hdr *)p->payload;
etharphdr = (struct etharp_hdr *)(ethhdr + 1);
ethhdr->dest = test_ethaddr;
ethhdr->src = test_ethaddr2;
ethhdr->type = htons(ETHTYPE_ARP);
etharphdr->hwtype = htons(LWIP_IANA_HWTYPE_ETHERNET);
etharphdr->proto = htons(ETHTYPE_IP);
etharphdr->hwlen = ETHARP_HWADDR_LEN;
etharphdr->protolen = sizeof(ip4_addr_t);
etharphdr->opcode = htons(ARP_REPLY);
SMEMCPY(&etharphdr->sipaddr, adr, sizeof(ip4_addr_t));
SMEMCPY(&etharphdr->dipaddr, &test_ipaddr, sizeof(ip4_addr_t));
k = 6;
while (k > 0) {
k--;
/* Write the ARP MAC-Addresses */
etharphdr->shwaddr.addr[k] = test_ethaddr2.addr[k];
etharphdr->dhwaddr.addr[k] = test_ethaddr.addr[k];
/* Write the Ethernet MAC-Addresses */
ethhdr->dest.addr[k] = test_ethaddr.addr[k];
ethhdr->src.addr[k] = test_ethaddr2.addr[k];
}
ethernet_input(p, &test_netif);
}
/* Setups/teardown functions */
static void
etharp_setup(void)
{
etharp_remove_all();
default_netif_add();
lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
}
static void
etharp_teardown(void)
{
etharp_remove_all();
default_netif_remove();
lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
}
/* Test functions */
START_TEST(test_etharp_table)
{
#if ETHARP_SUPPORT_STATIC_ENTRIES
err_t err;
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
ssize_t idx;
const ip4_addr_t *unused_ipaddr;
struct eth_addr *unused_ethaddr;
struct udp_pcb *pcb;
LWIP_UNUSED_ARG(_i);
if (netif_default != &test_netif) {
fail("This test needs a default netif");
}
linkoutput_ctr = 0;
pcb = udp_new();
fail_unless(pcb != NULL);
if (pcb != NULL) {
ip4_addr_t adrs[ARP_TABLE_SIZE + 2];
int i;
for (i = 0; i < ARP_TABLE_SIZE + 2; i++) {
IP4_ADDR(&adrs[i], 192, 168, 0, i + 2);
}
/* fill ARP-table with dynamic entries */
for (i = 0; i < ARP_TABLE_SIZE; i++) {
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 10, PBUF_RAM);
fail_unless(p != NULL);
if (p != NULL) {
err_t err2;
ip_addr_t dst;
ip_addr_copy_from_ip4(dst, adrs[i]);
err2 = udp_sendto(pcb, p, &dst, 123);
fail_unless(err2 == ERR_OK);
/* etharp request sent? */
fail_unless(linkoutput_ctr == (2 * i) + 1);
pbuf_free(p);
/* create an ARP response */
create_arp_response(&adrs[i]);
/* queued UDP packet sent? */
fail_unless(linkoutput_ctr == (2 * i) + 2);
idx = etharp_find_addr(NULL, &adrs[i], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == i);
etharp_tmr();
}
}
linkoutput_ctr = 0;
#if ETHARP_SUPPORT_STATIC_ENTRIES
/* create one static entry */
err = etharp_add_static_entry(&adrs[ARP_TABLE_SIZE], &test_ethaddr3);
fail_unless(err == ERR_OK);
idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == 0);
fail_unless(linkoutput_ctr == 0);
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
linkoutput_ctr = 0;
/* fill ARP-table with dynamic entries */
for (i = 0; i < ARP_TABLE_SIZE; i++) {
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 10, PBUF_RAM);
fail_unless(p != NULL);
if (p != NULL) {
err_t err2;
ip_addr_t dst;
ip_addr_copy_from_ip4(dst, adrs[i]);
err2 = udp_sendto(pcb, p, &dst, 123);
fail_unless(err2 == ERR_OK);
/* etharp request sent? */
fail_unless(linkoutput_ctr == (2 * i) + 1);
pbuf_free(p);
/* create an ARP response */
create_arp_response(&adrs[i]);
/* queued UDP packet sent? */
fail_unless(linkoutput_ctr == (2 * i) + 2);
idx = etharp_find_addr(NULL, &adrs[i], &unused_ethaddr, &unused_ipaddr);
if (i < ARP_TABLE_SIZE - 1) {
fail_unless(idx == i + 1);
} else {
/* the last entry must not overwrite the static entry! */
fail_unless(idx == 1);
}
etharp_tmr();
}
}
#if ETHARP_SUPPORT_STATIC_ENTRIES
/* create a second static entry */
err = etharp_add_static_entry(&adrs[ARP_TABLE_SIZE + 1], &test_ethaddr4);
fail_unless(err == ERR_OK);
idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == 0);
idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE + 1], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == 2);
/* and remove it again */
err = etharp_remove_static_entry(&adrs[ARP_TABLE_SIZE + 1]);
fail_unless(err == ERR_OK);
idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == 0);
idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE + 1], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == -1);
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
/* check that static entries don't time out */
etharp_remove_all();
idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == 0);
#if ETHARP_SUPPORT_STATIC_ENTRIES
/* remove the first static entry */
err = etharp_remove_static_entry(&adrs[ARP_TABLE_SIZE]);
fail_unless(err == ERR_OK);
idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == -1);
idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE + 1], &unused_ethaddr, &unused_ipaddr);
fail_unless(idx == -1);
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
udp_remove(pcb);
}
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
etharp_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_etharp_table)
};
return create_suite("ETHARP", tests, sizeof(tests) / sizeof(testfunc), etharp_setup, etharp_teardown);
}
#ifndef LWIP_HDR_TEST_ETHARP_H
#define LWIP_HDR_TEST_ETHARP_H
#include "../lwip_check.h"
Suite *etharp_suite(void);
#endif
#ifndef LWIP_HDR_TEST_IP4_H
#define LWIP_HDR_TEST_IP4_H
#include "../lwip_check.h"
Suite *ip4_suite(void);
#endif
#ifndef LWIP_HDR_TEST_IP6_H
#define LWIP_HDR_TEST_IP6_H
#include "../lwip_check.h"
Suite *ip6_suite(void);
#endif
#ifndef LWIP_HDR_LWIP_CHECK_H
#define LWIP_HDR_LWIP_CHECK_H
/* Common header file for lwIP unit tests using the check framework */
#include <config.h>
#include <check.h>
#include <stdlib.h>
#define FAIL_RET() do { fail(); return; } while(0)
#define EXPECT(x) fail_unless(x)
#define EXPECT_RET(x) do { fail_unless(x); if(!(x)) { return; }} while(0)
#define EXPECT_RETX(x, y) do { fail_unless(x); if(!(x)) { return y; }} while(0)
#define EXPECT_RETNULL(x) EXPECT_RETX(x, NULL)
#if (CHECK_MAJOR_VERSION == 0 && CHECK_MINOR_VERSION < 13)
typedef struct {
TFun func;
const char *name;
} testfunc;
#define TESTFUNC(x) {(x), "" # x "" }
/* Modified function from check.h, supplying function name */
#define tcase_add_named_test(tc,tf) \
_tcase_add_test((tc),(tf).func,(tf).name,0, 0, 0, 1)
#else
/* From 0.13.0 check keeps track of the method name internally */
typedef const TTest *testfunc;
#define TESTFUNC(x) x
#define tcase_add_named_test(tc,tf) tcase_add_test(tc,tf)
#endif
/** typedef for a function returning a test suite */
typedef Suite *(suite_getter_fn)(void);
/** Create a test suite */
Suite *create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown);
#ifdef LWIP_UNITTESTS_LIB
int lwip_unittests_run(void)
#endif
/* helper functions */
#define SKIP_POOL(x) (1 << x)
#define SKIP_HEAP (1 << MEMP_MAX)
void lwip_check_ensure_no_alloc(unsigned int skip);
#endif /* LWIP_HDR_LWIP_CHECK_H */
#ifndef LWIP_HDR_TEST_MDNS_H__
#define LWIP_HDR_TEST_MDNS_H__
#include "../lwip_check.h"
Suite *mdns_suite(void);
#endif
#ifndef LWIP_HDR_TEST_MQTT_H__
#define LWIP_HDR_TEST_MQTT_H__
#include "../lwip_check.h"
Suite *mqtt_suite(void);
#endif
#ifndef LWIP_HDR_TEST_PPPOS_H
#define LWIP_HDR_TEST_PPPOS_H
#include "../lwip_check.h"
#include "netif/ppp/ppp.h"
#if PPP_SUPPORT && PPPOS_SUPPORT
Suite *pppos_suite(void);
#endif /* PPP_SUPPORT && PPPOS_SUPPORT */
#endif /* LWIP_HDR_TEST_PPPOS_H */
#ifndef LWIP_HDR_TEST_TCP_H
#define LWIP_HDR_TEST_TCP_H
#include "../lwip_check.h"
Suite *tcp_suite(void);
#endif
#ifndef LWIP_HDR_TEST_TCP_OOS_H
#define LWIP_HDR_TEST_TCP_OOS_H
#include "../lwip_check.h"
Suite *tcp_oos_suite(void);
#endif
#ifndef LWIP_HDR_TEST_TCP_STATE_H
#define LWIP_HDR_TEST_TCP_STATE_H
#include "../lwip_check.h"
Suite *tcp_state_suite(void);
#endif
#ifndef LWIP_HDR_TEST_UDP_H
#define LWIP_HDR_TEST_UDP_H
#include "../lwip_check.h"
Suite *udp_suite(void);
#endif
/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.
Licensed under the Apache 2.0 License. */
/* This file is automatically included when compiling with -wasm -d force-c */
#define WasmSupport_check_buffer_size(X)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment