diff --git a/libc-test/src/functionalext/thread/pthread_guard_size.c b/libc-test/src/functionalext/thread/pthread_guard_size.c new file mode 100644 index 0000000000000000000000000000000000000000..7e2be0d1336897b2fdc6e29b2eb337665c6d4a4c --- /dev/null +++ b/libc-test/src/functionalext/thread/pthread_guard_size.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed 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. + */ + +#include +#include + +#include "pthread_util.h" + +#define DEFAULT_GUARD_SIZE 8192 + +static void pthread_guard_size_0100(void) +{ + pthread_attr_t attr = {0}; + size_t guard_size = 0; + pthread_getattr_default_np(&attr); + pthread_attr_getguardsize(&attr, &guard_size); +#ifdef TARGET_GUARD_SIZE + TEST(guard_size == TARGET_GUARD_SIZE); +#else + TEST(guard_size == DEFAULT_GUARD_SIZE); +#endif +} + +TEST_FUN G_Fun_Array[] = { + pthread_guard_size_0100, +}; + +int main(void) +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/thread/pthread_stack_size.c b/libc-test/src/functionalext/thread/pthread_stack_size.c new file mode 100644 index 0000000000000000000000000000000000000000..62c4ceb2591ec63c08ffd1899bfe057522c6e943 --- /dev/null +++ b/libc-test/src/functionalext/thread/pthread_stack_size.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed 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. + */ + +#include +#include + +#include "pthread_util.h" + +#define DEFAULT_STACK_SIZE 131072 + +static void pthread_stack_size_0100(void) +{ + pthread_attr_t attr = {0}; + size_t stack_size = 0; + pthread_getattr_default_np(&attr); + pthread_attr_getstacksize(&attr, &stack_size); +#ifdef TARGET_STACK_SIZE + TEST(stack_size == TARGET_STACK_SIZE); +#else + TEST(stack_size == DEFAULT_STACK_SIZE); +#endif +} + +TEST_FUN G_Fun_Array[] = { + pthread_stack_size_0100, +}; + +int main(void) +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/thread/test_src_functionalext_thread.gni b/libc-test/src/functionalext/thread/test_src_functionalext_thread.gni index db6e2f87059b261cee8f2b2827f060a9e5fe91aa..d4629ace4490deee4ccb7faa50bdcbaee1f0bf21 100644 --- a/libc-test/src/functionalext/thread/test_src_functionalext_thread.gni +++ b/libc-test/src/functionalext/thread/test_src_functionalext_thread.gni @@ -15,4 +15,6 @@ functionalext_thread_list = [ "pthread_mutex", "pthread_rwlock_rdlock", "pthread_rwlock_wrlock", + "pthread_guard_size", + "pthread_stack_size", ] diff --git a/libc-test/test_template.gni b/libc-test/test_template.gni index 9103a005cc9eaf2519e2786eda9b9a0dce085f87..27ac3f42b1650b2d64b55b01f5034dce907a81e8 100644 --- a/libc-test/test_template.gni +++ b/libc-test/test_template.gni @@ -1,4 +1,5 @@ import("//build/test.gni") +import("//third_party/musl/musl_config.gni") musl_base_dir = "third_party/musl/" test_dir = "${musl_base_dir}/libc-test" @@ -174,6 +175,28 @@ template("test_unittest") { ldflags += [ "-Wl,-rpath=./" ] } } + + if (target_dir == "functionalext/thread") { + if (!defined(defines)) { + defines = [] + } + if (musl_target_os == "linux" && product_path != "" && + product_path != rebase_path("//productdefine/common/products")) { + _product_config = read_file("${product_path}/config.json", "json") + if (target_name == "pthread_stack_size") { + if (defined(_product_config.device_stack_size)) { + defines += + [ "TARGET_STACK_SIZE=${_product_config.device_stack_size}" ] + } + } + if (target_name == "pthread_guard_size") { + if (defined(_product_config.device_guard_size)) { + defines += + [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ] + } + } + } + } } } diff --git a/musl_config.gni b/musl_config.gni index 8ce8b48b063de15be69c827933528326f0dfeaad..39cabcdacc710cd0e875281d02cbf34f119655d2 100644 --- a/musl_config.gni +++ b/musl_config.gni @@ -53,3 +53,9 @@ declare_args() { declare_args() { enable_musl_log = false } + +declare_args() { + if (!defined(product_path)) { + product_path = "" + } +} diff --git a/musl_template.gni b/musl_template.gni index 8ba52a57160a9973398aeb50383468c18cecd8e1..292a4cca8192c777a935721caa65a0644de5f05a 100644 --- a/musl_template.gni +++ b/musl_template.gni @@ -379,6 +379,20 @@ template("musl_libs") { configs -= musl_inherited_configs configs += [ ":${abi_prefix}_musl_config" ] + if (!defined(defines)) { + defines = [] + } + if (musl_target_os == "linux" && product_path != "" && + product_path != rebase_path("//productdefine/common/products")) { + _product_config = read_file("${product_path}/config.json", "json") + if (defined(_product_config.device_stack_size)) { + defines += [ "TARGET_STACK_SIZE=${_product_config.device_stack_size}" ] + } + if (defined(_product_config.device_guard_size)) { + defines += [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ] + } + } + deps = porting_deps } diff --git a/porting/linux/user/src/internal/pthread_impl.h b/porting/linux/user/src/internal/pthread_impl.h index 84a701fc3b121e0e3baae3e9e207bba7a6d980d2..dfc557a727458b792a9529e3093b9d1877db47c5 100644 --- a/porting/linux/user/src/internal/pthread_impl.h +++ b/porting/linux/user/src/internal/pthread_impl.h @@ -242,8 +242,17 @@ extern hidden volatile int __thread_list_lock; extern hidden unsigned __default_stacksize; extern hidden unsigned __default_guardsize; +#ifdef TARGET_STACK_SIZE +#define DEFAULT_STACK_SIZE TARGET_STACK_SIZE +#else #define DEFAULT_STACK_SIZE 131072 +#endif + +#ifdef TARGET_GUARD_SIZE +#define DEFAULT_GUARD_SIZE TARGET_GUARD_SIZE +#else #define DEFAULT_GUARD_SIZE 8192 +#endif #define DEFAULT_STACK_MAX (8<<20) #define DEFAULT_GUARD_MAX (1<<20)