Skip to content

Commit

Permalink
tests: provide unittests for gnrc_netif_pktq
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Sep 2, 2020
1 parent bd066bc commit bb2f1c2
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/unittests/tests-gnrc_netif_pktq/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
3 changes: 3 additions & 0 deletions tests/unittests/tests-gnrc_netif_pktq/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
USEMODULE += gnrc_netif_pktq

CFLAGS += -DCONFIG_GNRC_NETIF_PKTQ_POOL_SIZE=4
141 changes: 141 additions & 0 deletions tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.c
Original file line number Diff line number Diff line change
@@ -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());
}

/** @} */
35 changes: 35 additions & 0 deletions tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.h
Original file line number Diff line number Diff line change
@@ -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 */
/** @} */

0 comments on commit bb2f1c2

Please sign in to comment.