1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests: adapt unittests for ipv6_hdr module division

This commit is contained in:
Martine Lenders 2015-08-10 02:04:35 +02:00
parent 4f650b31f9
commit 2903667494
14 changed files with 212 additions and 114 deletions

View File

@ -107,15 +107,6 @@ ifneq (,$(filter ng_icmpv6,$(USEMODULE)))
USEMODULE += ng_ipv6
endif
ifneq (,$(filter ng_ipv6_hdr,$(USEMODULE)))
USEMODULE += ipv6_hdr
USEMODULE += ng_pktbuf
endif
ifneq (,$(filter ipv6_hdr,$(USEMODULE)))
USEMODULE += inet_csum
endif
ifneq (,$(filter ng_rpl_srh,$(USEMODULE)))
USEMODULE += ipv6_ext_rh
endif
@ -142,6 +133,15 @@ ifneq (,$(filter ng_ipv6,$(USEMODULE)))
USEMODULE += ng_netbase
endif
ifneq (,$(filter ng_ipv6_hdr,$(USEMODULE)))
USEMODULE += ipv6_hdr
USEMODULE += ng_pktbuf
endif
ifneq (,$(filter ipv6_hdr,$(USEMODULE)))
USEMODULE += inet_csum
endif
ifneq (,$(filter ng_ipv6_nc,$(USEMODULE)))
USEMODULE += ipv6_addr
endif

View File

@ -23,6 +23,7 @@
#include <stdint.h>
#include "byteorder.h"
#include "net/inet_csum.h"
#include "net/ipv6/addr.h"
#ifdef __cplusplus

View File

@ -21,6 +21,7 @@
#include <stdint.h>
#include "net/ipv6/hdr.h"
#include "net/ng_pkt.h"
#ifdef __cplusplus

View File

@ -365,8 +365,8 @@ static inline void _addr_set_multicast(uint8_t *dst, ng_pktsnip_t *payload)
if ((payload != NULL) && (payload->data != NULL)) {
ipv6_hdr_t *hdr = payload->data;
uint16_t *prefix = (uint16_t *)(&dst[2]);
prefix[0] = hdr->dst.u16[6];
prefix[1] = hdr->dst.u16[7];
prefix[0] = hdr->dst.u16[6].u16;
prefix[1] = hdr->dst.u16[7].u16;
}
break;
#endif

View File

@ -17,6 +17,7 @@
#include "od.h"
#include "net/ng_icmpv6.h"
#include "net/ng_icmpv6/echo.h"
#include "net/ng_ipv6/hdr.h"
#include "utlist.h"
#define ENABLE_DEBUG (0)

View File

