• 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 <errno.h>
17 #include <sched.h>
18 
19 #include "test.h"
20 
21 extern int __sched_rr_get_interval_time64(pid_t, struct timespec *);
22 
23 /**
24  * @tc.name      : sched_rr_get_interval_0100
25  * @tc.desc      : get the SCHED_RR interval for the named process
26  * @tc.level     : Level 0
27  */
sched_rr_get_interval_0100(void)28 void sched_rr_get_interval_0100(void)
29 {
30     pid_t pid = getpid();
31     struct timespec ts = {0};
32 
33     errno = 0;
34     int result = sched_rr_get_interval(pid, &ts);
35     if (result != 0 || errno != 0) {
36         t_error("%s failed: result = %d\n", __func__, result);
37         t_error("%s failed: errno = %d\n", __func__, errno);
38     }
39 
40     if (ts.tv_sec < 0 || ts.tv_nsec < 0) {
41         t_error("%s failed: ts.tv_sec = %ld\n", __func__, ts.tv_sec);
42         t_error("%s failed: ts.tv_nsec = %ld\n", __func__, ts.tv_nsec);
43     }
44 }
45 
46 /**
47  * @tc.name      : sched_rr_get_interval_0200
48  * @tc.desc      : get the SCHED_RR interval for an invalid process
49  * @tc.level     : Level 2
50  */
sched_rr_get_interval_0200(void)51 void sched_rr_get_interval_0200(void)
52 {
53     pid_t pid = -1;
54     struct timespec ts = {0};
55 
56     errno = 0;
57     int result = sched_rr_get_interval(pid, &ts);
58     if (result == 0 || errno == 0) {
59         t_error("%s failed: result = %d\n", __func__, result);
60         t_error("%s failed: errno = %d\n", __func__, errno);
61     }
62 }
63 
64 /**
65  * @tc.name      : sched_rr_get_interval_time64_0100
66  * @tc.desc      : get the SCHED_RR interval for the named process
67  * @tc.level     : Level 0
68  */
sched_rr_get_interval_time64_0100(void)69 void sched_rr_get_interval_time64_0100(void)
70 {
71     pid_t pid = getpid();
72     struct timespec ts = {0};
73 
74     errno = 0;
75     int result = __sched_rr_get_interval_time64(pid, &ts);
76     if (result != 0 || errno != 0) {
77         t_error("%s failed: result = %d\n", __func__, result);
78         t_error("%s failed: errno = %d\n", __func__, errno);
79     }
80 
81     if (ts.tv_sec < 0 || ts.tv_nsec < 0) {
82         t_error("%s failed: ts.tv_sec = %ld\n", __func__, ts.tv_sec);
83         t_error("%s failed: ts.tv_nsec = %ld\n", __func__, ts.tv_nsec);
84     }
85 }
86 
main(int argc,char * argv[])87 int main(int argc, char *argv[])
88 {
89     sched_rr_get_interval_0100();
90     sched_rr_get_interval_0200();
91     sched_rr_get_interval_time64_0100();
92     return t_status;
93 }
94