-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'contrib/github_pr_14384' into 'master'
fix(pthread): Add esp_pthread function implementations for linux target (GitHub PR) Closes IDFGH-13485 See merge request espressif/esp-idf!33278
- Loading branch information
Showing
10 changed files
with
213 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | | ||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | | ||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux | | ||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | ----- | |
23 changes: 15 additions & 8 deletions
23
components/pthread/test_apps/pthread_unity_tests/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
set(sources "test_app_main.c" | ||
"test_pthread.c" | ||
"test_pthread_cond_var.c" | ||
"test_pthread_local_storage.c" | ||
"test_pthread_cxx.cpp" | ||
"test_pthread_rwlock.c" | ||
"test_pthread_semaphore.c") | ||
idf_build_get_property(target IDF_TARGET) | ||
|
||
set(sources "test_app_main.c" "test_esp_pthread.c") | ||
set(priv_requires "pthread" "unity") | ||
|
||
if(NOT ${target} STREQUAL "linux") | ||
list(APPEND sources "test_pthread.c" | ||
"test_pthread_cond_var.c" | ||
"test_pthread_local_storage.c" | ||
"test_pthread_cxx.cpp" | ||
"test_pthread_rwlock.c" | ||
"test_pthread_semaphore.c") | ||
list(APPEND priv_requires "esp_timer" "test_utils") | ||
endif() | ||
|
||
idf_component_register(SRCS ${sources} | ||
INCLUDE_DIRS "." | ||
REQUIRES pthread esp_timer test_utils | ||
REQUIRES ${priv_requires} | ||
WHOLE_ARCHIVE) |
27 changes: 9 additions & 18 deletions
27
components/pthread/test_apps/pthread_unity_tests/main/test_app_main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
components/pthread/test_apps/pthread_unity_tests/main/test_esp_pthread.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
|
||
#include <pthread.h> | ||
#include "sdkconfig.h" | ||
#include "esp_pthread.h" | ||
#include "esp_heap_caps.h" | ||
#include "unity.h" | ||
|
||
TEST_CASE("esp_pthread_get_default_config creates correct stack memory capabilities", "[cfg]") | ||
{ | ||
esp_pthread_cfg_t default_config = esp_pthread_get_default_config(); | ||
|
||
// The default must always be internal, 8-bit accessible RAM | ||
TEST_ASSERT_EQUAL_HEX(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL, default_config.stack_alloc_caps); | ||
} | ||
|
||
TEST_CASE("null pointers are rejected", "[cfg]") | ||
{ | ||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_pthread_set_cfg(NULL)); | ||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_pthread_get_cfg(NULL)); | ||
} | ||
|
||
TEST_CASE("wrong heap caps are rejected", "[cfg]") | ||
{ | ||
esp_pthread_cfg_t default_config = esp_pthread_get_default_config(); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_set_cfg(&default_config)); // make sure we have saved a known value | ||
|
||
// Test the rejection of wrong values | ||
default_config.stack_alloc_caps = MALLOC_CAP_32BIT; | ||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_pthread_set_cfg(&default_config)); | ||
|
||
default_config.stack_alloc_caps = MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL; | ||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_pthread_set_cfg(&default_config)); | ||
|
||
// check that saved values are unaltered | ||
esp_pthread_cfg_t retrieved_config; | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_get_cfg(&retrieved_config)); | ||
TEST_ASSERT_EQUAL_HEX(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL, retrieved_config.stack_alloc_caps); | ||
} | ||
|
||
// On Linux, we silently adjust the stack size since pthread on Linux | ||
// requires a minimum stack size of 0x4000. | ||
#if !CONFIG_IDF_TARGET_LINUX | ||
TEST_CASE("invalid stack size is rejected", "[cfg]") | ||
{ | ||
esp_pthread_cfg_t default_config = esp_pthread_get_default_config(); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_set_cfg(&default_config)); // make sure we have saved a known value | ||
|
||
// Test the rejection of wrong values | ||
default_config.stack_size = PTHREAD_STACK_MIN - 1; | ||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_pthread_set_cfg(&default_config)); | ||
|
||
// check that saved values are unaltered | ||
esp_pthread_cfg_t retrieved_config; | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_get_cfg(&retrieved_config)); | ||
TEST_ASSERT_EQUAL(CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT, retrieved_config.stack_size); | ||
} | ||
#endif // !CONFIG_IDF_TARGET_LINUX | ||
|
||
TEST_CASE("correct memory is accepted", "[cfg]") | ||
{ | ||
esp_pthread_cfg_t default_config = esp_pthread_get_default_config(); | ||
|
||
default_config.stack_alloc_caps = MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL; | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_set_cfg(&default_config)); | ||
} | ||
|
||
TEST_CASE("configuration is preserved inside pthread", "[cfg]") | ||
{ | ||
esp_pthread_cfg_t saved_config; | ||
esp_pthread_cfg_t retrieved_config; | ||
saved_config.stack_size = PTHREAD_STACK_MIN; | ||
saved_config.prio = 5; | ||
saved_config.inherit_cfg = true; | ||
saved_config.thread_name = "test_esp_pthread"; | ||
saved_config.pin_to_core = 0; | ||
saved_config.stack_alloc_caps = MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL; | ||
|
||
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_set_cfg(&saved_config)); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_get_cfg(&retrieved_config)); | ||
|
||
TEST_ASSERT_EQUAL(saved_config.stack_size, retrieved_config.stack_size); | ||
TEST_ASSERT_EQUAL(saved_config.prio, retrieved_config.prio); | ||
TEST_ASSERT_EQUAL(saved_config.inherit_cfg, retrieved_config.inherit_cfg); | ||
TEST_ASSERT_EQUAL(saved_config.thread_name, retrieved_config.thread_name); | ||
TEST_ASSERT_EQUAL(saved_config.pin_to_core, retrieved_config.pin_to_core); | ||
TEST_ASSERT_EQUAL(saved_config.stack_alloc_caps, retrieved_config.stack_alloc_caps); | ||
|
||
esp_pthread_cfg_t cfg = esp_pthread_get_default_config(); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_pthread_set_cfg(&cfg)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters