• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <threads.h>
17 #include "test.h"
18 
19 #define TSS_SET_VALUE (void *)0xFF
20 static tss_t key;
21 
tssfunc(void * arg)22 int tssfunc(void *arg)
23 {
24     int ret;
25     ret = tss_create(&key, NULL);
26     if (ret != thrd_success) {
27         t_error("%s tss_create failed", __func__);
28     }
29     ret = tss_set(key, TSS_SET_VALUE);
30     if (ret != thrd_success) {
31         t_error("%s tss_set failed", __func__);
32     }
33     void *value = tss_get(key);
34     if (value == 0) {
35         t_error("%s tss_get failed", __func__);
36     }
37     if (value != TSS_SET_VALUE) {
38         t_error("%s tss_get return val is %p, expect %p", __func__, value, TSS_SET_VALUE);
39     }
40 
41     thrd_exit(thrd_success);
42 }
43 
44 /**
45  * @tc.name      : tss_set_0100
46  * @tc.desc      : Sets the value of the thread-specific storage identified by tss_id for the current thread to val
47  * @tc.level     : Level 0
48  */
tss_set_0100(void)49 void tss_set_0100(void)
50 {
51     thrd_t id;
52     int result;
53 
54     result = tss_create(&key, NULL);
55     if (result != thrd_success) {
56         t_error("%s tss_create failed", __func__);
57     }
58 
59     result = thrd_create(&id, tssfunc, NULL);
60     if (result != thrd_success) {
61         t_error("%s thrd_create failed", __func__);
62     }
63 
64     result = thrd_join(id, NULL);
65     if (result != thrd_success) {
66         t_error("%s thrd_join failed", __func__);
67     }
68 
69     void *value = tss_get(key);
70     if (value != 0) {
71         t_error("%s it should have failed", __func__);
72     }
73 
74     tss_delete(key);
75 }
76 
main(int argc,char * argv[])77 int main(int argc, char *argv[])
78 {
79     tss_set_0100();
80     return t_status;
81 }