diff --git a/vibrator/test/benchmarktest/BUILD.gn b/vibrator/test/benchmarktest/BUILD.gn index ac097dea3a29d6ff23dc4bd44957368c190aa611..ce118f80feacf0d26142947b16173344964dc6f3 100644 --- a/vibrator/test/benchmarktest/BUILD.gn +++ b/vibrator/test/benchmarktest/BUILD.gn @@ -31,6 +31,10 @@ ohos_benchmarktest("hdf_vibrator_benchmark_test") { "-fno-strict-aliasing", ] + if (drivers_peripheral_vibrator_feature_tv_flag) { + defines = ["TV_FLAG"] + } + if (is_standard_system) { external_deps = [ "drivers_interface_vibrator:libvibrator_proxy_2.0", diff --git a/vibrator/test/benchmarktest/hdf_vibrator_benchmark_test.cpp b/vibrator/test/benchmarktest/hdf_vibrator_benchmark_test.cpp index 47b54b257cd218b5f6626cd4fb83d42f99902f18..5bbf0c602a68fccd03287f1e5407824fbe48a717 100644 --- a/vibrator/test/benchmarktest/hdf_vibrator_benchmark_test.cpp +++ b/vibrator/test/benchmarktest/hdf_vibrator_benchmark_test.cpp @@ -23,6 +23,7 @@ #include "hdf_base.h" #include "osal_time.h" #include "v2_0/ivibrator_interface.h" +#include "vibrator_plug_callback_impl.h" using namespace OHOS::HDI::Vibrator; using namespace OHOS::HDI::Vibrator::V2_0; @@ -35,15 +36,20 @@ namespace { uint32_t g_duration = 100; int32_t g_intensity1 = 30; int32_t g_frequency1 = 200; - uint32_t g_sleepTime1 = 200; V2_0::HapticPaket g_hapticPaket = {434, 1, {{V2_0::TRANSIENT, 0, 149, 100, 50, 0, 4, {{0, 0, 0}, {1, 1, 0}, {32, 1, -39}, {149, 0, -39}}}}}; V2_0::VibratorPackage g_vibPackage = {434, 149, {{434, 1, {{V2_0::TRANSIENT, 0, 149, 100, 50, 0, 4, {{0, 0, 0}, {1, 1, 0}, {32, 1, -39}, {149, 0, -39}}}}}}}; int32_t g_sessionId = 1; + DeviceVibratorInfo g_deviceVibratorInfo = {-1, 1}; + uint16_t g_intensity = 50; + HapticPaket g_pkg = {434, 1, {{V2_0::CONTINUOUS, 0, 149, 100, 50, 0, 4, + {{0, 0, 0}, {1, 1, 0}, {32, 1, -39}, {149, 0, -39}}}}}; + std::vector g_info; std::string g_timeSequence = "haptic.clock.timer"; std::string g_builtIn = "haptic.default.effect"; sptr g_vibratorInterface = nullptr; + sptr g_vibratorPlugCallback = new VibratorPlugCallbackImpl(); std::vector g_vibratorInfo; class VibratorBenchmarkTest : public benchmark::Fixture { @@ -202,7 +208,6 @@ BENCHMARK_F(VibratorBenchmarkTest, EnableVibratorModulation)(benchmark::State &s startRet = g_vibratorInterface->EnableVibratorModulation({it.deviceId, it.vibratorId}, g_duration, g_intensity1, g_frequency1); EXPECT_EQ(startRet, HDF_SUCCESS); - OsalMSleep(g_sleepTime1); startRet = g_vibratorInterface->Stop({it.deviceId, it.vibratorId}, HDF_VIBRATOR_MODE_ONCE); EXPECT_EQ(startRet, HDF_SUCCESS); } @@ -254,7 +259,6 @@ BENCHMARK_F(VibratorBenchmarkTest, EnableCompositeEffect)(benchmark::State &stat } EXPECT_EQ(HDF_SUCCESS, ret); } - OsalMSleep(2); } BENCHMARK_REGISTER_F(VibratorBenchmarkTest, EnableCompositeEffect)-> @@ -320,7 +324,7 @@ BENCHMARK_F(VibratorBenchmarkTest, PlayPatternBySessionId)(benchmark::State &sta EXPECT_EQ(startRet, HDF_SUCCESS); } -BENCHMARK_REGISTER_F(VibratorBenchmarkTest, GetEffectInfo)-> +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, PlayPatternBySessionId)-> Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); /** @@ -341,7 +345,7 @@ BENCHMARK_F(VibratorBenchmarkTest, PlayPackageBySession)(benchmark::State &state EXPECT_EQ(startRet, HDF_SUCCESS); } -BENCHMARK_REGISTER_F(VibratorBenchmarkTest, GetEffectInfo)-> +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, PlayPackageBySession)-> Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); /** @@ -366,7 +370,185 @@ BENCHMARK_F(VibratorBenchmarkTest, StopVibrateBySessionId)(benchmark::State &sta } } -BENCHMARK_REGISTER_F(VibratorBenchmarkTest, GetEffectInfo)-> +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, StopVibrateBySessionId)-> + Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); + +/** + * @tc.name: DriverSystem_VibratorBenchmark_GetDeviceVibratorInfo + * @tc.desc: Benchmarktest for interface GetDeviceVibratorInfo + * Controls this Performing Time Series Vibrator Effects + * @tc.type: FUNC + */ +BENCHMARK_F(VibratorBenchmarkTest, GetDeviceVibratorInfo)(benchmark::State &state) +{ + ASSERT_NE(nullptr, g_vibratorInterface); + + std::vector info; + for (auto _ : state) { +#ifdef TV_FLAG + int32_t startRet = g_vibratorInterface->GetDeviceVibratorInfo(g_deviceVibratorInfo, info); + EXPECT_EQ(startRet, HDF_SUCCESS); +#else + (void)g_vibratorInterface->GetDeviceVibratorInfo(g_deviceVibratorInfo, info); +#endif + } +} + +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, GetDeviceVibratorInfo)-> + Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); + +/** + * @tc.name: DriverSystem_VibratorBenchmark_GetVibratorIdSingle + * @tc.desc: Benchmarktest for interface GetVibratorIdSingle + * Controls this Performing Time Series Vibrator Effects + * @tc.type: FUNC + */ +BENCHMARK_F(VibratorBenchmarkTest, GetVibratorIdSingle)(benchmark::State &state) +{ + ASSERT_NE(nullptr, g_vibratorInterface); + + std::vector info; + for (auto _ : state) { + int32_t startRet = g_vibratorInterface->GetVibratorIdSingle(g_deviceVibratorInfo, info); + EXPECT_EQ(startRet, HDF_SUCCESS); + } +} + +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, GetVibratorIdSingle)-> + Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); + +/** + * @tc.name: DriverSystem_VibratorBenchmark_PlayHapticPattern + * @tc.desc: Benchmarktest for interface PlayHapticPattern + * Controls this Performing Time Series Vibrator Effects + * @tc.type: FUNC + */ +BENCHMARK_F(VibratorBenchmarkTest, PlayHapticPattern)(benchmark::State &state) +{ + ASSERT_NE(nullptr, g_vibratorInterface); + + std::vector info; + for (auto _ : state) { + int32_t startRet = g_vibratorInterface->PlayHapticPattern(g_deviceVibratorInfo, g_pkg); + EXPECT_EQ(startRet, HDF_SUCCESS); + } +} + +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, PlayHapticPattern)-> + Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); + +/** + * @tc.name: DriverSystem_VibratorBenchmark_GetHapticStartUpTime + * @tc.desc: Benchmarktest for interface GetHapticStartUpTime + * Controls this Performing Time Series Vibrator Effects + * @tc.type: FUNC + */ +BENCHMARK_F(VibratorBenchmarkTest, GetHapticStartUpTime)(benchmark::State &state) +{ + ASSERT_NE(nullptr, g_vibratorInterface); + + std::vector info; + for (auto _ : state) { + + int32_t startUpTime = 0; + int32_t mode = 0; + int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(g_deviceVibratorInfo, mode, startUpTime); + EXPECT_EQ(startRet, HDF_SUCCESS); + } +} + +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, GetHapticStartUpTime)-> + Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); + +/** + * @tc.name: DriverSystem_VibratorBenchmark_StartByIntensity + * @tc.desc: Benchmarktest for interface StartByIntensity + * Controls this Performing Time Series Vibrator Effects + * @tc.type: FUNC + */ +BENCHMARK_F(VibratorBenchmarkTest, StartByIntensity)(benchmark::State &state) +{ + ASSERT_NE(nullptr, g_vibratorInterface); + + int32_t startRet; + int32_t endRet; + for (auto _ : state) { + for (auto it : g_vibratorInfo) { + HdfEffectInfo effectInfo; + g_vibratorInterface->GetEffectInfo({it.deviceId, it.vibratorId}, g_timeSequence, effectInfo); + if (effectInfo.isSupportEffect == true) { + startRet = g_vibratorInterface->StartByIntensity({it.deviceId, it.vibratorId}, g_timeSequence, + g_intensity); + EXPECT_EQ(startRet, HDF_SUCCESS); + + endRet = g_vibratorInterface->Stop({it.deviceId, it.vibratorId}, HDF_VIBRATOR_MODE_PRESET); + EXPECT_EQ(endRet, HDF_SUCCESS); + } + } + } +} + +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, StartByIntensity)-> + Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); + +/** + * @tc.name: DriverSystem_VibratorBenchmark_GetAllWaveInfo + * @tc.desc: Benchmarktest for interface GetAllWaveInfo + * Controls this Performing Time Series Vibrator Effects + * @tc.type: FUNC + */ +BENCHMARK_F(VibratorBenchmarkTest, GetAllWaveInfo)(benchmark::State &state) +{ + ASSERT_NE(nullptr, g_vibratorInterface); + + std::vector info; + for (auto _ : state) { + int32_t startRet = g_vibratorInterface->GetAllWaveInfo(g_deviceVibratorInfo, g_info); + EXPECT_EQ(startRet, HDF_SUCCESS); + } +} + +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, GetAllWaveInfo)-> + Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); + +/** + * @tc.name: DriverSystem_VibratorBenchmark_RegVibratorPlugCallback + * @tc.desc: Benchmarktest for interface RegVibratorPlugCallback + * Controls this Performing Time Series Vibrator Effects + * @tc.type: FUNC + */ +BENCHMARK_F(VibratorBenchmarkTest, RegVibratorPlugCallback)(benchmark::State &state) +{ + ASSERT_NE(nullptr, g_vibratorInterface); + + std::vector info; + for (auto _ : state) { + int32_t startRet = g_vibratorInterface->RegVibratorPlugCallback(g_vibratorPlugCallback); + EXPECT_EQ(startRet, HDF_SUCCESS); + } +} + +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, RegVibratorPlugCallback)-> + Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); + +/** + * @tc.name: DriverSystem_VibratorBenchmark_UnRegVibratorPlugCallback + * @tc.desc: Benchmarktest for interface UnRegVibratorPlugCallback + * Controls this Performing Time Series Vibrator Effects + * @tc.type: FUNC + */ +BENCHMARK_F(VibratorBenchmarkTest, UnRegVibratorPlugCallback)(benchmark::State &state) +{ + ASSERT_NE(nullptr, g_vibratorInterface); + + std::vector info; + for (auto _ : state) { + int32_t startRet = g_vibratorInterface->UnRegVibratorPlugCallback(g_vibratorPlugCallback); + EXPECT_EQ(startRet, HDF_SUCCESS); + } +} + +BENCHMARK_REGISTER_F(VibratorBenchmarkTest, UnRegVibratorPlugCallback)-> Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly(); } diff --git a/vibrator/test/benchmarktest/vibrator_plug_callback_impl.h b/vibrator/test/benchmarktest/vibrator_plug_callback_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..0cc5dfcbde4a6bd529724072cbd8cc795b9c1943 --- /dev/null +++ b/vibrator/test/benchmarktest/vibrator_plug_callback_impl.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_VIBRATOR_V2_0_VIBRATORPLUSCALLBACKIMPL_H +#define OHOS_HDI_VIBRATOR_V2_0_VIBRATORPLUSCALLBACKIMPL_H + +#include +#include "v2_0/ivibrator_plug_callback.h" + +namespace OHOS { +namespace HDI { +namespace Vibrator { +namespace V2_0 { +class VibratorPlugCallbackImpl : public V2_0::IVibratorPlugCallback { +public: + virtual ~VibratorPlugCallbackImpl() {} + + int32_t OnVibratorPlugEvent(const HdfVibratorPlugInfo& hdfVibratorPlugInfo) override + { + (void)hdfVibratorPlugInfo; + return HDF_SUCCESS; + } +}; +} // V2_0 +} // Vibrator +} // HDI +} // OHOS + +#endif // OHOS_HDI_VIBRATOR_V2_0_VIBRATORPLUSCALLBACKIMPL_H