mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(vfs): make case eventfd_select_block exit normally
This commit is contained in:
parent
85315941e3
commit
c3398f3373
@ -351,20 +351,23 @@ TEST_CASE("eventfd multiple selects", "[vfs][eventfd]")
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int *value;
|
QueueHandle_t queue;
|
||||||
int fd;
|
int fd;
|
||||||
} select_block_task_args_t;
|
} select_block_task_args_t;
|
||||||
|
|
||||||
static void select_block_task(void *arg)
|
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_set read_fds;
|
||||||
|
|
||||||
FD_ZERO(&read_fds);
|
FD_ZERO(&read_fds);
|
||||||
FD_SET(fd, &read_fds);
|
FD_SET(fd, &read_fds);
|
||||||
|
|
||||||
select(fd + 1, &read_fds, NULL, NULL, NULL);
|
int val = select(fd + 1, &read_fds, NULL, NULL, NULL);
|
||||||
*(((select_block_task_args_t *)arg)->value) = 1;
|
assert(val == 1);
|
||||||
|
bool is_selected = true;
|
||||||
|
xQueueSend(select_arg->queue, &is_selected, 0);
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,20 +379,20 @@ TEST_CASE("eventfd select block", "[vfs][eventfd]")
|
|||||||
select_block_task_args_t args;
|
select_block_task_args_t args;
|
||||||
args.fd = eventfd(0, 0);
|
args.fd = eventfd(0, 0);
|
||||||
TEST_ASSERT_GREATER_OR_EQUAL(0, args.fd);
|
TEST_ASSERT_GREATER_OR_EQUAL(0, args.fd);
|
||||||
int a = 0;
|
args.queue = xQueueCreate(1, sizeof(bool));
|
||||||
args.value = &a;
|
|
||||||
|
|
||||||
int fd_write = eventfd(0, 0);
|
int fd_write = eventfd(0, 0);
|
||||||
TEST_ASSERT_GREATER_OR_EQUAL(0, fd_write);
|
TEST_ASSERT_GREATER_OR_EQUAL(0, fd_write);
|
||||||
|
|
||||||
xTaskCreate(select_block_task, "select_block_task", 2048, &args, 5, NULL);
|
xTaskCreate(select_block_task, "select_block_task", 2048, &args, 5, NULL);
|
||||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
|
||||||
|
|
||||||
|
bool is_selected = false;
|
||||||
uint64_t val = 1;
|
uint64_t val = 1;
|
||||||
TEST_ASSERT_EQUAL(sizeof(val), write(fd_write, &val, sizeof(val)));
|
TEST_ASSERT_EQUAL(sizeof(val), write(fd_write, &val, sizeof(val)));
|
||||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
TEST_ASSERT(!xQueueReceive(args.queue, &is_selected, pdMS_TO_TICKS(2000)));
|
||||||
|
TEST_ASSERT_EQUAL(sizeof(val), write(args.fd, &val, sizeof(val)));
|
||||||
TEST_ASSERT_EQUAL(0, *(args.value));
|
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(args.fd));
|
||||||
TEST_ASSERT_EQUAL(0, close(fd_write));
|
TEST_ASSERT_EQUAL(0, close(fd_write));
|
||||||
TEST_ESP_OK(esp_vfs_eventfd_unregister());
|
TEST_ESP_OK(esp_vfs_eventfd_unregister());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user