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 <iostream>
17 #include <unistd.h>
18 #include <gtest/gtest.h>
19 #include <sys/times.h>
20 #include "securec.h"
21
22 using namespace testing::ext;
23
24 static const int TEST_DELAY_TIME = 100 * 1000;
25
26 class HatsTimesApiTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp();
31 void TearDown();
32 private:
33 };
SetUp()34 void HatsTimesApiTest::SetUp()
35 {
36 }
TearDown()37 void HatsTimesApiTest::TearDown()
38 {
39 }
SetUpTestCase()40 void HatsTimesApiTest::SetUpTestCase()
41 {
42 }
TearDownTestCase()43 void HatsTimesApiTest::TearDownTestCase()
44 {
45 }
46
47 /*
48 * @tc.number : SUB_KERNEL_SYSCALL_TIMES_0100
49 * @tc.name : TimesBasicSuccess_0001
50 * @tc.desc : Test the times basic functionality.
51 * @tc.size : MediumTest
52 * @tc.type : Function
53 * @tc.level : Level 1
54 */
HWTEST_F(HatsTimesApiTest, TimesBasicSuccess_0001, Function | MediumTest | Level1)55 HWTEST_F(HatsTimesApiTest, TimesBasicSuccess_0001, Function | MediumTest | Level1)
56 {
57 struct tms tms1, tms2;
58 clock_t init = 0;
59 clock_t start = times(&tms1);
60 EXPECT_GE(start, init);
61
62 usleep(TEST_DELAY_TIME);
63
64 clock_t end = times(&tms2);
65 EXPECT_GT(end, start);
66
67 EXPECT_EQ(tms2.tms_utime, tms1.tms_utime);
68 EXPECT_LE(tms2.tms_stime, tms1.tms_stime);
69 }