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

Merge pull request #15443 from benpicco/l2util_addr

replace netif_addr_to/from_str() with l2util_addr_to/from_str()
This commit is contained in:
Francisco 2020-12-02 09:21:16 +01:00 committed by GitHub
commit 0a064806e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 197 additions and 346 deletions

View File

@ -99,5 +99,9 @@ ifneq (,$(filter openwsn_debugpins,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio_irq
endif
ifneq (,$(filter shell_commands,$(USEMODULE)))
USEMODULE += l2util
endif
# This port currently requires setting ISR_STACKSIZE
FEATURES_BLACKLIST += arch_esp32 arch_esp8266 arch_riscv arch_avr8

View File

@ -489,6 +489,10 @@ ifneq (,$(filter ieee802154_submac,$(USEMODULE)))
USEMODULE += xtimer
endif
ifneq (,$(filter l2util,$(USEMODULE)))
USEMODULE += fmt
endif
ifneq (,$(filter od,$(USEMODULE)))
USEMODULE += fmt
endif

View File

@ -62,6 +62,7 @@
#if IS_USED(MODULE_GNRC_NETIF_PKTQ)
#include "net/gnrc/netif/pktq/type.h"
#endif
#include "net/l2util.h"
#include "net/ndp.h"
#include "net/netdev.h"
#include "net/netopt.h"
@ -568,7 +569,7 @@ int gnrc_netif_set_from_netdev(gnrc_netif_t *netif,
/**
* @brief Converts a hardware address to a human readable string.
*
* @note Compatibility wrapper for @see netif_addr_to_str
* @note Compatibility wrapper for @see l2util_addr_to_str
*
* @details The format will be like `xx:xx:xx:xx` where `xx` are the bytes
* of @p addr in hexadecimal representation.
@ -585,14 +586,14 @@ int gnrc_netif_set_from_netdev(gnrc_netif_t *netif,
*/
static inline char *gnrc_netif_addr_to_str(const uint8_t *addr, size_t addr_len, char *out)
{
return netif_addr_to_str(addr, addr_len, out);
return l2util_addr_to_str(addr, addr_len, out);
}
/**
* @brief Parses a string of colon-separated hexadecimals to a hardware
* address.
*
* @note Compatibility wrapper for @see netif_addr_from_str
* @note Compatibility wrapper for @see l2util_addr_from_str
*
* @details The input format must be like `xx:xx:xx:xx` where `xx` will be the
* bytes of @p addr in hexadecimal representation.
@ -610,7 +611,7 @@ static inline char *gnrc_netif_addr_to_str(const uint8_t *addr, size_t addr_len,
*/
static inline size_t gnrc_netif_addr_from_str(const char *str, uint8_t *out)
{
return netif_addr_from_str(str, out);
return l2util_addr_from_str(str, out);
}
/**

View File

@ -153,6 +153,44 @@ int l2util_ipv6_group_to_l2_group(int dev_type,
const ipv6_addr_t *ipv6_group,
uint8_t *l2_group);
/**
* @brief Converts a hardware address to a human readable string.
*
* @details The format will be like `xx:xx:xx:xx` where `xx` are the bytes
* of @p addr in hexadecimal representation.
*
* @pre `(out != NULL) && ((addr != NULL) || (addr_len == 0))`
* @pre @p out **MUST** have allocated at least 3 * @p addr_len bytes.
*
* @param[in] addr A hardware address.
* @param[in] addr_len Length of @p addr.
* @param[out] out A string to store the output in. Must at least have
* 3 * @p addr_len bytes allocated.
*
* @return @p out.
*/
char *l2util_addr_to_str(const uint8_t *addr, size_t addr_len, char *out);
/**
* @brief Parses a string of colon-separated hexadecimals to a hardware
* address.
*
* @details The input format must be like `xx:xx:xx:xx` where `xx` will be the
* bytes of @p addr in hexadecimal representation.
*
* @pre `(out != NULL)`
* @pre @p out **MUST** have allocated at least
* @ref GNRC_NETIF_L2ADDR_MAXLEN bytes.
*
* @param[in] str A string of colon-separated hexadecimals.
* @param[out] out The resulting hardware address. Must at least have
* @ref GNRC_NETIF_L2ADDR_MAXLEN bytes allocated.
*
* @return Actual length of @p out on success.
* @return 0, on failure.
*/
size_t l2util_addr_from_str(const char *str, uint8_t *out);
#ifdef __cplusplus
}
#endif

View File

@ -176,44 +176,6 @@ int netif_set_opt(netif_t *netif, netopt_t opt, uint16_t context,
*/
int netif_register(netif_t *netif);
/**
* @brief Converts a hardware address to a human readable string.
*
* @details The format will be like `xx:xx:xx:xx` where `xx` are the bytes
* of @p addr in hexadecimal representation.
*
* @pre `(out != NULL) && ((addr != NULL) || (addr_len == 0))`
* @pre @p out **MUST** have allocated at least 3 * @p addr_len bytes.
*
* @param[in] addr A hardware address.
* @param[in] addr_len Length of @p addr.
* @param[out] out A string to store the output in. Must at least have
* 3 * @p addr_len bytes allocated.
*
* @return @p out.
*/
char *netif_addr_to_str(const uint8_t *addr, size_t addr_len, char *out);
/**
* @brief Parses a string of colon-separated hexadecimals to a hardware
* address.
*
* @details The input format must be like `xx:xx:xx:xx` where `xx` will be the
* bytes of @p addr in hexadecimal representation.
*
* @pre `(out != NULL)`
* @pre @p out **MUST** have allocated at least
* @ref GNRC_NETIF_L2ADDR_MAXLEN bytes.
*
* @param[in] str A string of colon-separated hexadecimals.
* @param[out] out The resulting hardware address. Must at least have
* @ref GNRC_NETIF_L2ADDR_MAXLEN bytes allocated.
*
* @return Actual length of @p out on success.
* @return 0, on failure.
*/
size_t netif_addr_from_str(const char *str, uint8_t *out);
#ifdef __cplusplus
}
#endif

View File

@ -16,6 +16,7 @@
#include <assert.h>
#include "log.h"
#include "fmt.h"
#include "net/eui48.h"
#include "net/ieee802154.h"
#include "net/ipv6.h"
@ -23,6 +24,22 @@
#include "net/l2util.h"
static inline int _dehex(char c, int default_)
{
if ('0' <= c && c <= '9') {
return c - '0';
}
else if ('A' <= c && c <= 'F') {
return c - 'A' + 10;
}
else if ('a' <= c && c <= 'f') {
return c - 'a' + 10;
}
else {
return default_;
}
}
#if defined(MODULE_CC110X) || defined(MODULE_NRFMIN)
static void _create_eui64_from_short(const uint8_t *addr, size_t addr_len,
eui64_t *eui64)
@ -261,4 +278,67 @@ int l2util_ipv6_group_to_l2_group(int dev_type,
}
}
char *l2util_addr_to_str(const uint8_t *addr, size_t addr_len, char *out)
{
char *res = out;
assert((out != NULL) && ((addr != NULL) || (addr_len == 0U)));
out[0] = '\0';
for (size_t i = 0; i < addr_len; i++) {
out += fmt_byte_hex((out), *(addr++));
*(out++) = (i == (addr_len - 1)) ? '\0' : ':';
}
return res;
}
size_t l2util_addr_from_str(const char *str, uint8_t *out)
{
/* Walk over str from the end. */
/* Take two chars a time as one hex value (%hhx). */
/* Leading zeros can be omitted. */
/* Every non-hexadimal character is a delimiter. */
/* Leading, tailing and adjacent delimiters are forbidden. */
const char *end_str = str;
uint8_t *out_end = out;
size_t count = 0;
int assert_cell = 1;
assert(out != NULL);
if ((str == NULL) || (str[0] == '\0')) {
return 0;
}
/* find end of string */
while (end_str[1]) {
++end_str;
}
while (end_str >= str) {
int a = 0, b = _dehex(*end_str--, -1);
if (b < 0) {
if (assert_cell) {
return 0;
}
else {
assert_cell = 1;
continue;
}
}
assert_cell = 0;
if (end_str >= str) {
a = _dehex(*end_str--, 0);
}
count++;
*out_end++ = (a << 4) | b;
}
if (assert_cell) {
return 0;
}
/* out is reversed */
while (out < --out_end) {
uint8_t tmp = *out_end;
*out_end = *out;
*out++ = tmp;
}
return count;
}
/** @} */

View File

@ -1,98 +0,0 @@
/*
* Copyright (C) 2017 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 <assert.h>
#include "fmt.h"
char *netif_addr_to_str(const uint8_t *addr, size_t addr_len, char *out)
{
char *res = out;
assert((out != NULL) && ((addr != NULL) || (addr_len == 0U)));
out[0] = '\0';
for (size_t i = 0; i < addr_len; i++) {
out += fmt_byte_hex((out), *(addr++));
*(out++) = (i == (addr_len - 1)) ? '\0' : ':';
}
return res;
}
static inline int _dehex(char c, int default_)
{
if ('0' <= c && c <= '9') {
return c - '0';
}
else if ('A' <= c && c <= 'F') {
return c - 'A' + 10;
}
else if ('a' <= c && c <= 'f') {
return c - 'a' + 10;
}
else {
return default_;
}
}
size_t netif_addr_from_str(const char *str, uint8_t *out)
{
/* Walk over str from the end. */
/* Take two chars a time as one hex value (%hhx). */
/* Leading zeros can be omitted. */
/* Every non-hexadimal character is a delimiter. */
/* Leading, tailing and adjacent delimiters are forbidden. */
const char *end_str = str;
uint8_t *out_end = out;
size_t count = 0;
int assert_cell = 1;
assert(out != NULL);
if ((str == NULL) || (str[0] == '\0')) {
return 0;
}
/* find end of string */
while (end_str[1]) {
++end_str;
}
while (end_str >= str) {
int a = 0, b = _dehex(*end_str--, -1);
if (b < 0) {
if (assert_cell) {
return 0;
}
else {
assert_cell = 1;
continue;
}
}
assert_cell = 0;
if (end_str >= str) {
a = _dehex(*end_str--, 0);
}
count++;
*out_end++ = (a << 4) | b;
}
if (assert_cell) {
return 0;
}
/* out is reversed */
while (out < --out_end) {
uint8_t tmp = *out_end;
*out_end = *out;
*out++ = tmp;
}
return count;
}
/** @} */

