mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests: provide unittests for gnrc_netif_pktq
This commit is contained in:
parent
a72d0ef3e8
commit
818097f0dc
1
tests/unittests/tests-gnrc_netif_pktq/Makefile
Normal file
1
tests/unittests/tests-gnrc_netif_pktq/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
3
tests/unittests/tests-gnrc_netif_pktq/Makefile.include
Normal file
3
tests/unittests/tests-gnrc_netif_pktq/Makefile.include
Normal file
@ -0,0 +1,3 @@
|
||||
USEMODULE += gnrc_netif_pktq
|
||||
|
||||
CFLAGS += -DCONFIG_GNRC_NETIF_PKTQ_POOL_SIZE=4
|
141
tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.c
Normal file
141
tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.c
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 "embUnit.h"
|
||||
|
||||
#include "net/gnrc/netif/conf.h"
|
||||
#include "net/gnrc/netif/pktq.h"
|
||||
|
||||
#include "tests-gnrc_netif_pktq.h"
|
||||
|
||||
gnrc_netif_t _netif;
|
||||
|
||||
static void set_up(void)
|
||||
{
|
||||
while (gnrc_netif_pktq_get(&_netif)) { }
|
||||
}
|
||||
|
||||
static void test_pktq_get__empty(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(gnrc_netif_pktq_get(&_netif));
|
||||
}
|
||||
|
||||
static void test_pktq_put__full(void)
|
||||
{
|
||||
gnrc_pktsnip_t pkt;
|
||||
|
||||
for (unsigned i = 0; i < CONFIG_GNRC_NETIF_PKTQ_POOL_SIZE; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_pktq_put(&_netif, &pkt));
|
||||
}
|
||||
TEST_ASSERT_EQUAL_INT(-1, gnrc_netif_pktq_put(&_netif, &pkt));
|
||||
}
|
||||
|
||||
static void test_pktq_put_get1(void)
|
||||
{
|
||||
gnrc_pktsnip_t pkt_in, *pkt_out;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_pktq_put(&_netif, &pkt_in));
|
||||
TEST_ASSERT_NOT_NULL((pkt_out = gnrc_netif_pktq_get(&_netif)));
|
||||
TEST_ASSERT(&pkt_in == pkt_out);
|
||||
}
|
||||
|
||||
static void test_pktq_put_get3(void)
|
||||
{
|
||||
gnrc_pktsnip_t pkt_in[3];
|
||||
|
||||
for (unsigned i = 0; i < 3; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_pktq_put(&_netif, &pkt_in[i]));
|
||||
}
|
||||
for (unsigned i = 0; i < 3; i++) {
|
||||
gnrc_pktsnip_t *pkt_out;
|
||||
|
||||
TEST_ASSERT_NOT_NULL((pkt_out = gnrc_netif_pktq_get(&_netif)));
|
||||
TEST_ASSERT(&pkt_in[i] == pkt_out);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_pktq_push_back__full(void)
|
||||
{
|
||||
gnrc_pktsnip_t pkt;
|
||||
|
||||
for (unsigned i = 0; i < CONFIG_GNRC_NETIF_PKTQ_POOL_SIZE; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_pktq_put(&_netif, &pkt));
|
||||
}
|
||||
TEST_ASSERT_EQUAL_INT(-1, gnrc_netif_pktq_push_back(&_netif, &pkt));
|
||||
}
|
||||
|
||||
static void test_pktq_push_back_get1(void)
|
||||
{
|
||||
gnrc_pktsnip_t pkt_in, *pkt_out;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_pktq_push_back(&_netif, &pkt_in));
|
||||
TEST_ASSERT_NOT_NULL((pkt_out = gnrc_netif_pktq_get(&_netif)));
|
||||
TEST_ASSERT(&pkt_in == pkt_out);
|
||||
}
|
||||
|
||||
static void test_pktq_push_back_get3(void)
|
||||
{
|
||||
gnrc_pktsnip_t pkt_in[3];
|
||||
|
||||
for (unsigned i = 0; i < 3; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_pktq_push_back(&_netif, &pkt_in[i]));
|
||||
}
|
||||
for (unsigned i = 0; i < 3; i++) {
|
||||
gnrc_pktsnip_t *pkt_out;
|
||||
|
||||
TEST_ASSERT_NOT_NULL((pkt_out = gnrc_netif_pktq_get(&_netif)));
|
||||
TEST_ASSERT(&pkt_in[3 - i - 1] == pkt_out);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_pktq_empty(void)
|
||||
{
|
||||
gnrc_pktsnip_t pkt_in;
|
||||
|
||||
TEST_ASSERT(gnrc_netif_pktq_empty(&_netif));
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_pktq_put(&_netif, &pkt_in));
|
||||
TEST_ASSERT(!gnrc_netif_pktq_empty(&_netif));
|
||||
TEST_ASSERT_NOT_NULL(gnrc_netif_pktq_get(&_netif));
|
||||
TEST_ASSERT(gnrc_netif_pktq_empty(&_netif));
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_pktq_push_back(&_netif, &pkt_in));
|
||||
TEST_ASSERT(!gnrc_netif_pktq_empty(&_netif));
|
||||
TEST_ASSERT_NOT_NULL(gnrc_netif_pktq_get(&_netif));
|
||||
TEST_ASSERT(gnrc_netif_pktq_empty(&_netif));
|
||||
}
|
||||
|
||||
static Test *test_gnrc_netif_pktq(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_pktq_get__empty),
|
||||
new_TestFixture(test_pktq_put__full),
|
||||
new_TestFixture(test_pktq_put_get1),
|
||||
new_TestFixture(test_pktq_put_get3),
|
||||
new_TestFixture(test_pktq_push_back__full),
|
||||
new_TestFixture(test_pktq_push_back_get1),
|
||||
new_TestFixture(test_pktq_push_back_get3),
|
||||
new_TestFixture(test_pktq_empty),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(pktq_tests, set_up, NULL, fixtures);
|
||||
|
||||
return (Test *)&pktq_tests;
|
||||
}
|
||||
|
||||
void tests_gnrc_netif_pktq(void)
|
||||
{
|
||||
TESTS_RUN(test_gnrc_netif_pktq());
|
||||
}
|
||||
|
||||
/** @} */
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 unittests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief unittests for the `gnrc_netif_pktq` module
|
||||
*
|
||||
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
#ifndef TESTS_GNRC_NETIF_PKTQ_H
|
||||
#define TESTS_GNRC_NETIF_PKTQ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The entry point of this test suite.
|
||||
*/
|
||||
void tests_pktqueue(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TESTS_GNRC_NETIF_PKTQ_H */
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user