1 #include <gtest/gtest.h> 2 #include <sys/timerfd.h> 3 4 using namespace testing::ext; 5 6 class LinuxTimerfdsettimeTest : public testing::Test { SetUp()7 void SetUp() override {} TearDown()8 void TearDown() override {} 9 }; 10 11 /** 12 * @tc.name: timerfd_settime_001 13 * @tc.desc: This test verifies that for timerfd_create, timerfd_settime and timerfd_gettime functions create a 14 * timer file descriptor, set the timer time value, and obtain the current time value to check if their 15 * functions are normal, if any of these operations fail, the corresponding error message will be output. 16 * @tc.type: FUNC 17 */ 18 HWTEST_F(LinuxTimerfdsettimeTest, timerfd_settime_001, TestSize.Level1) 19 { 20 struct itimerspec its = { { 0, 0 }, { 2, 0 } }; 21 struct itimerspec val; 22 int fd = timerfd_create(CLOCK_REALTIME, 0); 23 EXPECT_GE(fd, 0); 24 int setResult = timerfd_settime(fd, 0, &its, nullptr); 25 EXPECT_EQ(setResult, 0); 26 int getResult = timerfd_gettime(fd, &val); 27 EXPECT_EQ(getResult, 0); 28 close(fd); 29 }