• 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 <pthread.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <semaphore.h>
20 #include "functionalext.h"
21 
22 static int32_t priorityTen = 10;
23 static int32_t priorityHundred = 100;
24 static sem_t g_sem;
25 
threadfuncA(void * arg)26 void *threadfuncA(void *arg)
27 {
28     sem_wait(&g_sem);
29     return arg;
30 }
31 
32 /**
33  * @tc.name      : pthread_setschedparam_0100
34  * @tc.desc      : Verify pthread_setschedparam process success when scheduling policy is SCHED_OTHER and priority is 0
35  * @tc.level     : Level 1
36  */
pthread_setschedparam_0100(void)37 void pthread_setschedparam_0100(void)
38 {
39     pthread_t tid;
40     sem_init(&g_sem, 0, 0);
41     pthread_create(&tid, NULL, threadfuncA, NULL);
42     struct sched_param sched;
43     sched.sched_priority = 0;
44     int32_t ret = pthread_setschedparam(tid, SCHED_OTHER, &sched);
45     EXPECT_EQ("pthread_setschedparam_0100", ret, 0);
46     int32_t semRet = sem_post(&g_sem);
47     EXPECT_EQ("pthread_setschedparam_0100", semRet, 0);
48     pthread_join(tid, NULL);
49     sem_destroy(&g_sem);
50 }
51 
main(void)52 int main(void)
53 {
54     pthread_setschedparam_0100();
55     return t_status;
56 }