diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 1a9de85f6cef..eee3b722d140 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -1922,11 +1922,6 @@ static void _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, bool push_back) /* try to send anyway */ } } - /* hold in case device was busy to not having to rewrite *all* the link - * layer implementations in case `gnrc_netif_pktq` is included */ - if (gnrc_netif_netdev_legacy_api(netif)) { - gnrc_pktbuf_hold(pkt, 1); - } #endif /* IS_USED(MODULE_GNRC_NETIF_PKTQ) */ /* Record send in neighbor statistics if destination is unicast */ @@ -1947,6 +1942,13 @@ static void _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, bool push_back) /* Split off the TX sync snip */ gnrc_pktsnip_t *tx_sync = IS_USED(MODULE_GNRC_TX_SYNC) ? gnrc_tx_sync_split(pkt) : NULL; +#if IS_USED(MODULE_GNRC_NETIF_PKTQ) + /* hold in case device was busy to not having to rewrite *all* the link + * layer implementations in case `gnrc_netif_pktq` is included */ + if (gnrc_netif_netdev_legacy_api(netif)) { + gnrc_pktbuf_hold(pkt, 1); + } +#endif /* IS_USED(MODULE_GNRC_NETIF_PKTQ) */ int res = netif->ops->send(netif, pkt); /* For legacy netdevs (no confirm_send) TX is blocking, thus it is always diff --git a/tests/net/gnrc_legacy_tx_sync/Makefile b/tests/net/gnrc_legacy_tx_sync/Makefile new file mode 100644 index 000000000000..06799805bccd --- /dev/null +++ b/tests/net/gnrc_legacy_tx_sync/Makefile @@ -0,0 +1,12 @@ +include ../Makefile.net_common + +USEMODULE += netdev_default +USEMODULE += auto_init_gnrc_netif +USEMODULE += gnrc_tx_sync +USEMODULE += gnrc_netif_pktq +USEMODULE += nrfmin +USEMODULE += ztimer_sec + +include $(RIOTBASE)/Makefile.include + +CFLAGS += -DDEBUG_ASSERT_VERBOSE=1 diff --git a/tests/net/gnrc_legacy_tx_sync/main.c b/tests/net/gnrc_legacy_tx_sync/main.c new file mode 100644 index 000000000000..222180d05fb4 --- /dev/null +++ b/tests/net/gnrc_legacy_tx_sync/main.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2025 Technische Universität Dresden + * + * 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 + * @brief Text application for gnrc_legacy_tx_sync + * + * @author Lukas Luger + * + * @} + */ + +#include + +#include "net/af.h" +#include "net/gnrc/pktbuf.h" +#include "net/gnrc/tx_sync.h" +#include "net/gnrc.h" +#include "ztimer.h" +#include "thread.h" + +static const char test_msg[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU" + "VWXYZ0123456789.,:;!?@#$%^&*()[]{}-_=+/<>`~\'\"" + "\\"; + +void print_failed(void *arg) +{ + (void)arg; + puts("TEST FAILED"); +} + +int main(void) +{ + puts( + "Test application for gnrc_legacy_tx_sync\n" + "========================================\n" + "\n" + "This application sends a single message over the nrfmin netdev.\n" + "Other legacy netdevs can be used by changing the board and using\n" + "a different driver. Note: RIOT will sometimes choose the\n" + "netdev_ieee802154_submac as default driver which is not legacy.\n" + "tx_sync will only fail if gnrc_netif_pktq is used with a legacy driver.\n" + "If tx_sync does not finish in one second, the test will fail.\n" + ); + + /* Preparing the gnrc message */ + gnrc_netif_t *netif = gnrc_netif_iter(NULL); + gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, test_msg, sizeof(test_msg), + GNRC_NETTYPE_UNDEF); + gnrc_tx_sync_t tx_sync; + gnrc_tx_sync_append(pkt, &tx_sync); + + /* Set timeout message in case tx sync fails */ + ztimer_t timer = { + .callback = print_failed, + .arg = NULL, + }; + ztimer_set(ZTIMER_SEC, &timer, 1); + + /* Sending and waiting */ + gnrc_netapi_send(netif->pid, pkt); + gnrc_tx_sync(&tx_sync); + + /* Cancel error message and print success message */ + ztimer_remove(ZTIMER_SEC, &timer); + puts("TEST PASSED"); + + return 0; +} diff --git a/tests/net/gnrc_legacy_tx_sync/tests/01-run.py b/tests/net/gnrc_legacy_tx_sync/tests/01-run.py new file mode 100755 index 000000000000..7e57a47a9a6d --- /dev/null +++ b/tests/net/gnrc_legacy_tx_sync/tests/01-run.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2025 Technische Universität Dresden +# +# 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. + +# @author Lukas Luger + +import sys +from testrunner import run + + +def testfunc(child): + child.expect("TEST PASSED", timeout=2) + + +if __name__ == "__main__": + sys.exit(run(testfunc))