提交 1beb02b0 编写于 作者: W wangjiahui

RM005 commit

Signed-off-by: Nwangjiahui <wangjiahui27@huawei.com>
上级 c7c56d10
......@@ -44,12 +44,14 @@ group("musl_headers") {
":musl_copy_inc_arpa",
":musl_copy_inc_bits",
":musl_copy_inc_hook",
":musl_copy_inc_info",
":musl_copy_inc_net",
":musl_copy_inc_netinet",
":musl_copy_inc_netpacket",
":musl_copy_inc_root",
":musl_copy_inc_scsi",
":musl_copy_inc_sys",
":musl_copy_inc_trace",
]
}
......@@ -253,6 +255,28 @@ copy("musl_copy_inc_sys") {
deps = [ ":create_porting_src" ]
}
copy("musl_copy_inc_trace") {
sources = []
sources_orig = musl_inc_trace_files
foreach(s, sources_orig) {
sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
}
outputs =
[ "${target_out_dir}/${musl_inc_out_dir}/trace/{{source_file_part}}" ]
deps = [ ":create_porting_src" ]
}
copy("musl_copy_inc_info") {
sources = []
sources_orig = musl_inc_info_files
foreach(s, sources_orig) {
sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
}
outputs =
[ "${target_out_dir}/${musl_inc_out_dir}/info/{{source_file_part}}" ]
deps = [ ":create_porting_src" ]
}
copy("musl_copy_inc_root") {
sources = []
sources_orig = musl_inc_root_files
......
#include <stdio.h>
#include <errno.h>
#include "test.h"
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/tgkill.h>
#include "test.h"
int main(int argc, char *argv[]){
int tgid, tid;
......
/*
* 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.
*/
#ifndef __FUNCTIONALEXT_PTHREAD_UTIL_H__
#define __FUNCTIONALEXT_PTHREAD_UTIL_H__
#include <time.h>
#include <sys/shm.h>
#include "test.h"
#define EXPECT_EQ(a, b) do { \
if ((a) != (b)) \
t_error("failed %d != %d \n", a, b); \
} while (0)
#define EXPECT_GE(a, b) do { \
if ((a) < (b)) \
t_error("failed %d < %d \n", a, b); \
} while (0)
#define EXPECT_LE(a, b) do { \
if ((a) > (b)) \
t_error("failed %d < %d \n", a, b); \
} while (0)
#define TEST(c, ...) ((c) || (t_error(#c " failed: " __VA_ARGS__), 0))
#define NSEC_PER_SEC 1000000000
#define NSEC_PER_100MS 100000000
#define NSEC_PER_MSEC 1000000
#define US_PER_S 1000000
#define MS_PER_S 1000
#define SLEEP_200_MS 200
#define SLEEP_100_MS 100
#define DELAY_TIME_100_MS 100
#define SLEEP_50_MS 50
#define SLEEP_20_MS 20
#define SLEEP_10_MS 10
#define CHECK_STEP_FIVE 5
#define CHECK_STEP_FOUR 4
#define CHECK_STEP_THREE 3
#define CHECK_STEP_TWO 2
#define CHECK_STEP_ONE 1
static int CARRY = 4;
static int SHMID_CHECK_STEP = 0;
static long unsigned int ONE_KB = 1024;
static int FLAG = 0666;
typedef void(*TEST_FUN)(void);
// get cur-time plus ms
static inline void GetDelayedTimeByClockid(struct timespec *ts, unsigned int ms, clockid_t clockid)
{
const unsigned int nsecPerSec = NSEC_PER_SEC;
unsigned int setTimeNs = ms * US_PER_S;
struct timespec tsNow = {0};
clock_gettime(clockid, &tsNow);
ts->tv_sec = tsNow.tv_sec + (tsNow.tv_nsec + setTimeNs) / nsecPerSec;
ts->tv_nsec = (tsNow.tv_nsec + setTimeNs) % nsecPerSec;
}
// calculate time difference, in ms
static inline int GetTimeDiff(struct timespec ts1, struct timespec ts2)
{
const unsigned int nsecPerSec = NSEC_PER_SEC;
int ms = (ts1.tv_sec - ts2.tv_sec) * nsecPerSec + (ts1.tv_nsec - ts2.tv_nsec);
ms = ms / NSEC_PER_MSEC;
return ms;
}
static inline void Msleep(int msec)
{
usleep(msec * MS_PER_S);
}
static inline uint64_t CheckStep(int value)
{
if (value == 1) {
shmctl(SHMID_CHECK_STEP, IPC_RMID, NULL);
SHMID_CHECK_STEP = shmget(IPC_PRIVATE, ONE_KB, FLAG | IPC_CREAT);
}
if (SHMID_CHECK_STEP != -1) {
uint64_t *shared = (uint64_t *)shmat(SHMID_CHECK_STEP, NULL, 0);
if (value == 1) {
*shared = 1;
} else {
*shared = (*shared << CARRY) + value;
}
uint64_t state = *shared;
shmdt(shared);
return state;
}
return 0;
}
#endif // __FUNCTIONALEXT_PTHREAD_UTIL_H__
\ No newline at end of file
# 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.
import("../../../test_template.gni")
import("test_src_functionalext_info.gni")
foreach(s, functionalext_info_list) {
test_unittest(s) {
target_dir = "functionalext/info"
}
}
group("functionalext_info_test") {
testonly = true
deps = []
foreach(s, functionalext_info_list) {
deps += [ ":${s}" ]
}
}
/*
* 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 <info/application_target_sdk_version.h>
#include <string.h>
#include <test.h>
// val1 == val2
#define EXPECT_EQ(a, b) do { \
if ((a) != (b)) \
t_error("failed %d != %d \n", a, b); \
} while (0)
typedef void (*TEST_FUN)(void);
/**
* @tc.name : set_application_target_sdk_version
* @tc.desc : Test the function of set_application_target_sdk_version.
* @tc.level : Level 0
*/
static void set_application_target_sdk_version_0010(void)
{
set_application_target_sdk_version(SDK_VERSION_7);
int target = get_application_target_sdk_version();
EXPECT_EQ(target, SDK_VERSION_7);
}
/**
* @tc.name : get_application_target_sdk_version
* @tc.desc : Test the function of get_application_target_sdk_version.
* @tc.level : Level 0
*/
static void get_application_target_sdk_version_0010(void)
{
set_application_target_sdk_version(SDK_VERSION_8);
int target = get_application_target_sdk_version();
EXPECT_EQ(target, SDK_VERSION_8);
}
TEST_FUN G_Fun_Array[] = {
set_application_target_sdk_version_0010,
get_application_target_sdk_version_0010,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
t_printf("application_target_sdk_version test ( %d ) start \n", pos + 1);
G_Fun_Array[pos]();
t_printf("application_target_sdk_version test ( %d ) finish \n", pos + 1);
}
return t_status;
}
\ No newline at end of file
/*
* 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 <info/device_api_version.h>
#include <string.h>
#include <test.h>
#define EXPECT_EQ(a, b) do { \
if ((a) != (b)) \
t_error("failed %d != %d \n", a, b); \
} while (0)
#define API_VERSION_DEFAULT 0
/**
* @tc.name : get_device_api_version
* @tc.desc : Test the function of get_device_api_version.
* @tc.level : Level 0
*/
static void get_device_api_version_0010(void)
{
int APIVersion = get_device_api_version();
EXPECT_EQ(APIVersion, API_VERSION_DEFAULT);
}
int main(void)
{
t_printf("get_device_api_version_0010 test start \n");
get_device_api_version_0010();
t_printf("get_device_api_version_0010 test finish \n");
return t_status;
}
/*
* 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 <info/fatal_message.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <test.h>
#include <pthread.h>
#include <unistd.h>
#define EXPECT_TRUE(c) \
do \
{ \
if (!(c)) \
t_error("[%s] failed\n"); \
} while (0)
// val1 == val2
#define EXPECT_EQ(a, b) \
do \
{ \
if ((a) != (b)) \
t_error("failed %d != %d \n", a, b); \
} while (0)
typedef void (*TEST_FUN)(void);
static const int WAIT_TIME = 1;
/**
* @tc.name : get_fatal_message
* @tc.desc : Test the function of get_fatal_message.
* @tc.level : Level 0
*/
static void fatal_message_0010(void)
{
fatal_msg_t *fatal_message = get_fatal_message();
EXPECT_TRUE(fatal_message == NULL);
}
/**
* @tc.name : set_fatal_message
* @tc.desc : Test the function of set_fatal_message.
* @tc.level : Level 0
*/
static void fatal_message_0020(void)
{
const char msg[1024] = {"abcdefghijklmnopqrstuvwxyz1234567890"};
fatal_msg_t *fatal_message = NULL;
int pidParent = 0;
int pidChild = 0;
pid_t fpid;
fpid = fork();
if (fpid < 0) {
t_printf("error in fork!");
} else if (fpid == 0) {
pidChild = getpid();
set_fatal_message(msg);
fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, msg) == 0);
exit(pidChild);
}
}
/**
* @tc.name : set_fatal_message
* @tc.desc : Test the multiple processes of set_fatal_message.
* @tc.level : Level 0
*/
static void fatal_message_0030(void)
{
fatal_msg_t *fatal_message = NULL;
const char msgChild[1024] = {"msgChild"};
const char msgParent[1024] = {"msgParent"};
int pidChild = 0;
int pidParent = 0;
int pidCParent = 0;
int pidCChild = 0;
pid_t fpid;
// start process
fpid = fork();
if (fpid < 0) {
t_printf("error in fork!");
} else if (fpid == 0) {
pidChild = getpid();
} else {
pidParent = getpid();
pid_t fpidChild;
// start process again
fpidChild = fork();
if (fpidChild < 0) {
t_printf("error in fork!");
} else if (fpidChild == 0) {
pidCChild = getpid();
set_fatal_message(msgParent);
fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, msgParent) == 0);
exit(pidCChild);
} else {
pidCParent = getpid();
set_fatal_message(msgChild);
fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, msgChild) == 0);
exit(pidCParent);
}
}
}
/**
* @tc.name : set_fatal_message
* @tc.desc : Test the multiple processes of set_fatal_message,
* One of the threads crashed.
* @tc.level : Level 0
*/
static void fatal_message_0040(void)
{
fatal_msg_t *fatal_message = NULL;
const char msgChild[1024] = {"msgChild004"};
const char msgParent[1024] = {"msgParent004"};
int pidChild = 0;
int pidParent = 0;
int pidCParent = 0;
int pidCChild = 0;
pid_t fpid;
// start process
fpid = fork();
if (fpid < 0) {
t_printf("error in fork!");
} else if (fpid == 0) {
pidChild = getpid();
} else {
pidParent = getpid();
pid_t fpidChild;
// start process again
fpidChild = fork();
if (fpidChild < 0) {
t_printf("error in fork!");
} else if (fpidChild == 0) {
pidCChild = getpid();
char *str = NULL;
str[0] = 0;
// Process crash. Unable to continue calling the set_fatal_message interface
} else {
pidCParent = getpid();
set_fatal_message(msgParent);
fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, msgParent) == 0);
exit(pidCParent);
}
}
}
void *ThreadFun1(void *arg)
{
if (arg == NULL) {
t_printf("ThreadFun1 arg is NULL");
}
fatal_msg_t *fatal_message = get_fatal_message();
EXPECT_TRUE(strcmp(fatal_message->msg, (char *)arg) == 0);
return NULL;
}
void *ThreadFun2(void *arg)
{
if (arg == NULL) {
t_printf("ThreadFun2 arg is NULL");
}
fatal_msg_t *fatal_message = get_fatal_message();
EXPECT_TRUE(fatal_message->msg != (char *)arg);
pthread_exit("ThreadFun2 Exit");
}
/**
* @tc.name : set_fatal_message
* @tc.desc : Test the multithreading of set_fatal_message.
* @tc.level : Level 0
*/
static void fatal_message_0050(void)
{
const char msgThread[1024] = {"msgThread"};
int res;
pthread_t fatalMessageThread1, fatalMessageThread2;
set_fatal_message(msgThread);
res = pthread_create(&fatalMessageThread1, NULL, ThreadFun1, (void *)msgThread);
if (res != 0) {
t_printf("pthread_create1 error.");
}
sleep(WAIT_TIME);
res = pthread_create(&fatalMessageThread2, NULL, ThreadFun2, (void *)msgThread);
if (res != 0) {
t_printf("pthread_create2 error.");
}
pthread_join(fatalMessageThread1, NULL);
pthread_join(fatalMessageThread2, NULL);
}
TEST_FUN G_Fun_Array[] = {
fatal_message_0010,
fatal_message_0020,
fatal_message_0030,
fatal_message_0040,
fatal_message_0050,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
t_printf("fatal_message test ( %d ) start \n", pos + 1);
G_Fun_Array[pos]();
t_printf("fatal_message test ( %d ) finish \n", pos + 1);
}
return t_status;
}
#
# 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.
#
functionalext_info_list = [
"application_target_sdk_version_test",
"device_api_version",
"fatal_message",
]
# 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.
import("../../../test_template.gni")
import("test_src_functionalext_reboot.gni")
foreach(s, functionalext_reboot_list) {
test_unittest(s) {
target_dir = "functionalext/reboot"
}
}
group("functionalext_reboot_test") {
testonly = true
deps = []
foreach(s, functionalext_reboot_list) {
deps += [ ":${s}" ]
}
}
/*
* 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 <sys/reboot.h>
#include "test.h"
#define TEST(c, ...) ((c) || (t_error(#c " failed: " __VA_ARGS__),0))
#define LINUX_REBOOT_CMD_RESTART 0x01234567
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
/**
* @tc.name : reboot_0010
* @tc.desc : test reboot with flag LINUX_REBOOT_CMD_CAD_ON
* @tc.level : Level 0
*/
static void reboot_0010(void)
{
TEST(reboot(LINUX_REBOOT_CMD_CAD_ON) == 0);
}
/**
* @tc.name : reboot_0020
* @tc.desc : test reboot with flag LINUX_REBOOT_CMD_CAD_OFF
* @tc.level : Level 0
*/
static void reboot_0020(void)
{
TEST(reboot(LINUX_REBOOT_CMD_CAD_OFF) == 0);
}
int main(void)
{
geteuid();
reboot_0010();
reboot_0020();
return t_status;
}
# 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.
functionalext_reboot_list = [ "reboot" ]
......@@ -14,4 +14,9 @@
functionalext_list = [
"locale:functionalext_locale_test",
"time:functionalext_time_test",
"reboot:functionalext_reboot_test",
"tgkill:functionalext_tgkill_test",
"thread:functionalext_thread_test",
"trace:functionalext_trace_test",
"info:functionalext_info_test",
]
# 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.
import("../../../test_template.gni")
import("test_src_functionalext_tgkill.gni")
foreach(s, functionalext_tgkill_list) {
test_unittest(s) {
target_dir = "functionalext/tgkill"
}
}
group("functionalext_tgkill_test") {
testonly = true
deps = []
foreach(s, functionalext_tgkill_list) {
deps += [ ":${s}" ]
}
}
# 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.
functionalext_tgkill_list = [ "tgkill" ]
/*
* 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 <pthread.h>
#include <signal.h>
#include <sys/tgkill.h>
#include "test.h"
#define TEST(c, ...) ((c) || (t_error(#c " failed: " __VA_ARGS__),0))
#define SLEEP_50_MS (50*1000)
static void *tgkillTest(void *arg)
{
pid_t *threadPid = (pid_t *)arg;
*threadPid = getpid();
return arg;
}
static void SignalHandler(int signum)
{
return;
}
/**
* @tc.name : tgkill_0010
* @tc.desc : test tgkill by sending SIGCONT sig in the same thread
* @tc.level : Level 0
*/
static void tgkill_0010(void)
{
TEST(tgkill(getpgid(getpid()), getpid(), SIGCONT) == 0);
}
/**
* @tc.name : tgkill_0020
* @tc.desc : test tgkill by sending SIGUSR1 sig in a different thread
* @tc.level : Level 0
*/
static void tgkill_0020(void)
{
pid_t threadPid;
pthread_t tid;
struct sigaction sigusr1 = {
.sa_handler = SignalHandler,
};
sigaction(SIGUSR1, &sigusr1, NULL);
TEST(pthread_create(&tid, NULL, tgkillTest, (void*)&threadPid) == 0);
usleep(SLEEP_50_MS);
TEST(tgkill(getpgid(threadPid), threadPid, SIGUSR1) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
int main(void)
{
tgkill_0010();
tgkill_0020();
return t_status;
}
\ No newline at end of file
# 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.
import("//build/test.gni")
import("../../../test_template.gni")
import("test_src_functionalext_thread.gni")
foreach(s, functionalext_thread_list) {
test_unittest(s) {
target_dir = "functionalext/thread"
}
}
group("functionalext_thread_test") {
testonly = true
deps = []
foreach(s, functionalext_thread_list) {
deps += [ ":${s}" ]
}
}
/*
* 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 <errno.h>
#include <pthread.h>
#include "pthread_util.h"
/********************************************* Test case dividing line ***********************************************/
static void *PthreadClocklockOutRealTime(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_REALTIME);
TEST(pthread_mutex_clocklock(mtx, CLOCK_REALTIME, &ts) == ETIMEDOUT);
clock_gettime(CLOCK_REALTIME, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
TEST(timeDiff > 0);
TEST(timeDiff < 20);
return arg;
}
/**
* @tc.name : pthread_mutex_clocklock_0010
* @tc.desc : test pthread_mutex_clocklock whith timeout by CLOCK_REALTIME
* @tc.level : Level 0
*/
static void pthread_mutex_clocklock_0010(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadClocklockOutRealTime, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
Msleep(SLEEP_100_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadClocklockNoOutRealTime(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_REALTIME);
TEST(pthread_mutex_clocklock(mtx, CLOCK_REALTIME, &ts) == 0);
return arg;
}
/**
* @tc.name : pthread_mutex_clocklock_0020
* @tc.desc : test pthread_mutex_clocklock with no timeout by CLOCK_REALTIME
* @tc.level : Level 0
*/
static void pthread_mutex_clocklock_0020(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadClocklockNoOutRealTime, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadClocklockOutMonoTime(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_MONOTONIC);
TEST(pthread_mutex_clocklock(mtx, CLOCK_MONOTONIC, &ts) == ETIMEDOUT);
clock_gettime(CLOCK_MONOTONIC, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
TEST(timeDiff > 0);
TEST(timeDiff < 20);
return arg;
}
/**
* @tc.name : pthread_mutex_clocklock_0030
* @tc.desc : test pthread_mutex_clocklock whith timeout by CLOCK_MONOTONIC
* @tc.level : Level 0
*/
static void pthread_mutex_clocklock_0030(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadClocklockOutMonoTime, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
Msleep(SLEEP_100_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadClocklockNoOutMonoTime(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_MONOTONIC);
TEST(pthread_mutex_clocklock(mtx, CLOCK_MONOTONIC, &ts) == 0);
return arg;
}
/**
* @tc.name : pthread_mutex_clocklock_0040
* @tc.desc : test pthread_mutex_clocklock with no timeout by CLOCK_MONOTONIC
* @tc.level : Level 0
*/
static void pthread_mutex_clocklock_0040(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadClocklockNoOutMonoTime, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadClocklockOutRealTime2(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_REALTIME);
clock_gettime(CLOCK_REALTIME, &tsNow);
tsNow.tv_sec += 1;
clock_settime(CLOCK_REALTIME, &tsNow);
TEST(pthread_mutex_clocklock(mtx, CLOCK_REALTIME, &ts) == ETIMEDOUT);
clock_gettime(CLOCK_REALTIME, &tsNow);
tsNow.tv_sec -= 1;
clock_settime(CLOCK_REALTIME, &tsNow);
return arg;
}
/**
* @tc.name : pthread_mutex_clocklock_0050
* @tc.desc : test pthread_mutex_clocklock whith timeout by CLOCK_REALTIME
* @tc.level : Level 2
*/
static void pthread_mutex_clocklock_0050(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadClocklockOutRealTime2, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadClocklockNoOutMonoTime2(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_MONOTONIC);
TEST(pthread_mutex_clocklock(mtx, CLOCK_MONOTONIC, &ts) == 0);
return arg;
}
/**
* @tc.name : pthread_mutex_clocklock_0060
* @tc.desc : test pthread_mutex_clocklock whith timeout by CLOCK_REALTIME
* @tc.level : Level 2
*/
static void pthread_mutex_clocklock_0060(void)
{
struct timespec tsNow = {0};
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadClocklockNoOutMonoTime2, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
clock_gettime(CLOCK_MONOTONIC, &tsNow);
tsNow.tv_sec += 1;
clock_settime(CLOCK_REALTIME, &tsNow);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
clock_gettime(CLOCK_REALTIME, &tsNow);
tsNow.tv_sec -= 1;
clock_settime(CLOCK_REALTIME, &tsNow);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadTimedlockMonotonicNPOut(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_MONOTONIC);
TEST(pthread_mutex_timedlock_monotonic_np(mtx, &ts) == ETIMEDOUT);
clock_gettime(CLOCK_MONOTONIC, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
TEST(timeDiff > 0);
TEST(timeDiff < 20);
return arg;
}
/**
* @tc.name : pthread_mutex_timedlock_monotonic_np_0010
* @tc.desc : test pthread_mutex_timedlock_monotonic_np whith timeout by CLOCK_MONOTONIC
* @tc.level : Level 0
*/
static void pthread_mutex_timedlock_monotonic_np_0010(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadTimedlockMonotonicNPOut, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
Msleep(SLEEP_100_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadTimedlockMonotonicNPNoOut(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, SLEEP_20_MS, CLOCK_MONOTONIC);
TEST(pthread_mutex_timedlock_monotonic_np(mtx, &ts) == 0);
return arg;
}
/**
* @tc.name : pthread_mutex_timedlock_monotonic_np_0020
* @tc.desc : test pthread_mutex_timedlock_monotonic_np with no timeout by CLOCK_MONOTONIC
* @tc.level : Level 0
*/
static void pthread_mutex_timedlock_monotonic_np_0020(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadTimedlockMonotonicNPNoOut, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadLockTimeoutNPOut(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
unsigned ms = DELAY_TIME_100_MS;
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, ms, CLOCK_MONOTONIC);
TEST(pthread_mutex_lock_timeout_np(mtx, ms) == ETIMEDOUT);
clock_gettime(CLOCK_MONOTONIC, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
TEST(timeDiff > 0);
TEST(timeDiff < 20);
return arg;
}
/**
* @tc.name : pthread_mutex_lock_timeout_np_0010
* @tc.desc : test pthread_mutex_lock_timeout_np whith timeout by CLOCK_MONOTONIC
* @tc.level : Level 0
*/
static void pthread_mutex_lock_timeout_np_0010(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadLockTimeoutNPOut, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
Msleep(SLEEP_100_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadLockTimeoutNPNoOut(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
unsigned ms = DELAY_TIME_100_MS;
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, ms, CLOCK_MONOTONIC);
TEST(pthread_mutex_lock_timeout_np(mtx, ms) == 0);
return arg;
}
/**
* @tc.name : pthread_mutex_lock_timeout_np_0020
* @tc.desc : test pthread_mutex_lock_timeout_np with no timeout by CLOCK_MONOTONIC
* @tc.level : Level 0
*/
static void pthread_mutex_lock_timeout_np_0020(void)
{
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
TEST(pthread_create(&tid, NULL, PthreadLockTimeoutNPNoOut, (void*)&mtx) == 0);
TEST(pthread_mutex_lock(&mtx) == 0);
Msleep(SLEEP_50_MS);
TEST(pthread_mutex_unlock(&mtx) == 0);
TEST(pthread_join(tid, NULL) == 0);
}
int main(void)
{
pthread_mutex_clocklock_0010();
pthread_mutex_clocklock_0020();
pthread_mutex_clocklock_0030();
pthread_mutex_clocklock_0040();
pthread_mutex_clocklock_0050();
pthread_mutex_clocklock_0060();
pthread_mutex_timedlock_monotonic_np_0010();
pthread_mutex_timedlock_monotonic_np_0020();
pthread_mutex_lock_timeout_np_0010();
pthread_mutex_lock_timeout_np_0020();
return t_status;
}
\ No newline at end of file
/*
* 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 <errno.h>
#include <pthread.h>
#include "pthread_util.h"
/********************************************* Test case dividing line ***********************************************/
pthread_rwlock_t g_rwlock1;
static void *PthreadClockRdlockNoOutRealTimeW1(void *arg)
{
TEST(pthread_rwlock_wrlock(&g_rwlock1) == 0);
Msleep(SLEEP_50_MS);
TEST(pthread_rwlock_unlock(&g_rwlock1) == 0);
return arg;
}
static void *PthreadClockRdlockNoOutRealTimeR2(void *arg)
{
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_REALTIME);
TEST(pthread_rwlock_clockrdlock(&g_rwlock1, CLOCK_REALTIME, &ts) == 0);
TEST(pthread_rwlock_unlock(&g_rwlock1) == 0);
return arg;
}
/**
* @tc.name : pthread_rwlock_clockrdlock_0010
* @tc.desc : test pthread_rwlock_clockrdlock with no timeout by CLOCK_REALTIME , write - read
* @tc.level : Level 0
*/
static void pthread_rwlock_clockrdlock_0010(void)
{
pthread_t tid[2];
TEST(pthread_rwlock_init(&g_rwlock1, NULL) == 0);
TEST(pthread_create(&tid[0], NULL, PthreadClockRdlockNoOutRealTimeW1, NULL) == 0);
TEST(pthread_create(&tid[1], NULL, PthreadClockRdlockNoOutRealTimeR2, NULL) == 0);
TEST(pthread_join(tid[0], NULL) == 0);
TEST(pthread_join(tid[1], NULL) == 0);
TEST(pthread_rwlock_destroy(&g_rwlock1) == 0);
}
/********************************************* Test case dividing line ***********************************************/
pthread_rwlock_t g_rwlock2;
static void *PthreadClockRdlockOutRealTimeW1(void *arg)
{
TEST(pthread_rwlock_wrlock(&g_rwlock2) == 0);
Msleep(SLEEP_50_MS);
Msleep(SLEEP_100_MS);
TEST(pthread_rwlock_unlock(&g_rwlock2) == 0);
return arg;
}
static void *PthreadClockRdlockOutRealTimeR2(void *arg)
{
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_REALTIME);
TEST(pthread_rwlock_clockrdlock(&g_rwlock2, CLOCK_REALTIME, &ts) == ETIMEDOUT);
clock_gettime(CLOCK_REALTIME, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
TEST(timeDiff > 0);
TEST(timeDiff < 20);
return arg;
}
/**
* @tc.name : pthread_rwlock_clockrdlock_0020
* @tc.desc : test pthread_rwlock_clockrdlock with timeout by CLOCK_REALTIME, write - read
* @tc.level : Level 0
*/
static void pthread_rwlock_clockrdlock_0020(void)
{
pthread_t tid[2];
TEST(pthread_rwlock_init(&g_rwlock2, NULL) == 0);
TEST(pthread_create(&tid[0], NULL, PthreadClockRdlockOutRealTimeW1, NULL) == 0);
TEST(pthread_create(&tid[1], NULL, PthreadClockRdlockOutRealTimeR2, NULL) == 0);
TEST(pthread_join(tid[0], NULL) == 0);
TEST(pthread_join(tid[1], NULL) == 0);
TEST(pthread_rwlock_destroy(&g_rwlock2) == 0);
}
/********************************************* Test case dividing line ***********************************************/
pthread_rwlock_t g_rwlock3;
static void *PthreadClockRdlockNoOutMonoTimeW1(void *arg)
{
TEST(pthread_rwlock_wrlock(&g_rwlock3) == 0);
Msleep(SLEEP_50_MS);
TEST(pthread_rwlock_unlock(&g_rwlock3) == 0);
return arg;
}
static void *PthreadClockRdlockNoOutMonoTimeR2(void *arg)
{
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_MONOTONIC);
TEST(pthread_rwlock_clockrdlock(&g_rwlock3, CLOCK_MONOTONIC, &ts) == 0);
TEST(pthread_rwlock_unlock(&g_rwlock3) == 0);
return arg;
}
/**
* @tc.name : pthread_rwlock_clockrdlock_0030
* @tc.desc : test pthread_rwlock_clockrdlock with no timeout by CLOCK_MONOTONIC , write - read
* @tc.level : Level 0
*/
static void pthread_rwlock_clockrdlock_0030(void)
{
pthread_t tid[2];
TEST(pthread_rwlock_init(&g_rwlock3, NULL) == 0);
TEST(pthread_create(&tid[0], NULL, PthreadClockRdlockNoOutMonoTimeW1, NULL) == 0);
TEST(pthread_create(&tid[1], NULL, PthreadClockRdlockNoOutMonoTimeR2, NULL) == 0);
TEST(pthread_join(tid[0], NULL) == 0);
TEST(pthread_join(tid[1], NULL) == 0);
TEST(pthread_rwlock_destroy(&g_rwlock3) == 0);
}
/********************************************* Test case dividing line ***********************************************/
pthread_rwlock_t g_rwlock4;
static void *PthreadClockRdlockOutMonoTimeW1(void *arg)
{
TEST(pthread_rwlock_wrlock(&g_rwlock4) == 0);
Msleep(SLEEP_50_MS);
Msleep(SLEEP_100_MS);
TEST(pthread_rwlock_unlock(&g_rwlock4) == 0);
return arg;
}
static void *PthreadClockRdlockOutMonoTimeR2(void *arg)
{
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_MONOTONIC);
TEST(pthread_rwlock_clockrdlock(&g_rwlock4, CLOCK_MONOTONIC, &ts) == ETIMEDOUT);
clock_gettime(CLOCK_MONOTONIC, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
TEST(timeDiff > 0);
TEST(timeDiff < 20);
return arg;
}
/**
* @tc.name : pthread_rwlock_clockrdlock_0040
* @tc.desc : test pthread_rwlock_clockrdlock with timeout by CLOCK_MONOTONIC, write - read
* @tc.level : Level 0
*/
static void pthread_rwlock_clockrdlock_0040(void)
{
pthread_t tid[2];
TEST(pthread_rwlock_init(&g_rwlock4, NULL) == 0);
TEST(pthread_create(&tid[0], NULL, PthreadClockRdlockOutMonoTimeW1, NULL) == 0);
TEST(pthread_create(&tid[1], NULL, PthreadClockRdlockOutMonoTimeR2, NULL) == 0);
TEST(pthread_join(tid[0], NULL) == 0);
TEST(pthread_join(tid[1], NULL) == 0);
TEST(pthread_rwlock_destroy(&g_rwlock4) == 0);
}
/********************************************* Test case dividing line ***********************************************/
pthread_rwlock_t g_rwlock5;
static void *PthreadTimedRdlockMonoNPNoOutW1(void *arg)
{
TEST(pthread_rwlock_wrlock(&g_rwlock5) == 0);
Msleep(SLEEP_50_MS);
TEST(pthread_rwlock_unlock(&g_rwlock5) == 0);
return arg;
}
static void *PthreadTimedRdlockMonoNPNoOutR2(void *arg)
{
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_MONOTONIC);
TEST(pthread_rwlock_timedrdlock_monotonic_np(&g_rwlock5, &ts) == 0);
TEST(pthread_rwlock_unlock(&g_rwlock5) == 0);
return arg;
}
/**
* @tc.name : pthread_rwlock_timedrdlock_monotonic_np_0010
* @tc.desc : test pthread_rwlock_timedrdlock_monotonic_np with no timeout by CLOCK_MONOTONIC, write - read
* @tc.level : Level 0
*/
static void pthread_rwlock_timedrdlock_monotonic_np_0010(void)
{
pthread_t tid[2];
TEST(pthread_rwlock_init(&g_rwlock5, NULL) == 0);
TEST(pthread_create(&tid[0], NULL, PthreadTimedRdlockMonoNPNoOutW1, NULL) == 0);
TEST(pthread_create(&tid[1], NULL, PthreadTimedRdlockMonoNPNoOutR2, NULL) == 0);
TEST(pthread_join(tid[0], NULL) == 0);
TEST(pthread_join(tid[1], NULL) == 0);
TEST(pthread_rwlock_destroy(&g_rwlock5) == 0);
}
/********************************************* Test case dividing line ***********************************************/
pthread_rwlock_t g_rwlock6;
static void *PthreadTimedRdlockMonoNPOutW1(void *arg)
{
TEST(pthread_rwlock_wrlock(&g_rwlock6) == 0);
Msleep(SLEEP_50_MS);
Msleep(SLEEP_100_MS);
TEST(pthread_rwlock_unlock(&g_rwlock6) == 0);
return arg;
}
static void *PthreadTimedRdlockMonoNPOutR2(void *arg)
{
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, DELAY_TIME_100_MS, CLOCK_MONOTONIC);
TEST(pthread_rwlock_timedrdlock_monotonic_np(&g_rwlock6, &ts) == ETIMEDOUT);
clock_gettime(CLOCK_MONOTONIC, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
TEST(timeDiff > 0);
TEST(timeDiff < 20);
return arg;
}
/**
* @tc.name : pthread_rwlock_timedrdlock_monotonic_np_0020
* @tc.desc : test pthread_rwlock_timedrdlock_monotonic_np with timeout by CLOCK_MONOTONIC, write - read
* @tc.level : Level 0
*/
static void pthread_rwlock_timedrdlock_monotonic_np_0020(void)
{
pthread_t tid[2];
TEST(pthread_rwlock_init(&g_rwlock6, NULL) == 0);
TEST(pthread_create(&tid[0], NULL, PthreadTimedRdlockMonoNPOutW1, NULL) == 0);
TEST(pthread_create(&tid[1], NULL, PthreadTimedRdlockMonoNPOutR2, NULL) == 0);
TEST(pthread_join(tid[0], NULL) == 0);
TEST(pthread_join(tid[1], NULL) == 0);
TEST(pthread_rwlock_destroy(&g_rwlock6) == 0);
}
int main(void)
{
pthread_rwlock_clockrdlock_0010();
pthread_rwlock_clockrdlock_0020();
pthread_rwlock_clockrdlock_0030();
pthread_rwlock_clockrdlock_0040();
pthread_rwlock_timedrdlock_monotonic_np_0010();
pthread_rwlock_timedrdlock_monotonic_np_0020();
return t_status;
}
\ No newline at end of file
/*
* 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 <errno.h>
#include <pthread.h>
#include "pthread_util.h"
static pthread_rwlock_t w_rwlock1;
static pthread_rwlock_t w_rwlock2;
static pthread_rwlock_t w_rwlock3;
static pthread_rwlock_t w_rwlock4;
static pthread_rwlock_t w_rwlock5;
static pthread_rwlock_t w_rwlock6;
static void *RwlockClockRealTimeOut1(void *arg)
{
EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock1), 0);
Msleep(SLEEP_50_MS);
CheckStep(CHECK_STEP_TWO);
Msleep(SLEEP_100_MS);
CheckStep(CHECK_STEP_FOUR);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock1), 0);
return arg;
}
static void *RwlockClockRealTimeOut2(void *arg)
{
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_REALTIME);
EXPECT_EQ(pthread_rwlock_clockwrlock(&w_rwlock1, CLOCK_REALTIME, &ts), ETIMEDOUT);
CheckStep(CHECK_STEP_THREE);
clock_gettime(CLOCK_REALTIME, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts);
EXPECT_GE(timeDiff, 0);
EXPECT_LE(timeDiff, SLEEP_20_MS);
return arg;
}
static void *RwlockClockRealTimeWait1(void *arg)
{
EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock2), 0);
Msleep(SLEEP_50_MS);
CheckStep(CHECK_STEP_TWO);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock2), 0);
return arg;
}
static void *RwlockClockRealTimeWait2(void *arg)
{
struct timespec ts = {0};
clockid_t clock_id = CLOCK_REALTIME;
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, SLEEP_100_MS, clock_id);
EXPECT_EQ(pthread_rwlock_clockwrlock(&w_rwlock2, clock_id, &ts), 0);
CheckStep(CHECK_STEP_THREE);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock2), 0);
return arg;
}
static void *RwlockClockMonotonicTimeOut1(void *arg)
{
EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock5), 0);
Msleep(SLEEP_50_MS);
CheckStep(CHECK_STEP_TWO);
Msleep(SLEEP_100_MS);
CheckStep(CHECK_STEP_FOUR);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock5), 0);
return arg;
}
static void *RwlockClockMonotonicTimeOut2(void *arg)
{
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_MONOTONIC);
EXPECT_EQ(pthread_rwlock_clockwrlock(&w_rwlock5, CLOCK_MONOTONIC, &ts), ETIMEDOUT);
CheckStep(CHECK_STEP_THREE);
clock_gettime(CLOCK_MONOTONIC, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts);
EXPECT_GE(timeDiff, 0);
EXPECT_LE(timeDiff, SLEEP_20_MS);
return arg;
}
static void *RwlockClockMonotonicTimeWait1(void *arg)
{
EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock6), 0);
Msleep(SLEEP_50_MS);
CheckStep(CHECK_STEP_TWO);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock6), 0);
return arg;
}
static void *RwlockClockMonotonicTimeWait2(void *arg)
{
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_MONOTONIC);
EXPECT_EQ(pthread_rwlock_clockwrlock(&w_rwlock6, CLOCK_MONOTONIC, &ts), 0);
CheckStep(CHECK_STEP_THREE);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock6), 0);
return arg;
}
static void *RwlockMonotonicTime1(void *arg)
{
EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock3), 0);
Msleep(SLEEP_50_MS);
CheckStep(CHECK_STEP_TWO);
Msleep(SLEEP_100_MS);
CheckStep(CHECK_STEP_FOUR);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock3), 0);
return arg;
}
static void *RwlockMonotonicTime2(void *arg)
{
struct timespec ts = {0};
struct timespec tsNow = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_MONOTONIC);
EXPECT_EQ(pthread_rwlock_timedwrlock_monotonic_np(&w_rwlock3, &ts), ETIMEDOUT);
CheckStep(CHECK_STEP_THREE);
clock_gettime(CLOCK_MONOTONIC, &tsNow);
int timeDiff = GetTimeDiff(tsNow, ts);
EXPECT_GE(timeDiff, 0);
EXPECT_LE(timeDiff, SLEEP_20_MS);
return arg;
}
static void *RwlockMonotonicTime3(void *arg)
{
EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock4), 0);
Msleep(SLEEP_50_MS);
CheckStep(CHECK_STEP_TWO);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock4), 0);
return arg;
}
static void *RwlockMonotonicTime4(void *arg)
{
struct timespec ts = {0};
Msleep(SLEEP_20_MS);
GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_MONOTONIC);
EXPECT_EQ(pthread_rwlock_timedwrlock_monotonic_np(&w_rwlock4, &ts), 0);
CheckStep(CHECK_STEP_THREE);
EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock4), 0);
return arg;
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0010
* @tc.desc : Test whether all the interfaces to be used are normal
* @tc.level : Level 0
*/
void pthread_rwlock_timedwrlock_0010(void)
{
pthread_rwlock_t w;
struct timespec ts = {0};
EXPECT_EQ(clock_gettime(CLOCK_MONOTONIC, &ts), 0);
EXPECT_EQ(pthread_rwlock_init(&w, NULL), 0);
EXPECT_EQ(pthread_rwlock_wrlock(&w), 0);
EXPECT_EQ(pthread_rwlock_timedwrlock_monotonic_np(&w, &ts), ETIMEDOUT);
EXPECT_EQ(pthread_rwlock_unlock(&w), 0);
EXPECT_EQ(pthread_rwlock_destroy(&w), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0020
* @tc.desc : Test the case of pthread_cond_clockwait no timeout by CLOCK_REALTIME
* @tc.level : Level 0
*/
void pthread_rwlock_timedwrlock_0020(void)
{
pthread_rwlock_t w;
struct timespec ts = {0};
clockid_t clock_id = CLOCK_REALTIME;
EXPECT_EQ(clock_gettime(CLOCK_REALTIME, &ts), 0);
EXPECT_EQ(pthread_rwlock_init(&w, NULL), 0);
EXPECT_EQ(pthread_rwlock_wrlock(&w), 0);
GetDelayedTimeByClockid(&ts, SLEEP_100_MS, clock_id);
EXPECT_EQ(pthread_rwlock_clockwrlock(&w, clock_id, &ts), ETIMEDOUT);
EXPECT_EQ(pthread_rwlock_unlock(&w), 0);
EXPECT_EQ(pthread_rwlock_destroy(&w), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0030
* @tc.desc : Test the case of pthread_cond_clockwait no timeout by CLOCK_REALTIME
* @tc.level : Level 0
*/
void pthread_rwlock_timedwrlock_0030(void)
{
pthread_rwlock_t w;
struct timespec ts = {0};
clockid_t clock_id = CLOCK_MONOTONIC;
EXPECT_EQ(clock_gettime(CLOCK_MONOTONIC, &ts), 0);
EXPECT_EQ(pthread_rwlock_init(&w, NULL), 0);
EXPECT_EQ(pthread_rwlock_wrlock(&w), 0);
GetDelayedTimeByClockid(&ts, SLEEP_100_MS, clock_id);
EXPECT_EQ(pthread_rwlock_clockwrlock(&w, clock_id, &ts), ETIMEDOUT);
EXPECT_EQ(pthread_rwlock_unlock(&w), 0);
EXPECT_EQ(pthread_rwlock_destroy(&w), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0040
* @tc.desc : Test the case of pthread_cond_clockwait no timeout by CLOCK_REALTIME
* @tc.level : Level 2
*/
void pthread_rwlock_timedwrlock_0040(void)
{
pthread_rwlock_t w;
struct timespec ts = {0};
clockid_t clock_id = CLOCK_PROCESS_CPUTIME_ID;
EXPECT_EQ(pthread_rwlock_init(&w, NULL), 0);
EXPECT_EQ(pthread_rwlock_wrlock(&w), 0);
EXPECT_EQ(pthread_rwlock_clockwrlock(&w, clock_id, &ts), EINVAL);
EXPECT_EQ(pthread_rwlock_unlock(&w), 0);
EXPECT_EQ(pthread_rwlock_destroy(&w), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0050
* @tc.desc : Test the case of pthread_cond_clockwait no timeout by CLOCK_REALTIME
* @tc.level : Level 1
*/
void pthread_rwlock_timedwrlock_0050(void)
{
pthread_t tid[2];
CheckStep(CHECK_STEP_ONE);
EXPECT_EQ(pthread_rwlock_init(&w_rwlock2, NULL), 0);
EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockClockRealTimeWait1, NULL), 0);
EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockClockRealTimeWait2, NULL), 0);
EXPECT_EQ(pthread_join(tid[0], NULL), 0);
EXPECT_EQ(pthread_join(tid[1], NULL), 0);
EXPECT_EQ(CheckStep(CHECK_STEP_FOUR), (uint64_t)0x1234);
EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock2), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0060
* @tc.desc : Test the case of pthread_cond_clockwait timeout by CLOCK_REALTIME
* @tc.level : Level 1
*/
void pthread_rwlock_timedwrlock_0060(void)
{
pthread_t tid[2];
CheckStep(CHECK_STEP_ONE);
EXPECT_EQ(pthread_rwlock_init(&w_rwlock1, NULL), 0);
EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockClockRealTimeOut1, NULL), 0);
EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockClockRealTimeOut2, NULL), 0);
EXPECT_EQ(pthread_join(tid[0], NULL), 0);
EXPECT_EQ(pthread_join(tid[1], NULL), 0);
EXPECT_EQ(CheckStep(CHECK_STEP_FIVE), (uint64_t)0x12345);
EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock1), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0070
* @tc.desc : Test the case of pthread_cond_clockwait timeout by CLOCK_MONOTONIC
* @tc.level : Level 1
*/
void pthread_rwlock_timedwrlock_0070(void)
{
pthread_t tid[2];
CheckStep(CHECK_STEP_ONE);
EXPECT_EQ(pthread_rwlock_init(&w_rwlock5, NULL), 0);
EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockClockMonotonicTimeOut1, NULL), 0);
EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockClockMonotonicTimeOut2, NULL), 0);
EXPECT_EQ(pthread_join(tid[0], NULL), 0);
EXPECT_EQ(pthread_join(tid[1], NULL), 0);
EXPECT_EQ(CheckStep(CHECK_STEP_FIVE), (uint64_t)0x12345);
EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock5), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0080
* @tc.desc : Test the case of pthread_cond_clockwait timeout by CLOCK_MONOTONIC
* @tc.level : Level 1
*/
void pthread_rwlock_timedwrlock_0080(void)
{
pthread_t tid[2];
CheckStep(CHECK_STEP_ONE);
EXPECT_EQ(pthread_rwlock_init(&w_rwlock6, NULL), 0);
EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockClockMonotonicTimeWait1, NULL), 0);
EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockClockMonotonicTimeWait2, NULL), 0);
EXPECT_EQ(pthread_join(tid[0], NULL), 0);
EXPECT_EQ(pthread_join(tid[1], NULL), 0);
EXPECT_EQ(CheckStep(CHECK_STEP_FOUR), (uint64_t)0x1234);
EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock6), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0090
* @tc.desc : Test the case of pthread_rwlock_timedwrlock_monotonic_np no timeout
* @tc.level : Level 1
*/
void pthread_rwlock_timedwrlock_0090(void)
{
pthread_t tid[2];
CheckStep(CHECK_STEP_ONE);
EXPECT_EQ(pthread_rwlock_init(&w_rwlock3, NULL), 0);
EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockMonotonicTime1, NULL), 0);
EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockMonotonicTime2, NULL), 0);
EXPECT_EQ(pthread_join(tid[0], NULL), 0);
EXPECT_EQ(pthread_join(tid[1], NULL), 0);
EXPECT_EQ(CheckStep(CHECK_STEP_FIVE), (uint64_t)0x12345);
EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock3), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0100
* @tc.desc : Test the case of pthread_rwlock_timedwrlock_monotonic_np timeout
* @tc.level : Level 1
*/
void pthread_rwlock_timedwrlock_0100(void)
{
pthread_t tid[2];
CheckStep(CHECK_STEP_ONE);
EXPECT_EQ(pthread_rwlock_init(&w_rwlock4, NULL), 0);
EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockMonotonicTime3, NULL), 0);
EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockMonotonicTime4, NULL), 0);
EXPECT_EQ(pthread_join(tid[0], NULL), 0);
EXPECT_EQ(pthread_join(tid[1], NULL), 0);
EXPECT_EQ(CheckStep(CHECK_STEP_FOUR), (uint64_t)0x1234);
EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock4), 0);
}
TEST_FUN G_Fun_Array[] = {
pthread_rwlock_timedwrlock_0010,
pthread_rwlock_timedwrlock_0020,
pthread_rwlock_timedwrlock_0030,
pthread_rwlock_timedwrlock_0040,
pthread_rwlock_timedwrlock_0050,
pthread_rwlock_timedwrlock_0060,
pthread_rwlock_timedwrlock_0070,
pthread_rwlock_timedwrlock_0080,
pthread_rwlock_timedwrlock_0090,
pthread_rwlock_timedwrlock_0100,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
t_printf("pthread_rwlock_timedwrlock test ( %d ) start \n", pos + 1);
G_Fun_Array[pos]();
t_printf("pthread_rwlock_timedwrlock test ( %d ) finish \n", pos + 1);
}
return t_status;
}
\ No newline at end of file
# 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.
functionalext_thread_list = [
"pthread_cond_timedwait",
"pthread_mutex",
"pthread_rwlock_rdlock",
"pthread_rwlock_wrlock",
]
# 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.
import("../../../test_template.gni")
import("test_src_functionalext_trace.gni")
foreach(s, functionalext_trace_list) {
test_unittest(s) {
target_dir = "functionalext/trace"
}
}
group("functionalext_trace_test") {
testonly = true
deps = []
foreach(s, functionalext_trace_list) {
deps += [ ":${s}" ]
}
}
#
# 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.
#
functionalext_trace_list = [
"trace_marker",
"trace_stresstest",
]
此差异已折叠。
/*
* 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 <trace/trace_marker.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <test.h>
#include <unistd.h>
#define BUFFER_LEN 1000000
#define RUNNUM 10000
static const int count = 10;
/**
* @tc.name : trace_marker
* @tc.desc : The stress test of trace_marker.
* @tc.level : Level 0
*/
static void trace_marker_stresstest_0010(void)
{
int pidChild = 0;
int pidCParent = 0;
int pidCChild = 0;
pid_t fpid;
fpid = fork();
if (fpid < 0) {
printf("error in fork! \n");
} else if (fpid == 0) {
int pidChild = getpid();
int traceCount = 0;
bool trace_async_sucess = false;
char buf[BUFFER_LEN] = {0};
while (1) {
snprintf(buf, BUFFER_LEN, "%d", traceCount);
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin("Trace_Marker_Async_Begin", buf);
trace_marker_async_end("Trace_Marker_Async_End", buf);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
if (traceCount % RUNNUM == 0) {
printf("trace_marker_async_begin has been running times is:%d\n", traceCount);
}
traceCount++;
}
exit(pidChild);
} else {
pid_t pidCChild;
int traceCount = 0;
bool trace_sucess = false;
char buf[BUFFER_LEN] = {0};
// start process again
pidCChild = fork();
if (pidCChild < 0) {
t_printf("error in fork!");
} else if (pidCChild == 0) {
while (1) {
snprintf(buf, BUFFER_LEN, "%d", traceCount);
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin("Trace_Marker", buf);
trace_marker_end();
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
if (traceCount % RUNNUM == 0) {
printf("trace_marker_begin has been running times is:%d\n", traceCount);
}
traceCount++;
}
exit(pidCChild);
} else {
pidCParent = getpid();
int traceCount = 0;
while (1) {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_count("traceCount", traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
if (traceCount % RUNNUM == 0) {
printf("trace_marker_count has been running times is:%d\n", traceCount);
}
traceCount++;
}
exit(pidCParent);
}
}
}
int main(void)
{
t_printf("trace_marker_stresstest_0010 start \n");
trace_marker_stresstest_0010();
t_printf("trace_marker_stresstest_0010 finish \n");
return t_status;
}
......@@ -142,6 +142,16 @@ if (musl_arch == "arm") {
}
musl_src_file = [
"src/thread/pthread_cond_clockwait.c",
"src/thread/pthread_cond_timedwait_monotonic_np.c",
"src/thread/pthread_cond_timeout_np.c",
"src/internal/pthread_impl.h",
"src/thread/pthread_rwlock_clockrdlock.c",
"src/thread/pthread_rwlock_timedrdlock.c",
"src/thread/pthread_rwlock_timedrdlock_monotonic_np.c",
"src/thread/pthread_rwlock_clockwrlock.c",
"src/thread/pthread_rwlock_timedwrlock_monotonic_np.c",
"src/thread/pthread_rwlock_timedwrlock.c",
"src/aio/aio.c",
"src/aio/aio_suspend.c",
"src/aio/lio_listio.c",
......@@ -394,6 +404,7 @@ musl_src_file = [
"src/linux/quotactl.c",
"src/linux/readahead.c",
"src/linux/reboot.c",
"src/linux/tgkill.c",
"src/linux/remap_file_pages.c",
"src/linux/sbrk.c",
"src/linux/sendfile.c",
......@@ -1293,6 +1304,9 @@ musl_src_file = [
"src/thread/pthread_mutex_lock.c",
"src/thread/pthread_mutex_setprioceiling.c",
"src/thread/pthread_mutex_timedlock.c",
"src/thread/pthread_mutex_clocklock.c",
"src/thread/pthread_mutex_timedlock_monotonic_np.c",
"src/thread/pthread_mutex_lock_timeout_np.c",
"src/thread/pthread_mutex_trylock.c",
"src/thread/pthread_mutex_unlock.c",
"src/thread/pthread_mutexattr_destroy.c",
......@@ -1305,8 +1319,6 @@ musl_src_file = [
"src/thread/pthread_rwlock_destroy.c",
"src/thread/pthread_rwlock_init.c",
"src/thread/pthread_rwlock_rdlock.c",
"src/thread/pthread_rwlock_timedrdlock.c",
"src/thread/pthread_rwlock_timedwrlock.c",
"src/thread/pthread_rwlock_tryrdlock.c",
"src/thread/pthread_rwlock_trywrlock.c",
"src/thread/pthread_rwlock_unlock.c",
......@@ -1469,6 +1481,10 @@ musl_src_file = [
"src/unistd/usleep.c",
"src/unistd/write.c",
"src/unistd/writev.c",
"src/trace/trace_marker.c",
"src/info/application_target_sdk_version.c",
"src/info/device_api_version.c",
"src/info/fatal_message.c",
]
if (musl_arch == "arm") {
......@@ -1694,6 +1710,7 @@ musl_inc_sys_files = [
"include/sys/quota.h",
"include/sys/random.h",
"include/sys/reboot.h",
"include/sys/tgkill.h",
"include/sys/reg.h",
"include/sys/resource.h",
"include/sys/select.h",
......@@ -1732,6 +1749,14 @@ musl_inc_sys_files = [
"include/sys/xattr.h",
]
musl_inc_trace_files = [ "include/trace/trace_marker.h" ]
musl_inc_info_files = [
"include/info/application_target_sdk_version.h",
"include/info/device_api_version.h",
"include/info/fatal_message.h",
]
musl_inc_root_files = [
"include/aio.h",
"include/alloca.h",
......@@ -1831,15 +1856,25 @@ musl_src_porting_file = [
"arch/generic/bits/shm.h",
"arch/generic/crtbrand.s",
"include/ctype.h",
"include/info/application_target_sdk_version.h",
"include/info/device_api_version.h",
"include/info/fatal_message.h",
"include/pthread.h",
"include/sys/capability.h",
"include/sys/reboot.h",
"include/sys/socket.h",
"include/sys/sysinfo.h",
"include/signal.h",
"include/sched.h",
"src/internal/dynlink.h",
"include/sys/tgkill.h",
"include/trace/trace_marker.h",
"include/unistd.h",
"include/dlfcn.h",
"src/internal/musl_log.h",
"src/info/application_target_sdk_version.c",
"src/info/device_api_version.c",
"src/info/fatal_message.c",
"src/env/__init_tls.c",
"src/internal/pthread_impl.h",
"src/internal/syscall.h",
......@@ -1848,6 +1883,8 @@ musl_src_porting_file = [
"ldso/strops.h",
"src/legacy/ulimit.c",
"src/linux/gettid.c",
"src/linux/reboot.c",
"src/linux/tgkill.c",
"src/malloc/malloc.c",
"src/multibyte/wcsnrtombs.c",
"src/network/inet_legacy.c",
......@@ -1858,6 +1895,20 @@ musl_src_porting_file = [
"src/sched/sched_getscheduler.c",
"src/thread/arm/clone.s",
"src/thread/arm/syscall_cp.s",
"src/thread/pthread_mutex_clocklock.c",
"src/thread/pthread_mutex_timedlock.c",
"src/thread/pthread_mutex_timedlock_monotonic_np.c",
"src/thread/pthread_mutex_lock_timeout_np.c",
"src/thread/pthread_rwlock_clockrdlock.c",
"src/thread/pthread_rwlock_timedrdlock.c",
"src/thread/pthread_rwlock_timedrdlock_monotonic_np.c",
"src/thread/pthread_cond_timedwait_monotonic_np.c",
"src/thread/pthread_cond_timeout_np.c",
"src/thread/pthread_cond_clockwait.c",
"src/thread/pthread_rwlock_clockwrlock.c",
"src/thread/pthread_rwlock_timedwrlock_monotonic_np.c",
"src/thread/pthread_rwlock_timedwrlock.c",
"src/trace/trace_marker.c",
"src/ldso/dlclose.c",
"ldso/dynlink.c",
"src/exit/atexit.c",
......
/*
* 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.
*/
#ifndef _INFO_APPLICATION_TARGET_SDK_VERSION_H
#define _INFO_APPLICATION_TARGET_SDK_VERSION_H
#ifdef __cplusplus
extern "C" {
#endif
#define SDK_VERSION_FUTURE 9999
#define SDK_VERSION_7 7
#define SDK_VERSION_8 8
#define SDK_VERSION_9 9
/**
* @brief Get the target sdk version number of the application.
* @return The target sdk version number.
*/
int get_application_target_sdk_version(void);
/**
* @brief Set the target sdk version number of the application.
* @param target The target sdk version number.
*/
void set_application_target_sdk_version(int target);
#ifdef __cplusplus
}
#endif
#endif // _INFO_APPLICATION_TARGET_SDK_VERSION_H
/*
* 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.
*/
#ifndef _INFO_DEVICE_API_VERSION_H
#define _INFO_DEVICE_API_VERSION_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Get the api version number of the device.
* @return The api version number of the device.
*/
int get_device_api_version(void);
#ifdef __cplusplus
}
#endif
#endif // _INFO_DEVICE_API_VERSION_H
/*
* 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.
*/
#ifndef _INFO_FATAL_MESSAGE_H
#define _INFO_FATAL_MESSAGE_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct fatal_msg {
size_t size;
char msg[0];
} fatal_msg_t;
/**
* @brief Set up fatal message
* @param msg The fatal message
*/
void set_fatal_message(const char *msg);
/**
* @brief Get the set fatal message
* @return Address of fatal message
*/
fatal_msg_t *get_fatal_message(void);
#ifdef __cplusplus
}
#endif
#endif // _INFO_FATAL_MESSAGE_H
/*
* 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.
*/
#ifndef _PTHREAD_H
#define _PTHREAD_H
#ifdef __cplusplus
......@@ -119,6 +134,49 @@ int pthread_mutex_trylock(pthread_mutex_t *);
int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict);
int pthread_mutex_destroy(pthread_mutex_t *);
int pthread_mutex_consistent(pthread_mutex_t *);
/**
* @brief lock the mutex object referenced by mutex. If the mutex is already locked,
* the calling thread shall block until the mutex becomes available as in the
* pthread_mutex_lock() function. If the mutex cannot be locked without waiting for
* another thread to unlock the mutex, this wait shall be terminated when the specified
* timeout expires. The timeout shall be based on the CLOCK_REALTIME or CLOCK_MONOTONIC clock.
* The resolution of the timeout shall be the resolution of the clock on which it is based.
* @param mutex a robust mutex and the process containing the owning thread terminated while holding the mutex lock.
* @param clock_id specified CLOCK_REALTIME or CLOCK_MONOTONIC clock.
* @param timespec the timeout shall expire specified by abstime passes.
* @return clocklock result.
* @retval 0 is returned on success.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int pthread_mutex_clocklock(pthread_mutex_t *__restrict, clockid_t, const struct timespec *__restrict);
/**
* @brief lock the mutex object referenced by mutex. If the mutex is already locked,
* the calling thread shall block until the mutex becomes available as in the
* pthread_mutex_lock() function. If the mutex cannot be locked without waiting for
* another thread to unlock the mutex, this wait shall be terminated when the specified
* timeout expires. The timeout shall be based on the CLOCK_MONOTONIC clock.
* The resolution of the timeout shall be the resolution of the clock on which it is based.
* @param mutex a robust mutex and the process containing the owning thread terminated while holding the mutex lock.
* @param timespec the timeout shall expire specified by abstime passes.
* @return clocklock result.
* @retval 0 is returned on success.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int pthread_mutex_timedlock_monotonic_np(pthread_mutex_t *__restrict, const struct timespec *__restrict);
/**
* @brief lock the mutex object referenced by mutex. If the mutex is already locked,
* the calling thread shall block until the mutex becomes available as in the
* pthread_mutex_lock() function. If the mutex cannot be locked without waiting for
* another thread to unlock the mutex, this wait shall be terminated when the specified
* timeout expires. The timeout shall be based on the CLOCK_MONOTONIC clock.
* The resolution of the timeout shall be the resolution of the clock on which it is based.
* @param mutex a robust mutex and the process containing the owning thread terminated while holding the mutex lock.
* @param ms the timeout shall expire specified by relative time(ms) passes.
* @return clocklock result.
* @retval 0 is returned on success.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int pthread_mutex_lock_timeout_np(pthread_mutex_t *__restrict, unsigned int);
int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict);
int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict);
......@@ -127,6 +185,49 @@ int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__re
int pthread_cond_destroy(pthread_cond_t *);
int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict);
int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict);
/**
* @brief The thread waits for a signal to trigger, and if timeout or signal is triggered,
* the thread wakes up.
* @param pthread_cond_t Condition variables for multithreading.
* @param pthread_mutex_t Thread mutex variable.
* @param clockid_t Clock ID used in clock and timer functions.
* @param timespec The timeout shall expire specified by abstime passes.
* @return pthread_cond_clockwait result.
* @retval 0 pthread_cond_clockwait successful.
* @retval ETIMEDOUT pthread_cond_clockwait Connection timed out.
* @retval EINVAL pthread_cond_clockwait error.
*/
int pthread_cond_clockwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict,
clockid_t, const struct timespec *__restrict);
/**
* @brief Condition variables have an initialization option to use CLOCK_MONOTONIC.
* The thread waits for a signal to trigger, and if timeout or signal is triggered,
* the thread wakes up.
* @param pthread_cond_t Condition variables for multithreading.
* @param pthread_mutex_t Thread mutex variable.
* @param timespec The timeout shall expire specified by abstime passes.
* @return pthread_cond_timedwait_monotonic_np result.
* @retval 0 pthread_cond_timedwait_monotonic_np successful.
* @retval ETIMEDOUT pthread_cond_timedwait_monotonic_np Connection timed out.
* @retval EINVAL pthread_cond_timedwait_monotonic_np error.
*/
int pthread_cond_timedwait_monotonic_np(pthread_cond_t *__restrict, pthread_mutex_t *__restrict,
const struct timespec *__restrict);
/**
* @brief Condition variables have an initialization option to use CLOCK_MONOTONIC and The time
* parameter is in milliseconds. The thread waits for a signal to trigger, and if timeout or
* signal is triggered, the thread wakes up.
* @param pthread_cond_t Condition variables for multithreading.
* @param pthread_mutex_t Thread mutex variable.
* @param unsigned Timeout, in milliseconds.
* @return pthread_cond_timeout_np result.
* @retval 0 pthread_cond_timeout_np successful.
* @retval ETIMEDOUT pthread_cond_timeout_np Connection timed out.
* @retval EINVAL pthread_cond_timeout_np error.
*/
int pthread_cond_timeout_np(pthread_cond_t* __restrict, pthread_mutex_t* __restrict, unsigned int);
int pthread_cond_broadcast(pthread_cond_t *);
int pthread_cond_signal(pthread_cond_t *);
......@@ -135,10 +236,74 @@ int pthread_rwlock_destroy(pthread_rwlock_t *);
int pthread_rwlock_rdlock(pthread_rwlock_t *);
int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
/**
* @brief Apply a read lock to the read-write lock referenced by rwlock as in the
* pthread_rwlock_rdlock() function. However, if the lock cannot be acquired without
* waiting for other threads to unlock the lock, this wait shall be terminated when
* the specified timeout expires. The timeout shall expire when the absolute time specified by
* abstime passes, as measured by the clock on which timeouts are based, or if the absolute time
* specified by abstime has already been passed at the time of the call.
* The timeout shall be based on the CLOCK_REALTIME or CLOCK_MONOTONIC clock.
* @param rw a read lock to the read-write lock referenced.
* @param clock_id specified CLOCK_REALTIME or CLOCK_MONOTONIC clock.
* @param timespec the timeout shall expire specified by abstime passes.
* @return clockrdlock result.
* @retval 0 is returned on success.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict, clockid_t, const struct timespec *__restrict);
/**
* @brief Apply a read lock to the read-write lock referenced by rwlock as in the
* pthread_rwlock_rdlock() function. However, if the lock cannot be acquired without
* waiting for other threads to unlock the lock, this wait shall be terminated when
* the specified timeout expires. The timeout shall expire when the absolute time specified by
* abstime passes, as measured by the clock on which timeouts are based, or if the absolute time
* specified by abstime has already been passed at the time of the call.
* The timeout shall be based on the CLOCK_MONOTONIC clock.
* @param rw a read lock to the read-write lock referenced.
* @param timespec the timeout shall expire specified by abstime passes.
* @return clockrdlock result.
* @retval 0 is returned on success.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int pthread_rwlock_timedrdlock_monotonic_np(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
int pthread_rwlock_wrlock(pthread_rwlock_t *);
int pthread_rwlock_trywrlock(pthread_rwlock_t *);
int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
int pthread_rwlock_unlock(pthread_rwlock_t *);
/**
* @brief Read-write lock variables have an initialization option to use CLOCK_MONOTONIC.
* apply a read lock to the read-write lock referenced by rwlock as in the
* pthread_rwlock_wrlock() function. However, if the lock cannot be acquired without
* waiting for other threads to unlock the lock, this wait shall be terminated when
* the specified timeout expires. The timeout shall expire when the absolute time specified by
* abstime passes, as measured by the clock on which timeouts are based, or if the absolute time
* specified by abstime has already been passed at the time of the call.
* The timeout shall be based on the CLOCK_MONOTONIC clock.
* @param rw a read lock to the read-write lock referenced.
* @param timespec the timeout shall expire specified by abstime passes.
* @return clockrdlock result.
* @retval 0 is returned on success.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int pthread_rwlock_timedwrlock_monotonic_np(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
/**
* @brief Apply a read lock to the read-write lock referenced by rwlock as in the
* pthread_rwlock_wrlock() function. However, if the lock cannot be acquired without
* waiting for other threads to unlock the lock, this wait shall be terminated when
* the specified timeout expires. The timeout shall expire when the absolute time specified by
* abstime passes, as measured by the clock on which timeouts are based, or if the absolute time
* specified by abstime has already been passed at the time of the call.
* The timeout shall be based on the CLOCK_REALTIME or CLOCK_MONOTONIC clock.
* @param rw a read lock to the read-write lock referenced.
* @param clock_id specified CLOCK_REALTIME or CLOCK_MONOTONIC clock.
* @param timespec the timeout shall expire specified by abstime passes.
* @return clockrdlock result.
* @retval 0 is returned on success.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict, clockid_t, const struct timespec *__restrict);
int pthread_spin_init(pthread_spinlock_t *, int);
int pthread_spin_destroy(pthread_spinlock_t *);
......
......@@ -204,7 +204,6 @@ int __libc_current_sigrtmax(void);
#define MUSL_SIGNAL_JSHEAP_PRIV (SIGRTMIN + 5)
int kill(pid_t, int);
int tgkill(int __tgid, int __tid, int __signal);
int sigemptyset(sigset_t *);
int sigfillset(sigset_t *);
int sigaddset(sigset_t *, int);
......
/*
* 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.
*/
#ifndef _SYS_REBOOT_H
#define _SYS_REBOOT_H
#ifdef __cplusplus
extern "C"
{
#endif
#define RB_AUTOBOOT 0x01234567
#define RB_HALT_SYSTEM 0xcdef0123
#define RB_ENABLE_CAD 0x89abcdef
#define RB_DISABLE_CAD 0
#define RB_POWER_OFF 0x4321fedc
#define RB_SW_SUSPEND 0xd000fce2
#define RB_KEXEC 0x45584543
#define RB_MAGIC1 0xfee1dead
#define RB_MAGIC2 672274793
/**
* @brief reboots the device, or enables/disables the reboot keystroke.
* @param type commands accepted by the reboot() system call.
* -- RESTART Restart system using default command and mode.
* -- HALT Stop OS and give system control to ROM monitor, if any.
* -- CAD_ON Ctrl-Alt-Del sequence causes RESTART command.
* -- CAD_OFF Ctrl-Alt-Del sequence sends SIGINT to init task.
* -- POWER_OFF Stop OS and remove all power from system, if possible.
* -- RESTART2 Restart system using given command string.
* -- SW_SUSPEND Suspend system using software suspend if compiled in.
* -- KEXEC Restart system using a previously loaded Linux kernel.
* @return reboot result.
* @retval 0 is returned on success, if CAD was successfully enabled/disabled.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int reboot(int);
#ifdef __cplusplus
}
#endif
#endif
/*
* 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.
*/
#ifndef _SYS_TGKILL_H
#define _SYS_TGKILL_H
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief send any signal to any process group or process.
* @param tgid the group ID of the calling process.
* @param tid the thread ID of the calling process.
* @param sig the actual signal.
* @return tgkill result.
* @retval 0 is returned on success.
* @retval -1 is returned on failure, and errno is set to indicate the error.
*/
int tgkill(int tgid, int tid, int sig);
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
/*
* 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.
*/
#ifndef _TRACE_TRACE_MARKER_H
#define _TRACE_TRACE_MARKER_H
#define TRACE_MARKER_MESSAGE_LEN 1024
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief Write the function call information to the trace_marker node in kernel space,
* used on the same thread as trace_marker_end(),with the symbol "B".
* @param message The function of information.
* @param value The value which want to trace.
*/
void trace_marker_begin(const char *message, const char *value);
/**
* @brief Write the terminator to the trace_marker node of the kernel space,
* used on the same thread as trace_marker_begin(),with the symbol "E".
*/
void trace_marker_end(void);
/**
* @brief Write the function call information to the trace_marker node in kernel space,
* used in a different thread than trace_marker_async_end(),with the symbol "S".
* @param message The function of information.
* @param value The value which want to trace.
*/
void trace_marker_async_begin(const char *message, const char *value);
/**
* @brief Write the terminator to the trace_marker node in kernel space,
* used in a different thread than trace_marker_async_begin(),with the symbol "F".
* @param message The function of information.
* @param value The value which want to trace.
*/
void trace_marker_async_end(const char *message, const char *value);
/**
* @brief Marks a pre-traced numeric variable,with the symbol "C".
* @param message The function of information.
* @param value The value which want to trace.
*/
void trace_marker_count(const char *message, int value);
#ifdef __cplusplus
}
#endif
#endif
/*
* 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 <info/application_target_sdk_version.h>
static int application_target_sdk_version = SDK_VERSION_FUTURE;
int get_application_target_sdk_version(void)
{
return application_target_sdk_version;
}
void set_application_target_sdk_version(int target)
{
if (target == 0) {
target = SDK_VERSION_FUTURE;
}
application_target_sdk_version = target;
}
/*
* 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 <info/device_api_version.h>
#define API_VERSION_DEFAULT 0
int get_device_api_version(void)
{
// depend subsystem of syspara support the interface of get system property
return API_VERSION_DEFAULT;
}
\ No newline at end of file
/*
* 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 <info/fatal_message.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include "musl_log.h"
static pthread_mutex_t fatal_msg_lock = PTHREAD_MUTEX_INITIALIZER;
static fatal_msg_t *fatal_message = NULL;
void set_fatal_message(const char *msg)
{
pthread_mutex_lock(&fatal_msg_lock);
if (msg == NULL) {
MUSL_LOGW("message null");
pthread_mutex_unlock(&fatal_msg_lock);
return;
}
if (fatal_message != NULL) {
pthread_mutex_unlock(&fatal_msg_lock);
return;
}
size_t size = sizeof(fatal_msg_t) + strlen(msg) + 1;
void *map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (map == MAP_FAILED) {
MUSL_LOGW("mmap failed");
fatal_message = NULL;
pthread_mutex_unlock(&fatal_msg_lock);
return;
}
int ret = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, map, size, "fatal message");
if (ret < 0) {
MUSL_LOGW("prctl set vma failed");
munmap(map, size);
fatal_message = NULL;
pthread_mutex_unlock(&fatal_msg_lock);
return;
}
fatal_message = (fatal_msg_t *)(map);
fatal_message->size = size;
strcpy(fatal_message->msg, msg);
pthread_mutex_unlock(&fatal_msg_lock);
return;
}
fatal_msg_t *get_fatal_message(void)
{
return fatal_message;
}
/*
* 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.
*/
#ifndef _MUSL_LOG_H
#define _MUSL_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
#define MUSL_LOG_TYPE LOG_CORE
#define MUSL_LOG_DOMAIN 0xD003F00
#define MUSL_LOG_TAG "musl_linker"
#ifdef ENABLE_MUSL_LOG
#define MUSL_LOGE(...) ((void)HiLogBasePrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, MUSL_LOG_TAG, __VA_ARGS__))
#define MUSL_LOGW(...) ((void)HiLogBasePrint(MUSL_LOG_TYPE, LOG_WARN, MUSL_LOG_DOMAIN, MUSL_LOG_TAG, __VA_ARGS__))
#define MUSL_LOGI(...) ((void)HiLogBasePrint(MUSL_LOG_TYPE, LOG_INFO, MUSL_LOG_DOMAIN, MUSL_LOG_TAG, __VA_ARGS__))
#define MUSL_LOGD(...) ((void)HiLogBasePrint(MUSL_LOG_TYPE, LOG_DEBUG, MUSL_LOG_DOMAIN, MUSL_LOG_TAG, __VA_ARGS__))
#else
#define MUSL_LOGE(...)
#define MUSL_LOGW(...)
#define MUSL_LOGI(...)
#define MUSL_LOGD(...)
#endif
#ifdef __cplusplus
}
#endif
#endif
#ifndef _PTHREAD_IMPL_H
#define _PTHREAD_IMPL_H
/*
* 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.
*/
#ifndef _INTERNAL_PTHREAD_IMPL_H
#define _INTERNAL_PTHREAD_IMPL_H
#include <pthread.h>
#include <signal.h>
......@@ -14,59 +29,59 @@
#define pthread __pthread
struct pthread {
/* Part 1 -- these fields may be external or
* internal (accessed via asm) ABI. Do not change. */
struct pthread *self;
uintptr_t *dtv;
struct pthread *prev, *next; /* non-ABI */
uintptr_t sysinfo;
uintptr_t canary, canary2;
/* Part 2 -- implementation details, non-ABI. */
int tid;
int errno_val;
volatile int detach_state;
volatile int cancel;
volatile unsigned char canceldisable, cancelasync;
unsigned char tsd_used:1;
unsigned char dlerror_flag:1;
unsigned char *map_base;
size_t map_size;
void *stack;
size_t stack_size;
size_t guard_size;
void *result;
struct __ptcb *cancelbuf;
void **tsd;
struct {
volatile void *volatile head;
long off;
volatile void *volatile pending;
} robust_list;
volatile int timer_id;
locale_t locale;
volatile int killlock[1];
char *dlerror_buf;
void *stdio_locks;
/* Part 1 -- these fields may be external or
* internal (accessed via asm) ABI. Do not change. */
struct pthread *self;
uintptr_t *dtv;
struct pthread *prev, *next; /* non-ABI */
uintptr_t sysinfo;
uintptr_t canary, canary2;
/* Part 2 -- implementation details, non-ABI. */
int tid;
int errno_val;
volatile int detach_state;
volatile int cancel;
volatile unsigned char canceldisable, cancelasync;
unsigned char tsd_used:1;
unsigned char dlerror_flag:1;
unsigned char *map_base;
size_t map_size;
void *stack;
size_t stack_size;
size_t guard_size;
void *result;
struct __ptcb *cancelbuf;
void **tsd;
struct {
volatile void *volatile head;
long off;
volatile void *volatile pending;
} robust_list;
volatile int timer_id;
locale_t locale;
volatile int killlock[1];
char *dlerror_buf;
void *stdio_locks;
#ifdef RESERVE_SIGNAL_STACK
void *signal_stack;
void *signal_stack;
#endif
/* Part 3 -- the positions of these fields relative to
* the end of the structure is external and internal ABI. */
uintptr_t canary_at_end;
uintptr_t *dtv_copy;
/* Part 3 -- the positions of these fields relative to
* the end of the structure is external and internal ABI. */
uintptr_t canary_at_end;
uintptr_t *dtv_copy;
};
enum {
DT_EXITING = 0,
DT_JOINABLE,
DT_DETACHED,
DT_EXITING = 0,
DT_JOINABLE,
DT_DETACHED,
};
struct __timer {
int timerid;
pthread_t thread;
int timerid;
pthread_t thread;
};
#define __SU (sizeof(size_t)/sizeof(int))
......@@ -92,6 +107,7 @@ struct __timer {
#define _m_waiters __u.__vi[2]
#define _m_prev __u.__p[3]
#define _m_next __u.__p[4]
#define _m_clock __u.__i[4]
#define _m_count __u.__i[5]
#define _c_shared __u.__p[0]
......@@ -104,6 +120,7 @@ struct __timer {
#define _rw_lock __u.__vi[0]
#define _rw_waiters __u.__vi[1]
#define _rw_shared __u.__i[2]
#define _rw_clock __u.__i[4]
#define _b_lock __u.__vi[0]
#define _b_waiters __u.__vi[1]
#define _b_limit __u.__i[2]
......@@ -131,11 +148,11 @@ struct __timer {
#define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 })
#define SIGPT_SET \
((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \
[sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) })
((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \
[sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) })
#define SIGTIMER_SET \
((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \
0x80000000 })
((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \
0x80000000 })
void *__tls_get_addr(tls_mod_off_t *);
hidden int __init_tp(void *);
......@@ -167,16 +184,43 @@ hidden int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec
hidden void __wait(volatile int *, volatile int *, int, int);
static inline void __wake(volatile void *addr, int cnt, int priv)
{
if (priv) priv = FUTEX_PRIVATE;
if (cnt<0) cnt = INT_MAX;
__syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS ||
__syscall(SYS_futex, addr, FUTEX_WAKE, cnt);
if (priv) priv = FUTEX_PRIVATE;
if (cnt<0) cnt = INT_MAX;
__syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS ||
__syscall(SYS_futex, addr, FUTEX_WAKE, cnt);
}
static inline void __futexwait(volatile void *addr, int val, int priv)
{
if (priv) priv = FUTEX_PRIVATE;
__syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS ||
__syscall(SYS_futex, addr, FUTEX_WAIT, val, 0);
if (priv) priv = FUTEX_PRIVATE;
__syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS ||
__syscall(SYS_futex, addr, FUTEX_WAIT, val, 0);
}
#define MS_PER_S 1000
#define US_PER_S 1000000
static inline void __timespec_from_ms(struct timespec* ts, const unsigned ms)
{
if (ts == NULL) {
return;
}
ts->tv_sec = ms / MS_PER_S;
ts->tv_nsec = (ms % MS_PER_S) * US_PER_S;
}
#define NS_PER_S 1000000000
static inline void __absolute_timespec_from_timespec(struct timespec *abs_ts,
const struct timespec *ts, clockid_t clock)
{
if (abs_ts == NULL || ts == NULL) {
return;
}
clock_gettime(clock, abs_ts);
abs_ts->tv_sec += ts->tv_sec;
abs_ts->tv_nsec += ts->tv_nsec;
if (abs_ts->tv_nsec >= NS_PER_S) {
abs_ts->tv_nsec -= NS_PER_S;
abs_ts->tv_sec++;
}
}
hidden void __acquire_ptc(void);
......
/*
* 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 <sys/reboot.h>
#include "syscall.h"
int __reboot(int type)
{
return syscall(SYS_reboot, RB_MAGIC1, RB_MAGIC2, type);
}
weak_alias(__reboot, reboot);
\ No newline at end of file
/*
* 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 <sys/tgkill.h>
#include "syscall.h"
int tgkill(int tgid, int tid, int sig)
{
return syscall(__NR_tgkill, tgid, tid, sig);
}
\ No newline at end of file
#include <signal.h>
#include "syscall.h"
void (*signal(int sig, void (*func)(int)))(int)
{
......@@ -9,10 +8,5 @@ void (*signal(int sig, void (*func)(int)))(int)
return sa_old.sa_handler;
}
int tgkill(int __tgid, int __tid, int __signal){
return __syscall(SYS_tgkill, __tgid, __tid, __signal);
}
weak_alias(signal, bsd_signal);
weak_alias(signal, __sysv_signal);
/*
* 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 "pthread_impl.h"
int pthread_cond_clockwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
clockid_t clock_id, const struct timespec *abs_timeout)
{
if (cond == NULL) {
return EINVAL;
}
switch (clock_id) {
case CLOCK_MONOTONIC:
cond->_c_clock = CLOCK_MONOTONIC;
return __pthread_cond_timedwait(cond, mutex, abs_timeout);
case CLOCK_REALTIME:
cond->_c_clock = CLOCK_REALTIME;
return __pthread_cond_timedwait(cond, mutex, abs_timeout);
default:
return EINVAL;
}
}
\ No newline at end of file
/*
* 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 "pthread_impl.h"
int pthread_cond_timedwait_monotonic_np(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abs_timeout)
{
if (cond == NULL) {
return EINVAL;
}
cond->_c_clock = CLOCK_MONOTONIC;
return __pthread_cond_timedwait(cond, mutex, abs_timeout);
}
\ No newline at end of file
/*
* 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 "pthread_impl.h"
int pthread_cond_timeout_np(pthread_cond_t *cond, pthread_mutex_t *mutex, unsigned int ms)
{
struct timespec ts;
__timespec_from_ms(&ts, ms);
struct timespec abs_timeout;
__absolute_timespec_from_timespec(&abs_timeout, &ts, CLOCK_MONOTONIC);
return pthread_cond_timedwait_monotonic_np(cond, mutex, &abs_timeout);
}
/*
* 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 "pthread_impl.h"
int pthread_mutex_clocklock(pthread_mutex_t* mutex_interface, clockid_t clock_id,
const struct timespec* abs_timeout)
{
if (mutex_interface == NULL) {
return EINVAL;
}
switch (clock_id) {
case CLOCK_MONOTONIC:
mutex_interface->_m_clock = CLOCK_MONOTONIC;
return __pthread_mutex_timedlock(mutex_interface, abs_timeout);
case CLOCK_REALTIME:
mutex_interface->_m_clock = CLOCK_REALTIME;
return __pthread_mutex_timedlock(mutex_interface, abs_timeout);
default:
return EINVAL;
}
}
\ No newline at end of file
/*
* 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 "pthread_impl.h"
#define NS_PER_S 1000000000
int pthread_mutex_lock_timeout_np(pthread_mutex_t* mutex_interface, unsigned int ms)
{
struct timespec ts;
__timespec_from_ms(&ts, ms);
struct timespec abs_timeout;
__absolute_timespec_from_timespec(&abs_timeout, &ts, CLOCK_MONOTONIC);
return pthread_mutex_timedlock_monotonic_np(mutex_interface, &abs_timeout);
}
\ No newline at end of file
/*
* 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 "pthread_impl.h"
#define IS32BIT(x) !((x)+0x80000000ULL>>32)
#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
static int __futex4(volatile void *addr, int op, int val, const struct timespec *to)
{
#ifdef SYS_futex_time64
time_t s = to ? to->tv_sec : 0;
long ns = to ? to->tv_nsec : 0;
int r = -ENOSYS;
if (SYS_futex == SYS_futex_time64 || !IS32BIT(s))
r = __syscall(SYS_futex_time64, addr, op, val,
to ? ((long long[]) {s, ns}) : 0);
if (SYS_futex == SYS_futex_time64 || r!=-ENOSYS) return r;
to = to ? (void *)(long[]) {CLAMP(s), ns} : 0;
#endif
return __syscall(SYS_futex, addr, op, val, to);
}
static int pthread_mutex_timedlock_pi(pthread_mutex_t *restrict m, const struct timespec *restrict at)
{
int clock = m->_m_clock;
int type = m->_m_type;
int priv = (type & 128) ^ 128;
pthread_t self = __pthread_self();
int e;
if (!priv) self->robust_list.pending = &m->_m_next;
do e = -__futex4(&m->_m_lock, FUTEX_LOCK_PI|priv, 0, at);
while (e==EINTR);
if (e) self->robust_list.pending = 0;
switch (e) {
case 0:
/* Catch spurious success for non-robust mutexes. */
if (!(type&4) && ((m->_m_lock & 0x40000000) || m->_m_waiters)) {
a_store(&m->_m_waiters, -1);
__syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv);
self->robust_list.pending = 0;
break;
}
/* Signal to trylock that we already have the lock. */
m->_m_count = -1;
return __pthread_mutex_trylock(m);
case ETIMEDOUT:
return e;
case EDEADLK:
if ((type&3) == PTHREAD_MUTEX_ERRORCHECK) return e;
default:
break;
}
do e = __timedwait(&(int) {0}, 0, clock, at, 1);
while (e != ETIMEDOUT);
return e;
}
int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at)
{
if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
&& !a_cas(&m->_m_lock, 0, EBUSY))
return 0;
int clock = (m->_m_clock == CLOCK_MONOTONIC) ? CLOCK_MONOTONIC : CLOCK_REALTIME;
int type = m->_m_type;
int r, t, priv = (type & 128) ^ 128;
r = __pthread_mutex_trylock(m);
if (r != EBUSY) return r;
if (type&8) return pthread_mutex_timedlock_pi(m, at);
int spins = 100;
while (spins-- && m->_m_lock && !m->_m_waiters) a_spin();
while ((r=__pthread_mutex_trylock(m)) == EBUSY) {
r = m->_m_lock;
int own = r & 0x3fffffff;
if (!own && (!r || (type&4)))
continue;
if ((type&3) == PTHREAD_MUTEX_ERRORCHECK
&& own == __pthread_self()->tid)
return EDEADLK;
a_inc(&m->_m_waiters);
t = r | 0x80000000;
a_cas(&m->_m_lock, r, t);
r = __timedwait(&m->_m_lock, t, clock, at, priv);
a_dec(&m->_m_waiters);
if (r && r != EINTR) break;
}
return r;
}
weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock);
\ No newline at end of file
/*
* 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 "pthread_impl.h"
int pthread_mutex_timedlock_monotonic_np(pthread_mutex_t* mutex_interface, const struct timespec* abs_timeout)
{
if (mutex_interface == NULL) {
return EINVAL;
}
mutex_interface->_m_clock = CLOCK_MONOTONIC;
return __pthread_mutex_timedlock(mutex_interface, abs_timeout);
}
/*
* 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 "pthread_impl.h"
int pthread_rwlock_clockrdlock(pthread_rwlock_t *rw, clockid_t clock_id, const struct timespec *at)
{
if (rw == NULL) {
return EINVAL;
}
switch (clock_id) {
case CLOCK_MONOTONIC:
rw->_rw_clock = CLOCK_MONOTONIC;
return __pthread_rwlock_timedrdlock(rw, at);
case CLOCK_REALTIME:
rw->_rw_clock = CLOCK_REALTIME;
return __pthread_rwlock_timedrdlock(rw, at);
default:
return EINVAL;
}
}
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册