This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new eb2dd99ce testing/nettest: Add a test of radio sockets with no device.
eb2dd99ce is described below
commit eb2dd99ce3a625289d59d59274adbded76eb0b7f
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Nov 10 22:59:23 2026 +0100
testing/nettest: Add a test of radio sockets with no device.
cmocka_net_radio calls recvfrom() three times on each of these sockets:
a Bluetooth L2CAP socket that is not bound, a Bluetooth HCI socket bound
to a device index that no device has, and an IEEE 802.15.4 socket that
is not bound. No radio device matches these sockets, so each call must
fail with ENODEV, and close() must work after them.
Before the kernel fix, the first call unlocked a socket lock that it did
not take. With CONFIG_DEBUG_ASSERTIONS, the program then fails an
assertion in nxrmutex_unlock().
The test is on by default when NET_BLUETOOTH or NET_IEEE802154 is set,
as the other nettest groups.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
testing/nettest/CMakeLists.txt | 27 ++++++++
testing/nettest/Kconfig | 9 +++
testing/nettest/Makefile | 15 +++++
testing/nettest/radio/test_radio.c | 55 ++++++++++++++++
testing/nettest/radio/test_radio.h | 65 +++++++++++++++++++
testing/nettest/radio/test_radio_bluetooth.c | 93 +++++++++++++++++++++++++++
testing/nettest/radio/test_radio_common.c | 65 +++++++++++++++++++
testing/nettest/radio/test_radio_ieee802154.c | 58 +++++++++++++++++
8 files changed, 387 insertions(+)
diff --git a/testing/nettest/CMakeLists.txt b/testing/nettest/CMakeLists.txt
index 8703b51ac..2b506689a 100644
--- a/testing/nettest/CMakeLists.txt
+++ b/testing/nettest/CMakeLists.txt
@@ -148,6 +148,33 @@ if(CONFIG_TESTING_NET_TEST)
${SRCS})
endif()
+ if(CONFIG_TESTING_NET_RADIO)
+ set(SRCS ${CMAKE_CURRENT_LIST_DIR}/radio/test_radio.c
+ ${CMAKE_CURRENT_LIST_DIR}/radio/test_radio_common.c)
+
+ if(CONFIG_NET_BLUETOOTH)
+ list(APPEND SRCS ${CMAKE_CURRENT_LIST_DIR}/radio/test_radio_bluetooth.c)
+ endif()
+
+ if(CONFIG_NET_IEEE802154)
+ list(APPEND SRCS ${CMAKE_CURRENT_LIST_DIR}/radio/test_radio_ieee802154.c)
+ endif()
+
+ nuttx_add_application(
+ NAME
+ cmocka_net_radio
+ PRIORITY
+ ${CONFIG_TESTING_NET_TEST_PRIORITY}
+ STACKSIZE
+ ${CONFIG_TESTING_NET_TEST_STACKSIZE}
+ MODULE
+ ${CONFIG_TESTING_NET_TEST}
+ DEPENDS
+ cmocka
+ SRCS
+ ${SRCS})
+ endif()
+
if(CONFIG_TESTING_NET_TIMESTAMP)
set(SRCS ${CMAKE_CURRENT_LIST_DIR}/timestamp/test_timestamp.c
${CMAKE_CURRENT_LIST_DIR}/timestamp/test_timestamp_common.c)
diff --git a/testing/nettest/Kconfig b/testing/nettest/Kconfig
index b4e8a2f3d..c4a089639 100644
--- a/testing/nettest/Kconfig
+++ b/testing/nettest/Kconfig
@@ -64,6 +64,15 @@ config TESTING_NET_MCAST
depends on NET_IGMP || NET_MLD
default y
+config TESTING_NET_RADIO
+ bool "Enable cmocka net radio socket test"
+ depends on NET_BLUETOOTH || NET_IEEE802154
+ default y
+ ---help---
+ Test that recvfrom() on a Bluetooth or IEEE 802.15.4 socket with
+ no radio device fails with ENODEV and leaves the socket usable
+ (cmocka_net_radio).
+
config TESTING_NET_TIMESTAMP
bool "Enable cmocka net timestamp test"
depends on NET_TIMESTAMP && NET_PKT
diff --git a/testing/nettest/Makefile b/testing/nettest/Makefile
index 31dd32261..6e1ab5784 100644
--- a/testing/nettest/Makefile
+++ b/testing/nettest/Makefile
@@ -81,6 +81,21 @@ endif
endif
+ifeq ($(CONFIG_TESTING_NET_RADIO),y)
+MAINSRC += radio/test_radio.c
+PROGNAME += cmocka_net_radio
+CSRCS += radio/test_radio_common.c
+
+ifeq ($(CONFIG_NET_BLUETOOTH),y)
+CSRCS += radio/test_radio_bluetooth.c
+endif
+
+ifeq ($(CONFIG_NET_IEEE802154),y)
+CSRCS += radio/test_radio_ieee802154.c
+endif
+
+endif
+
ifeq ($(CONFIG_TESTING_NET_TIMESTAMP),y)
MAINSRC += timestamp/test_timestamp.c
PROGNAME += cmocka_net_timestamp
diff --git a/testing/nettest/radio/test_radio.c
b/testing/nettest/radio/test_radio.c
new file mode 100644
index 000000000..b76eda37f
--- /dev/null
+++ b/testing/nettest/radio/test_radio.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * apps/testing/nettest/radio/test_radio.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <cmocka.h>
+
+#include "test_radio.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+ const struct CMUnitTest radio_tests[] =
+ {
+#ifdef CONFIG_NET_BLUETOOTH
+ cmocka_unit_test(test_radio_bluetooth_l2cap),
+ cmocka_unit_test(test_radio_bluetooth_hci),
+#endif
+#ifdef CONFIG_NET_IEEE802154
+ cmocka_unit_test(test_radio_ieee802154),
+#endif
+ };
+
+ return cmocka_run_group_tests(radio_tests, NULL, NULL);
+}
diff --git a/testing/nettest/radio/test_radio.h
b/testing/nettest/radio/test_radio.h
new file mode 100644
index 000000000..2a3ef8501
--- /dev/null
+++ b/testing/nettest/radio/test_radio.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * apps/testing/nettest/radio/test_radio.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __APPS_TESTING_NETTEST_RADIO_TEST_RADIO_H
+#define __APPS_TESTING_NETTEST_RADIO_TEST_RADIO_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/compiler.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_radio_recv_nodev
+ *
+ * Description:
+ * recvfrom() on fd, a socket with no radio device, must fail with ENODEV
+ * each time, and close() must work. Closes fd.
+ *
+ ****************************************************************************/
+
+void test_radio_recv_nodev(int fd);
+
+/****************************************************************************
+ * Name: test_radio_bluetooth_l2cap
+ ****************************************************************************/
+
+void test_radio_bluetooth_l2cap(FAR void **state);
+
+/****************************************************************************
+ * Name: test_radio_bluetooth_hci
+ ****************************************************************************/
+
+void test_radio_bluetooth_hci(FAR void **state);
+
+/****************************************************************************
+ * Name: test_radio_ieee802154
+ ****************************************************************************/
+
+void test_radio_ieee802154(FAR void **state);
+
+#endif /* __APPS_TESTING_NETTEST_RADIO_TEST_RADIO_H */
diff --git a/testing/nettest/radio/test_radio_bluetooth.c
b/testing/nettest/radio/test_radio_bluetooth.c
new file mode 100644
index 000000000..54866a6dc
--- /dev/null
+++ b/testing/nettest/radio/test_radio_bluetooth.c
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * apps/testing/nettest/radio/test_radio_bluetooth.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netpacket/bluetooth.h>
+#include <cmocka.h>
+
+#include "test_radio.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* An HCI device index that no Bluetooth device has */
+
+#define RADIO_HCI_NODEV 200
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_radio_bluetooth_l2cap
+ *
+ * Description:
+ * An L2CAP socket that is not bound: no Bluetooth device has its
+ * all-zero local address.
+ *
+ ****************************************************************************/
+
+void test_radio_bluetooth_l2cap(FAR void **state)
+{
+ int fd;
+
+ fd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_L2CAP);
+ assert_return_code(fd, errno);
+ test_radio_recv_nodev(fd);
+}
+
+/****************************************************************************
+ * Name: test_radio_bluetooth_hci
+ *
+ * Description:
+ * An HCI socket bound to a device index that no Bluetooth device has.
+ *
+ ****************************************************************************/
+
+void test_radio_bluetooth_hci(FAR void **state)
+{
+ struct sockaddr_hci addr;
+ int fd;
+
+ fd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
+ assert_return_code(fd, errno);
+
+ memset(&addr, 0, sizeof(addr));
+ addr.hci_family = AF_BLUETOOTH;
+ addr.hci_dev = RADIO_HCI_NODEV;
+ addr.hci_channel = HCI_CHANNEL_RAW;
+ assert_return_code(bind(fd, (FAR struct sockaddr *)&addr, sizeof(addr)),
+ errno);
+
+ test_radio_recv_nodev(fd);
+}
diff --git a/testing/nettest/radio/test_radio_common.c
b/testing/nettest/radio/test_radio_common.c
new file mode 100644
index 000000000..a96bcf7e1
--- /dev/null
+++ b/testing/nettest/radio/test_radio_common.c
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * apps/testing/nettest/radio/test_radio_common.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <cmocka.h>
+
+#include "test_radio.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_radio_recv_nodev
+ ****************************************************************************/
+
+void test_radio_recv_nodev(int fd)
+{
+ struct sockaddr_storage from;
+ socklen_t fromlen;
+ char buf[16];
+ int i;
+
+ /* The socket lock must stay usable after each failed call */
+
+ for (i = 0; i < 3; i++)
+ {
+ fromlen = sizeof(from);
+ assert_int_equal(recvfrom(fd, buf, sizeof(buf), 0,
+ (FAR struct sockaddr *)&from, &fromlen),
+ -1);
+ assert_int_equal(errno, ENODEV);
+ }
+
+ assert_return_code(close(fd), errno);
+}
diff --git a/testing/nettest/radio/test_radio_ieee802154.c
b/testing/nettest/radio/test_radio_ieee802154.c
new file mode 100644
index 000000000..f7ab2a4ef
--- /dev/null
+++ b/testing/nettest/radio/test_radio_ieee802154.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * apps/testing/nettest/radio/test_radio_ieee802154.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <sys/socket.h>
+#include <netpacket/ieee802154.h>
+#include <cmocka.h>
+
+#include "test_radio.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_radio_ieee802154
+ *
+ * Description:
+ * An IEEE 802.15.4 socket that is not bound: the device lookup finds no
+ * radio for a socket with no local address.
+ *
+ ****************************************************************************/
+
+void test_radio_ieee802154(FAR void **state)
+{
+ int fd;
+
+ fd = socket(AF_IEEE802154, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ assert_return_code(fd, errno);
+ test_radio_recv_nodev(fd);
+}