mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
test(esp_netif): clear errno before L2TAP asserts
select() does not set errno on timeout per POSIX; remove the incorrect EAGAIN check after select timeout and clear errno before asserting it. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -527,6 +527,7 @@ TEST_CASE("esp32 l2tap - non blocking read", "[ethernet]")
|
||||
|
||||
// Verify the read does not block
|
||||
while (loop_cnt < 100) {
|
||||
errno = 0;
|
||||
if ((n = read(eth_tap_fd, in_buffer, IN_BUFFER_SIZE)) > 0) {
|
||||
ESP_LOG_BUFFER_HEX(TAG, in_buffer, n);
|
||||
ESP_LOGI(TAG, "recv test string: %s", ((test_vfs_eth_tap_msg_t *)in_buffer)->str);
|
||||
@@ -594,8 +595,8 @@ TEST_CASE("esp32 l2tap - non blocking read", "[ethernet]")
|
||||
FD_SET(eth_tap_fd, &rfds);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, select(eth_tap_fd + 1, &rfds, NULL, NULL, &tv));
|
||||
TEST_ASSERT_EQUAL(EAGAIN, errno);
|
||||
|
||||
errno = 0;
|
||||
n = read(eth_tap_fd, in_buffer, IN_BUFFER_SIZE);
|
||||
TEST_ASSERT_EQUAL(EAGAIN, errno);
|
||||
TEST_ASSERT_EQUAL(-1, n);
|
||||
@@ -703,6 +704,7 @@ TEST_CASE("esp32 l2tap - write", "[ethernet]")
|
||||
esp_eth_ioctl(eth_network_hndls.eth_handle, ETH_CMD_G_MAC_ADDR, &test_msg.header.dest.addr);
|
||||
// set different Ethernet type than the fd is configured to
|
||||
test_msg.header.type = htons(ETH_FILTER_LE + 10);
|
||||
errno = 0;
|
||||
TEST_ASSERT_EQUAL(-1, write(eth_tap_fd, &test_msg, sizeof(test_msg)));
|
||||
TEST_ASSERT_EQUAL(EBADMSG, errno);
|
||||
|
||||
@@ -904,9 +906,11 @@ TEST_CASE("esp32 l2tap - time stamping", "[ethernet]")
|
||||
ESP_LOGI(TAG, "Verify response when trying to write/read in standard way (input len > 0) but tap configured as TS enabled");
|
||||
test_ptp_msg.ptp_msg.ptp_hdr.sequence_id++;
|
||||
exp_sequence_id++;
|
||||
errno = 0;
|
||||
n = write(eth_tap_fd, &test_ptp_msg, sizeof(test_ptp_msg));
|
||||
TEST_ASSERT_EQUAL(-1, n);
|
||||
TEST_ASSERT_EQUAL(EINVAL, errno);
|
||||
errno = 0;
|
||||
n = read(eth_tap_fd, &in_buffer, sizeof(test_ptp_msg));
|
||||
TEST_ASSERT_EQUAL(-1, n);
|
||||
TEST_ASSERT_EQUAL(EINVAL, errno);
|
||||
@@ -985,6 +989,7 @@ TEST_CASE("esp32 l2tap - time stamping", "[ethernet]")
|
||||
ts_info->len = L2TAP_IREC_LEN(sizeof(struct timespec));
|
||||
ptp_msg_ext_buff.buff = NULL;
|
||||
ptp_msg_ext_buff.buff_len = sizeof(test_ptp_msg);
|
||||
errno = 0;
|
||||
n = write(eth_tap_fd, &ptp_msg_ext_buff, 0);
|
||||
TEST_ASSERT_EQUAL(-1, n);
|
||||
TEST_ASSERT_EQUAL(EFAULT, errno);
|
||||
@@ -993,6 +998,7 @@ TEST_CASE("esp32 l2tap - time stamping", "[ethernet]")
|
||||
ts_info->len = L2TAP_IREC_LEN(1);
|
||||
ptp_msg_ext_buff.buff = NULL;
|
||||
ptp_msg_ext_buff.buff_len = IN_BUFFER_SIZE;
|
||||
errno = 0;
|
||||
n = read(eth_tap_fd, &ptp_msg_ext_buff, 0);
|
||||
TEST_ASSERT_EQUAL(-1, n);
|
||||
TEST_ASSERT_EQUAL(EFAULT, errno);
|
||||
@@ -1056,6 +1062,7 @@ TEST_CASE("esp32 l2tap - ioctl - RCV_FILTER", "[ethernet]")
|
||||
TEST_ASSERT_NOT_EQUAL(-1, eth_tap_fd);
|
||||
ESP_LOGI(TAG, "Verify that RCV_FILTER is allowed to be configured only after interface is set...");
|
||||
uint16_t eth_type_filter = ETH_FILTER_LE;
|
||||
errno = 0;
|
||||
TEST_ASSERT_EQUAL(-1, ioctl(eth_tap_fd, L2TAP_S_RCV_FILTER, ð_type_filter));
|
||||
TEST_ASSERT_EQUAL(EACCES, errno);
|
||||
TEST_ASSERT_EQUAL(0, close(eth_tap_fd));
|
||||
@@ -1122,6 +1129,7 @@ TEST_CASE("esp32 l2tap - ioctl - RCV_FILTER", "[ethernet]")
|
||||
TEST_ASSERT_EQUAL_STRING("ETH_DEF", if_key_str);
|
||||
|
||||
ESP_LOGI(TAG, "Verify that the setting the same Ethernet type to other fd at the same interface was unsuccessful...");
|
||||
errno = 0;
|
||||
TEST_ASSERT_EQUAL(-1, ioctl(eth_tap_fd_2, L2TAP_S_RCV_FILTER, ð_type_filter));
|
||||
TEST_ASSERT_EQUAL(EINVAL, errno);
|
||||
TEST_ASSERT_NOT_EQUAL(-1, ioctl(eth_tap_fd_2, L2TAP_G_RCV_FILTER, ð_type_filter_get));
|
||||
@@ -1182,6 +1190,7 @@ TEST_CASE("esp32 l2tap - ioctl - INTF_DEVICE/DEVICE_DRV_HNDL", "[ethernet]")
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(&s_test_msg, in_buffer, n);
|
||||
|
||||
ESP_LOGI(TAG, "Try to set non-existing Ethernet interface...");
|
||||
errno = 0;
|
||||
TEST_ASSERT_EQUAL(-1, ioctl(eth_tap_fd, L2TAP_S_INTF_DEVICE, "ETH_NOT_DEF"));
|
||||
TEST_ASSERT_EQUAL(ENODEV, errno);
|
||||
ESP_LOGI(TAG, "Verify that previous setting is kept...");
|
||||
@@ -1302,6 +1311,7 @@ TEST_CASE("esp32 l2tap - fcntl", "[ethernet]")
|
||||
int loop_cnt = 0;
|
||||
xTaskCreate(send_task, "raw_eth_send_task", 1024, &send_task_ctrl, tskIDLE_PRIORITY + 2, NULL);
|
||||
while (loop_cnt < 100) {
|
||||
errno = 0;
|
||||
if ((n = read(eth_tap_fd, in_buffer, IN_BUFFER_SIZE)) > 0) {
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(&s_test_msg, in_buffer, n);
|
||||
break;
|
||||
@@ -1329,6 +1339,7 @@ TEST_CASE("esp32 l2tap - fcntl", "[ethernet]")
|
||||
loop_cnt = 0;
|
||||
xTaskCreate(send_task, "raw_eth_send_task", 1024, &send_task_ctrl, tskIDLE_PRIORITY + 2, NULL);
|
||||
while (loop_cnt < 100) {
|
||||
errno = 0;
|
||||
if ((n = read(eth_tap_fd, in_buffer, IN_BUFFER_SIZE)) > 0) {
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(&s_test_msg, in_buffer, n);
|
||||
break;
|
||||
@@ -1343,14 +1354,17 @@ TEST_CASE("esp32 l2tap - fcntl", "[ethernet]")
|
||||
TEST_ASSERT_EQUAL(0, loop_cnt);
|
||||
|
||||
// Try to use unsupported operation
|
||||
errno = 0;
|
||||
flags = fcntl(eth_tap_fd, F_DUPFD, 0);
|
||||
TEST_ASSERT_EQUAL(-1, flags);
|
||||
TEST_ASSERT_EQUAL(ENOSYS, errno);
|
||||
|
||||
// Try to set unsupported flag
|
||||
errno = 0;
|
||||
flags = fcntl(eth_tap_fd, F_SETFL, O_TRUNC);
|
||||
TEST_ASSERT_EQUAL(-1, flags);
|
||||
TEST_ASSERT_EQUAL(EINVAL, errno);
|
||||
errno = 0;
|
||||
flags = fcntl(eth_tap_fd, F_SETFL, O_TRUNC | O_NONBLOCK);
|
||||
TEST_ASSERT_EQUAL(-1, flags);
|
||||
TEST_ASSERT_EQUAL(EINVAL, errno);
|
||||
|
||||
Reference in New Issue
Block a user