View File

@ -25,6 +25,7 @@
#include "shell.h"
#include "net/ieee802154.h"
#include "net/ipv6/addr.h"
#include "net/l2util.h"
#include "net/netif.h"
#include "openwsn.h"
@ -107,17 +108,17 @@ int _openwsn_ifconfig(char *arg)
addr = idmanager_getMyID(ADDR_16B);
printf("\tHWaddr: %s ",
netif_addr_to_str(addr->addr_16b, sizeof(addr->addr_16b),
l2util_addr_to_str(addr->addr_16b, sizeof(addr->addr_16b),
addr_str));
addr = idmanager_getMyID(ADDR_PANID);
printf("NID: %s\n\n",
netif_addr_to_str(addr->panid, sizeof(addr->panid),
l2util_addr_to_str(addr->panid, sizeof(addr->panid),
addr_str));
addr = idmanager_getMyID(ADDR_64B);
printf("\t\tLong HWaddr: %s\n",
netif_addr_to_str(addr->addr_64b, sizeof(addr->addr_64b),
l2util_addr_to_str(addr->addr_64b, sizeof(addr->addr_64b),
addr_str));
if (IS_USED(MODULE_OPENWSN_IPV6)) {
@ -155,7 +156,7 @@ int _openwsn_ifconfig(char *arg)
else {
icmpv6rpl_getPreferredParentEui64(&neighbor);
printf("\t\tRPL parent: %s\n",
netif_addr_to_str(neighbor.addr_64b,
l2util_addr_to_str(neighbor.addr_64b,
sizeof(neighbor.addr_64b),
addr_str));
}
@ -164,7 +165,7 @@ int _openwsn_ifconfig(char *arg)
if (neighbors_isNeighborWithHigherDAGrank(i)) {
neighbors_getNeighborEui64(&neighbor, ADDR_64B, i);
printf("\t\t\t%s\n",
netif_addr_to_str(neighbor.addr_64b,
l2util_addr_to_str(neighbor.addr_64b,
sizeof(neighbor.addr_64b),
addr_str));
}
@ -192,7 +193,7 @@ static int _neighbors_cmd(char *arg)
for (int i = 0; i < MAXNUMNEIGHBORS; i++) {
neighbors_getNeighborEui64(&neighbor, ADDR_64B, i);
netif_addr_to_str(neighbor.addr_64b, sizeof(neighbor.addr_64b),
l2util_addr_to_str(neighbor.addr_64b, sizeof(neighbor.addr_64b),
hwaddr_str);
if (memcmp(hwaddr_str, "00:00:00:00:00:00:00:00",
IEEE802154_LONG_ADDRESS_LEN_STR_MAX)) {
@ -224,7 +225,7 @@ static int _cell_list_cmd(char *arg)
switch (schedule_vars.scheduleBuf[i].type) {
case CELLTYPE_TX:
printf("neigh: %s, slot: %03i, chan: %02i, type: TX\n",
netif_addr_to_str(
l2util_addr_to_str(
schedule_vars.scheduleBuf[i].neighbor.addr_64b,
IEEE802154_LONG_ADDRESS_LEN, hwaddr_str),
schedule_vars.scheduleBuf[i].slotOffset,
@ -237,7 +238,7 @@ static int _cell_list_cmd(char *arg)
break;
case CELLTYPE_TXRX:
printf("neigh: %s, slot: %03i, chan: %02i, type: RXTX\n",
netif_addr_to_str(
l2util_addr_to_str(
schedule_vars.scheduleBuf[i].neighbor.addr_64b,
IEEE802154_LONG_ADDRESS_LEN, hwaddr_str),
schedule_vars.scheduleBuf[i].slotOffset,
@ -266,7 +267,7 @@ static int _cell_manage_cmd(int argc, char **argv)
if (argc == 6) {
addr.type = ADDR_64B;
size_t len = netif_addr_from_str(argv[5], addr.addr_64b);
size_t len = l2util_addr_from_str(argv[5], addr.addr_64b);
if (len == 0) {
puts("Error: invalid address");
return -1;
@ -358,7 +359,7 @@ static int _6top_manage_cmd(int argc, char **argv)
if (argc == 5) {
neigh.type = ADDR_64B;
size_t len = netif_addr_from_str(argv[4], neigh.addr_64b);
size_t len = l2util_addr_from_str(argv[4], neigh.addr_64b);
if (len == 0) {
puts("Error: invalid address");
return -1;
@ -445,7 +446,7 @@ static int _6top_cmd(int argc, char **argv)
if (argc == 3) {
neighbor.type = ADDR_64B;
size_t len = netif_addr_from_str(argv[2], neighbor.addr_64b);
size_t len = l2util_addr_from_str(argv[2], neighbor.addr_64b);
if (len == 0) {
puts("Error: invalid address");
return -1;

View File

@ -1,5 +1,6 @@
BOARD_INSUFFICIENT_MEMORY := \
arduino-duemilanove \
arduino-leonardo \
arduino-nano \
arduino-uno \
atmega328p \

View File

@ -7,7 +7,6 @@
*/
/**
* @defgroup tests_gnrc_ipv6_nib Common header for GNRC's NIB tests
* @ingroup tests
* @brief Common definitions for GNRC's NIB tests
* @{
@ -19,7 +18,6 @@
#ifndef COMMON_H
#define COMMON_H
#include "net/gnrc/netif.h"
#ifdef __cplusplus
@ -93,14 +91,6 @@ extern "C" {
#define GLOBAL_PFX64 { GP1, GP2, GP3, GP4, GP5, GP6, GP7, GP8, \
LA1 ^ 0x82, LA2, LA3, LA4, LA5, LA6, LA7, LA8 }
extern netdev_t *ethernet_dev;
extern netdev_t *ieee802154_dev;
extern netdev_t *devs[DEFAULT_DEVS_NUMOF];
void _tests_init(void);
void _test_trigger_recv(gnrc_netif_t *netif, const uint8_t *data,
size_t data_len);
#ifdef __cplusplus
}
#endif

View File

@ -18,6 +18,7 @@
#include <stdint.h>
#include "common.h"
#include "embUnit.h"
#include "net/eui48.h"
#include "net/eui64.h"
@ -416,6 +417,56 @@ static void test_ipv6_group_to_l2group__ENOTSUP(void)
&test_group, res));
}
static void test_l2util_addr_to_str(void)
{
static const uint8_t ethernet_l2addr[] = ETHERNET_SRC;
static const uint8_t ieee802154_l2addr_long[] = IEEE802154_LONG_SRC;
static const uint8_t ieee802154_l2addr_short[] = IEEE802154_SHORT_SRC;
static const uint8_t netif0_l2addr[] = NETIF0_SRC;
char out[sizeof(netif0_l2addr) * 3];
TEST_ASSERT(out == l2util_addr_to_str(NULL, 0, out));
TEST_ASSERT_EQUAL_STRING("", &out[0]);
TEST_ASSERT(out == l2util_addr_to_str(ethernet_l2addr,
sizeof(ethernet_l2addr), out));
TEST_ASSERT_EQUAL_STRING("3E:E6:B5:22:FD:0A", &out[0]);
TEST_ASSERT(out == l2util_addr_to_str(ieee802154_l2addr_long,
sizeof(ieee802154_l2addr_long),
out));
TEST_ASSERT_EQUAL_STRING("3E:E6:B5:0F:19:22:FD:0A", &out[0]);
TEST_ASSERT(out == l2util_addr_to_str(ieee802154_l2addr_short,
sizeof(ieee802154_l2addr_short),
out));
TEST_ASSERT_EQUAL_STRING("FD:0A", &out[0]);
TEST_ASSERT(out == l2util_addr_to_str(netif0_l2addr,
sizeof(netif0_l2addr),
out));
TEST_ASSERT_EQUAL_STRING("3E:E7:B5:0F:19:22:FD:0A", &out[0]);
}
static void test_l2util_addr_from_str(void)
{
static const uint8_t ethernet_l2addr[] = ETHERNET_SRC;
static const uint8_t ieee802154_l2addr_long[] = IEEE802154_LONG_SRC;
static const uint8_t ieee802154_l2addr_short[] = IEEE802154_SHORT_SRC;
uint8_t out[GNRC_NETIF_L2ADDR_MAXLEN];
TEST_ASSERT_EQUAL_INT(0, l2util_addr_from_str("", out));
TEST_ASSERT_EQUAL_INT(sizeof(ethernet_l2addr),
l2util_addr_from_str("3E:E6:B5:22:FD:0A", out));
TEST_ASSERT_EQUAL_INT(0, memcmp(ethernet_l2addr, out,
sizeof(ethernet_l2addr)));
TEST_ASSERT_EQUAL_INT(sizeof(ieee802154_l2addr_long),
l2util_addr_from_str("3E:E6:B5:0F:19:22:FD:0A",
out));
TEST_ASSERT_EQUAL_INT(0, memcmp(ieee802154_l2addr_long, out,
sizeof(ieee802154_l2addr_long)));
TEST_ASSERT_EQUAL_INT(sizeof(ieee802154_l2addr_short),
l2util_addr_from_str("FD:0A", out));
TEST_ASSERT_EQUAL_INT(0, memcmp(ieee802154_l2addr_short, out,
sizeof(ieee802154_l2addr_short)));
}
TestRef test_l2util(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
@ -432,6 +483,8 @@ TestRef test_l2util(void)
new_TestFixture(test_addr_len_from_l2ao__ENOTSUP),
new_TestFixture(test_ipv6_group_to_l2group__success),
new_TestFixture(test_ipv6_group_to_l2group__ENOTSUP),
new_TestFixture(test_l2util_addr_to_str),
new_TestFixture(test_l2util_addr_from_str),
};
EMB_UNIT_TESTCALLER(tests_l2util, NULL, NULL, fixtures);

View File

@ -1,7 +0,0 @@
include ../Makefile.tests_common
USEMODULE += embunit
USEMODULE += netif
USEMODULE += od
include $(RIOTBASE)/Makefile.include

View File

@ -1,57 +0,0 @@
BOARD_INSUFFICIENT_MEMORY := \
airfy-beacon \
arduino-duemilanove \
arduino-leonardo \
arduino-mega2560 \
arduino-nano \
arduino-uno \
atmega1284p \
atmega328p \
b-l072z-lrwan1 \
blackpill \
blackpill-128kib \
bluepill \
bluepill-128kib \
calliope-mini \
cc2650-launchpad \
cc2650stk \
derfmega128 \
hifive1 \
hifive1b \
i-nucleo-lrwan1 \
im880b \
lsn50 \
maple-mini \
mega-xplained \
microbit \
microduino-corerf \
msb-430 \
msb-430h \
nrf51dk \
nrf51dongle \
nrf6310 \
nucleo-f030r8 \
nucleo-f031k6 \
nucleo-f042k6 \
nucleo-f070rb \
nucleo-f072rb \
nucleo-f103rb \
nucleo-f302r8 \
nucleo-f303k8 \
nucleo-f334r8 \
nucleo-l031k6 \
nucleo-l053r8 \
nucleo-l073rz \
olimexino-stm32 \
opencm904 \
saml10-xpro \
saml11-xpro \
spark-core \
stm32f030f4-demo \
stm32f0discovery \
stm32l0538-disco \
telosb \
waspmote-pro \
yunjia-nrf51822 \
z1 \
#

View File

@ -1,101 +0,0 @@
/*
* Copyright (C) 2017 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.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Tests common netif functions
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
*
* @}
*/
#include <errno.h>
#include <stdio.h>
#include "common.h"
#include "embUnit.h"
#include "embUnit/embUnit.h"
#include "net/ethernet.h"
#include "net/ipv6.h"
#include "net/netif.h"
#include "test_utils/expect.h"
static void test_netif_addr_to_str(void)
{
static const uint8_t ethernet_l2addr[] = ETHERNET_SRC;
static const uint8_t ieee802154_l2addr_long[] = IEEE802154_LONG_SRC;
static const uint8_t ieee802154_l2addr_short[] = IEEE802154_SHORT_SRC;
static const uint8_t netif0_l2addr[] = NETIF0_SRC;
char out[sizeof(netif0_l2addr) * 3];
TEST_ASSERT(out == netif_addr_to_str(NULL, 0, out));
TEST_ASSERT_EQUAL_STRING("", &out[0]);
TEST_ASSERT(out == netif_addr_to_str(ethernet_l2addr,
sizeof(ethernet_l2addr), out));
TEST_ASSERT_EQUAL_STRING("3E:E6:B5:22:FD:0A", &out[0]);
TEST_ASSERT(out == netif_addr_to_str(ieee802154_l2addr_long,
sizeof(ieee802154_l2addr_long),
out));
TEST_ASSERT_EQUAL_STRING("3E:E6:B5:0F:19:22:FD:0A", &out[0]);
TEST_ASSERT(out == netif_addr_to_str(ieee802154_l2addr_short,
sizeof(ieee802154_l2addr_short),
out));
TEST_ASSERT_EQUAL_STRING("FD:0A", &out[0]);
TEST_ASSERT(out == netif_addr_to_str(netif0_l2addr,
sizeof(netif0_l2addr),
out));
TEST_ASSERT_EQUAL_STRING("3E:E7:B5:0F:19:22:FD:0A", &out[0]);
}
static void test_netif_addr_from_str(void)
{
static const uint8_t ethernet_l2addr[] = ETHERNET_SRC;
static const uint8_t ieee802154_l2addr_long[] = IEEE802154_LONG_SRC;
static const uint8_t ieee802154_l2addr_short[] = IEEE802154_SHORT_SRC;
uint8_t out[GNRC_NETIF_L2ADDR_MAXLEN];
TEST_ASSERT_EQUAL_INT(0, netif_addr_from_str("", out));
TEST_ASSERT_EQUAL_INT(sizeof(ethernet_l2addr),
netif_addr_from_str("3E:E6:B5:22:FD:0A", out));
TEST_ASSERT_EQUAL_INT(0, memcmp(ethernet_l2addr, out,
sizeof(ethernet_l2addr)));
TEST_ASSERT_EQUAL_INT(sizeof(ieee802154_l2addr_long),
netif_addr_from_str("3E:E6:B5:0F:19:22:FD:0A",
out));
TEST_ASSERT_EQUAL_INT(0, memcmp(ieee802154_l2addr_long, out,
sizeof(ieee802154_l2addr_long)));
TEST_ASSERT_EQUAL_INT(sizeof(ieee802154_l2addr_short),
netif_addr_from_str("FD:0A", out));
TEST_ASSERT_EQUAL_INT(0, memcmp(ieee802154_l2addr_short, out,
sizeof(ieee802154_l2addr_short)));
}
static Test *embunit_tests_netif(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_netif_addr_to_str),
new_TestFixture(test_netif_addr_from_str),
/* only add tests not involving output here */
};
EMB_UNIT_TESTCALLER(tests, NULL, NULL, fixtures);
return (Test *)&tests;
}
int main(void)
{
TESTS_START();
TESTS_RUN(embunit_tests_netif());
TESTS_END();
return 0;
}

View File

@ -1,20 +0,0 @@
#!/usr/bin/env python3
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
# Copyright (C) 2016 Takuo Yonezawa <Yonezawa-T2@mail.dnp.co.jp>
#
# 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.
import sys
from testrunner import run, check_unittests
def testfunc(child):
# embUnit tests
check_unittests(child)
if __name__ == "__main__":
sys.exit(run(testfunc, timeout=1, traceback=True))