diff --git a/sensor/test/BUILD.gn b/sensor/test/BUILD.gn index b041b8f069d1e3e0f8b4eed18b680c1adc948143..ba1a94715f7ef2c181fb2ea37bc288d8697cfed0 100644 --- a/sensor/test/BUILD.gn +++ b/sensor/test/BUILD.gn @@ -41,6 +41,7 @@ if (defined(ohos_lite)) { "unittest/sensor_test_five_clients:SensorTestFiveClients", "unittest/sensor_test_multi_clients:SensorTestMultiClients", "unittest/sensor_test_three_clients:SensorTestThreeClients", + "unittest/setsdcsensor_test_multi_clients:SetSdcSensorTestMultiClients", ] } } diff --git a/sensor/test/unittest/setsdcsensor_test_multi_clients/BUILD.gn b/sensor/test/unittest/setsdcsensor_test_multi_clients/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f07e19b4648c5c653a4d9066f55031105d1182f0 --- /dev/null +++ b/sensor/test/unittest/setsdcsensor_test_multi_clients/BUILD.gn @@ -0,0 +1,107 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../sensor.gni") + +module_output_path = "drivers_peripheral_sensor/drivers_peripheral_sensor/SetSdcSensorTestMultiClients" + +group("SetSdcSensorTestMultiClients") { + deps = [] + testonly = true + deps += [ + ":SensorSetSdcSensorTest1", + ":SensorSetSdcSensorTest2", + ] +} + +ohos_unittest("SensorSetSdcSensorTest1") { + module_out_path = module_output_path + + include_dirs = [ + "../../../interfaces/include", + "../../../interfaces/v1_0", + "../../../utils/include", + ] + + sources = [ "sensor_setsdcsensor_test1.cpp" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + if (is_standard_system) { + external_deps = [ + "drivers_interface_sensor:libsensor_proxy_2.0", + "drivers_interface_sensor:libsensor_proxy_2.1", + "drivers_interface_sensor:libsensor_proxy_3.0", + "hdf_core:libhdf_host", + "hdf_core:libhdf_utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_single", + ] + if (c_utils_enable) { + external_deps += [ "c_utils:utils" ] + } + } else { + external_deps = [ "hilog:libhilog" ] + } + external_deps += [ "ipc:ipc_single" ] +} + +ohos_unittest("SensorSetSdcSensorTest2") { + module_out_path = module_output_path + + include_dirs = [ + "../../../interfaces/include", + "../../../interfaces/v1_0", + "../../../utils/include", + ] + + sources = [ "sensor_setsdcsensor_test2.cpp" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + if (is_standard_system) { + external_deps = [ + "drivers_interface_sensor:libsensor_proxy_2.0", + "drivers_interface_sensor:libsensor_proxy_2.1", + "drivers_interface_sensor:libsensor_proxy_3.0", + "hdf_core:libhdf_host", + "hdf_core:libhdf_utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_single", + ] + if (c_utils_enable) { + external_deps += [ "c_utils:utils" ] + } + } else { + external_deps = [ "hilog:libhilog" ] + } + external_deps += [ "ipc:ipc_single" ] +} \ No newline at end of file diff --git a/sensor/test/unittest/setsdcsensor_test_multi_clients/readme_zh.md b/sensor/test/unittest/setsdcsensor_test_multi_clients/readme_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..4bbebbbf260b64d25b33f8c924b4c5698130f0b5 --- /dev/null +++ b/sensor/test/unittest/setsdcsensor_test_multi_clients/readme_zh.md @@ -0,0 +1,42 @@ +# sensor��ͻ�����������1 + +> ����������ģ���������η�����sensor�������
+> ����1��ͨ��setbatch(acc������, 100�������Ƶ��, ��������)�ķ�ʽ���ġ�
+> ����2��ͨ��SetSdcSensor(acc������, enable, 200���Ȳ���Ƶ��)�ķ�ʽ���ġ�
+> ����������Ч���ǣ������ؼ���setSaBatch��ӡ�ɿ������õ��ϱ�Ƶ��Ϊ100000000���������ϱ�Ƶ��Ϊ100����/�Σ�ͨ��������־�ؼ���OnDataEvent.*sensorType1s��ӡ��ʱ����Լ���ӡ�����۲��Ƿ����Ԥ�ڡ� + +--- + +## Ŀ¼ + +- [���](#���) +- [��װ˵��](#��װ˵��) +- [ʹ��ʾ��](#ʹ��ʾ��) +- [����](#����) +- [����֤](#����֤) + +--- + +## ��� +**ͼ 1** Sensor��������ģ��ͼ +![ʾ��ͼƬ](sensor_test.jpg) +--- + +## ����������Ҫ�죺 + +### 1. �������� + +��������������ú󣬷ŵ�ͳһ·�����ڵ�ǰ·��ִ��������� + +```bash +hdc target mount +hdc shell hilog -b D -D 0xD002516 +hdc file send SensorSetSdcSensorTest1 /data/SensorSetSdcSensorTest1 +hdc file send SensorSetSdcSensorTest2 /data/SensorSetSdcSensorTest2 +hdc shell chmod 777 /data/SensorSetSdcSensorTest1 +hdc shell chmod 777 /data/SensorSetSdcSensorTest2 + +start cmd /k "hdc shell /data/SensorSetSdcSensorTest2" +ping -n 1 -w 200 127.0.0.1 > nul +start cmd /k "hdc shell /data/SensorSetSdcSensorTest1" +parse \ No newline at end of file diff --git a/sensor/test/unittest/setsdcsensor_test_multi_clients/sensor_setsdcsensor_test1.cpp b/sensor/test/unittest/setsdcsensor_test_multi_clients/sensor_setsdcsensor_test1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3065c964ad34917bdee5c5d4f0ffe3537dd79b21 --- /dev/null +++ b/sensor/test/unittest/setsdcsensor_test_multi_clients/sensor_setsdcsensor_test1.cpp @@ -0,0 +1,90 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include "hdf_base.h" +#include "osal_time.h" +#include "v3_0/isensor_interface.h" +#include "sensor_type.h" +#include "sensor_uhdf_log.h" +#include "sensor_trace.h" + +using namespace OHOS::HDI::Sensor::V3_0; +using namespace OHOS::HDI::Sensor; +using namespace testing::ext; + +namespace { + sptr g_sensorInterface = nullptr; + + class SensorSetSdcSensorTest : public testing::Test { + public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + }; + + void SensorSetSdcSensorTest::SetUpTestCase() + { + g_sensorInterface = V3_0::ISensorInterface::Get(); + } + + void SensorSetSdcSensorTest::TearDownTestCase() + { + } + + void SensorSetSdcSensorTest::SetUp() + { + } + + void SensorSetSdcSensorTest::TearDown() + { + } + + /** + * @tc.name: SensorSetSdcSensorTest1 + * @tc.desc: Get a client and check whether the client is empty. + * @tc.type: FUNC + * @tc.require: #I4L3LF + */ + HWTEST_F(SensorSetSdcSensorTest, SensorSetSdcSensorTest1, TestSize.Level1) + { + ASSERT_NE(nullptr, g_sensorInterface); + std::vector info; + int32_t ret = g_sensorInterface->GetAllSensorInfo(info); + EXPECT_EQ(ret, HDF_SUCCESS); + bool accSensorExist = false; + DeviceSensorInfo deviceSensorInfo; + for (auto it : info) { + if (it.deviceSensorInfo.sensorType == HDF_SENSOR_TYPE_ACCELEROMETER) { + accSensorExist = true; + deviceSensorInfo = {0, it.deviceSensorInfo.sensorType, 0, 0}; + } + } + if (accSensorExist == false) { + GTEST_SKIP() << "acc Sensor not Exist" << std::endl; + } + ret = g_sensorInterface->SetSdcSensor(deviceSensorInfo, true, 100); + EXPECT_EQ(ret, HDF_SUCCESS); + + OsalMSleep(2000); + + ret = g_sensorInterface->SetSdcSensor(deviceSensorInfo, false, 100); + } +} \ No newline at end of file diff --git a/sensor/test/unittest/setsdcsensor_test_multi_clients/sensor_setsdcsensor_test2.cpp b/sensor/test/unittest/setsdcsensor_test_multi_clients/sensor_setsdcsensor_test2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bfcdc26b3071110007d1abe839a6870f9188d5f5 --- /dev/null +++ b/sensor/test/unittest/setsdcsensor_test_multi_clients/sensor_setsdcsensor_test2.cpp @@ -0,0 +1,90 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include "hdf_base.h" +#include "osal_time.h" +#include "v3_0/isensor_interface.h" +#include "sensor_type.h" +#include "sensor_uhdf_log.h" +#include "sensor_trace.h" + +using namespace OHOS::HDI::Sensor::V3_0; +using namespace OHOS::HDI::Sensor; +using namespace testing::ext; + +namespace { + sptr g_sensorInterface = nullptr; + + class SensorSetSdcSensorTest : public testing::Test { + public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + }; + + void SensorSetSdcSensorTest::SetUpTestCase() + { + g_sensorInterface = V3_0::ISensorInterface::Get(); + } + + void SensorSetSdcSensorTest::TearDownTestCase() + { + } + + void SensorSetSdcSensorTest::SetUp() + { + } + + void SensorSetSdcSensorTest::TearDown() + { + } + + /** + * @tc.name: SensorSetSdcSensorTest1 + * @tc.desc: Get a client and check whether the client is empty. + * @tc.type: FUNC + * @tc.require: #I4L3LF + */ + HWTEST_F(SensorSetSdcSensorTest, SensorSetSdcSensorTest1, TestSize.Level1) + { + ASSERT_NE(nullptr, g_sensorInterface); + std::vector info; + int32_t ret = g_sensorInterface->GetAllSensorInfo(info); + EXPECT_EQ(ret, HDF_SUCCESS); + bool accSensorExist = false; + DeviceSensorInfo deviceSensorInfo; + for (auto it : info) { + if (it.deviceSensorInfo.sensorType == HDF_SENSOR_TYPE_ACCELEROMETER) { + accSensorExist = true; + deviceSensorInfo = {-1, it.deviceSensorInfo.sensorType, 0, 1}; + } + } + if (accSensorExist == false) { + GTEST_SKIP() << "acc Sensor not Exist" << std::endl; + } + ret = g_sensorInterface->SetSdcSensor(deviceSensorInfo, true, 100); + EXPECT_EQ(ret, HDF_SUCCESS); + + OsalMSleep(1000); + + ret = g_sensorInterface->SetSdcSensor(deviceSensorInfo, false, 100); + } +} \ No newline at end of file