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 <semaphore.h>
18
19 #include "functionalext.h"
20
21 /**
22 * @tc.name : pthread_attr_setinheritsched_0100
23 * @tc.desc : Verify that the preset properties can be obtained through get inheritsched in a single-threaded
24 * environment
25 * @tc.level : Level 0
26 */
pthread_attr_setinheritsched_0100(void)27 void pthread_attr_setinheritsched_0100(void)
28 {
29 pthread_attr_t attr;
30
31 pthread_attr_init(&attr);
32
33 pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
34 int result = pthread_attr_getinheritsched(&attr, &result);
35 EXPECT_EQ("pthread_attr_setinheritsched_0100", result, PTHREAD_INHERIT_SCHED);
36
37 pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
38 pthread_attr_getinheritsched(&attr, &result);
39 EXPECT_EQ("pthread_attr_setinheritsched_0100", result, PTHREAD_EXPLICIT_SCHED);
40
41 pthread_attr_destroy(&attr);
42 }
43
44 /**
45 * @tc.name : pthread_attr_setinheritsched_0200
46 * @tc.desc : Verify that the return value is EINVAL when setting an exception value in a single-threaded
47 * environment
48 * @tc.level : Level 2
49 */
pthread_attr_setinheritsched_0200(void)50 void pthread_attr_setinheritsched_0200(void)
51 {
52 pthread_attr_t attr;
53 int inheritsched = 2;
54 int result = -1;
55
56 int ret = pthread_attr_init(&attr);
57 EXPECT_EQ("pthread_attr_setinheritsched_0200", ret, CMPFLAG);
58
59 ret = pthread_attr_setinheritsched(&attr, inheritsched);
60 EXPECT_EQ("pthread_attr_setinheritsched_0200", ret, EINVAL);
61
62 pthread_attr_destroy(&attr);
63 }
64
main(void)65 int main(void)
66 {
67 pthread_attr_setinheritsched_0100();
68 pthread_attr_setinheritsched_0200();
69
70 return t_status;
71 }