LCOV - code coverage report
Current view: top level - app/test - test_net_ip6.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 66 66 100.0 %
Date: 2025-03-01 20:23:48 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 45 90 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2024 Robin Jarry
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_ip6.h>
       6                 :            : 
       7                 :            : #include "test.h"
       8                 :            : 
       9                 :            : static const struct rte_ipv6_addr mask_full = RTE_IPV6_MASK_FULL;
      10                 :            : static const struct rte_ipv6_addr zero_addr = RTE_IPV6_ADDR_UNSPEC;
      11                 :            : 
      12                 :            : static int
      13                 :            : test_ipv6_check_version(void)
      14                 :            : {
      15                 :            :         struct rte_ipv6_hdr h;
      16                 :            : 
      17                 :            :         h.vtc_flow = 0;
      18                 :            :         TEST_ASSERT_EQUAL(rte_ipv6_check_version(&h), -EINVAL, "");
      19                 :            :         h.vtc_flow = RTE_BE32(0x7f00ba44);
      20                 :            :         TEST_ASSERT_EQUAL(rte_ipv6_check_version(&h), -EINVAL, "");
      21                 :            :         h.vtc_flow = RTE_BE32(0x6badcaca);
      22                 :            :         TEST_ASSERT_EQUAL(rte_ipv6_check_version(&h), 0, "");
      23                 :            : 
      24                 :            :         return 0;
      25                 :            : }
      26                 :            : 
      27                 :            : static int
      28                 :          1 : test_ipv6_addr_mask(void)
      29                 :            : {
      30                 :          1 :         const struct rte_ipv6_addr masked_3 = RTE_IPV6(0xe000, 0, 0, 0, 0, 0, 0, 0);
      31                 :          1 :         const struct rte_ipv6_addr masked_42 = RTE_IPV6(0xffff, 0xffff, 0xffc0, 0, 0, 0, 0, 0);
      32                 :          1 :         const struct rte_ipv6_addr masked_85 =
      33                 :            :                 RTE_IPV6(0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf800, 0, 0);
      34                 :          1 :         const struct rte_ipv6_addr masked_127 =
      35                 :            :                 RTE_IPV6(0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfffe);
      36                 :            :         struct rte_ipv6_addr ip;
      37                 :            : 
      38                 :          1 :         ip = mask_full;
      39                 :            :         rte_ipv6_addr_mask(&ip, 0);
      40         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&ip, &zero_addr), "");
      41                 :            :         TEST_ASSERT_EQUAL(rte_ipv6_mask_depth(&zero_addr), 0, "");
      42                 :            : 
      43                 :          1 :         ip = mask_full;
      44                 :            :         rte_ipv6_addr_mask(&ip, 3);
      45         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&ip, &masked_3), "");
      46         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(rte_ipv6_mask_depth(&masked_3), 3, "");
      47                 :            : 
      48                 :          1 :         ip = mask_full;
      49                 :            :         rte_ipv6_addr_mask(&ip, 42);
      50         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&ip, &masked_42), "");
      51         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(rte_ipv6_mask_depth(&masked_42), 42, "");
      52                 :            : 
      53                 :          1 :         ip = mask_full;
      54                 :            :         rte_ipv6_addr_mask(&ip, 85);
      55         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&ip, &masked_85), "");
      56         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(rte_ipv6_mask_depth(&masked_85), 85, "");
      57                 :            : 
      58         [ -  + ]:          1 :         ip = mask_full;
      59                 :            :         rte_ipv6_addr_mask(&ip, 127);
      60         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&ip, &masked_127), "");
      61         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(rte_ipv6_mask_depth(&masked_127), 127, "");
      62                 :            : 
      63         [ -  + ]:          1 :         ip = mask_full;
      64                 :            :         rte_ipv6_addr_mask(&ip, 128);
      65         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&ip, &mask_full), "");
      66         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(rte_ipv6_mask_depth(&mask_full), 128, "");
      67                 :            : 
      68                 :          1 :         const struct rte_ipv6_addr mask_holed =
      69                 :            :                 RTE_IPV6(0xffff, 0xffff, 0xffff, 0xefff, 0xffff, 0xffff, 0xffff, 0xffff);
      70         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(rte_ipv6_mask_depth(&mask_holed), 51, "");
      71                 :            : 
      72                 :            :         return TEST_SUCCESS;
      73                 :            : }
      74                 :            : 
      75                 :            : static int
      76                 :          1 : test_ipv6_addr_eq_prefix(void)
      77                 :            : {
      78                 :          1 :         const struct rte_ipv6_addr ip1 =
      79                 :            :                 RTE_IPV6(0x2a01, 0xcb00, 0x0254, 0x3300, 0x1b9f, 0x8071, 0x67cd, 0xbf20);
      80                 :          1 :         const struct rte_ipv6_addr ip2 =
      81                 :            :                 RTE_IPV6(0x2a01, 0xcb00, 0x0254, 0x3300, 0x6239, 0xe1f4, 0x7a0b, 0x2371);
      82                 :          1 :         const struct rte_ipv6_addr ip3 =
      83                 :            :                 RTE_IPV6(0xfd10, 0x0039, 0x0208, 0x0001, 0x0000, 0x0000, 0x0000, 0x1008);
      84                 :            : 
      85         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq_prefix(&ip1, &ip2, 1), "");
      86         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq_prefix(&ip1, &ip2, 37), "");
      87         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq_prefix(&ip1, &ip2, 64), "");
      88         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_eq_prefix(&ip1, &ip2, 112), "");
      89         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq_prefix(&ip1, &ip3, 0), "");
      90         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_eq_prefix(&ip1, &ip3, 13), "");
      91                 :            : 
      92                 :            :         return TEST_SUCCESS;
      93                 :            : }
      94                 :            : 
      95                 :            : static int
      96         [ -  + ]:          1 : test_ipv6_addr_kind(void)
      97                 :            : {
      98         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_is_unspec(&zero_addr), "");
      99                 :            :         TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&zero_addr), "");
     100         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_is_loopback(&zero_addr), "");
     101                 :            :         TEST_ASSERT(!rte_ipv6_addr_is_mcast(&zero_addr), "");
     102                 :            : 
     103         [ -  + ]:          1 :         const struct rte_ipv6_addr ucast =
     104                 :            :                 RTE_IPV6(0x2a01, 0xcb00, 0x0254, 0x3300, 0x6239, 0xe1f4, 0x7a0b, 0x2371);
     105         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_is_unspec(&ucast), "");
     106                 :            :         TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&ucast), "");
     107         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_is_loopback(&ucast), "");
     108                 :            :         TEST_ASSERT(!rte_ipv6_addr_is_mcast(&ucast), "");
     109                 :            : 
     110         [ -  + ]:          1 :         const struct rte_ipv6_addr mcast = RTE_IPV6(0xff01, 0, 0, 0, 0, 0, 0, 1);
     111         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_is_unspec(&mcast), "");
     112                 :            :         TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&mcast), "");
     113         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_is_loopback(&mcast), "");
     114                 :            :         TEST_ASSERT(rte_ipv6_addr_is_mcast(&mcast), "");
     115                 :            : 
     116         [ -  + ]:          1 :         const struct rte_ipv6_addr lo = RTE_IPV6_ADDR_LOOPBACK;
     117         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_is_unspec(&lo), "");
     118                 :            :         TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&lo), "");
     119         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_is_loopback(&lo), "");
     120                 :            :         TEST_ASSERT(!rte_ipv6_addr_is_mcast(&lo), "");
     121                 :            : 
     122         [ -  + ]:          1 :         const struct rte_ipv6_addr local =
     123                 :            :                 RTE_IPV6(0xfe80, 0, 0, 0, 0x5a84, 0xc52c, 0x6aef, 0x4639);
     124         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_is_unspec(&local), "");
     125                 :            :         TEST_ASSERT(rte_ipv6_addr_is_linklocal(&local), "");
     126         [ -  + ]:          1 :         TEST_ASSERT(!rte_ipv6_addr_is_loopback(&local), "");
     127                 :            :         TEST_ASSERT(!rte_ipv6_addr_is_mcast(&local), "");
     128                 :            : 
     129                 :            :         return TEST_SUCCESS;
     130                 :            : }
     131                 :            : 
     132                 :            : static int
     133                 :          1 : test_ipv6_llocal_from_ethernet(void)
     134                 :            : {
     135                 :          1 :         const struct rte_ether_addr local_mac = {{0x04, 0x7b, 0xcb, 0x5c, 0x08, 0x44}};
     136                 :          1 :         const struct rte_ipv6_addr local_ip =
     137                 :            :                 RTE_IPV6(0xfe80, 0, 0, 0, 0x047b, 0xcbff, 0xfe5c, 0x0844);
     138                 :            :         struct rte_ipv6_addr ip;
     139                 :            : 
     140                 :          1 :         rte_ipv6_llocal_from_ethernet(&ip, &local_mac);
     141         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&ip, &local_ip), "");
     142                 :            : 
     143                 :            :         return TEST_SUCCESS;
     144                 :            : }
     145                 :            : 
     146                 :            : static int
     147                 :          1 : test_ipv6_solnode_from_addr(void)
     148                 :            : {
     149                 :            :         struct rte_ipv6_addr sol;
     150                 :            : 
     151                 :            :         const struct rte_ipv6_addr llocal =
     152                 :            :                 RTE_IPV6(0xfe80, 0, 0, 0, 0x047b, 0xcbff, 0xfe5c, 0x0844);
     153         [ -  + ]:          1 :         const struct rte_ipv6_addr llocal_sol =
     154                 :            :                 RTE_IPV6(0xff02, 0, 0, 0, 0, 0x0001, 0xff5c, 0x0844);
     155                 :            :         rte_ipv6_solnode_from_addr(&sol, &llocal);
     156         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&sol, &llocal_sol), "");
     157                 :            : 
     158                 :            :         const struct rte_ipv6_addr ucast =
     159                 :            :                 RTE_IPV6(0x2a01, 0xcb00, 0x0254, 0x3300, 0x1b9f, 0x8071, 0x67cd, 0xbf20);
     160         [ -  + ]:          1 :         const struct rte_ipv6_addr ucast_sol =
     161                 :            :                 RTE_IPV6(0xff02, 0, 0, 0, 0, 0x0001, 0xffcd, 0xbf20);
     162                 :            :         rte_ipv6_solnode_from_addr(&sol, &ucast);
     163         [ -  + ]:          1 :         TEST_ASSERT(rte_ipv6_addr_eq(&sol, &ucast_sol), "");
     164                 :            : 
     165                 :            :         return TEST_SUCCESS;
     166                 :            : }
     167                 :            : 
     168                 :            : static int
     169                 :            : test_ether_mcast_from_ipv6(void)
     170                 :            : {
     171                 :            :         const struct rte_ether_addr mcast_mac = {{0x33, 0x33, 0xd3, 0x00, 0x02, 0x01}};
     172                 :            :         const struct rte_ipv6_addr mcast_ip =
     173                 :            :                 RTE_IPV6(0xff02, 0, 0, 0x0201, 0, 0, 0xd300, 0x0201);
     174                 :            :         struct rte_ether_addr mac;
     175                 :            : 
     176                 :            :         rte_ether_mcast_from_ipv6(&mac, &mcast_ip);
     177                 :            :         TEST_ASSERT(rte_is_same_ether_addr(&mac, &mcast_mac), "");
     178                 :            : 
     179                 :            :         return TEST_SUCCESS;
     180                 :            : }
     181                 :            : 
     182                 :            : static int
     183                 :          1 : test_net_ipv6(void)
     184                 :            : {
     185                 :            :         TEST_ASSERT_SUCCESS(test_ipv6_check_version(), "");
     186         [ -  + ]:          1 :         TEST_ASSERT_SUCCESS(test_ipv6_addr_mask(), "");
     187         [ -  + ]:          1 :         TEST_ASSERT_SUCCESS(test_ipv6_addr_eq_prefix(), "");
     188         [ -  + ]:          1 :         TEST_ASSERT_SUCCESS(test_ipv6_addr_kind(), "");
     189         [ -  + ]:          1 :         TEST_ASSERT_SUCCESS(test_ipv6_llocal_from_ethernet(), "");
     190         [ -  + ]:          1 :         TEST_ASSERT_SUCCESS(test_ipv6_solnode_from_addr(), "");
     191                 :            :         TEST_ASSERT_SUCCESS(test_ether_mcast_from_ipv6(), "");
     192                 :            :         return TEST_SUCCESS;
     193                 :            : }
     194                 :            : 
     195                 :        252 : REGISTER_FAST_TEST(net_ipv6_autotest, true, true, test_net_ipv6);

Generated by: LCOV version 1.14