19762338dSopenharmony_ci/* 29762338dSopenharmony_ci * Copyright (C) 2024 HiHope Open Source Organization. 39762338dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49762338dSopenharmony_ci * you may not use this file except in compliance with the License. 59762338dSopenharmony_ci * You may obtain a copy of the License at 69762338dSopenharmony_ci * 79762338dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89762338dSopenharmony_ci * 99762338dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109762338dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119762338dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129762338dSopenharmony_ci * See the License for the specific language governing permissions and 139762338dSopenharmony_ci * limitations under the License. 149762338dSopenharmony_ci */ 159762338dSopenharmony_ci 169762338dSopenharmony_ci#include <iostream> 179762338dSopenharmony_ci#include <unistd.h> 189762338dSopenharmony_ci#include <gtest/gtest.h> 199762338dSopenharmony_ci#include <sys/timex.h> 209762338dSopenharmony_ci#include <sys/times.h> 219762338dSopenharmony_ci#include "securec.h" 229762338dSopenharmony_ci 239762338dSopenharmony_ciusing namespace testing::ext; 249762338dSopenharmony_ci 259762338dSopenharmony_ciclass HatsAdjTimexApiTest : public testing::Test { 269762338dSopenharmony_cipublic: 279762338dSopenharmony_cistatic void SetUpTestCase(); 289762338dSopenharmony_cistatic void TearDownTestCase(); 299762338dSopenharmony_civoid SetUp(); 309762338dSopenharmony_civoid TearDown(); 319762338dSopenharmony_ciprivate: 329762338dSopenharmony_ci}; 339762338dSopenharmony_civoid HatsAdjTimexApiTest::SetUp() 349762338dSopenharmony_ci{ 359762338dSopenharmony_ci} 369762338dSopenharmony_civoid HatsAdjTimexApiTest::TearDown() 379762338dSopenharmony_ci{ 389762338dSopenharmony_ci} 399762338dSopenharmony_civoid HatsAdjTimexApiTest::SetUpTestCase() 409762338dSopenharmony_ci{ 419762338dSopenharmony_ci} 429762338dSopenharmony_civoid HatsAdjTimexApiTest::TearDownTestCase() 439762338dSopenharmony_ci{ 449762338dSopenharmony_ci} 459762338dSopenharmony_ci 469762338dSopenharmony_ci/* 479762338dSopenharmony_ci * @tc.number : SUB_KERNEL_SYSCALL_ADJTIMEX_0100 489762338dSopenharmony_ci * @tc.name : AdjTimexGetCurrentTimeSuccess_0001 499762338dSopenharmony_ci * @tc.desc : Test the adjtimex get current time success. 509762338dSopenharmony_ci * @tc.size : MediumTest 519762338dSopenharmony_ci * @tc.type : Function 529762338dSopenharmony_ci * @tc.level : Level 1 539762338dSopenharmony_ci */ 549762338dSopenharmony_ciHWTEST_F(HatsAdjTimexApiTest, AdjTimexGetCurrentTimeSuccess_0001, Function | MediumTest | Level1) 559762338dSopenharmony_ci{ 569762338dSopenharmony_ci struct timex tx; 579762338dSopenharmony_ci tx.modes = 0; 589762338dSopenharmony_ci int result = adjtimex(&tx); 599762338dSopenharmony_ci EXPECT_GE(result, 0); 609762338dSopenharmony_ci 619762338dSopenharmony_ci struct timeval now; 629762338dSopenharmony_ci gettimeofday(&now, nullptr); 639762338dSopenharmony_ci 649762338dSopenharmony_ci EXPECT_NEAR(tx.time.tv_sec, now.tv_sec, 1); 659762338dSopenharmony_ci} 669762338dSopenharmony_ci 679762338dSopenharmony_ci/* 689762338dSopenharmony_ci * @tc.number : SUB_KERNEL_SYSCALL_CLOCK_ADJTIMEX_0200 699762338dSopenharmony_ci * @tc.name : ClockAdjTimexGetCurrentTimeSuccess_0002 709762338dSopenharmony_ci * @tc.desc : Test the clock_adjtimex get current time success. 719762338dSopenharmony_ci * @tc.size : MediumTest 729762338dSopenharmony_ci * @tc.type : Function 739762338dSopenharmony_ci * @tc.level : Level 1 749762338dSopenharmony_ci */ 759762338dSopenharmony_ciHWTEST_F(HatsAdjTimexApiTest, ClockAdjTimexGetCurrentTimeSuccess_0002, Function | MediumTest | Level1) 769762338dSopenharmony_ci{ 779762338dSopenharmony_ci struct timex tx; 789762338dSopenharmony_ci tx.modes = 0; 799762338dSopenharmony_ci clockid_t clock_id = CLOCK_REALTIME; 809762338dSopenharmony_ci int result = clock_adjtime(clock_id, &tx); 819762338dSopenharmony_ci EXPECT_GE(result, 0); 829762338dSopenharmony_ci 839762338dSopenharmony_ci struct timespec now; 849762338dSopenharmony_ci clock_gettime(clock_id, &now); 859762338dSopenharmony_ci 869762338dSopenharmony_ci EXPECT_NEAR(tx.time.tv_sec, now.tv_sec, 1); 879762338dSopenharmony_ci} 88