1/*
2 * Copyright (c) 2023 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 <sched.h>
17#include <stdio.h>
18#include <errno.h>
19#include <string.h>
20#include "functionalext.h"
21#include "test.h"
22
23typedef void (*TEST_FUN)(void);
24
25/**
26 * @tc.name      : sched_setparam
27 * @tc.desc      : Test the function of sched_setparam with normal input.
28 * @tc.level     : Level 1
29 */
30
31static void sched_setparam_0010(void)
32{
33    struct sched_param param;
34    int maxpri,minpri;
35    pid_t pid;
36    int sched;
37
38    pid = getpid();
39    sched = SCHED_OTHER;
40    maxpri = sched_get_priority_max(sched);
41    minpri = sched_get_priority_min(sched);
42    if(maxpri == -1 || minpri == -1)
43    {
44        t_error("get maxpriority or minpriority failed");
45    }
46    param.sched_priority = 0;//取值范围:minpri~maxpri
47    EXPECT_EQ("sched_setparam_0010", sched_setparam(pid, &param), 0);
48}
49
50/**
51 * @tc.name      : sched_setparam
52 * @tc.desc      : When param is NULL, call sched_setparam.
53 * @tc.level     : Level 2
54 */
55static void sched_setparam_0020(void)
56{
57    pid_t pid;
58    pid = getpid();
59    EXPECT_EQ("sched_setparam_0020", sched_setparam(pid, NULL), -1);
60}
61
62TEST_FUN G_Fun_Array[] = {
63    sched_setparam_0010,
64    sched_setparam_0020,
65};
66
67int main(void)
68{
69    int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
70    for (int pos = 0; pos < num; ++pos) {
71        G_Fun_Array[pos]();
72    }
73
74    return t_status;
75}