Blame view

RIOT/tests/unittests/tests-ipv6_netif/tests-ipv6_netif.c 21.1 KB
a752c7ab   elopes   add first test an...
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
  /*
   * Copyright (C) 2015 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 <stdint.h>
  #include <stdlib.h>
  
  #include "embUnit/embUnit.h"
  
  #include "byteorder.h"
  #include "net/gnrc/netif.h"
  #include "net/gnrc/ipv6/netif.h"
  
  #include "unittests-constants.h"
  #include "tests-ipv6_netif.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 \
          } \
      }
  /* default IPv6 prefix length */
  #define DEFAULT_TEST_PREFIX_LEN (18)
  
  /* another interface for testing */
  #define OTHER_TEST_NETIF        (TEST_UINT16 + TEST_UINT8)
  /* another IPv6 addr for testing */
  #define OTHER_TEST_IPV6_ADDR    { { \
              0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
              0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f \
          } \
      }
  /* matches DEFAULT_TEST_IPV6_ADDR with 18 byte */
  #define DEFAULT_TEST_IPV6_PREFIX18  { { \
              0x00, 0x01, 0x22, 0x03, 0x04, 0x05, 0x06, 0x07, \
              0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f \
          } \
      }
  /* matches DEFAULT_TEST_IPV6_ADDR with 23 byte */
  #define DEFAULT_TEST_IPV6_PREFIX23  { { \
              0x00, 0x01, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07, \
              0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f \
          } \
      }
  /* matches DEFAULT_TEST_IPV6_ADDR with 64 byte */
  #define DEFAULT_TEST_IPV6_PREFIX64  { { \
              0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
              0x88, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f \
          } \
      }
  
  static void set_up(void)
  {
      gnrc_netif_init();
      gnrc_ipv6_netif_init();
  }
  
  static void test_ipv6_netif_add__success(void)
  {
      gnrc_ipv6_netif_t *entry;
  
      gnrc_ipv6_netif_add(DEFAULT_TEST_NETIF);
  
      TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_netif_get(DEFAULT_TEST_NETIF)));
      TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, entry->pid);
  }
  
  static void test_netif_add__success_with_ipv6(void)
  {
      kernel_pid_t pids[GNRC_NETIF_NUMOF];
      size_t pid_num;
      gnrc_ipv6_netif_t *entry;
      ipv6_addr_t exp_addr = IPV6_ADDR_ALL_NODES_LINK_LOCAL;
  
      gnrc_netif_add(DEFAULT_TEST_NETIF);
  
      TEST_ASSERT_EQUAL_INT(1, (pid_num = gnrc_netif_get(pids)));
      TEST_ASSERT_EQUAL_INT(1, pid_num);
      TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, pids[0]);
      TEST_ASSERT_NOT_NULL((entry = gnrc_ipv6_netif_get(DEFAULT_TEST_NETIF)));
      TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, entry->pid);
      TEST_ASSERT_EQUAL_STRING((char *)exp_addr.u8, (char *)entry->addrs[0].addr.u8);
  }
  
  static void test_ipv6_netif_add__despite_free_entry(void)
  {
      /* Tests for possible duplicates as described in http://github.com/RIOT-OS/RIOT/issues/2965 */
  
      gnrc_ipv6_netif_add(OTHER_TEST_NETIF);
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      /* create space by removing first entry */
      gnrc_ipv6_netif_remove(OTHER_TEST_NETIF);
  
      /* add DEFAULT_TEST_NETIF yet again and remove it */
      test_ipv6_netif_add__success();
      gnrc_ipv6_netif_remove(DEFAULT_TEST_NETIF);
  
      /* see if there's a duplicate left */
      TEST_ASSERT_NULL(gnrc_ipv6_netif_get(DEFAULT_TEST_NETIF));
  }
  
  static void test_ipv6_netif_remove__not_allocated(void)
  {
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
      gnrc_ipv6_netif_remove(OTHER_TEST_NETIF);
      TEST_ASSERT_NULL(gnrc_ipv6_netif_get(OTHER_TEST_NETIF));
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_get(DEFAULT_TEST_NETIF));
  }
  
  static void test_ipv6_netif_remove__success(void)
  {
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
      gnrc_ipv6_netif_remove(DEFAULT_TEST_NETIF);
      TEST_ASSERT_NULL(gnrc_ipv6_netif_get(DEFAULT_TEST_NETIF));
  }
  
  static void test_ipv6_netif_get__empty(void)
  {
      for (kernel_pid_t pid = KERNEL_PID_FIRST; pid <= KERNEL_PID_LAST; pid++) {
          TEST_ASSERT_NULL(gnrc_ipv6_netif_get(pid));
      }
  }
  
  static void test_ipv6_netif_add_addr__no_iface1(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN, 0));
  }
  
  static void test_ipv6_netif_add_addr__no_iface2(void)
  {
      TEST_ASSERT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, NULL, DEFAULT_TEST_PREFIX_LEN, 0));
  }
  
  static void test_ipv6_netif_add_addr__addr_NULL(void)
  {
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, NULL, DEFAULT_TEST_PREFIX_LEN, 0));
  }
  
  static void test_ipv6_netif_add_addr__addr_unspecified(void)
  {
      ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN, 0));
  }
  
  static void test_ipv6_netif_add_addr__full(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR, *res = &addr;
      int i;
  
      /* make link local to avoid automatic link local adding */
      ipv6_addr_set_link_local_prefix(&addr);
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      for (i = 0; res != NULL; i++, addr.u8[15]++) {
          res =  gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN, 0);
      }
  }
  
  static void test_ipv6_netif_add_addr__success(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr,
                                                    DEFAULT_TEST_PREFIX_LEN, 0));
  }
  
  static void test_ipv6_netif_add_addr__despite_free_entry(void)
  {
      /* Tests for possible duplicates as described in http://github.com/RIOT-OS/RIOT/issues/2965 */
      ipv6_addr_t *entry_1;
      ipv6_addr_t *entry_2;
  
      ipv6_addr_t default_addr = DEFAULT_TEST_IPV6_ADDR;
      ipv6_addr_t sol_addr;
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      /* add addresses to the interface */
      TEST_ASSERT_NOT_NULL((entry_1 = gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &default_addr,
                                                               DEFAULT_TEST_PREFIX_LEN, 0)));
  
      /* remove default_addr, but not the corresponding solicited-node addr that
       * came with it */
      gnrc_ipv6_netif_remove_addr(DEFAULT_TEST_NETIF, &default_addr);
  
      /* create and re-add corresponding solicited node address and check that it
       * hasn't taken the old place of default_addr*/
      ipv6_addr_set_solicited_nodes(&sol_addr, &default_addr);
      TEST_ASSERT_NOT_NULL((entry_2 = gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &sol_addr,
                                                               DEFAULT_TEST_PREFIX_LEN, 0)));
  
      TEST_ASSERT(entry_1 != entry_2);
  }
  
  static void test_ipv6_netif_remove_addr__not_allocated(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
      ipv6_addr_t other_addr = OTHER_TEST_IPV6_ADDR;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      gnrc_ipv6_netif_remove_addr(DEFAULT_TEST_NETIF, &other_addr);
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &other_addr));
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr));
  }
  
  static void test_ipv6_netif_remove_addr__success(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      gnrc_ipv6_netif_remove_addr(DEFAULT_TEST_NETIF, &addr);
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr));
  }
  
  static void test_ipv6_netif_reset_addr__success(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      gnrc_ipv6_netif_reset_addr(DEFAULT_TEST_NETIF);
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr));
  }
  
  static void test_ipv6_netif_find_by_addr__empty(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
      ipv6_addr_t *out = NULL;
  
      TEST_ASSERT_EQUAL_INT(KERNEL_PID_UNDEF, gnrc_ipv6_netif_find_by_addr(&out, &addr));
      TEST_ASSERT_NULL(out);
  }
  
  static void test_ipv6_netif_find_by_addr__success(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, gnrc_ipv6_netif_find_by_addr(&out, &addr));
      TEST_ASSERT_NOT_NULL(out);
      TEST_ASSERT(out != &addr);
      TEST_ASSERT_EQUAL_INT(true, ipv6_addr_equal(out, &addr));
  }
  
  static void test_ipv6_netif_find_addr__no_iface(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr));
  }
  
  static void test_ipv6_netif_find_addr__wrong_iface(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_find_addr(OTHER_TEST_NETIF, &addr));
  }
  
  static void test_ipv6_netif_find_addr__wrong_addr(void)
  {
      ipv6_addr_t addr = OTHER_TEST_IPV6_ADDR;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr));
  }
  
  static void test_ipv6_netif_find_addr__success(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT(out != &addr);
      TEST_ASSERT_EQUAL_INT(true, ipv6_addr_equal(out, &addr));
  
      /* also test for link local address */
      ipv6_addr_set_solicited_nodes(&addr, &addr);
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT_EQUAL_INT(true, ipv6_addr_equal(out, &addr));
  }
  
  static void test_ipv6_netif_find_by_prefix__success1(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_PREFIX23;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, gnrc_ipv6_netif_find_by_prefix(&out, &addr));
      TEST_ASSERT_NOT_NULL(out);
      TEST_ASSERT(out != &addr);
      TEST_ASSERT_EQUAL_INT(23, ipv6_addr_match_prefix(out, &addr));
  }
  
  static void test_ipv6_netif_find_by_prefix__success2(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_PREFIX18;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, gnrc_ipv6_netif_find_by_prefix(&out, &addr));
      TEST_ASSERT_NOT_NULL(out);
      TEST_ASSERT(out != &addr);
      TEST_ASSERT_EQUAL_INT(18, ipv6_addr_match_prefix(out, &addr));
  }
  
  static void test_ipv6_netif_find_by_prefix__success3(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_PREFIX64;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, gnrc_ipv6_netif_find_by_prefix(&out, &addr));
      TEST_ASSERT_NOT_NULL(out);
      TEST_ASSERT(out != &addr);
      TEST_ASSERT_EQUAL_INT(64, ipv6_addr_match_prefix(out, &addr));
  }
  
  static void test_ipv6_netif_match_prefix__success1(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_PREFIX23;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_match_prefix(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT(out != &addr);
      TEST_ASSERT_EQUAL_INT(23, ipv6_addr_match_prefix(out, &addr));
  }
  
  static void test_ipv6_netif_match_prefix__success2(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_PREFIX18;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_match_prefix(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT(out != &addr);
      TEST_ASSERT_EQUAL_INT(18, ipv6_addr_match_prefix(out, &addr));
  }
  
  static void test_ipv6_netif_match_prefix__success3(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_PREFIX64;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_match_prefix(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT(out != &addr);
      TEST_ASSERT_EQUAL_INT(64, ipv6_addr_match_prefix(out, &addr));
  }
  
  static void test_ipv6_netif_find_best_src_addr__no_unicast(void)
  {
      ipv6_addr_t ll_dst_addr = IPV6_ADDR_UNSPECIFIED;
      ipv6_addr_t mc_addr1 = IPV6_ADDR_ALL_NODES_LINK_LOCAL;
      ipv6_addr_t mc_addr2 = IPV6_ADDR_ALL_ROUTERS_SITE_LOCAL;
  
      ll_dst_addr.u8[15] = 1;
      ipv6_addr_set_link_local_prefix(&ll_dst_addr);
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &mc_addr1,
                                                    DEFAULT_TEST_PREFIX_LEN, 0));
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &mc_addr2,
                                                    DEFAULT_TEST_PREFIX_LEN, 0));
  
      TEST_ASSERT_NULL(gnrc_ipv6_netif_find_best_src_addr(DEFAULT_TEST_NETIF, &ll_dst_addr, false));
  }
  
  static void test_ipv6_netif_find_best_src_addr__success(void)
  {
      ipv6_addr_t ll_addr1 = IPV6_ADDR_UNSPECIFIED;
      ipv6_addr_t ll_addr2 = IPV6_ADDR_UNSPECIFIED;
      ipv6_addr_t mc_addr = IPV6_ADDR_ALL_NODES_LINK_LOCAL;
      ipv6_addr_t *out = NULL;
  
      ll_addr1.u8[15] = 1;
      ipv6_addr_set_link_local_prefix(&ll_addr1);
      ll_addr2.u8[15] = 2;
      ipv6_addr_set_link_local_prefix(&ll_addr2);
  
      TEST_ASSERT_EQUAL_INT(126, ipv6_addr_match_prefix(&ll_addr2, &ll_addr1));
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &mc_addr,
                                                    DEFAULT_TEST_PREFIX_LEN, 0));
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &ll_addr1,
                                                    DEFAULT_TEST_PREFIX_LEN, 0));
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_best_src_addr(DEFAULT_TEST_NETIF, &ll_addr2, false)));
      TEST_ASSERT(out != &ll_addr1);
      TEST_ASSERT(out != &ll_addr2);
      TEST_ASSERT_EQUAL_INT(true, ipv6_addr_equal(out, &ll_addr1));
  }
  
  static void test_ipv6_netif_find_best_src_addr__multicast_input(void)
  {
      ipv6_addr_t mc_addr = IPV6_ADDR_ALL_ROUTERS_LINK_LOCAL;
      ipv6_addr_t *out = NULL;
  
      /* Adds DEFAULT_TEST_NETIF as interface and to it fe80::1, fe80::2 and ff02::1 */
      test_ipv6_netif_find_best_src_addr__success();
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_best_src_addr(DEFAULT_TEST_NETIF, &mc_addr, false)));
      TEST_ASSERT_EQUAL_INT(false, ipv6_addr_equal(&mc_addr, out));
      TEST_ASSERT_EQUAL_INT(false, ipv6_addr_is_unspecified(out));
  }
  
  static void test_ipv6_netif_find_best_src_addr__other_subnet(void)
  {
      ipv6_addr_t addr1 = DEFAULT_TEST_IPV6_ADDR;
      ipv6_addr_t addr2 = OTHER_TEST_IPV6_ADDR;
  
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr1, DEFAULT_TEST_PREFIX_LEN,
                           0));
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_best_src_addr(DEFAULT_TEST_NETIF, &addr2, false)));
      TEST_ASSERT(out != &addr1);
      TEST_ASSERT_EQUAL_INT(true, ipv6_addr_equal(out, &addr1));
  }
  
  static void test_ipv6_netif_addr_is_non_unicast__unicast(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add_addr__success(); /* adds DEFAULT_TEST_IPV6_ADDR to
                                            * DEFAULT_TEST_NETIF */
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT_EQUAL_INT(false, gnrc_ipv6_netif_addr_is_non_unicast(out));
  }
  
  static void test_ipv6_netif_addr_is_non_unicast__anycast(void)
  {
      ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN,
                           GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST));
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT_EQUAL_INT(true, gnrc_ipv6_netif_addr_is_non_unicast(out));
  }
  
  static void test_ipv6_netif_addr_is_non_unicast__multicast1(void)
  {
      ipv6_addr_t addr = IPV6_ADDR_ALL_ROUTERS_LINK_LOCAL;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr,
                                                    DEFAULT_TEST_PREFIX_LEN, 0));
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT_EQUAL_INT(true, gnrc_ipv6_netif_addr_is_non_unicast(out));
  }
  
  static void test_ipv6_netif_addr_is_non_unicast__multicast2(void)
  {
      ipv6_addr_t addr = IPV6_ADDR_ALL_ROUTERS_LINK_LOCAL;
      ipv6_addr_t *out = NULL;
  
      test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
  
      TEST_ASSERT_NOT_NULL(gnrc_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN,
                                                    GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST));
  
      TEST_ASSERT_NOT_NULL((out = gnrc_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
      TEST_ASSERT_EQUAL_INT(true, gnrc_ipv6_netif_addr_is_non_unicast(out));
  }
  
  Test *tests_ipv6_netif_tests(void)
  {
      EMB_UNIT_TESTFIXTURES(fixtures) {
          new_TestFixture(test_ipv6_netif_add__success),
          new_TestFixture(test_netif_add__success_with_ipv6),
          new_TestFixture(test_ipv6_netif_add__despite_free_entry),
          new_TestFixture(test_ipv6_netif_remove__not_allocated),
          new_TestFixture(test_ipv6_netif_remove__success),
          new_TestFixture(test_ipv6_netif_get__empty),
          new_TestFixture(test_ipv6_netif_add_addr__no_iface1),
          new_TestFixture(test_ipv6_netif_add_addr__no_iface2),
          new_TestFixture(test_ipv6_netif_add_addr__addr_NULL),
          new_TestFixture(test_ipv6_netif_add_addr__addr_unspecified),
          new_TestFixture(test_ipv6_netif_add_addr__full),
          new_TestFixture(test_ipv6_netif_add_addr__success),
          new_TestFixture(test_ipv6_netif_add_addr__despite_free_entry),
          new_TestFixture(test_ipv6_netif_remove_addr__not_allocated),
          new_TestFixture(test_ipv6_netif_remove_addr__success),
          new_TestFixture(test_ipv6_netif_reset_addr__success),
          new_TestFixture(test_ipv6_netif_find_by_addr__empty),
          new_TestFixture(test_ipv6_netif_find_by_addr__success),
          new_TestFixture(test_ipv6_netif_find_addr__no_iface),
          new_TestFixture(test_ipv6_netif_find_addr__wrong_iface),
          new_TestFixture(test_ipv6_netif_find_addr__wrong_addr),
          new_TestFixture(test_ipv6_netif_find_addr__success),
          new_TestFixture(test_ipv6_netif_find_by_prefix__success1),
          new_TestFixture(test_ipv6_netif_find_by_prefix__success2),
          new_TestFixture(test_ipv6_netif_find_by_prefix__success3),
          new_TestFixture(test_ipv6_netif_match_prefix__success1),
          new_TestFixture(test_ipv6_netif_match_prefix__success2),
          new_TestFixture(test_ipv6_netif_match_prefix__success3),
          new_TestFixture(test_ipv6_netif_find_best_src_addr__no_unicast),
          new_TestFixture(test_ipv6_netif_find_best_src_addr__success),
          new_TestFixture(test_ipv6_netif_find_best_src_addr__multicast_input),
          new_TestFixture(test_ipv6_netif_find_best_src_addr__other_subnet),
          new_TestFixture(test_ipv6_netif_addr_is_non_unicast__unicast),
          new_TestFixture(test_ipv6_netif_addr_is_non_unicast__anycast),
          new_TestFixture(test_ipv6_netif_addr_is_non_unicast__multicast1),
          new_TestFixture(test_ipv6_netif_addr_is_non_unicast__multicast2),
      };
  
      EMB_UNIT_TESTCALLER(ipv6_netif_tests, set_up, NULL, fixtures);
  
      return (Test *)&ipv6_netif_tests;
  }
  
  void tests_ipv6_netif(void)
  {
      TESTS_RUN(tests_ipv6_netif_tests());
  }
  /** @} */