106f6ba60Sopenharmony_ci/* 206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 506f6ba60Sopenharmony_ci * You may obtain a copy of the License at 606f6ba60Sopenharmony_ci * 706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806f6ba60Sopenharmony_ci * 906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 1306f6ba60Sopenharmony_ci * limitations under the License. 1406f6ba60Sopenharmony_ci */ 1506f6ba60Sopenharmony_ci 1606f6ba60Sopenharmony_ci#include <gtest/gtest.h> 1706f6ba60Sopenharmony_ci#include "plugin_service.ipc.h" 1806f6ba60Sopenharmony_ci#include "service_entry.h" 1906f6ba60Sopenharmony_ci 2006f6ba60Sopenharmony_ciusing namespace testing::ext; 2106f6ba60Sopenharmony_cinamespace { 2206f6ba60Sopenharmony_ciclass ServiceEntryTest : public testing::Test { 2306f6ba60Sopenharmony_cipublic: 2406f6ba60Sopenharmony_ci static void SetUpTestCase() {} 2506f6ba60Sopenharmony_ci static void TearDownTestCase() {} 2606f6ba60Sopenharmony_ci void SetUp() {} 2706f6ba60Sopenharmony_ci void TearDown() {} 2806f6ba60Sopenharmony_ci}; 2906f6ba60Sopenharmony_ci 3006f6ba60Sopenharmony_cinamespace { 3106f6ba60Sopenharmony_ciconst int MS_PER_S = 1000; 3206f6ba60Sopenharmony_ciconst int US_PER_S = 1000000; 3306f6ba60Sopenharmony_ciconst int NS_PER_US = 1000; 3406f6ba60Sopenharmony_ciconst int NS_PER_S = 1000000000; 3506f6ba60Sopenharmony_ciconst int NS_PER_MS = 1000000; 3606f6ba60Sopenharmony_ciconst int SLEEP_TIME = 30000; 3706f6ba60Sopenharmony_ci} // namespace 3806f6ba60Sopenharmony_ci 3906f6ba60Sopenharmony_ci/** 4006f6ba60Sopenharmony_ci * @tc.name: Service 4106f6ba60Sopenharmony_ci * @tc.desc: Server process monitoring. 4206f6ba60Sopenharmony_ci * @tc.type: FUNC 4306f6ba60Sopenharmony_ci */ 4406f6ba60Sopenharmony_ciHWTEST_F(ServiceEntryTest, AllCase, TestSize.Level1) 4506f6ba60Sopenharmony_ci{ 4606f6ba60Sopenharmony_ci ServiceEntry serviceEntry; 4706f6ba60Sopenharmony_ci IPluginServiceServer pluginService; 4806f6ba60Sopenharmony_ci serviceEntry.StartServer("test_unix_socket_service_entry"); 4906f6ba60Sopenharmony_ci serviceEntry.RegisterService(pluginService); 5006f6ba60Sopenharmony_ci serviceEntry.FindServiceByName(pluginService.serviceName_); 5106f6ba60Sopenharmony_ci 5206f6ba60Sopenharmony_ci usleep(SLEEP_TIME); 5306f6ba60Sopenharmony_ci 5406f6ba60Sopenharmony_ci IPluginServiceClient pluginClient; 5506f6ba60Sopenharmony_ci ASSERT_TRUE(pluginClient.Connect("test_unix_socket_service_entry")); 5606f6ba60Sopenharmony_ci 5706f6ba60Sopenharmony_ci usleep(SLEEP_TIME); 5806f6ba60Sopenharmony_ci} 5906f6ba60Sopenharmony_ci 6006f6ba60Sopenharmony_ci/** 6106f6ba60Sopenharmony_ci * @tc.name: Service 6206f6ba60Sopenharmony_ci * @tc.desc: Gets the time in milliseconds. 6306f6ba60Sopenharmony_ci * @tc.type: FUNC 6406f6ba60Sopenharmony_ci */ 6506f6ba60Sopenharmony_ciHWTEST_F(ServiceEntryTest, GetTimeMS, TestSize.Level1) 6606f6ba60Sopenharmony_ci{ 6706f6ba60Sopenharmony_ci struct timespec ts; 6806f6ba60Sopenharmony_ci clock_gettime(CLOCK_BOOTTIME, &ts); 6906f6ba60Sopenharmony_ci long t1 = ts.tv_sec * MS_PER_S + ts.tv_nsec / NS_PER_MS; 7006f6ba60Sopenharmony_ci long t2 = GetTimeMS(); 7106f6ba60Sopenharmony_ci 7206f6ba60Sopenharmony_ci ASSERT_TRUE(t2 - t1 >= 0); 7306f6ba60Sopenharmony_ci} 7406f6ba60Sopenharmony_ci 7506f6ba60Sopenharmony_ci/** 7606f6ba60Sopenharmony_ci * @tc.name: Service 7706f6ba60Sopenharmony_ci * @tc.desc: Gets the time in microseconds. 7806f6ba60Sopenharmony_ci * @tc.type: FUNC 7906f6ba60Sopenharmony_ci */ 8006f6ba60Sopenharmony_ciHWTEST_F(ServiceEntryTest, GetTimeUS, TestSize.Level1) 8106f6ba60Sopenharmony_ci{ 8206f6ba60Sopenharmony_ci struct timespec ts; 8306f6ba60Sopenharmony_ci clock_gettime(CLOCK_BOOTTIME, &ts); 8406f6ba60Sopenharmony_ci long t1= ts.tv_sec * US_PER_S + ts.tv_nsec / NS_PER_US; 8506f6ba60Sopenharmony_ci long t2 = GetTimeUS(); 8606f6ba60Sopenharmony_ci 8706f6ba60Sopenharmony_ci ASSERT_TRUE(t2 - t1 >= 0); 8806f6ba60Sopenharmony_ci} 8906f6ba60Sopenharmony_ci 9006f6ba60Sopenharmony_ci/** 9106f6ba60Sopenharmony_ci * @tc.name: Service 9206f6ba60Sopenharmony_ci * @tc.desc: Gets the time in nanoseconds. 9306f6ba60Sopenharmony_ci * @tc.type: FUNC 9406f6ba60Sopenharmony_ci */ 9506f6ba60Sopenharmony_ciHWTEST_F(ServiceEntryTest, GetTimeNS, TestSize.Level1) 9606f6ba60Sopenharmony_ci{ 9706f6ba60Sopenharmony_ci struct timespec ts; 9806f6ba60Sopenharmony_ci clock_gettime(CLOCK_BOOTTIME, &ts); 9906f6ba60Sopenharmony_ci long t1 = ts.tv_sec * NS_PER_S + ts.tv_nsec; 10006f6ba60Sopenharmony_ci long t2 = GetTimeNS(); 10106f6ba60Sopenharmony_ci ASSERT_TRUE(t2 - t1 >= 0); 10206f6ba60Sopenharmony_ci} 10306f6ba60Sopenharmony_ci} // namespace