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/times.h> 209762338dSopenharmony_ci#include "securec.h" 219762338dSopenharmony_ci 229762338dSopenharmony_ciusing namespace testing::ext; 239762338dSopenharmony_ci 249762338dSopenharmony_cistatic const int TEST_DELAY_TIME = 100 * 1000; 259762338dSopenharmony_ci 269762338dSopenharmony_ciclass HatsTimesApiTest : public testing::Test { 279762338dSopenharmony_cipublic: 289762338dSopenharmony_cistatic void SetUpTestCase(); 299762338dSopenharmony_cistatic void TearDownTestCase(); 309762338dSopenharmony_civoid SetUp(); 319762338dSopenharmony_civoid TearDown(); 329762338dSopenharmony_ciprivate: 339762338dSopenharmony_ci}; 349762338dSopenharmony_civoid HatsTimesApiTest::SetUp() 359762338dSopenharmony_ci{ 369762338dSopenharmony_ci} 379762338dSopenharmony_civoid HatsTimesApiTest::TearDown() 389762338dSopenharmony_ci{ 399762338dSopenharmony_ci} 409762338dSopenharmony_civoid HatsTimesApiTest::SetUpTestCase() 419762338dSopenharmony_ci{ 429762338dSopenharmony_ci} 439762338dSopenharmony_civoid HatsTimesApiTest::TearDownTestCase() 449762338dSopenharmony_ci{ 459762338dSopenharmony_ci} 469762338dSopenharmony_ci 479762338dSopenharmony_ci/* 489762338dSopenharmony_ci * @tc.number : SUB_KERNEL_SYSCALL_TIMES_0100 499762338dSopenharmony_ci * @tc.name : TimesBasicSuccess_0001 509762338dSopenharmony_ci * @tc.desc : Test the times basic functionality. 519762338dSopenharmony_ci * @tc.size : MediumTest 529762338dSopenharmony_ci * @tc.type : Function 539762338dSopenharmony_ci * @tc.level : Level 1 549762338dSopenharmony_ci */ 559762338dSopenharmony_ciHWTEST_F(HatsTimesApiTest, TimesBasicSuccess_0001, Function | MediumTest | Level1) 569762338dSopenharmony_ci{ 579762338dSopenharmony_ci struct tms tms1, tms2; 589762338dSopenharmony_ci clock_t init = 0; 599762338dSopenharmony_ci clock_t start = times(&tms1); 609762338dSopenharmony_ci EXPECT_GE(start, init); 619762338dSopenharmony_ci 629762338dSopenharmony_ci usleep(TEST_DELAY_TIME); 639762338dSopenharmony_ci 649762338dSopenharmony_ci clock_t end = times(&tms2); 659762338dSopenharmony_ci EXPECT_GT(end, start); 669762338dSopenharmony_ci 679762338dSopenharmony_ci EXPECT_EQ(tms2.tms_utime, tms1.tms_utime); 689762338dSopenharmony_ci EXPECT_LE(tms2.tms_stime, tms1.tms_stime); 699762338dSopenharmony_ci}