fb11e647
vrobic
reseau statique a...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
/*
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
*
* @file
*/
#include <errno.h>
#include <stdlib.h>
#include "embUnit.h"
#include "net/ipv6/addr.h"
#include "net/gnrc/ipv6/nc.h"
#include "net/gnrc/ipv6/netif.h"
#include "unittests-constants.h"
#include "tests-ipv6_nc.h"
/* default interface for testing */
#define DEFAULT_TEST_NETIF (TEST_UINT16)
/* default IPv6 addr for testing */
#define DEFAULT_TEST_IPV6_ADDR { { \
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f \
} \
}
/* another interface for testing */
#define OTHER_TEST_NETIF (TEST_UINT16 + TEST_UINT8)
/* another IPv6 addr for testing */
#define OTHER_TEST_IPV6_ADDR { { \
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f \
} \
}
/* a third IPv6 addr for testing */
#define THIRD_TEST_IPV6_ADDR { { \
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f \
} \
}
static void set_up(void)
{
gnrc_ipv6_nc_init();
gnrc_ipv6_netif_add(DEFAULT_TEST_NETIF);
}
static void tear_down(void)
{
/* remove all ncache entries, this is necesaary in case
* the last test initializes timers. */
gnrc_ipv6_nc_init();
gnrc_ipv6_netif_init();
}
static void test_ipv6_nc_add__address_registered(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry1, *entry2;
TEST_ASSERT_NOT_NULL((entry1 = gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
sizeof(TEST_STRING4), 0)));
TEST_ASSERT_NOT_NULL((entry2 = gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
sizeof(TEST_STRING4), 0)));
TEST_ASSERT(entry1 == entry2);
}
static void test_ipv6_nc_add__address_NULL(void)
{
TEST_ASSERT_NULL(gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, NULL, TEST_STRING4,
sizeof(TEST_STRING4), 0));
}
static void test_ipv6_nc_add__iface_KERNEL_PID_UNDEF(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_add(KERNEL_PID_UNDEF, &addr, TEST_STRING4,
sizeof(TEST_STRING4), 0));
}
static void test_ipv6_nc_add__addr_unspecified(void)
{
ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
TEST_ASSERT_NULL(gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
sizeof(TEST_STRING4), 0));
}
static void test_ipv6_nc_add__l2addr_too_long(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
TEST_ASSERT_NULL(gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
GNRC_IPV6_NC_L2_ADDR_MAX + TEST_UINT8, 0));
}
static void test_ipv6_nc_add__full(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
for (int i = 0; i < GNRC_IPV6_NC_SIZE; i++) {
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
sizeof(TEST_STRING4), 0));
addr.u16[7].u16++;
}
TEST_ASSERT_NULL(gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
sizeof(TEST_STRING4), 0));
}
static void test_ipv6_nc_add__success(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry1, *entry2;
TEST_ASSERT_NOT_NULL((entry1 = gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING4,
sizeof(TEST_STRING4), 0)));
TEST_ASSERT_NOT_NULL((entry2 = gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr)));
TEST_ASSERT(entry1 == entry2);
}
static void test_ipv6_nc_add__address_update_despite_free_entry(void)
{
ipv6_addr_t default_addr = DEFAULT_TEST_IPV6_ADDR;
ipv6_addr_t other_addr = OTHER_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry1, *entry2;
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_add(OTHER_TEST_NETIF, &other_addr, TEST_STRING4,
sizeof(TEST_STRING4), 0));
TEST_ASSERT_NOT_NULL((entry1 = gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &default_addr, TEST_STRING4,
sizeof(TEST_STRING4), 0)));
/* create space by removing first entry and see if duplicate is still detected & updated */
gnrc_ipv6_nc_remove(OTHER_TEST_NETIF, &other_addr);
TEST_ASSERT_NOT_NULL((entry2 = gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &default_addr, TEST_STRING4,
sizeof(TEST_STRING4), 0)));
TEST_ASSERT(entry1 == entry2);
}
static void test_ipv6_nc_remove__no_entry_pid(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
gnrc_ipv6_nc_remove(OTHER_TEST_NETIF, &addr);
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr));
TEST_ASSERT_NULL(gnrc_ipv6_nc_get(OTHER_TEST_NETIF, &addr));
}
static void test_ipv6_nc_remove__no_entry_addr1(void)
{
ipv6_addr_t addr = OTHER_TEST_IPV6_ADDR;
ipv6_addr_t exp_addr = DEFAULT_TEST_IPV6_ADDR;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
gnrc_ipv6_nc_remove(DEFAULT_TEST_NETIF, &addr);
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &exp_addr));
TEST_ASSERT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr));
}
static void test_ipv6_nc_remove__no_entry_addr2(void)
{
ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
ipv6_addr_t exp_addr = DEFAULT_TEST_IPV6_ADDR;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
gnrc_ipv6_nc_remove(DEFAULT_TEST_NETIF, &addr);
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &exp_addr));
TEST_ASSERT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr));
}
static void test_ipv6_nc_remove__success(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr));
gnrc_ipv6_nc_remove(DEFAULT_TEST_NETIF, &addr);
TEST_ASSERT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr));
}
static void test_ipv6_nc_get__empty(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
TEST_ASSERT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr));
}
static void test_ipv6_nc_get__different_if(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NULL(gnrc_ipv6_nc_get(OTHER_TEST_NETIF, &addr));
}
static void test_ipv6_nc_get__different_addr(void)
{
ipv6_addr_t addr = OTHER_TEST_IPV6_ADDR;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NULL(gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr));
}
static void test_ipv6_nc_get__success_if_local(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr)));
TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, entry->iface);
TEST_ASSERT(ipv6_addr_equal(&(entry->ipv6_addr), &addr));
TEST_ASSERT_EQUAL_STRING(TEST_STRING4, (char *)entry->l2_addr);
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), entry->l2_addr_len);
TEST_ASSERT_EQUAL_INT(0, entry->flags);
}
static void test_ipv6_nc_get__success_if_global(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, entry->iface);
TEST_ASSERT(ipv6_addr_equal(&(entry->ipv6_addr), &addr));
TEST_ASSERT_EQUAL_STRING(TEST_STRING4, (char *)entry->l2_addr);
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), entry->l2_addr_len);
TEST_ASSERT_EQUAL_INT(0, entry->flags);
}
static void test_ipv6_nc_get_next__empty(void)
{
TEST_ASSERT_NULL(gnrc_ipv6_nc_get_next(NULL));
}
static void test_ipv6_nc_get_next__1_entry(void)
{
gnrc_ipv6_nc_t *entry = NULL;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get_next(NULL)));
TEST_ASSERT_NULL(gnrc_ipv6_nc_get_next(entry));
}
static void test_ipv6_nc_get_next__2_entries(void)
{
ipv6_addr_t addr = OTHER_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr, TEST_STRING8,
sizeof(TEST_STRING8) - 1, 0));
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get_next(NULL)));
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get_next(entry)));
TEST_ASSERT_NULL(gnrc_ipv6_nc_get_next(entry));
}
static void test_ipv6_nc_get_next__holey(void)
{
ipv6_addr_t addr1 = OTHER_TEST_IPV6_ADDR;
ipv6_addr_t addr2 = THIRD_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL, *exp_entry = NULL;
/* adds DEFAULT_TEST_IPV6_ADDR and OTHER_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
test_ipv6_nc_get_next__2_entries();
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_add(DEFAULT_TEST_NETIF, &addr2, TEST_STRING8,
sizeof(TEST_STRING8) - 2, 0));
TEST_ASSERT_NOT_NULL((exp_entry = gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr2)));
gnrc_ipv6_nc_remove(DEFAULT_TEST_NETIF, &addr1);
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get_next(NULL)));
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get_next(entry)));
TEST_ASSERT(exp_entry == entry);
TEST_ASSERT_NULL(gnrc_ipv6_nc_get_next(entry));
}
static void test_ipv6_nc_get_next_router__empty(void)
{
TEST_ASSERT_NULL(gnrc_ipv6_nc_get_next_router(NULL));
}
static void test_ipv6_nc_get_next_router__first_entry(void)
{
gnrc_ipv6_nc_t *entry = NULL;
/* adds DEFAULT_TEST_IPV6_ADDR and OTHER_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
test_ipv6_nc_get_next__2_entries();
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get_next(NULL)));
entry->flags = (GNRC_IPV6_NC_STATE_REACHABLE << GNRC_IPV6_NC_STATE_POS);
entry->flags |= GNRC_IPV6_NC_IS_ROUTER;
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get_next_router(NULL)));
TEST_ASSERT_NULL(gnrc_ipv6_nc_get_next_router(entry));
}
static void test_ipv6_nc_get_next_router__second_entry(void)
{
gnrc_ipv6_nc_t *entry1 = NULL, *entry2 = NULL;
/* adds DEFAULT_TEST_IPV6_ADDR and OTHER_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
test_ipv6_nc_get_next__2_entries();
TEST_ASSERT_NOT_NULL((entry1 = gnrc_ipv6_nc_get_next(NULL)));
TEST_ASSERT_NOT_NULL((entry2 = gnrc_ipv6_nc_get_next(entry1)));
entry2->flags = (GNRC_IPV6_NC_STATE_REACHABLE << GNRC_IPV6_NC_STATE_POS);
entry2->flags |= GNRC_IPV6_NC_IS_ROUTER;
TEST_ASSERT_NOT_NULL((entry1 = gnrc_ipv6_nc_get_next_router(NULL)));
TEST_ASSERT(entry2 == entry1);
TEST_ASSERT_NULL(gnrc_ipv6_nc_get_next_router(entry1));
}
static void test_ipv6_nc_is_reachable__incomplete(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
entry->flags = (GNRC_IPV6_NC_STATE_INCOMPLETE << GNRC_IPV6_NC_STATE_POS);
TEST_ASSERT(!gnrc_ipv6_nc_is_reachable(entry));
}
static void test_ipv6_nc_is_reachable__reachable(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr)));
entry->flags = (GNRC_IPV6_NC_STATE_REACHABLE << GNRC_IPV6_NC_STATE_POS);
TEST_ASSERT(gnrc_ipv6_nc_is_reachable(entry));
}
static void test_ipv6_nc_is_reachable__unmanaged(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(DEFAULT_TEST_NETIF, &addr)));
entry->flags = (GNRC_IPV6_NC_STATE_UNMANAGED << GNRC_IPV6_NC_STATE_POS);
TEST_ASSERT(gnrc_ipv6_nc_is_reachable(entry));
}
static void test_ipv6_nc_still_reachable__incomplete(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
/* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF and sets flags to
* (GNRC_IPV6_NC_STATE_INCOMPLETE << GNRC_IPV6_NC_STATE_POS) */
test_ipv6_nc_is_reachable__incomplete();
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
TEST_ASSERT(!gnrc_ipv6_nc_is_reachable(entry));
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_still_reachable(&addr));
TEST_ASSERT(!gnrc_ipv6_nc_is_reachable(entry));
}
static void test_ipv6_nc_still_reachable__success(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
/* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF and sets flags to
* (GNRC_IPV6_NC_STATE_REACHABLE << GNRC_IPV6_NC_STATE_POS) */
test_ipv6_nc_is_reachable__reachable();
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
TEST_ASSERT(gnrc_ipv6_nc_is_reachable(entry));
entry->flags = (GNRC_IPV6_NC_STATE_STALE << GNRC_IPV6_NC_STATE_POS);
TEST_ASSERT_NOT_NULL(gnrc_ipv6_nc_still_reachable(&addr));
TEST_ASSERT(gnrc_ipv6_nc_is_reachable(entry));
}
static void test_ipv6_nc_get_l2_addr__NULL_entry(void)
{
gnrc_ipv6_nc_t *entry = NULL;
uint8_t l2_addr[GNRC_IPV6_NC_L2_ADDR_MAX];
uint8_t l2_addr_len = 0;
TEST_ASSERT_EQUAL_INT(KERNEL_PID_UNDEF,
gnrc_ipv6_nc_get_l2_addr(l2_addr, &l2_addr_len, entry));
}
static void test_ipv6_nc_get_l2_addr__unreachable(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
uint8_t l2_addr[GNRC_IPV6_NC_L2_ADDR_MAX];
uint8_t l2_addr_len = 0;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
entry->flags = (GNRC_IPV6_NC_STATE_INCOMPLETE << GNRC_IPV6_NC_STATE_POS);
TEST_ASSERT_EQUAL_INT(KERNEL_PID_UNDEF,
gnrc_ipv6_nc_get_l2_addr(l2_addr, &l2_addr_len, entry));
}
static void test_ipv6_nc_get_l2_addr__reachable(void)
{
ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
gnrc_ipv6_nc_t *entry = NULL;
uint8_t l2_addr[GNRC_IPV6_NC_L2_ADDR_MAX];
uint8_t l2_addr_len = 0;
test_ipv6_nc_add__success(); /* adds DEFAULT_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_nc_get(KERNEL_PID_UNDEF, &addr)));
entry->flags = (GNRC_IPV6_NC_STATE_REACHABLE << GNRC_IPV6_NC_STATE_POS);
TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF,
gnrc_ipv6_nc_get_l2_addr(l2_addr, &l2_addr_len, entry));
TEST_ASSERT_EQUAL_STRING(TEST_STRING4, (char *)l2_addr);
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), l2_addr_len);
}
Test *tests_ipv6_nc_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_ipv6_nc_add__address_registered),
new_TestFixture(test_ipv6_nc_add__address_NULL),
new_TestFixture(test_ipv6_nc_add__iface_KERNEL_PID_UNDEF),
new_TestFixture(test_ipv6_nc_add__addr_unspecified),
new_TestFixture(test_ipv6_nc_add__l2addr_too_long),
new_TestFixture(test_ipv6_nc_add__full),
new_TestFixture(test_ipv6_nc_add__success),
new_TestFixture(test_ipv6_nc_add__address_update_despite_free_entry),
new_TestFixture(test_ipv6_nc_remove__no_entry_pid),
new_TestFixture(test_ipv6_nc_remove__no_entry_addr1),
new_TestFixture(test_ipv6_nc_remove__no_entry_addr2),
new_TestFixture(test_ipv6_nc_remove__success),
new_TestFixture(test_ipv6_nc_get__empty),
new_TestFixture(test_ipv6_nc_get__different_if),
new_TestFixture(test_ipv6_nc_get__different_addr),
new_TestFixture(test_ipv6_nc_get__success_if_local),
new_TestFixture(test_ipv6_nc_get__success_if_global),
new_TestFixture(test_ipv6_nc_get_next__empty),
new_TestFixture(test_ipv6_nc_get_next__1_entry),
new_TestFixture(test_ipv6_nc_get_next__2_entries),
new_TestFixture(test_ipv6_nc_get_next__holey),
new_TestFixture(test_ipv6_nc_get_next_router__empty),
new_TestFixture(test_ipv6_nc_get_next_router__first_entry),
new_TestFixture(test_ipv6_nc_get_next_router__second_entry),
new_TestFixture(test_ipv6_nc_is_reachable__incomplete),
new_TestFixture(test_ipv6_nc_is_reachable__reachable),
new_TestFixture(test_ipv6_nc_is_reachable__unmanaged),
new_TestFixture(test_ipv6_nc_still_reachable__incomplete),
new_TestFixture(test_ipv6_nc_still_reachable__success),
new_TestFixture(test_ipv6_nc_get_l2_addr__NULL_entry),
new_TestFixture(test_ipv6_nc_get_l2_addr__unreachable),
new_TestFixture(test_ipv6_nc_get_l2_addr__reachable),
};
EMB_UNIT_TESTCALLER(ipv6_nc_tests, set_up, tear_down, fixtures);
return (Test *)&ipv6_nc_tests;
}
void tests_ipv6_nc(void)
{
TESTS_RUN(tests_ipv6_nc_tests());
}
/** @} */
|