ReactOS 0.4.16-dev-297-gc569aee
test_netif.c
Go to the documentation of this file.
1#include "test_netif.h"
2
3#include "lwip/netif.h"
4#include "lwip/stats.h"
5#include "lwip/etharp.h"
6#include "netif/ethernet.h"
7
8#if !LWIP_NETIF_EXT_STATUS_CALLBACK
9#error "This tests needs LWIP_NETIF_EXT_STATUS_CALLBACK enabled"
10#endif
11
12static struct netif net_test;
13
14
15/* Setups/teardown functions */
16
17static void
19{
20 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
21}
22
23static void
25{
26 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
27}
28
29/* test helper functions */
30
31static err_t
32testif_tx_func(struct netif *netif, struct pbuf *p)
33{
36 return ERR_OK;
37}
38
39static err_t
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}
59
60#define MAX_NSC_REASON_IDX 10
62static int callback_ctr;
63
64static int dummy_active;
65
66static void
68{
72
73 fail_unless(dummy_active);
74}
75
76static void
78{
79 LWIP_UNUSED_ARG(args); /* @todo */
81
82 fail_unless(netif == &net_test);
83
84 fail_unless(expected_reasons == reason);
85}
86
87/* Test functions */
88
89NETIF_DECLARE_EXT_CALLBACK(netif_callback_1)
90NETIF_DECLARE_EXT_CALLBACK(netif_callback_2)
91NETIF_DECLARE_EXT_CALLBACK(netif_callback_3)
92
93START_TEST(test_netif_extcallbacks)
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}
220END_TEST
221
222START_TEST(test_netif_flag_set)
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}
245END_TEST
246
247START_TEST(test_netif_find)
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}
273END_TEST
274
276Suite *
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}
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
GLenum const GLvoid * addr
Definition: glext.h:9621
GLfloat GLfloat p
Definition: glext.h:8902
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
s8_t err_t
Definition: err.h:96
@ ERR_OK
Definition: err.h:55
#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
struct netif * netif_find(const char *name)
Definition: netif.c:1755
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
struct netif * netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:250
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define SKIP_POOL(x)
Definition: lwip_check.h:48
void lwip_check_ensure_no_alloc(unsigned int skip)
#define TESTFUNC(x)
Definition: lwip_check.h:22
static struct test_info tests[]
#define netif_is_flag_set(netif, flag)
Definition: netif.h:472
#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 NETIF_DECLARE_EXT_CALLBACK(name)
Definition: netif.h:683
#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
Definition: match.c:390
Definition: netif.h:269
u8_t flags
Definition: netif.h:354
char name[2]
Definition: netif.h:356
u8_t num
Definition: netif.h:359
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
Definition: pbuf.h:186
static netif_nsc_reason_t expected_reasons
Definition: test_netif.c:61
static void netif_setup(void)
Definition: test_netif.c:18
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
END_TEST Suite * netif_suite(void)
Definition: test_netif.c:277
static err_t testif_tx_func(struct netif *netif, struct pbuf *p)
Definition: test_netif.c:32
static int callback_ctr
Definition: test_netif.c:62
static void netif_teardown(void)
Definition: test_netif.c:24
static err_t testif_init(struct netif *netif)
Definition: test_netif.c:40
static struct netif net_test
Definition: test_netif.c:12