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 <ctype.h>
17 #include <dirent.h>
18 #include <netinet/in.h>
19 #include <sched.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include "functionalext.h"
23
24 /*
25 * @tc.name : __sched_cpucount_0100
26 * @tc.desc : Each parameter value is valid, and the number of CPUs included in the collection can be obtained.
27 * @tc.level : Level 0
28 */
__sched_cpucount_0100(void)29 void __sched_cpucount_0100(void)
30 {
31 int ret = 0;
32 cpu_set_t *cpusetp;
33 size_t size;
34 int num_cpus;
35 num_cpus = sysconf(_SC_NPROCESSORS_CONF);
36 cpusetp = CPU_ALLOC(num_cpus);
37 EXPECT_PTRNE("__sched_cpucount_0100", cpusetp, NULL);
38
39 size = CPU_ALLOC_SIZE(num_cpus);
40 CPU_ZERO_S(size, cpusetp);
41 for (int cpu = 0; cpu < num_cpus; cpu++) {
42 CPU_SET_S(cpu, size, cpusetp);
43 }
44 ret = __sched_cpucount(size, cpusetp);
45 EXPECT_EQ("__sched_cpucount_0100", ret, num_cpus);
46 CPU_FREE(cpusetp);
47 }
48
49 /*
50 * @tc.name : __sched_cpucount_0200
51 * @tc.desc : The size parameter is invalid (0), the set parameter is valid, and the number of CPUs
52 * contained in the set cannot be obtained.
53 * @tc.level : Level 2
54 */
__sched_cpucount_0200(void)55 void __sched_cpucount_0200(void)
56 {
57 int ret = 0;
58 cpu_set_t *cpusetp;
59 size_t size;
60 int num_cpus;
61 num_cpus = sysconf(_SC_NPROCESSORS_CONF);
62 cpusetp = CPU_ALLOC(num_cpus);
63 EXPECT_PTRNE("__sched_cpucount_0200", cpusetp, NULL);
64
65 size = CPU_ALLOC_SIZE(num_cpus);
66 CPU_ZERO_S(size, cpusetp);
67 for (int cpu = 0; cpu < num_cpus; cpu++) {
68 CPU_SET_S(cpu, size, cpusetp);
69 }
70 ret = __sched_cpucount(0, cpusetp);
71 EXPECT_EQ("__sched_cpucount_0200", ret, 0);
72 CPU_FREE(cpusetp);
73 }
74
75 /*
76 * @tc.name : __sched_cpucount_0300
77 * @tc.desc : The size parameter is valid, the set parameter is invalid (null), and the number of CPUs
78 * contained in the set cannot be obtained.
79 * @tc.level : Level 2
80 */
__sched_cpucount_0300(void)81 void __sched_cpucount_0300(void)
82 {
83 int ret = 0;
84 cpu_set_t *cpusetp;
85 size_t size;
86 int num_cpus;
87 num_cpus = sysconf(_SC_NPROCESSORS_CONF);
88 cpusetp = CPU_ALLOC(num_cpus);
89 EXPECT_PTRNE("__sched_cpucount_0300", cpusetp, NULL);
90
91 size = CPU_ALLOC_SIZE(num_cpus);
92 CPU_ZERO_S(size, cpusetp);
93 ret = __sched_cpucount(size, cpusetp);
94 EXPECT_EQ("__sched_cpucount_0300", ret, 0);
95 CPU_FREE(cpusetp);
96 }
97
main(int argc,char * argv[])98 int main(int argc, char *argv[])
99 {
100 __sched_cpucount_0100();
101 __sched_cpucount_0200();
102 __sched_cpucount_0300();
103 return t_status;
104 }