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 <csignal> 17#include <cstdlib> 18#include <cstdio> 19#include <ctime> 20#include <unistd.h> 21#include <gtest/gtest.h> 22 23using namespace testing::ext; 24using namespace std; 25 26class ClockGetresApiTest : public testing::Test { 27public: 28 static void SetUpTestCase(); 29 static void TearDownTestCase(); 30 void SetUp(); 31 void TearDown(); 32private: 33}; 34void ClockGetresApiTest::SetUp() 35{ 36} 37void ClockGetresApiTest::TearDown() 38{ 39} 40void ClockGetresApiTest::SetUpTestCase() 41{ 42} 43void ClockGetresApiTest::TearDownTestCase() 44{ 45} 46 47/* 48 * @tc.number : SUB_KERNEL_SYSCALL_CLOCK_GETRES_0100 49 * @tc.name : ClockGetresInvalidClockId_0001 50 * @tc.desc : Test clock_getres with an invalid clock_id. 51 * @tc.size : MediumTest 52 * @tc.type : Function 53 * @tc.level : Level 2 54 */ 55HWTEST_F(ClockGetresApiTest, ClockGetresInvalidClockId_0001, Function | MediumTest | Level2) 56{ 57 struct timespec res; 58 clockid_t invalidClockId = -1; 59 int ret = clock_getres(invalidClockId, &res); 60 61 EXPECT_EQ(ret, -1); 62 EXPECT_EQ(errno, EINVAL); 63} 64 65/* 66 * @tc.number : SUB_KERNEL_SYSCALL_CLOCK_GETRES_0200 67 * @tc.name : ClockGetresSuccess_0002 68 * @tc.desc : Test clock_getres successfully gets the resolution of a valid clock. 69 * @tc.size : MediumTest 70 * @tc.type : Function 71 * @tc.level : Level 1 72 */ 73HWTEST_F(ClockGetresApiTest, ClockGetresSuccess_0002, Function | MediumTest | Level1) 74{ 75 struct timespec res = { 0 }; 76 clockid_t validClockId = CLOCK_REALTIME; 77 78 int ret = clock_getres(validClockId, &res); 79 EXPECT_EQ(ret, 0); 80 81 EXPECT_GE(res.tv_sec, 0); 82 EXPECT_GE(res.tv_nsec, 0); 83}