Blame view

RIOT/tests/unittests/tests-gnrc_ipv6_nib/tests-gnrc_ipv6_nib-abr.c 2.79 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
  /*
   * Copyright (C) 2016 Freie Universitรคt Berlin
   *
   * 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
   * @author  Martine Lenders <m.lenders@fu-berlin.de>
   */
  
  #include <inttypes.h>
  
  #include "net/ipv6/addr.h"
  #include "net/gnrc/ipv6/nib.h"
  #include "net/gnrc/ipv6/nib/abr.h"
  
  #include "_nib-internal.h"
  
  #include "unittests-constants.h"
  
  #include "tests-gnrc_ipv6_nib.h"
  
  #define GLOBAL_PREFIX       { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0 }
  
  static void set_up(void)
  {
      evtimer_event_t *tmp;
  
      for (evtimer_event_t *ptr = _nib_evtimer.events;
           (ptr != NULL) && (tmp = (ptr->next), 1);
           ptr = tmp) {
          evtimer_del((evtimer_t *)(&_nib_evtimer), ptr);
      }
      _nib_init();
  }
  
  /*
   * Creates GNRC_IPV6_NIB_ABR_NUMOF authoritative border router list entries with
   * different addresses and then tries to create another one
   * Expected result: gnrc_ipv6_nib_abr_add() returns -ENOMEM
   */
  static void test_nib_abr_add__ENOMEM(void)
  {
      ipv6_addr_t addr = { .u64 = { { .u8 = GLOBAL_PREFIX },
                                  { .u64 = TEST_UINT64 } } };
  
      for (unsigned i = 0; i < GNRC_IPV6_NIB_ABR_NUMOF; i++) {
          TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_abr_add(&addr));
          addr.u16[0].u16++;
      }
      TEST_ASSERT_EQUAL_INT(-ENOMEM, gnrc_ipv6_nib_abr_add(&addr));
  }
  
  /*
   * Creates GNRC_IPV6_NIB_ABR_NUMOF authoritative border router list entries with
   * different addresses and then tries to add another equal to the last.
   * Expected result: should return 0.
   */
  static void test_nib_abr_add__success(void)
  {
      ipv6_addr_t addr = { .u64 = { { .u8 = GLOBAL_PREFIX },
                                  { .u64 = TEST_UINT64 } } };
  
      for (unsigned i = 0; i < GNRC_IPV6_NIB_ABR_NUMOF; i++) {
          addr.u16[0].u16++;
          TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_abr_add(&addr));
      }
      TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_abr_add(&addr));
  }
  
  /*
   * Creates an authoritative border router list entry and removes it.
   * Expected result: system does not crash ;-)
   */
  static void test_nib_abr_del__success(void)
  {
      ipv6_addr_t addr = { .u64 = { { .u8 = GLOBAL_PREFIX },
                                    { .u64 = TEST_UINT64 } } };
  
      TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_abr_add(&addr));
      gnrc_ipv6_nib_abr_del(&addr);
  }
  
  Test *tests_gnrc_ipv6_nib_abr_tests(void)
  {
      EMB_UNIT_TESTFIXTURES(fixtures) {
          new_TestFixture(test_nib_abr_add__ENOMEM),
          new_TestFixture(test_nib_abr_add__success),
          new_TestFixture(test_nib_abr_del__success),
          /* gnrc_ipv6_nib_pl_iter() is tested during all the tests above */
      };
  
      EMB_UNIT_TESTCALLER(tests, set_up, NULL,
                          fixtures);
  
      return (Test *)&tests;
  }