1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 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 <hwext/gtest-ext.h> 17 #include <hwext/gtest-tag.h> 18 19 #include "plugin_service.ipc.h" 20 #include "service_entry.h" 21 22 using namespace testing::ext; 23 namespace { 24 class ServiceEntryTest : public testing::Test { 25 public: SetUpTestCase()26 static void SetUpTestCase() {} TearDownTestCase()27 static void TearDownTestCase() {} SetUp()28 void SetUp() {} TearDown()29 void TearDown() {} 30 }; 31 32 namespace { 33 const int MS_PER_S = 1000; 34 const int US_PER_S = 1000000; 35 const int NS_PER_US = 1000; 36 const int NS_PER_S = 1000000000; 37 const int NS_PER_MS = 1000000; 38 const int SLEEP_TIME = 30000; 39 } // namespace 40 41 /** 42 * @tc.name: Service 43 * @tc.desc: Server process monitoring. 44 * @tc.type: FUNC 45 */ 46 HWTEST_F(ServiceEntryTest, AllCase, TestSize.Level1) 47 { 48 ServiceEntry serviceEntry; 49 IPluginServiceServer pluginService; 50 serviceEntry.StartServer("test_unix_socket_service_entry"); 51 serviceEntry.RegisterService(pluginService); 52 serviceEntry.FindServiceByName(pluginService.serviceName_); 53 54 usleep(SLEEP_TIME); 55 56 IPluginServiceClient pluginClient; 57 ASSERT_TRUE(pluginClient.Connect("test_unix_socket_service_entry")); 58 59 usleep(SLEEP_TIME); 60 } 61 62 /** 63 * @tc.name: Service 64 * @tc.desc: Gets the time in milliseconds. 65 * @tc.type: FUNC 66 */ 67 HWTEST_F(ServiceEntryTest, GetTimeMS, TestSize.Level1) 68 { 69 struct timespec ts; 70 clock_gettime(CLOCK_BOOTTIME, &ts); 71 long t1 = ts.tv_sec * MS_PER_S + ts.tv_nsec / NS_PER_MS; 72 long t2 = GetTimeMS(); 73 74 ASSERT_TRUE(t2 - t1 >= 0); 75 } 76 77 /** 78 * @tc.name: Service 79 * @tc.desc: Gets the time in microseconds. 80 * @tc.type: FUNC 81 */ 82 HWTEST_F(ServiceEntryTest, GetTimeUS, TestSize.Level1) 83 { 84 struct timespec ts; 85 clock_gettime(CLOCK_BOOTTIME, &ts); 86 long t1= ts.tv_sec * US_PER_S + ts.tv_nsec / NS_PER_US; 87 long t2 = GetTimeUS(); 88 89 ASSERT_TRUE(t2 - t1 >= 0); 90 } 91 92 /** 93 * @tc.name: Service 94 * @tc.desc: Gets the time in nanoseconds. 95 * @tc.type: FUNC 96 */ 97 HWTEST_F(ServiceEntryTest, GetTimeNS, TestSize.Level1) 98 { 99 struct timespec ts; 100 clock_gettime(CLOCK_BOOTTIME, &ts); 101 long t1 = ts.tv_sec * NS_PER_S + ts.tv_nsec; 102 long t2 = GetTimeNS(); 103 ASSERT_TRUE(t2 - t1 >= 0); 104 } 105 } // namespace