-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: provide unittests for gnrc_netif_pktq
- Loading branch information
Showing
4 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
141
tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
tests/unittests/tests-gnrc_netif_pktq/tests-gnrc_netif_pktq.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
/** @} */ |