Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions testing/nettest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions testing/nettest/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions testing/nettest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions testing/nettest/radio/test_radio.c
Original file line number Diff line number Diff line change
@@ -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);
}
65 changes: 65 additions & 0 deletions testing/nettest/radio/test_radio.h
Original file line number Diff line number Diff line change
@@ -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 */
93 changes: 93 additions & 0 deletions testing/nettest/radio/test_radio_bluetooth.c
Original file line number Diff line number Diff line change
@@ -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);
}
65 changes: 65 additions & 0 deletions testing/nettest/radio/test_radio_common.c
Original file line number Diff line number Diff line change
@@ -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);
}
Loading
Loading