From 871a6f9cde8020f0d0d0cd29346e285ab4ebe8a0 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 24 Jun 2015 02:50:11 +0200 Subject: [PATCH] ng_nettest: some fixes --- Makefile.dep | 1 + sys/include/net/ng_nettest.h | 4 +++ sys/net/crosslayer/ng_nettest/ng_nettest.c | 33 +++++++++++----------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Makefile.dep b/Makefile.dep index 706e157af8..dee1f81c7a 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -193,6 +193,7 @@ ifneq (,$(filter ng_nettest,$(USEMODULE))) USEMODULE += ng_netreg USEMODULE += ng_netif USEMODULE += ng_pktbuf + USEMODULE += vtimer endif ifneq (,$(filter ng_netbase,$(USEMODULE))) diff --git a/sys/include/net/ng_nettest.h b/sys/include/net/ng_nettest.h index 05f837066b..4878845cc0 100644 --- a/sys/include/net/ng_nettest.h +++ b/sys/include/net/ng_nettest.h @@ -125,6 +125,8 @@ void ng_nettest_register_set(ng_netconf_opt_t opt, ng_nettest_opt_cb_t cb); * If no message was received after @ref NG_NETTEST_TIMEOUT microseconds, while * there are still packets expected, the function will return NG_NETTEST_TIMED_OUT. * + * In case of success it releases all packets send by the tested module. + * * @param[in] pid The thread you want to test the * @ref NG_NETAPI_MSG_TYPE_SND command for. * @param[in] in The packet you want to send through @p pid. @@ -154,6 +156,8 @@ ng_nettest_res_t ng_nettest_send(kernel_pid_t pid, ng_pktsnip_t *in, * was received after @ref NG_NETTEST_TIMEOUT microseconds, while there are * still packets expected, the function will return NG_NETTEST_TIMED_OUT. * + * In case of success it releases all packets received from the tested module. + * * @param[in] pid The thread you want to test the * @ref NG_NETAPI_MSG_TYPE_SND command for. * @param[in] in The packet you want to send through @p pid. diff --git a/sys/net/crosslayer/ng_nettest/ng_nettest.c b/sys/net/crosslayer/ng_nettest/ng_nettest.c index 2fcf19fb6d..9997c8b3f3 100644 --- a/sys/net/crosslayer/ng_nettest/ng_nettest.c +++ b/sys/net/crosslayer/ng_nettest/ng_nettest.c @@ -61,38 +61,39 @@ static ng_nettest_res_t _pkt_test(uint16_t cmd_type, kernel_pid_t pid, ng_pktsni msg.content.ptr = (char *)in; msg_send(&msg, pid); + timex_normalize(&t); for (unsigned int i = 0; i < exp_pkts; i++) { - ng_pktsnip_t *out; + ng_pktsnip_t *out, *exp = exp_out[i]; - if ((vtimer_msg_receive_timeout(&msg, t) < 0) && res == NG_NETTEST_SUCCESS) { - res = NG_NETTEST_TIMED_OUT; + if (vtimer_msg_receive_timeout(&msg, t) < 0) { + return NG_NETTEST_TIMED_OUT; } - if (msg.type != NG_NETAPI_MSG_TYPE_SND && (res == NG_NETTEST_SUCCESS)) { - res = NG_NETTEST_WRONG_MSG; + if (msg.type != cmd_type) { + return NG_NETTEST_WRONG_MSG; } - if (msg.sender_pid != exp_senders[i] && (res == NG_NETTEST_SUCCESS)) { - res = NG_NETTEST_WRONG_SENDER; + if (msg.sender_pid != exp_senders[i]) { + return NG_NETTEST_WRONG_SENDER; } out = (ng_pktsnip_t *)msg.content.ptr; - if ((out == NULL) && (res == NG_NETTEST_SUCCESS)) { - res = NG_NETTEST_FAIL; + if (out == NULL) { + return NG_NETTEST_FAIL; } - while (out) { - if ((res == NG_NETTEST_SUCCESS) && - ((out->users != exp_out[i]->users) || - (out->size != exp_out[i]->size) || - (out->type != exp_out[i]->type) || - (memcmp(out->data, exp_out[i]->data, out->size) != 0))) { - res = NG_NETTEST_FAIL; + while (out && exp) { + if ((out->users != exp->users) || + (out->size != exp->size) || + (out->type != exp->type) || + (memcmp(out->data, exp->data, out->size) != 0)) { + return NG_NETTEST_FAIL; } out = out->next; + exp = exp->next; } ng_pktbuf_release((ng_pktsnip_t *)msg.content.ptr);