1 /*
2 * Copyright (C) 2024 HiHope Open Source Organization.
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 <cerrno>
17 #include <cstdio>
18 #include <cstdlib>
19 #include <string>
20 #include <vector>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <gtest/gtest.h>
24 #include <sys/file.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <sys/utsname.h>
28 #include <sys/xattr.h>
29 #include "securec.h"
30
31 using namespace testing::ext;
32 using namespace std;
33
34 class UnameApiTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp();
39 void TearDown();
40 private:
41 };
SetUp()42 void UnameApiTest::SetUp()
43 {
44 }
TearDown()45 void UnameApiTest::TearDown()
46 {
47 }
SetUpTestCase()48 void UnameApiTest::SetUpTestCase()
49 {
50 }
TearDownTestCase()51 void UnameApiTest::TearDownTestCase()
52 {
53 }
54
55 /*
56 * @tc.number : SUB_KERNEL_SYSCALL_UNAME_0100
57 * @tc.name : UnameAcquireInformationSuccess_0001
58 * @tc.desc : Uname acquire system information in the valid struct success.
59 * @tc.size : MediumTest
60 * @tc.type : Function
61 * @tc.level : Level 1
62 */
HWTEST_F(UnameApiTest, UnameAcquireInformationSuccess_0001, Function | MediumTest | Level1)63 HWTEST_F(UnameApiTest, UnameAcquireInformationSuccess_0001, Function | MediumTest | Level1)
64 {
65 int ret;
66 struct utsname buffer;
67 ret = uname(&buffer);
68 EXPECT_EQ(ret, 0);
69 }
70
71 /*
72 * @tc.number : SUB_KERNEL_SYSCALL_UNAME_0200
73 * @tc.name : UnameAcquireInformationFail_0002
74 * @tc.desc : Uname acquire system information in the invalid struct fail, errno EFAULT.
75 * @tc.size : MediumTest
76 * @tc.type : Function
77 * @tc.level : Level 2
78 */
HWTEST_F(UnameApiTest, UnameAcquireInformationFail_0002, Function | MediumTest | Level2)79 HWTEST_F(UnameApiTest, UnameAcquireInformationFail_0002, Function | MediumTest | Level2)
80 {
81 errno = 0;
82 int ret = uname(nullptr);
83 EXPECT_EQ(ret, -1);
84 EXPECT_EQ(errno, EFAULT);
85 }
86