From e80463096df82c9303c5c1acde3fddb98d4dea93 Mon Sep 17 00:00:00 2001 From: zzulilyw Date: Sat, 30 Aug 2025 16:34:31 +0800 Subject: [PATCH] Ignore static_link bugs Issue: https://gitee.com/openharmony/third_party_musl/issues/ICVKHY Signed-off-by: zzulilyw --- etc/musl.para | 1 + .../lock_info/pthread_internal_lock_info.c | 61 +++++++++++-------- .../unittest/unit_test_hilog_adapter.c | 3 + porting/linux/user/etc/musl.para | 3 +- porting/linux/user/src/hilog/hilog_adapter.c | 2 +- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/etc/musl.para b/etc/musl.para index fc21685db..38c73a3eb 100644 --- a/etc/musl.para +++ b/etc/musl.para @@ -29,3 +29,4 @@ musl.log.enable=true # ================================ musl.log.ld.all=true +musl.log.level=WARN \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/lock_info/pthread_internal_lock_info.c b/libc-test/src/functionalext/supplement/lock_info/pthread_internal_lock_info.c index 5d01df8a5..02fb3a2b1 100644 --- a/libc-test/src/functionalext/supplement/lock_info/pthread_internal_lock_info.c +++ b/libc-test/src/functionalext/supplement/lock_info/pthread_internal_lock_info.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -29,23 +29,10 @@ #include #include #include -#include #define NEGATIVE_ONE (-1) #define ZERO (0) -void WaitUntilSignal(int signum) -{ - sigset_t set; - sigemptyset(&set); - sigaddset(&set, signum); - // 设置超时结构,设置超时为 0.5 秒 - struct timespec timeout; - timeout.tv_sec = 0; // 秒部分为 0 - timeout.tv_nsec = 500000000; // 纳秒部分为 500000000,即 0.5 秒 - (void)sigtimedwait(&set, NULL, &timeout); -} - // 检查是否有相应的日志生成,如果有当前日志,则返回true,如果没有则返回false bool CheckHiLogPrint(char *needToMatch) { @@ -59,7 +46,7 @@ bool CheckHiLogPrint(char *needToMatch) char finalCommand[COMMAND_SIZE]; int res = snprintf_s(finalCommand, COMMAND_SIZE, READ_SIZE, "%s%s", command, needToMatch); if (res == NEGATIVE_ONE) { - printf("CheckHiLogPrint command generate snprintf_s failed\n"); + t_error("CheckHiLogPrint command generate snprintf_s failed\n"); return false; } finalCommand[READ_SIZE] = '\0'; @@ -67,7 +54,7 @@ bool CheckHiLogPrint(char *needToMatch) FILE* pipe; pipe = popen(finalCommand, "r"); if (pipe == NULL) { - printf("CheckHiLogPrint: Failed to run command\n"); + t_error("CheckHiLogPrint: Failed to run command\n"); return false; } @@ -80,7 +67,7 @@ bool CheckHiLogPrint(char *needToMatch) // 关闭管道并获取返回值 int returnValue = pclose(pipe); if (returnValue == FAIL_CLOSE) { - printf("CheckHiLogPrint pclose failed returnValue=-1 errno=%d\n", errno); + t_error("CheckHiLogPrint pclose failed returnValue=-1 errno=%d\n", errno); } return flag; } @@ -90,27 +77,51 @@ bool CheckHiLogPrint(char *needToMatch) #include #include +// 不执行任何操作的信号处理函数 +void ignore_signal(int signum) +{ + // 什么都不做 +} + #define FREEZE_SIGNAL_35 (35) +#define INVALID_SIGNAL_40 (40) void PthreadInternalLockInfoTest(void) { - // 发送信号35和40到自己 + // 发送信号35, 38和40到自己 + sighandler_t sigResult = signal(FREEZE_SIGNAL_35, ignore_signal); + if (sigResult == SIG_ERR) { + t_error("signal 35 failed errno=%d", errno); + return; + } int result = raise(FREEZE_SIGNAL_35); if (result != ZERO) { - printf("raise 35 failed errno=%d\n", errno); + t_error("raise 35 failed errno=%d", errno); return; } - WaitUntilSignal(FREEZE_SIGNAL_35); bool hilogResult = CheckHiLogPrint("FREEZE_signo_35"); - printf("hilogResult=%d\n", hilogResult); + EXPECT_EQ("signal35_check_output", hilogResult, true); hilogResult = CheckHiLogPrint("tl_lock_count"); - printf("hilogResult=%d\n", hilogResult); + EXPECT_EQ("signal35_check_output", hilogResult, true); hilogResult = CheckHiLogPrint("tl_lock_waiters"); - printf("hilogResult=%d\n", hilogResult); + EXPECT_EQ("signal35_check_output", hilogResult, true); hilogResult = CheckHiLogPrint("tl_lock_tid_fail"); - printf("hilogResult=%d\n", hilogResult); + EXPECT_EQ("signal35_check_output", hilogResult, true); hilogResult = CheckHiLogPrint("tl_lock_count_tid"); - printf("hilogResult=%d\n", hilogResult); + EXPECT_EQ("signal35_check_output", hilogResult, true); + + // 在发送信号40之前,先将它的处理函数设置为不做任何操作 + sigResult = signal(INVALID_SIGNAL_40, ignore_signal); + if (sigResult == SIG_ERR) { + t_error("signal 40 failed errno=%d", errno); + } + result = raise(INVALID_SIGNAL_40); + if (result != ZERO) { + t_error("raise 40 failed errno=%d", errno); + return; + } + hilogResult = CheckHiLogPrint("FREEZE_signo_40"); + EXPECT_EQ("signal38_check_output", hilogResult, false); } int main(void) diff --git a/libc-test/src/functionalext/unittest/unit_test_hilog_adapter.c b/libc-test/src/functionalext/unittest/unit_test_hilog_adapter.c index 75862a989..dc818d468 100644 --- a/libc-test/src/functionalext/unittest/unit_test_hilog_adapter.c +++ b/libc-test/src/functionalext/unittest/unit_test_hilog_adapter.c @@ -39,6 +39,7 @@ #define ENABLE_LOG "param set musl.log.enable true" #define LOG_LEVEL_ERROR "param set musl.log.level ERROR" +#define LOG_LEVEL_WARN "param set musl.log.level WARN" #define MUSL_LOGE(...) ((void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, MUSL_LOG_TAG, __VA_ARGS__)) @@ -220,6 +221,8 @@ int main(void) HilogAdapterPrint_0020(); HilogAdapterPrint_0030(); + // 恢复默认日志等级 + system(LOG_LEVEL_WARN); // 恢复限制 system("/bin/hilog -Q pidon"); system("/bin/hilog -Q domainon"); diff --git a/porting/linux/user/etc/musl.para b/porting/linux/user/etc/musl.para index 6c7941cb1..38c73a3eb 100644 --- a/porting/linux/user/etc/musl.para +++ b/porting/linux/user/etc/musl.para @@ -28,4 +28,5 @@ musl.log.enable=true # musl.log.ld.app.your_app_name=false # ================================ -musl.log.ld.all=true \ No newline at end of file +musl.log.ld.all=true +musl.log.level=WARN \ No newline at end of file diff --git a/porting/linux/user/src/hilog/hilog_adapter.c b/porting/linux/user/src/hilog/hilog_adapter.c index bfe1a34cb..678477af2 100644 --- a/porting/linux/user/src/hilog/hilog_adapter.c +++ b/porting/linux/user/src/hilog/hilog_adapter.c @@ -207,7 +207,7 @@ void resetLogLevel() { static CachedHandle muslLogLevelHandle = NULL; if (muslLogLevelHandle == NULL) { - muslLogLevelHandle = CachedParameterCreate(g_logLevelParam, "ERROR"); + muslLogLevelHandle = CachedParameterCreate(g_logLevelParam, "WARN"); } const char *value = CachedParameterGet(muslLogLevelHandle); if (value != NULL) { -- Gitee