From cdc252ab7bd4161cc046bf93a3e55995704b24d4 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Wed, 17 Jun 2020 16:12:43 +0200 Subject: [PATCH] net/gnrc/nettest: Remove module This module has been deprecated and scheduled for removal in release 2020.07. --- Makefile.dep | 8 - sys/include/net/gnrc/nettest.h | 289 ---------------------------- sys/net/gnrc/Makefile | 3 - sys/net/gnrc/nettest/Makefile | 3 - sys/net/gnrc/nettest/gnrc_nettest.c | 254 ------------------------ 5 files changed, 557 deletions(-) delete mode 100644 sys/include/net/gnrc/nettest.h delete mode 100644 sys/net/gnrc/nettest/Makefile delete mode 100644 sys/net/gnrc/nettest/gnrc_nettest.c diff --git a/Makefile.dep b/Makefile.dep index eb4e8a138d9d..0b9f7cdc8d99 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -432,14 +432,6 @@ ifneq (,$(filter gnrc_tcp,$(USEMODULE))) USEMODULE += core_mbox endif -ifneq (,$(filter gnrc_nettest,$(USEMODULE))) - USEMODULE += gnrc_netapi - USEMODULE += gnrc_netreg - USEMODULE += gnrc_netif - USEMODULE += gnrc_pktbuf - USEMODULE += xtimer -endif - ifneq (,$(filter gnrc_pktdump,$(USEMODULE))) DEFAULT_MODULE += auto_init_gnrc_pktdump USEMODULE += gnrc_pktbuf diff --git a/sys/include/net/gnrc/nettest.h b/sys/include/net/gnrc/nettest.h deleted file mode 100644 index 6a54e7d24448..000000000000 --- a/sys/include/net/gnrc/nettest.h +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * - * 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. - */ - -/** - * @defgroup net_gnrc_nettest NETAPI test framework - * @ingroup net_gnrc_netapi - * @brief This provides a framework to test the @ref net_gnrc_netapi IPC - * calls. - * - * @deprecated This module was intended to be a test framework for GNRC but - * it never got used. It has not been maintained for 3 years. - * It will be removed after the 2020.07 release at the latest. - * @{ - * - * @file - * @brief Definitions for the @ref net_gnrc_netapi test framework - * - * @author Martine Lenders - */ -#ifndef NET_GNRC_NETTEST_H -#define NET_GNRC_NETTEST_H - -#include -#include - -#include "kernel_types.h" -#include "net/gnrc/netapi.h" -#include "net/netopt.h" -#include "net/gnrc/nettype.h" -#include "net/gnrc/pkt.h" -#include "thread.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup net_gnrc_nettest_conf GNRC NETAPI test compile configurations - * @ingroup net_gnrc_conf - * @{ - */ -/** - * @brief Timeout for tests in microseconds - */ -#ifndef GNRC_NETTEST_TIMEOUT -#define GNRC_NETTEST_TIMEOUT (1000) -#endif - -/** - * @brief Default stack size to use for the nettest thread - */ -#ifndef GNRC_NETTEST_STACK_SIZE -#define GNRC_NETTEST_STACK_SIZE (THREAD_STACKSIZE_DEFAULT) -#endif - -/** - * @brief Default priority for the nettest thread - */ -#ifndef GNRC_NETTEST_PRIO -#define GNRC_NETTEST_PRIO (THREAD_PRIORITY_MAIN) -#endif - -/** - * @brief Default message queue size to use for the nettest thread (as - * exponent of 2^n). - * - * As the queue size ALWAYS needs to be power of two, this option - * represents the exponent of 2^n, which will be used as the size of - * the queue. - */ -#ifndef CONFIG_GNRC_NETTEST_MSG_QUEUE_SIZE_EXP -#define CONFIG_GNRC_NETTEST_MSG_QUEUE_SIZE_EXP (3U) -#endif -/** @} */ - -/** - * @brief Message queue size to use for the nettest thread. - */ -#ifndef GNRC_NETTEST_MSG_QUEUE_SIZE -#define GNRC_NETTEST_MSG_QUEUE_SIZE (1 << CONFIG_GNRC_NETTEST_MSG_QUEUE_SIZE_EXP) -#endif - -/** - * @brief Type for get/set callbacks. - * - * @param[in] context (Optional) context for the option. - * Compare gnrc_netapi_opt_t::context. - * @param[in,out] data Data to set or buffer to read into. - * Compare gnrc_netapi_opt_t::data. - * @param[in] data_len Size of the data / the buffer. - * Compare gnrc_netapi_opt_t::data_len - * - * @return The value for the @ref GNRC_NETAPI_MSG_TYPE_ACK message. - */ -typedef int (*gnrc_nettest_opt_cb_t)(uint16_t context, void *data, uint16_t data_len); - -/** - * @brief Option callback list element. - */ -typedef struct { - gnrc_nettest_opt_cb_t get; /**< getter for an option */ - gnrc_nettest_opt_cb_t set; /**< setter for an option */ -} gnrc_nettest_opt_cbs_t; - -/** - * @brief Result type for tests. - */ -typedef enum { - GNRC_NETTEST_SUCCESS = 0, /**< test was successful */ - GNRC_NETTEST_FAIL, /**< test failed */ - GNRC_NETTEST_TIMED_OUT, /**< test timed out */ - GNRC_NETTEST_WRONG_MSG, /**< wrong message type received */ - GNRC_NETTEST_WRONG_SENDER, /**< wrong message type received */ -} gnrc_nettest_res_t; - -/** - * @brief Registers a getter for an option. - * - * @details Overrides previous registrations. - * - * @param[in] opt The option to register the getter for. - * @param[in] cb An option getter. NULL to delete. - */ -void gnrc_nettest_register_get(netopt_t opt, gnrc_nettest_opt_cb_t cb); - -/** - * @brief Registers a setter for an option. - * - * @details Overrides previous registrations. - * - * @param[in] opt The option to register the setter for. - * @param[in] cb An option setter. NULL to delete. - */ -void gnrc_nettest_register_set(netopt_t opt, gnrc_nettest_opt_cb_t cb); - -/** - * @brief Test @ref GNRC_NETAPI_MSG_TYPE_SND command to @p pid. - * - * @details This registered the nettest thread to (@p exp_type, @p exp_demux_ctx) - * and checks if @p exp_pkts of @p exp_out were received from @p exp_senders. - * If no message was received after @ref GNRC_NETTEST_TIMEOUT microseconds, while - * there are still packets expected, the function will return GNRC_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 GNRC_NETAPI_MSG_TYPE_SND command for. - * @param[in] in The packet you want to send through @p pid. - * @param[in] exp_pkts The number of packets expected to be received. - * @param[in] exp_senders The PID the resulting packet should be coming from. - * Must be of dimension @p exp_pkts. - * @param[in] exp_out The expected packet from @p exp_sender. - * Must be of dimension @p exp_pkts. - * @param[in] exp_type The expected receiver type for the - * @ref GNRC_NETAPI_MSG_TYPE_SND command. - * @param[in] exp_demux_ctx The expected receiver demux type for the - * @ref GNRC_NETAPI_MSG_TYPE_SND command. - * - * @return @see gnrc_nettest_res_t - */ -gnrc_nettest_res_t gnrc_nettest_send(kernel_pid_t pid, gnrc_pktsnip_t *in, - unsigned int exp_pkts, - const kernel_pid_t *exp_senders, - const gnrc_pktsnip_t **exp_out, - gnrc_nettype_t exp_type, uint32_t exp_demux_ctx); - -/** - * @brief Test @ref GNRC_NETAPI_MSG_TYPE_SND command to @p pid with the receiving - * thread being an interface. - * - * @details This registered the nettest thread as an interface and checks ifx - * @p exp_pkts of @p exp_out were received from @p exp_senders. If no message - * was received after @ref GNRC_NETTEST_TIMEOUT microseconds, while there are - * still packets expected, the function will return GNRC_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 GNRC_NETAPI_MSG_TYPE_SND command for. - * @param[in] in The packet you want to send through @p pid. - * @param[in] exp_pkts The number of packets expected to be received. - * @param[in] exp_senders The PID the resulting packet should be coming from. - * Must be of dimension @p exp_pkts. May be NULL if - * @p exp_pkts == 0. - * @param[in] exp_out The expected packet from @p exp_sender. - * Must be of dimension @p exp_pkts. May be NULL if - * @p exp_pkts == 0. - * - * @return @see gnrc_nettest_res_t - */ -gnrc_nettest_res_t gnrc_nettest_send_iface(kernel_pid_t pid, gnrc_pktsnip_t *in, - unsigned int exp_pkts, - const kernel_pid_t *exp_senders, - const gnrc_pktsnip_t **exp_out); - -/** - * @brief Test @ref GNRC_NETAPI_MSG_TYPE_RCV command to @p pid. - * - * @details This registered the nettest thread to (@p exp_type, @p exp_demux_ctx) - * and checks if @p exp_pkts of @p exp_out were received from @p exp_senders. - * If no message was received after @ref GNRC_NETTEST_TIMEOUT microseconds, while - * there are still packets expected, the function will return GNRC_NETTEST_TIMED_OUT. - * - * @param[in] pid The thread you want to test the - * @ref GNRC_NETAPI_MSG_TYPE_RCV command for. - * @param[in] in The packet you want to send through @p pid. - * @param[in] exp_pkts The number of packets expected to be received. - * @param[in] exp_senders The PID the resulting packet should be coming from. - * Must be of dimension @p exp_pkts. - * @param[in] exp_out The expected packet from @p exp_sender. - * Must be of dimension @p exp_pkts. - * @param[in] exp_type The expected receiver type for the - * @ref GNRC_NETAPI_MSG_TYPE_RCV command. - * @param[in] exp_demux_ctx The expected receiver demux type for the - * @ref GNRC_NETAPI_MSG_TYPE_RCV command. - * - * @return @see gnrc_nettest_res_t - */ -gnrc_nettest_res_t gnrc_nettest_receive(kernel_pid_t pid, gnrc_pktsnip_t *in, - unsigned int exp_pkts, - const kernel_pid_t *exp_senders, - const gnrc_pktsnip_t **exp_out, - gnrc_nettype_t exp_type, uint32_t exp_demux_ctx); - -/** - * @brief Test @ref GNRC_NETAPI_MSG_TYPE_GET command to @p pid. - * - * @param[in] pid The thread you want to test the - * @ref GNRC_NETAPI_MSG_TYPE_GET command for. - * @param[in] opt The option you want to test. - * @param[in] context The context for the option. - * @param[in] data The data pointer for the @ref GNRC_NETAPI_MSG_TYPE_GET - * command. - * @param[in] data_len The maximum length for @p data. - * @param[in] exp_data The expected value for the returned data. May be - * NULL if @p exp_res < 0 - * @param[in] exp_res The expected return value for the - * @ref GNRC_NETAPI_MSG_TYPE_GET command. - * - * @return @see gnrc_nettest_res_t - */ -gnrc_nettest_res_t gnrc_nettest_get(kernel_pid_t pid, netopt_t opt, - uint16_t context, void *data, size_t data_len, - void *exp_data, int exp_res); - -/** - * @brief Test @ref GNRC_NETAPI_MSG_TYPE_SET command to @p pid. - * - * @param[in] pid The thread you want to test the - * @ref GNRC_NETAPI_MSG_TYPE_SET command for. - * @param[in] opt The option you want to test. - * @param[in] context The context for the option. - * @param[in] data The data pointer for the @ref GNRC_NETAPI_MSG_TYPE_SET - * command. - * @param[in] data_len The maximum length for @p data. - * @param[in] exp_res The expected return value for the - * @ref GNRC_NETAPI_MSG_TYPE_SET command. - * - * @return @see gnrc_nettest_res_t - */ -gnrc_nettest_res_t gnrc_nettest_set(kernel_pid_t pid, netopt_t opt, - uint16_t context, void *data, size_t data_len, - int exp_res); - -/** - * @brief Initializes the @ref net_gnrc_nettest module. - * - * @return The PID to the nettest thread, on success. - * @return a negative errno on error. - * @return -EOVERFLOW, if there are too many threads running already - */ -int gnrc_nettest_init(void); - -/** - * @brief Resets gnrc_nettest_opt_cbs_t list. - */ -void gnrc_nettest_reset(void); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_NETTEST_H */ -/** @} */ diff --git a/sys/net/gnrc/Makefile b/sys/net/gnrc/Makefile index dfd7cb3af246..2322bed62ec5 100644 --- a/sys/net/gnrc/Makefile +++ b/sys/net/gnrc/Makefile @@ -49,9 +49,6 @@ endif ifneq (,$(filter gnrc_netreg,$(USEMODULE))) DIRS += netreg endif -ifneq (,$(filter gnrc_nettest,$(USEMODULE))) - DIRS += nettest -endif ifneq (,$(filter gnrc_mac,$(USEMODULE))) DIRS += link_layer/mac endif diff --git a/sys/net/gnrc/nettest/Makefile b/sys/net/gnrc/nettest/Makefile deleted file mode 100644 index c70fa91575d8..000000000000 --- a/sys/net/gnrc/nettest/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_nettest - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/nettest/gnrc_nettest.c b/sys/net/gnrc/nettest/gnrc_nettest.c deleted file mode 100644 index bce9c20ad298..000000000000 --- a/sys/net/gnrc/nettest/gnrc_nettest.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * - * 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 - */ - -#include -#include - -#include "msg.h" -#include "mutex.h" -#include "net/gnrc/netapi.h" -#include "net/netopt.h" -#include "net/gnrc/netreg.h" -#include "net/gnrc/pktbuf.h" -#include "thread.h" -#include "xtimer.h" - -#include "net/gnrc/nettest.h" - -static gnrc_nettest_opt_cbs_t _opt_cbs[NETOPT_NUMOF]; -static mutex_t _mutex = MUTEX_INIT; -static kernel_pid_t _pid = KERNEL_PID_UNDEF; -static char _stack[GNRC_NETTEST_STACK_SIZE]; - -static void *_event_loop(void *arg); - -void gnrc_nettest_register_get(netopt_t opt, gnrc_nettest_opt_cb_t cb) -{ - mutex_lock(&_mutex); - _opt_cbs[opt].get = cb; - mutex_unlock(&_mutex); -} - -void gnrc_nettest_register_set(netopt_t opt, gnrc_nettest_opt_cb_t cb) -{ - mutex_lock(&_mutex); - _opt_cbs[opt].set = cb; - mutex_unlock(&_mutex); -} - -static gnrc_nettest_res_t _pkt_test(uint16_t cmd_type, kernel_pid_t pid, - gnrc_pktsnip_t *in, unsigned int exp_pkts, - const kernel_pid_t *exp_senders, - const gnrc_pktsnip_t **exp_out) -{ - msg_t msg; - gnrc_nettest_res_t res = GNRC_NETTEST_SUCCESS; - - msg.type = cmd_type; - msg.content.ptr = in; - - msg_send(&msg, pid); - - if (exp_pkts == 0) { - thread_yield(); - } - - for (unsigned int i = 0; i < exp_pkts; i++) { - gnrc_pktsnip_t *out; - const gnrc_pktsnip_t *exp = exp_out[i]; - - if (xtimer_msg_receive_timeout(&msg, GNRC_NETTEST_TIMEOUT) < 0) { - return GNRC_NETTEST_TIMED_OUT; - } - - if (msg.type != cmd_type) { - return GNRC_NETTEST_WRONG_MSG; - } - - if (msg.sender_pid != exp_senders[i]) { - return GNRC_NETTEST_WRONG_SENDER; - } - - out = msg.content.ptr; - - if (out == NULL) { - return GNRC_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 GNRC_NETTEST_FAIL; - } - - out = out->next; - exp = exp->next; - } - - gnrc_pktbuf_release(msg.content.ptr); - } - - return res; -} - -gnrc_nettest_res_t gnrc_nettest_send(kernel_pid_t pid, gnrc_pktsnip_t *in, - unsigned int exp_pkts, - const kernel_pid_t *exp_senders, - const gnrc_pktsnip_t **exp_out, - gnrc_nettype_t exp_type, uint32_t exp_demux_ctx) -{ - gnrc_netreg_entry_t reg_entry = GNRC_NETREG_ENTRY_INIT_PID(exp_demux_ctx, - sched_active_pid); - gnrc_nettest_res_t res; - - gnrc_netreg_register(exp_type, ®_entry); - - res = _pkt_test(GNRC_NETAPI_MSG_TYPE_SND, pid, in, exp_pkts, exp_senders, - exp_out); - - gnrc_netreg_unregister(exp_type, ®_entry); - - return res; -} - -gnrc_nettest_res_t gnrc_nettest_send_iface(kernel_pid_t pid, gnrc_pktsnip_t *in, - unsigned int exp_pkts, - const kernel_pid_t *exp_senders, - const gnrc_pktsnip_t **exp_out) -{ - gnrc_nettest_res_t res; - - res = _pkt_test(GNRC_NETAPI_MSG_TYPE_SND, pid, in, exp_pkts, exp_senders, - exp_out); - - return res; -} - -gnrc_nettest_res_t gnrc_nettest_receive(kernel_pid_t pid, gnrc_pktsnip_t *in, - unsigned int exp_pkts, - const kernel_pid_t *exp_senders, - const gnrc_pktsnip_t **exp_out, - gnrc_nettype_t exp_type, uint32_t exp_demux_ctx) -{ - gnrc_netreg_entry_t reg_entry = GNRC_NETREG_ENTRY_INIT_PID(exp_demux_ctx, - sched_active_pid); - gnrc_nettest_res_t res; - - gnrc_netreg_register(exp_type, ®_entry); - - res = _pkt_test(GNRC_NETAPI_MSG_TYPE_RCV, pid, in, exp_pkts, exp_senders, - exp_out); - - gnrc_netreg_unregister(exp_type, ®_entry); - - return res; -} - -gnrc_nettest_res_t gnrc_nettest_get(kernel_pid_t pid, netopt_t opt, - uint16_t context, void *data, size_t data_len, - void *exp_data, int exp_res) -{ - if ((exp_res != gnrc_netapi_get(pid, opt, context, data, data_len)) || - ((exp_res > 0) && (memcpy(exp_data, data, exp_res)))) { - return GNRC_NETTEST_FAIL; - } - - return GNRC_NETTEST_SUCCESS; -} - -gnrc_nettest_res_t gnrc_nettest_set(kernel_pid_t pid, netopt_t opt, - uint16_t context, void *data, size_t data_len, - int exp_res) -{ - if (exp_res != gnrc_netapi_get(pid, opt, context, data, data_len)) { - return GNRC_NETTEST_FAIL; - } - - return GNRC_NETTEST_SUCCESS; -} - -int gnrc_nettest_init(void) -{ - if (_pid <= KERNEL_PID_UNDEF) { - _pid = thread_create(_stack, sizeof(_stack), GNRC_NETTEST_PRIO, - THREAD_CREATE_STACKTEST, - _event_loop, NULL, "nettest"); - } - - return _pid; -} - -void gnrc_nettest_reset(void) -{ - for (int i = 0; i < NETOPT_NUMOF; i++) { - _opt_cbs[i].get = NULL; - _opt_cbs[i].set = NULL; - } -} - -static inline uint32_t _get_set_opt(gnrc_nettest_opt_cb_t cb, uint16_t context, - void *data, uint16_t data_len) -{ - int res; - - mutex_lock(&_mutex); - if (cb != NULL) { - res = cb(context, data, data_len); - } - else { - res = -ENOTSUP; - } - mutex_unlock(&_mutex); - return (uint32_t)res; -} - -static void *_event_loop(void *arg) -{ - msg_t reply, msg_queue[GNRC_NETTEST_MSG_QUEUE_SIZE]; - - (void)arg; - msg_init_queue(msg_queue, GNRC_NETTEST_MSG_QUEUE_SIZE); - reply.type = GNRC_NETAPI_MSG_TYPE_ACK; - - while (1) { - msg_t msg; - gnrc_netapi_opt_t *opt; - - msg_receive(&msg); - - switch (msg.type) { - case GNRC_NETAPI_MSG_TYPE_GET: - opt = msg.content.ptr; - reply.content.value = _get_set_opt(_opt_cbs[opt->opt].get, - opt->context, opt->data, - opt->data_len); - break; - - case GNRC_NETAPI_MSG_TYPE_SET: - opt = msg.content.ptr; - reply.content.value = _get_set_opt(_opt_cbs[opt->opt].set, - opt->context, opt->data, - opt->data_len); - break; - } - - msg_reply(&msg, &reply); - } - - return NULL; -} - -/** @} */