ReactOS 0.4.16-dev-257-g6aa11ac
test_netif.c File Reference
#include "test_netif.h"
#include "lwip/netif.h"
#include "lwip/stats.h"
#include "lwip/etharp.h"
#include "netif/ethernet.h"
Include dependency graph for test_netif.c:

Go to the source code of this file.

Macros

#define MAX_NSC_REASON_IDX   10
 

Functions

static void netif_setup (void)
 
static void netif_teardown (void)
 
static err_t testif_tx_func (struct netif *netif, struct pbuf *p)
 
static err_t testif_init (struct netif *netif)
 
static void test_netif_ext_callback_dummy (struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
 
static void test_netif_ext_callback (struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
 
 START_TEST (test_netif_extcallbacks)
 
END_TEST START_TEST (test_netif_flag_set)
 
END_TEST START_TEST (test_netif_find)
 
END_TEST Suite * netif_suite (void)
 

Variables

static struct netif net_test
 
static netif_nsc_reason_t expected_reasons
 
static int callback_ctr
 
static int dummy_active
 

Macro Definition Documentation

◆ MAX_NSC_REASON_IDX

#define MAX_NSC_REASON_IDX   10

Definition at line 60 of file test_netif.c.

Function Documentation

◆ netif_setup()

static void netif_setup ( void  )
static

Definition at line 18 of file test_netif.c.

19{
20 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
21}
#define SKIP_POOL(x)
Definition: lwip_check.h:48
void lwip_check_ensure_no_alloc(unsigned int skip)

Referenced by netif_suite().

◆ netif_suite()

END_TEST Suite * netif_suite ( void  )

Create the suite including all tests for this module

Definition at line 277 of file test_netif.c.

278{
279 testfunc tests[] = {
280 TESTFUNC(test_netif_extcallbacks),
281 TESTFUNC(test_netif_flag_set),
282 TESTFUNC(test_netif_find)
283 };
284 return create_suite("NETIF", tests, sizeof(tests)/sizeof(testfunc), netif_setup, netif_teardown);
285}
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define TESTFUNC(x)
Definition: lwip_check.h:22
static struct test_info tests[]
static void netif_setup(void)
Definition: test_netif.c:18
static void netif_teardown(void)
Definition: test_netif.c:24

Referenced by main().

◆ netif_teardown()

static void netif_teardown ( void  )
static

Definition at line 24 of file test_netif.c.

25{
26 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
27}

Referenced by netif_suite().

◆ START_TEST() [1/3]

START_TEST ( test_netif_extcallbacks  )

Definition at line 93 of file test_netif.c.

94{
95 ip4_addr_t addr;
96 ip4_addr_t netmask;
97 ip4_addr_t gw;
99
100 IP4_ADDR(&addr, 0, 0, 0, 0);
101 IP4_ADDR(&netmask, 0, 0, 0, 0);
102 IP4_ADDR(&gw, 0, 0, 0, 0);
103
107
108 dummy_active = 1;
109
110 /* positive tests: check that single events come as expected */
111
113 callback_ctr = 0;
114 netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
115 fail_unless(callback_ctr == 1);
116
118 callback_ctr = 0;
120 fail_unless(callback_ctr == 1);
121
123 callback_ctr = 0;
125 fail_unless(callback_ctr == 1);
126
127 IP4_ADDR(&addr, 1, 2, 3, 4);
129 callback_ctr = 0;
130 netif_set_ipaddr(&net_test, &addr);
131 fail_unless(callback_ctr == 1);
132
133 IP4_ADDR(&netmask, 255, 255, 255, 0);
135 callback_ctr = 0;
136 netif_set_netmask(&net_test, &netmask);
137 fail_unless(callback_ctr == 1);
138
139 IP4_ADDR(&gw, 1, 2, 3, 254);
141 callback_ctr = 0;
142 netif_set_gw(&net_test, &gw);
143 fail_unless(callback_ctr == 1);
144
145 IP4_ADDR(&addr, 0, 0, 0, 0);
147 callback_ctr = 0;
148 netif_set_ipaddr(&net_test, &addr);
149 fail_unless(callback_ctr == 1);
150
151 IP4_ADDR(&netmask, 0, 0, 0, 0);
153 callback_ctr = 0;
154 netif_set_netmask(&net_test, &netmask);
155 fail_unless(callback_ctr == 1);
156
157 IP4_ADDR(&gw, 0, 0, 0, 0);
159 callback_ctr = 0;
160 netif_set_gw(&net_test, &gw);
161 fail_unless(callback_ctr == 1);
162
163 /* check for multi-events (only one combined callback expected) */
164
165 IP4_ADDR(&addr, 1, 2, 3, 4);
166 IP4_ADDR(&netmask, 255, 255, 255, 0);
167 IP4_ADDR(&gw, 1, 2, 3, 254);
171 callback_ctr = 0;
172 netif_set_addr(&net_test, &addr, &netmask, &gw);
173 fail_unless(callback_ctr == 1);
174
175 /* check that for no-change, no callback is expected */
177 callback_ctr = 0;
178 netif_set_ipaddr(&net_test, &addr);
179 fail_unless(callback_ctr == 0);
180
181 netif_set_netmask(&net_test, &netmask);
182 callback_ctr = 0;
183 fail_unless(callback_ctr == 0);
184
185 callback_ctr = 0;
186 netif_set_gw(&net_test, &gw);
187 fail_unless(callback_ctr == 0);
188
189 /* netif_set_addr() always issues at least LWIP_NSC_IPV4_ADDR_VALID */
191 callback_ctr = 0;
192 netif_set_addr(&net_test, &addr, &netmask, &gw);
193 fail_unless(callback_ctr == 1);
194
195 /* check for single-events */
196 IP4_ADDR(&addr, 1, 2, 3, 5);
199 callback_ctr = 0;
200 netif_set_addr(&net_test, &addr, &netmask, &gw);
201 fail_unless(callback_ctr == 1);
202
204 callback_ctr = 0;
206 fail_unless(callback_ctr == 1);
207
209 callback_ctr = 0;
211 fail_unless(callback_ctr == 1);
212
214
215 netif_remove_ext_callback(&netif_callback_2);
216 netif_remove_ext_callback(&netif_callback_3);
217 netif_remove_ext_callback(&netif_callback_1);
218 dummy_active = 0;
219}
GLenum const GLvoid * addr
Definition: glext.h:9621
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
void netif_set_down(struct netif *netif)
Definition: netif.c:949
void netif_remove(struct netif *netif)
Definition: netif.c:764
u16_t netif_nsc_reason_t
Definition: netif.h:586
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:287
void netif_set_link_up(struct netif *netif)
Definition: netif.c:1018
void netif_set_up(struct netif *netif)
Definition: netif.c:871
#define LWIP_NSC_IPV4_GATEWAY_CHANGED
Definition: netif.h:603
#define LWIP_NSC_NONE
Definition: netif.h:589
#define LWIP_NSC_IPV4_SETTINGS_CHANGED
Definition: netif.h:607
#define LWIP_NSC_LINK_CHANGED
Definition: netif.h:595
#define LWIP_NSC_STATUS_CHANGED
Definition: netif.h:599
#define LWIP_NSC_IPV4_ADDR_VALID
Definition: netif.h:613
#define netif_add_ext_callback(callback, fn)
Definition: netif.h:684
#define LWIP_NSC_IPV4_NETMASK_CHANGED
Definition: netif.h:605
#define LWIP_NSC_NETIF_ADDED
Definition: netif.h:591
#define netif_remove_ext_callback(callback)
Definition: netif.h:685
#define LWIP_NSC_NETIF_REMOVED
Definition: netif.h:593
#define LWIP_NSC_IPV4_ADDRESS_CHANGED
Definition: netif.h:601
static netif_nsc_reason_t expected_reasons
Definition: test_netif.c:61
static void test_netif_ext_callback(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
Definition: test_netif.c:77
static int dummy_active
Definition: test_netif.c:64
static void test_netif_ext_callback_dummy(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
Definition: test_netif.c:67
static int callback_ctr
Definition: test_netif.c:62
static err_t testif_init(struct netif *netif)
Definition: test_netif.c:40
static struct netif net_test
Definition: test_netif.c:12

◆ START_TEST() [2/3]

END_TEST START_TEST ( test_netif_find  )

Definition at line 247 of file test_netif.c.

248{
249 struct netif net0;
250 struct netif net1;
251 LWIP_UNUSED_ARG(_i);
252
253 /* No netifs available */
254 fail_unless(netif_find("ch0") == NULL);
255
256 /* Add netifs with known names */
257 fail_unless(netif_add_noaddr(&net0, NULL, testif_init, ethernet_input) == &net0);
258 net0.num = 0;
259 fail_unless(netif_add_noaddr(&net1, NULL, testif_init, ethernet_input) == &net1);
260 net1.num = 1;
261
262 fail_unless(netif_find("ch0") == &net0);
263 fail_unless(netif_find("CH0") == NULL);
264 fail_unless(netif_find("ch1") == &net1);
265 fail_unless(netif_find("ch3") == NULL);
266 /* atoi failure is not treated as zero */
267 fail_unless(netif_find("chX") == NULL);
268 fail_unless(netif_find("ab0") == NULL);
269
270 netif_remove(&net0);
271 netif_remove(&net1);
272}
#define NULL
Definition: types.h:112
struct netif * netif_find(const char *name)
Definition: netif.c:1755
struct netif * netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:250
Definition: netif.h:269

◆ START_TEST() [3/3]

END_TEST START_TEST ( test_netif_flag_set  )

Definition at line 222 of file test_netif.c.

223{
224 ip4_addr_t addr;
225 ip4_addr_t netmask;
226 ip4_addr_t gw;
227 LWIP_UNUSED_ARG(_i);
228
229 IP4_ADDR(&addr, 0, 0, 0, 0);
230 IP4_ADDR(&netmask, 0, 0, 0, 0);
231 IP4_ADDR(&gw, 0, 0, 0, 0);
232
233 netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
234
242
244}
#define NETIF_FLAG_LINK_UP
Definition: netif.h:93
#define NETIF_FLAG_ETHERNET
Definition: netif.h:101
#define NETIF_FLAG_ETHARP
Definition: netif.h:97
#define NETIF_FLAG_MLD6
Definition: netif.h:107
#define NETIF_FLAG_UP
Definition: netif.h:84
#define NETIF_FLAG_IGMP
Definition: netif.h:104
#define NETIF_FLAG_BROADCAST
Definition: netif.h:87
#define netif_is_flag_set(netif, flag)
Definition: netif.h:472

◆ test_netif_ext_callback()

static void test_netif_ext_callback ( struct netif netif,
netif_nsc_reason_t  reason,
const netif_ext_callback_args_t args 
)
static

Definition at line 77 of file test_netif.c.

78{
79 LWIP_UNUSED_ARG(args); /* @todo */
81
82 fail_unless(netif == &net_test);
83
84 fail_unless(expected_reasons == reason);
85}
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
Definition: match.c:390

Referenced by START_TEST().

◆ test_netif_ext_callback_dummy()

static void test_netif_ext_callback_dummy ( struct netif netif,
netif_nsc_reason_t  reason,
const netif_ext_callback_args_t args 
)
static

Definition at line 67 of file test_netif.c.

68{
72
73 fail_unless(dummy_active);
74}

Referenced by START_TEST().

◆ testif_init()

static err_t testif_init ( struct netif netif)
static

Definition at line 40 of file test_netif.c.

41{
42 netif->name[0] = 'c';
43 netif->name[1] = 'h';
44 netif->output = etharp_output;
46 netif->mtu = 1500;
47 netif->hwaddr_len = 6;
49
50 netif->hwaddr[0] = 0x02;
51 netif->hwaddr[1] = 0x03;
52 netif->hwaddr[2] = 0x04;
53 netif->hwaddr[3] = 0x05;
54 netif->hwaddr[4] = 0x06;
55 netif->hwaddr[5] = 0x07;
56
57 return ERR_OK;
58}
@ ERR_OK
Definition: err.h:55
u8_t flags
Definition: netif.h:354
char name[2]
Definition: netif.h:356
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:350
u16_t mtu
Definition: netif.h:344
netif_linkoutput_fn linkoutput
Definition: netif.h:308
u8_t hwaddr_len
Definition: netif.h:352
static err_t testif_tx_func(struct netif *netif, struct pbuf *p)
Definition: test_netif.c:32

Referenced by START_TEST().

◆ testif_tx_func()

static err_t testif_tx_func ( struct netif netif,
struct pbuf p 
)
static

Definition at line 32 of file test_netif.c.

33{
36 return ERR_OK;
37}
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by testif_init().

Variable Documentation

◆ callback_ctr

int callback_ctr
static

Definition at line 62 of file test_netif.c.

Referenced by START_TEST(), and test_netif_ext_callback().

◆ dummy_active

int dummy_active
static

Definition at line 64 of file test_netif.c.

Referenced by START_TEST(), and test_netif_ext_callback_dummy().

◆ expected_reasons

netif_nsc_reason_t expected_reasons
static

Definition at line 61 of file test_netif.c.

Referenced by START_TEST(), and test_netif_ext_callback().

◆ net_test

struct netif net_test
static

Definition at line 12 of file test_netif.c.

Referenced by lwip_fuzztest(), START_TEST(), and test_netif_ext_callback().