1 /*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <pthread.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include "functionalext.h"
20
21 static pthread_key_t g_key;
22
threadfuncA(void * arg)23 void *threadfuncA(void *arg)
24 {
25 int32_t value = 0;
26 int32_t ret = pthread_setspecific(g_key, &value);
27 EXPECT_EQ("pthread_getspecific_0100", ret, 0);
28 int32_t *keyRet = (int32_t *)pthread_getspecific(g_key);
29 EXPECT_EQ("pthread_getspecific_0100", *keyRet, 0);
30 return arg;
31 }
32
33 /**
34 * @tc.name: pthread_getspecific_0100
35 * @tc.desc: Verify pthread_getspecific process success.
36 * @tc.level: level 0
37 */
pthread_getspecific_0100(void)38 void pthread_getspecific_0100(void)
39 {
40 pthread_key_create(&g_key, NULL);
41 pthread_t tid1;
42 pthread_create(&tid1, NULL, threadfuncA, NULL);
43 pthread_join(tid1, NULL);
44 pthread_key_delete(g_key);
45 }
46
main(void)47 int main(void)
48 {
49 pthread_getspecific_0100();
50 return t_status;
51 }