Merge branch 'fix/make_eventfd_case_exit_normally_5_2' into 'release/v5.2'

fix(vfs): make case eventfd_select_block exit normally

See merge request espressif/esp-idf!29928
This commit is contained in:
Shu Chen 2024-04-23 10:07:18 +08:00
commit 1b9597f961
9 changed files with 85 additions and 23 deletions

View File

@ -266,6 +266,14 @@ menu "OpenThread"
default 1024
range 512 8192
config OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
int "Maximum backoffs times before declaring a channel access failure."
depends on OPENTHREAD_ENABLED || OPENTHREAD_SPINEL_ONLY
default 4
help
The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access
failure.
config OPENTHREAD_MLE_MAX_CHILDREN
int "The size of max MLE children entries"
depends on OPENTHREAD_ENABLED

View File

@ -6,15 +6,16 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "sdkconfig.h"
#include <sys/select.h>
#include "esp_ieee802154_types.h"
#include "driver/uart.h"
#include "soc/gpio_num.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ESP_SPINEL_LOG_TAG "ESP_RADIO_SPINEL"
#define SPINEL_PROP_VENDOR_ESP_SET_COORDINATOR (SPINEL_PROP_VENDOR_ESP__BEGIN + 1) /* Vendor command for coordinator.*/
@ -55,11 +56,11 @@ typedef struct
void (*transmit_started)(const uint8_t *frame); /* Callback for Transmit Started.*/
void (*switchover_done)(bool success); /* Callback for Switchover Done.*/
#if OPENTHREAD_CONFIG_DIAG_ENABLE
#if CONFIG_OPENTHREAD_DIAG
void (*diag_receive_done)(const uint8_t *frame, esp_ieee802154_frame_info_t *frame_info); /* Callback for Receive Done (diag).*/
void (*diag_transmit_done)(const uint8_t *frame, esp_ieee802154_frame_info_t *frame_info); /* Callback for Transmit Done (diag).*/
void (*diag_transmit_failed)(esp_ieee802154_tx_error_t error); /* Callback for Transmit Failed (diag).*/
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE
#endif // CONFIG_OPENTHREAD_DIAG
} esp_radio_spinel_callbacks_t; /* ESP Radio Spinel Callbacks.*/
/**

View File

@ -620,4 +620,16 @@
#define OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY CONFIG_OPENTHREAD_ADDRESS_QUERY_MAX_RETRY_DELAY
#endif
/**
* @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
*
* The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure.
*
* Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
#endif
#define OPENTHREAD_FTD 1

View File

@ -304,4 +304,16 @@
#define OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY CONFIG_OPENTHREAD_ADDRESS_QUERY_MAX_RETRY_DELAY
#endif
/**
* @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
*
* The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure.
*
* Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
#endif
#define OPENTHREAD_MTD 1

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -230,3 +230,15 @@
#define OPENTHREAD_ENABLE_NCP_VENDOR_HOOK 1
#endif
#endif //CONFIG_OPENTHREAD_NCP_VENDOR_HOOK
/**
* @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
*
* The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure.
*
* Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
#endif

View File

@ -46,3 +46,15 @@
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE CONFIG_OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE
/**
* @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
*
* The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure.
*
* Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
#endif

View File

@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include "esp_check.h"
#include "esp_log.h"
#include "platform/exit_code.h"
@ -123,7 +124,7 @@ void SwitchoverDone(otInstance *aInstance, bool aSuccess)
s_esp_radio_spinel_callbacks[idx].switchover_done(aSuccess);
}
#if OPENTHREAD_CONFIG_DIAG_ENABLE
#if CONFIG_OPENTHREAD_DIAG
void DiagReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError)
{
esp_radio_spinel_idx_t idx = get_index_from_instance(aInstance);
@ -172,7 +173,7 @@ void DiagTransmitDone(otInstance *aInstance, otRadioFrame *aFrame, otError aErro
}
}
}
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE
#endif // CONFIG_OPENTHREAD_DIAG
void esp_radio_spinel_set_callbacks(const esp_radio_spinel_callbacks_t aCallbacks, esp_radio_spinel_idx_t idx)
@ -184,10 +185,10 @@ void esp_radio_spinel_set_callbacks(const esp_radio_spinel_callbacks_t aCallback
Callbacks.mEnergyScanDone = EnergyScanDone;
Callbacks.mTxStarted = TxStarted;
Callbacks.mSwitchoverDone = SwitchoverDone;
#if OPENTHREAD_CONFIG_DIAG_ENABLE
#if CONFIG_OPENTHREAD_DIAG
Callbacks.mDiagReceiveDone = DiagReceiveDone;
Callbacks.mDiagTransmitDone = DiagTransmitDone;
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE
#endif // CONFIG_OPENTHREAD_DIAG
s_radio[idx].SetCallbacks(Callbacks);
}
@ -268,6 +269,7 @@ esp_err_t esp_radio_spinel_transmit(uint8_t *frame, uint8_t channel, bool cca, e
s_transmit_frame.mLength = frame[0];
s_transmit_frame.mPsdu = frame + 1;
s_transmit_frame.mInfo.mTxInfo.mCsmaCaEnabled = cca;
s_transmit_frame.mInfo.mTxInfo.mMaxCsmaBackoffs = CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT;
s_transmit_frame.mChannel = channel;
s_transmit_frame.mInfo.mTxInfo.mRxChannelAfterTxDone = channel;
return (s_radio[idx].Transmit(s_transmit_frame) == OT_ERROR_NONE) ? ESP_OK : ESP_FAIL;

View File

@ -351,20 +351,23 @@ TEST_CASE("eventfd multiple selects", "[vfs][eventfd]")
}
typedef struct {
int *value;
QueueHandle_t queue;
int fd;
} select_block_task_args_t;
static void select_block_task(void *arg)
{
int fd = ((select_block_task_args_t *)arg)->fd;
select_block_task_args_t *select_arg = (select_block_task_args_t *)arg;
int fd = select_arg->fd;
fd_set read_fds;
FD_ZERO(&read_fds);
FD_SET(fd, &read_fds);
select(fd + 1, &read_fds, NULL, NULL, NULL);
*(((select_block_task_args_t *)arg)->value) = 1;
int val = select(fd + 1, &read_fds, NULL, NULL, NULL);
assert(val == 1);
bool is_selected = true;
xQueueSend(select_arg->queue, &is_selected, 0);
vTaskDelete(NULL);
}
@ -376,20 +379,20 @@ TEST_CASE("eventfd select block", "[vfs][eventfd]")
select_block_task_args_t args;
args.fd = eventfd(0, 0);
TEST_ASSERT_GREATER_OR_EQUAL(0, args.fd);
int a = 0;
args.value = &a;
args.queue = xQueueCreate(1, sizeof(bool));
int fd_write = eventfd(0, 0);
TEST_ASSERT_GREATER_OR_EQUAL(0, fd_write);
xTaskCreate(select_block_task, "select_block_task", 2048, &args, 5, NULL);
vTaskDelay(pdMS_TO_TICKS(2000));
bool is_selected = false;
uint64_t val = 1;
TEST_ASSERT_EQUAL(sizeof(val), write(fd_write, &val, sizeof(val)));
vTaskDelay(pdMS_TO_TICKS(2000));
TEST_ASSERT_EQUAL(0, *(args.value));
TEST_ASSERT(!xQueueReceive(args.queue, &is_selected, pdMS_TO_TICKS(2000)));
TEST_ASSERT_EQUAL(sizeof(val), write(args.fd, &val, sizeof(val)));
TEST_ASSERT(xQueueReceive(args.queue, &is_selected, pdMS_TO_TICKS(1000)));
TEST_ASSERT_EQUAL(true, is_selected);
TEST_ASSERT_EQUAL(0, close(args.fd));
TEST_ASSERT_EQUAL(0, close(fd_write));
TEST_ESP_OK(esp_vfs_eventfd_unregister());

View File

@ -562,11 +562,11 @@ def test_TCP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> N
'config, count, app_path, target', [
('cli_h2|sleepy_c6', 2,
f'{os.path.join(os.path.dirname(__file__), "ot_cli")}'
f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device")}',
f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device/light_sleep")}',
'esp32h2|esp32c6'),
('cli_c6|sleepy_h2', 2,
f'{os.path.join(os.path.dirname(__file__), "ot_cli")}'
f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device")}',
f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device/light_sleep")}',
'esp32c6|esp32h2'),
],
indirect=True,