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/utsname.h>
19
20 #include "test.h"
21
22 /**
23 * @tc.name : uname_0100
24 * @tc.desc : get system infomation
25 * @tc.level : Level 0
26 */
uname_0100(void)27 void uname_0100(void)
28 {
29 struct utsname buf;
30 int result = uname(&buf);
31 if (result != 0) {
32 t_error("%s failed: result = %d\n", __func__, result);
33 return;
34 }
35
36 if (strlen(buf.sysname) == 0) {
37 t_error("%s failed: sysname\n", __func__, result);
38 }
39
40 if (strlen(buf.nodename) == 0) {
41 t_error("%s failed: nodename\n", __func__);
42 }
43
44 if (strlen(buf.release) == 0) {
45 t_error("%s failed: release\n", __func__);
46 }
47
48 if (strlen(buf.version) == 0) {
49 t_error("%s failed: version\n", __func__);
50 }
51
52 if (strlen(buf.machine) == 0) {
53 t_error("%s failed: machine\n", __func__);
54 }
55
56 #ifdef _GNU_SOURCE
57 if (strlen(buf.domainname) == 0) {
58 t_error("%s failed: domainname\n", __func__);
59 }
60 #else
61 if (strlen(buf.__domainname) == 0) {
62 t_error("%s failed: __domainname\n", __func__);
63 }
64 #endif
65 }
66
67 /**
68 * @tc.name : uname_0200
69 * @tc.desc : get system infomation with NULL
70 * @tc.level : Level 2
71 */
uname_0200(void)72 void uname_0200(void)
73 {
74 int result = uname(NULL);
75 if (result == 0) {
76 t_error("%s failed\n", __func__);
77 return;
78 }
79
80 if (errno != EFAULT) {
81 t_error("%s failed: errno = %d\n", __func__, errno);
82 return;
83 }
84 }
85
main(int argc,char * argv[])86 int main(int argc, char *argv[])
87 {
88 uname_0100();
89 uname_0200();
90
91 return t_status;
92 }
93