@ -213,7 +213,7 @@ void ng_ndp_internal_send_nbr_adv(kernel_pid_t iface, ipv6_addr_t *tgt,
return;
}
((ng_ipv6_hdr_t *)hdr->data)->hl = 255;
((ipv6_hdr_t *)hdr->data)->hl = 255;
pkt = hdr;
/* add netif header for send interface specification */
@ -293,7 +293,7 @@ void ng_ndp_internal_send_nbr_sol(kernel_pid_t iface, ipv6_addr_t *tgt,
return;
}
((ng_ipv6_hdr_t *)hdr->data)->hl = 255;
((ipv6_hdr_t *)hdr->data)->hl = 255;
pkt = hdr;
/* add netif header for send interface specification */
@ -312,7 +312,7 @@ void ng_ndp_internal_send_nbr_sol(kernel_pid_t iface, ipv6_addr_t *tgt,
}
bool ng_ndp_internal_sl2a_opt_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
ng_ipv6_hdr_t *ipv6, uint8_t icmpv6_type,
ipv6_hdr_t *ipv6, uint8_t icmpv6_type,
ng_ndp_opt_t *sl2a_opt)
{
ng_ipv6_nc_t *nc_entry = NULL;
@ -371,7 +371,7 @@ bool ng_ndp_internal_sl2a_opt_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
}
}
int ng_ndp_internal_tl2a_opt_handle(ng_pktsnip_t *pkt, ng_ipv6_hdr_t *ipv6,
int ng_ndp_internal_tl2a_opt_handle(ng_pktsnip_t *pkt, ipv6_hdr_t *ipv6,
uint8_t icmpv6_type, ng_ndp_opt_t *tl2a_opt,
uint8_t *l2addr)
{

View File

@ -63,7 +63,12 @@ kernel_pid_t ng_ndp_node_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len,
ipv6_addr_t *next_hop_ip = NULL, *prefix = NULL;
#ifdef MODULE_NG_IPV6_EXT_RH
next_hop_ip = ng_ipv6_ext_rh_next_hop(hdr);
ipv6_hdr_t *hdr;
ng_pktsnip_t *ipv6;
LL_SEARCH_SCALAR(pkt, ipv6, type, NG_NETTYPE_IPV6);
assert(ipv6);
hdr = ipv6->data;
next_hop_ip = ipv6_ext_rh_next_hop(hdr);
#endif
#ifdef MODULE_FIB
/* don't look-up link local addresses in FIB */

View File

@ -80,7 +80,7 @@ static inline bool _expected_seq(uint16_t seq)
int _handle_reply(ng_pktsnip_t *pkt, uint64_t time)
{
ng_pktsnip_t *ipv6, *icmpv6;
ng_ipv6_hdr_t *ipv6_hdr;
ipv6_hdr_t *ipv6_hdr;
ng_icmpv6_echo_t *icmpv6_hdr;
uint16_t seq;

View File

@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1 @@
USEMODULE += ng_ipv6_hdr

View File

@ -0,0 +1,148 @@
/*
* 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/ipv6/hdr.h"
#include "net/ng_ipv6/hdr.h"
#include "net/ng_pktbuf.h"
#include "unittests-constants.h"
#include "tests-gnrc_ipv6_hdr.h"
#define DEFAULT_TEST_SRC { { \
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f \
} \
}
#define DEFAULT_TEST_DST { { \
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f \
} \
}
static void test_gnrc_ipv6_hdr_build__wrong_src_len(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ipv6_addr_t dst = DEFAULT_TEST_DST;
ng_pktbuf_init();
TEST_ASSERT_NULL(ng_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t) + TEST_UINT8,
(uint8_t *)&dst,
sizeof(ipv6_addr_t)));
TEST_ASSERT(ng_pktbuf_is_empty());
}
static void test_gnrc_ipv6_hdr_build__wrong_dst_len(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ipv6_addr_t dst = DEFAULT_TEST_DST;
ng_pktbuf_init();
TEST_ASSERT_NULL(ng_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
(uint8_t *)&dst,
sizeof(ipv6_addr_t) + TEST_UINT8));
TEST_ASSERT(ng_pktbuf_is_empty());
}
static void test_gnrc_ipv6_hdr_build__src_NULL(void)
{
ipv6_addr_t dst = DEFAULT_TEST_DST;
ng_pktsnip_t *pkt;
ipv6_hdr_t *hdr;
ng_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, NULL, 0, (uint8_t *)&dst,
sizeof(ipv6_addr_t))));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ipv6_hdr_is(hdr));
TEST_ASSERT_EQUAL_INT(0, ipv6_hdr_get_tc(hdr));
TEST_ASSERT_EQUAL_INT(0, ipv6_hdr_get_fl(hdr));
TEST_ASSERT_EQUAL_INT(PROTNUM_RESERVED, hdr->nh);
TEST_ASSERT_EQUAL_INT(0, hdr->hl);
TEST_ASSERT(ipv6_addr_equal(&dst, &hdr->dst));
TEST_ASSERT(!ng_pktbuf_is_empty());
}
static void test_gnrc_ipv6_hdr_build__dst_NULL(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ng_pktsnip_t *pkt;
ipv6_hdr_t *hdr;
ng_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
NULL, 0)));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ipv6_hdr_is(hdr));
TEST_ASSERT_EQUAL_INT(0, ipv6_hdr_get_tc(hdr));
TEST_ASSERT_EQUAL_INT(0, ipv6_hdr_get_fl(hdr));
TEST_ASSERT_EQUAL_INT(PROTNUM_RESERVED, hdr->nh);
TEST_ASSERT_EQUAL_INT(0, hdr->hl);
TEST_ASSERT(ipv6_addr_equal(&src, &hdr->src));
TEST_ASSERT(!ng_pktbuf_is_empty());
}
static void test_gnrc_ipv6_hdr_build__complete(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ipv6_addr_t dst = DEFAULT_TEST_DST;
ng_pktsnip_t *pkt;
ipv6_hdr_t *hdr;
ng_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
(uint8_t *)&dst,
sizeof(ipv6_addr_t))));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ipv6_hdr_is(hdr));
TEST_ASSERT_EQUAL_INT(0, ipv6_hdr_get_tc(hdr));
TEST_ASSERT_EQUAL_INT(0, ipv6_hdr_get_fl(hdr));
TEST_ASSERT_EQUAL_INT(PROTNUM_RESERVED, hdr->nh);
TEST_ASSERT_EQUAL_INT(0, hdr->hl);
TEST_ASSERT(ipv6_addr_equal(&src, &hdr->src));
TEST_ASSERT(ipv6_addr_equal(&dst, &hdr->dst));
TEST_ASSERT(!ng_pktbuf_is_empty());
}
Test *tests_gnrc_ipv6_hdr_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_gnrc_ipv6_hdr_build__wrong_src_len),
new_TestFixture(test_gnrc_ipv6_hdr_build__wrong_dst_len),
new_TestFixture(test_gnrc_ipv6_hdr_build__src_NULL),
new_TestFixture(test_gnrc_ipv6_hdr_build__dst_NULL),
new_TestFixture(test_gnrc_ipv6_hdr_build__complete),
};
EMB_UNIT_TESTCALLER(ipv6_hdr_tests, NULL, NULL, fixtures);
return (Test *)&ipv6_hdr_tests;
}
void tests_gnrc_ipv6_hdr(void)
{
TESTS_RUN(tests_gnrc_ipv6_hdr_tests());
}
/** @} */

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2015 Martin Lenders
*
* 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.
*/
/**
* @addtogroup unittests
* @{
*
* @file
* @brief Unittests for the ``gnrc_ipv6_hdr`` module
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef TESTS_GNRC_IPV6_HDR_H_
#define TESTS_GNRC_IPV6_HDR_H_
#include "embUnit.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The entry point of this test suite.
*/
void tests_gnrc_ipv6_hdr(void);
#ifdef __cplusplus
}
#endif
#endif /* TESTS_GNRC_IPV6_HDR_H_ */
/** @} */

View File

@ -1,2 +1 @@
USEMODULE += ipv6_hdr
USEMODULE += ng_ipv6_hdr

View File

@ -297,97 +297,6 @@ static void test_ipv6_hdr_inet_csum__initial_sum_0(void)
TEST_ASSERT_EQUAL_INT(0xab32, res);
}
static void test_ipv6_hdr_build__wrong_src_len(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ipv6_addr_t dst = DEFAULT_TEST_DST;
ng_pktbuf_init();
TEST_ASSERT_NULL(ng_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t) + TEST_UINT8,
(uint8_t *)&dst,
sizeof(ipv6_addr_t)));
TEST_ASSERT(ng_pktbuf_is_empty());
}
static void test_ipv6_hdr_build__wrong_dst_len(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ipv6_addr_t dst = DEFAULT_TEST_DST;
ng_pktbuf_init();
TEST_ASSERT_NULL(ng_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
(uint8_t *)&dst,
sizeof(ipv6_addr_t) + TEST_UINT8));
TEST_ASSERT(ng_pktbuf_is_empty());
}
static void test_ipv6_hdr_build__src_NULL(void)
{
ipv6_addr_t dst = DEFAULT_TEST_DST;
ng_pktsnip_t *pkt;
ng_ipv6_hdr_t *hdr;
ng_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, NULL, 0, (uint8_t *)&dst,
sizeof(ipv6_addr_t))));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ng_ipv6_hdr_is(hdr));
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_hdr_get_tc(hdr));
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_hdr_get_fl(hdr));
TEST_ASSERT_EQUAL_INT(PROTNUM_RESERVED, hdr->nh);
TEST_ASSERT_EQUAL_INT(0, hdr->hl);
TEST_ASSERT(ipv6_addr_equal(&dst, &hdr->dst));
TEST_ASSERT(!ng_pktbuf_is_empty());
}
static void test_ipv6_hdr_build__dst_NULL(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ng_pktsnip_t *pkt;
ng_ipv6_hdr_t *hdr;
ng_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
NULL, 0)));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ng_ipv6_hdr_is(hdr));
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_hdr_get_tc(hdr));
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_hdr_get_fl(hdr));
TEST_ASSERT_EQUAL_INT(PROTNUM_RESERVED, hdr->nh);
TEST_ASSERT_EQUAL_INT(0, hdr->hl);
TEST_ASSERT(ipv6_addr_equal(&src, &hdr->src));
TEST_ASSERT(!ng_pktbuf_is_empty());
}
static void test_ipv6_hdr_build__complete(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ipv6_addr_t dst = DEFAULT_TEST_DST;
ng_pktsnip_t *pkt;
ng_ipv6_hdr_t *hdr;
ng_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
(uint8_t *)&dst,
sizeof(ipv6_addr_t))));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ng_ipv6_hdr_is(hdr));
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_hdr_get_tc(hdr));
TEST_ASSERT_EQUAL_INT(0, ng_ipv6_hdr_get_fl(hdr));
TEST_ASSERT_EQUAL_INT(PROTNUM_RESERVED, hdr->nh);
TEST_ASSERT_EQUAL_INT(0, hdr->hl);
TEST_ASSERT(ipv6_addr_equal(&src, &hdr->src));
TEST_ASSERT(ipv6_addr_equal(&dst, &hdr->dst));
TEST_ASSERT(!ng_pktbuf_is_empty());
}
Test *tests_ipv6_hdr_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
@ -405,11 +314,6 @@ Test *tests_ipv6_hdr_tests(void)
new_TestFixture(test_ipv6_hdr_get_fl),
new_TestFixture(test_ipv6_hdr_inet_csum__initial_sum_overflows),
new_TestFixture(test_ipv6_hdr_inet_csum__initial_sum_0),
new_TestFixture(test_ipv6_hdr_build__wrong_src_len),
new_TestFixture(test_ipv6_hdr_build__wrong_dst_len),
new_TestFixture(test_ipv6_hdr_build__src_NULL),
new_TestFixture(test_ipv6_hdr_build__dst_NULL),
new_TestFixture(test_ipv6_hdr_build__complete),
};
EMB_UNIT_TESTCALLER(ipv6_hdr_tests, NULL, NULL, fixtures);