diff --git a/tests/unittests/tests-gnrc_netif_pktq/Makefile b/tests/unittests/tests-gnrc_netif_pktq/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/tests/unittests/tests-gnrc_netif_pktq/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-gnrc_netif_pktq/Makefile.include b/tests/unittests/tests-gnrc_netif_pktq/Makefile.include new file mode 100644 index 0000000000..72aa5c7b7c --- /dev/null +++ b/tests/unittests/tests-gnrc_netif_pktq/Makefile.include @@ -0,0 +1,3 @@ +USEMODULE += gnrc_netif_pktq + +CFLAGS += -DCONFIG_GNRC_NETIF_PKTQ_POOL_SIZE=4 diff --git a/tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.c b/tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.c new file mode 100644 index 0000000000..dded729fe5 --- /dev/null +++ b/tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.c @@ -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 + */ + +#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()); +} + +/** @} */ diff --git a/tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.h b/tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.h new file mode 100644 index 0000000000..c7443df293 --- /dev/null +++ b/tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.h @@ -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 + */ +#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 */ +/** @} */