1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 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 <gtest/gtest.h> 17 #include "plugin_service.ipc.h" 18 #include "service_entry.h" 19 20 using namespace testing::ext; 21 namespace { 22 class ServiceEntryTest : public testing::Test { 23 public: SetUpTestCase()24 static void SetUpTestCase() {} TearDownTestCase()25 static void TearDownTestCase() {} SetUp()26 void SetUp() {} TearDown()27 void TearDown() {} 28 }; 29 30 namespace { 31 const int MS_PER_S = 1000; 32 const int US_PER_S = 1000000; 33 const int NS_PER_US = 1000; 34 const int NS_PER_S = 1000000000; 35 const int NS_PER_MS = 1000000; 36 } // namespace 37 38 /** 39 * @tc.name: Service 40 * @tc.desc: Gets the time in milliseconds. 41 * @tc.type: FUNC 42 */ 43 HWTEST_F(ServiceEntryTest, GetTimeMS, TestSize.Level1) 44 { 45 struct timespec ts; 46 clock_gettime(CLOCK_BOOTTIME, &ts); 47 long t1 = ts.tv_sec * MS_PER_S + ts.tv_nsec / NS_PER_MS; 48 long t2 = GetTimeMS(); 49 50 ASSERT_TRUE(t2 - t1 >= 0); 51 } 52 53 /** 54 * @tc.name: Service 55 * @tc.desc: Gets the time in microseconds. 56 * @tc.type: FUNC 57 */ 58 HWTEST_F(ServiceEntryTest, GetTimeUS, TestSize.Level1) 59 { 60 struct timespec ts; 61 clock_gettime(CLOCK_BOOTTIME, &ts); 62 long t1= ts.tv_sec * US_PER_S + ts.tv_nsec / NS_PER_US; 63 long t2 = GetTimeUS(); 64 65 ASSERT_TRUE(t2 - t1 >= 0); 66 } 67 68 /** 69 * @tc.name: Service 70 * @tc.desc: Gets the time in nanoseconds. 71 * @tc.type: FUNC 72 */ 73 HWTEST_F(ServiceEntryTest, GetTimeNS, TestSize.Level1) 74 { 75 struct timespec ts; 76 clock_gettime(CLOCK_BOOTTIME, &ts); 77 long t1 = ts.tv_sec * NS_PER_S + ts.tv_nsec; 78 long t2 = GetTimeNS(); 79 ASSERT_TRUE(t2 - t1 >= 0); 80 } 81 } // namespace