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 <string.h>
18 #include <sys/sysinfo.h>
19
20 #include "test.h"
21
22 /**
23 * @tc.name : sysinfo_0100
24 * @tc.desc : return system information
25 * @tc.level : Level 0
26 */
sysinfo_0100(void)27 void sysinfo_0100(void)
28 {
29 struct sysinfo info;
30 memset(&info, 0, sizeof(info));
31
32 int result = sysinfo(&info);
33 if (result != 0) {
34 t_error("%s failed: result = %d\n", __func__, result);
35 return;
36 }
37
38 if (info.uptime <= 0) {
39 t_error("%s failed: info.uptime = %ld\n", __func__, info.uptime);
40 return;
41 }
42
43 if (info.totalram < 0) {
44 t_error("%s failed: info.totalram = %ld\n", __func__, info.totalram);
45 return;
46 }
47
48 if (info.totalram < info.freeram) {
49 t_error("%s failed: info.totalram = %ld, info.freeram = %ld\n", __func__, info.totalram, info.freeram);
50 return;
51 }
52
53 if (info.totalswap < 0) {
54 t_error("%s failed: info.totalswap = %ld\n", __func__, info.totalswap);
55 return;
56 }
57
58 if (info.totalswap < info.freeswap) {
59 t_error("%s failed: info.totalswap = %ld, info.freeswap = %ld\n", __func__, info.totalswap, info.freeswap);
60 return;
61 }
62 }
63
64 /**
65 * @tc.name : sysinfo_0200
66 * @tc.desc : return system information with NULL
67 * @tc.level : Level 2
68 */
sysinfo_0200(void)69 void sysinfo_0200(void)
70 {
71 int result = sysinfo(NULL);
72 if (result == 0) {
73 t_error("%s failed: result = %d\n", __func__, result);
74 return;
75 }
76
77 if (errno != EFAULT) {
78 t_error("%s failed: errno = %d\n", __func__, errno);
79 }
80 }
81
main(int argc, char *argv[])82 int main(int argc, char *argv[])
83 {
84 sysinfo_0100();
85 sysinfo_0200();
86
87 return t_status;
88 }
89