• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "sched_api_test.h"
32 
33 LITE_TEST_SUIT(SCHED, ProcessSchedApi, ProcessSchedApiTestSuite);
34 
ProcessSchedApiTestSuiteSetUp(void)35 static BOOL ProcessSchedApiTestSuiteSetUp(void)
36 {
37     return TRUE;
38 }
39 
ProcessSchedApiTestSuiteTearDown(void)40 static BOOL ProcessSchedApiTestSuiteTearDown(void)
41 {
42     return TRUE;
43 }
44 
45 /**
46  * @tc.number   SUB_KERNEL_SCHED_API_GET_PRIORITY_MAX_0200
47  * @tc.name     sched_get_priority_max api error test with unsupport policy.
48  * @tc.desc     [C- SOFTWARE -0200]
49  */
50 LITE_TEST_CASE(ProcessSchedApiTestSuite, testSchedGetPriorityMaxError0200, Function | MediumTest | Level3)
51 {
52     int invalidPolicy[] = {SCHED_FIFO, SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, SCHED_DEADLINE, SCHED_RESET_ON_FORK};
53     int testLoop = sizeof(invalidPolicy) / sizeof(int);
54     for (int i = 0; i < testLoop; i++) {
55         errno = 0;
56         int prio = sched_get_priority_max(invalidPolicy[i]);
57         ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
58         ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
59     }
60     return 0;
61 }
62 
63 /**
64  * @tc.number   SUB_KERNEL_SCHED_API_GET_PRIORITY_MAX_0300
65  * @tc.name     sched_get_priority_max api error test with invalid policy.
66  * @tc.desc     [C- SOFTWARE -0200]
67  */
68 LITE_TEST_CASE(ProcessSchedApiTestSuite, testSchedGetPriorityMaxError0300, Function | MediumTest | Level3)
69 {
70     int invalidPolicyVal;
71     int prio;
72 
73     invalidPolicyVal = -GetRandom(10000); /* 10000, common data for test, no special meaning */
74     errno = 0;
75     prio = sched_get_priority_max(invalidPolicyVal);
76     ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
77     ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
78 
79     invalidPolicyVal = GetRandom(10000) + SCHED_DEADLINE; /* 10000, common data for test, no special meaning */
80     errno = 0;
81     prio = sched_get_priority_max(invalidPolicyVal);
82     ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
83     ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
84     return 0;
85 }
86 
87 /**
88  * @tc.number   SUB_KERNEL_SCHED_API_GET_PRIORITY_MIN_0200
89  * @tc.name     sched_get_priority_min api error test with unsupport policy.
90  * @tc.desc     [C- SOFTWARE -0200]
91  */
92 LITE_TEST_CASE(ProcessSchedApiTestSuite, testSchedGetPriorityMinError0200, Function | MediumTest | Level3)
93 {
94     int invalidPolicy[] = {SCHED_FIFO, SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, SCHED_DEADLINE, SCHED_RESET_ON_FORK};
95     int testLoop = sizeof(invalidPolicy) / sizeof(int);
96     for (int i = 0; i < testLoop; i++) {
97         errno = 0;
98         int prio = sched_get_priority_min(invalidPolicy[i]);
99         ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
100         ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
101     }
102     return 0;
103 }
104 
105 /**
106  * @tc.number   SUB_KERNEL_SCHED_API_GET_PRIORITY_MIN_0300
107  * @tc.name     sched_get_priority_min api error test with invalid policy.
108  * @tc.desc     [C- SOFTWARE -0200]
109  */
110 LITE_TEST_CASE(ProcessSchedApiTestSuite, testSchedGetPriorityMinError0300, Function | MediumTest | Level3)
111 {
112     int invalidPolicyVal;
113     int prio;
114     invalidPolicyVal = -GetRandom(10000); /* 10000, common data for test, no special meaning */
115     errno = 0;
116     prio = sched_get_priority_min(invalidPolicyVal);
117     ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
118     ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
119 
120     invalidPolicyVal = GetRandom(10000) + SCHED_DEADLINE; /* 10000, common data for test, no special meaning */
121     errno = 0;
122     prio = sched_get_priority_min(invalidPolicyVal);
123     ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
124     ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
125     return 0;
126 }
127 
128 RUN_TEST_SUITE(ProcessSchedApiTestSuite);
129 
ProcessSchedApiTest(void)130 void ProcessSchedApiTest(void)
131 {
132     RUN_ONE_TESTCASE(testSchedGetPriorityMaxError0200);
133     RUN_ONE_TESTCASE(testSchedGetPriorityMaxError0300);
134     RUN_ONE_TESTCASE(testSchedGetPriorityMinError0200);
135     RUN_ONE_TESTCASE(testSchedGetPriorityMinError0300);
136 }
137