1 #include <gtest/gtest.h> 2 #include <sys/utsname.h> 3 4 using namespace testing::ext; 5 6 class MiscUnameTest : public testing::Test { SetUp()7 void SetUp() override {} TearDown()8 void TearDown() override {} 9 }; 10 11 /** 12 * @tc.name: uname_001 13 * @tc.desc: This test verifies that the uname function can successfully obtain operating system information, ensuring 14 * that the return value is 0, while asserting the various fields of the obtained operating system information 15 * to ensure that they are not empty or have a length of zero. 16 * @tc.type: FUNC 17 */ 18 HWTEST_F(MiscUnameTest, uname_001, TestSize.Level1) 19 { 20 struct utsname osInfo; 21 int unameResult = uname(&osInfo); 22 EXPECT_TRUE(unameResult == 0); 23 EXPECT_EQ(0, strcmp("Linux", osInfo.sysname)); 24 EXPECT_TRUE(strcmp("", osInfo.machine) != 0); 25 EXPECT_TRUE(strcmp("", osInfo.release) != 0); 26 EXPECT_TRUE(strcmp("", osInfo.version) != 0); 27 EXPECT_TRUE(strlen(osInfo.domainname) != 0); 28 }