1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

tests/l2util: provide tests for l2util_ipv6_group_to_l2_group()

This commit is contained in:
Martine Lenders 2020-10-26 11:18:45 +01:00
parent d8c78a9910
commit 55ed65650d
No known key found for this signature in database
GPG Key ID: CCD317364F63286F
3 changed files with 44 additions and 1 deletions

View File

@ -243,7 +243,7 @@ int l2util_ipv6_group_to_l2_group(int dev_type,
uint8_t *l2_group)
{
switch (dev_type) {
#if defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW)
#if IS_USED(MODULE_NETDEV_ETH)
case NETDEV_TYPE_ETHERNET:
/* see https://tools.ietf.org/html/rfc2464#section-7 */
l2_group[0] = 0x33;

6
tests/l2util/Makefile.ci Normal file
View File

@ -0,0 +1,6 @@
BOARD_INSUFFICIENT_MEMORY := \
arduino-duemilanove \
arduino-nano \
arduino-uno \
atmega328p \
#

View File

@ -32,6 +32,10 @@
#define TEST_EUI48_EUI64 { 0x21, 0x55, 0x31, 0xff, 0xfe, 0x02, 0x41, 0xfd }
#define TEST_EUI48_IID { 0x23, 0x55, 0x31, 0xff, 0xfe, 0x02, 0x41, 0xfd }
#define TEST_EUI64_IID { 0x23, 0x55, 0x31, 0x02, 0x41, 0xfd, 0xfb, 0xfd }
#define TEST_IPV6_GROUP { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x3f, 0x6c, 0xa1, 0xbb, 0xe5, 0x03, 0x6b, 0xe2 }
/* see https://tools.ietf.org/html/rfc2464#section-7 */
#define TEST_ETHERNET_GROUP { 0x33, 0x33, 0xe5, 0x03, 0x6b, 0xe2 }
static void test_eui64_from_addr__success(void)
{
@ -381,6 +385,37 @@ static void test_addr_len_from_l2ao__ENOTSUP(void)
&opt));
}
static void test_ipv6_group_to_l2group__success(void)
{
static const ipv6_addr_t test_group = {
.u8 = TEST_IPV6_GROUP,
};
static const eui48_t test_ethernet = {
.uint8 = TEST_ETHERNET_GROUP,
};
uint8_t res[L2UTIL_ADDR_MAX_LEN];
/* test Ethernet */
memset(res, 0, sizeof(res));
TEST_ASSERT_EQUAL_INT(sizeof(test_ethernet),
l2util_ipv6_group_to_l2_group(NETDEV_TYPE_ETHERNET,
&test_group, res));
TEST_ASSERT_EQUAL_INT(0, memcmp(&test_ethernet, res,
sizeof(test_ethernet)));
}
static void test_ipv6_group_to_l2group__ENOTSUP(void)
{
static const ipv6_addr_t test_group = {
.u8 = TEST_IPV6_GROUP,
};
uint8_t res[L2UTIL_ADDR_MAX_LEN];
TEST_ASSERT_EQUAL_INT(-ENOTSUP,
l2util_ipv6_group_to_l2_group(NETDEV_TYPE_UNKNOWN,
&test_group, res));
}
TestRef test_l2util(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
@ -395,6 +430,8 @@ TestRef test_l2util(void)
new_TestFixture(test_addr_len_from_l2ao__success),
new_TestFixture(test_addr_len_from_l2ao__EINVAL),
new_TestFixture(test_addr_len_from_l2ao__ENOTSUP),
new_TestFixture(test_ipv6_group_to_l2group__success),
new_TestFixture(test_ipv6_group_to_l2group__ENOTSUP),
};
EMB_UNIT_TESTCALLER(tests_l2util, NULL, NULL, fixtures);