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 "functionalext.h"
18
19 /**
20 * @tc.name : pthread_mutexattr_setprotocol_0100
21 * @tc.desc : Correct parameter setting condition variable property value
22 * @tc.level : Level 0
23 */
pthread_mutexattr_setprotocol_0100(void)24 void pthread_mutexattr_setprotocol_0100(void)
25 {
26 pthread_mutexattr_t attr;
27 int ret = pthread_mutexattr_init(&attr);
28 EXPECT_EQ("pthread_mutexattr_setprotocol_0100", ret, CMPFLAG);
29
30 ret = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_NONE);
31 EXPECT_EQ("pthread_mutexattr_setprotocol_0100", ret, CMPFLAG);
32
33 ret = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_PROTECT);
34 EXPECT_EQ("pthread_mutexattr_setprotocol_0100", ret, ENOTSUP);
35
36 pthread_mutexattr_destroy(&attr);
37 }
38
39 /**
40 * @tc.name : pthread_mutexattr_setprotocol_0200
41 * @tc.desc : Exception parameter sets mutex variable property value
42 * @tc.level : Level 2
43 */
pthread_mutexattr_setprotocol_0200(void)44 void pthread_mutexattr_setprotocol_0200(void)
45 {
46 pthread_mutexattr_t attr;
47 int error = PTHREAD_PRIO_PROTECT + 1;
48
49 int ret = pthread_mutexattr_init(&attr);
50 EXPECT_EQ("pthread_mutexattr_setprotocol_0200", ret, CMPFLAG);
51
52 ret = pthread_mutexattr_setprotocol(&attr, error);
53 EXPECT_EQ("pthread_mutexattr_setprotocol_0200", ret, EINVAL);
54
55 pthread_mutexattr_destroy(&attr);
56 }
57
main(void)58 int main(void)
59 {
60 pthread_mutexattr_setprotocol_0100();
61 pthread_mutexattr_setprotocol_0200();
62 return t_status;
63 }