mirror of
https://gitee.com/openharmony/xts_hats
synced 2024-12-11 17:07:55 +00:00
!175 【驱动子系统】【xts_hats】sensor benchmark 用例提交
Merge pull request !175 from Yyyingchao/benchmark_2022_06_24
This commit is contained in:
commit
80ef9b97d6
@ -20,6 +20,7 @@ group("HatsHdfSensorTest") {
|
||||
deps = [
|
||||
":HatsHdfSensorHdiTest",
|
||||
"hdiService:HatsHdfSensorServiceTest",
|
||||
"sensorBenchmarkTest:HatsHdfSensorbenchmarkTest",
|
||||
]
|
||||
}
|
||||
|
||||
|
60
hdf/sensor/sensorBenchmarkTest/BUILD.gn
Normal file
60
hdf/sensor/sensorBenchmarkTest/BUILD.gn
Normal file
@ -0,0 +1,60 @@
|
||||
# Copyright (c) 2021-2022 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_var.gni")
|
||||
import("//build/test.gni")
|
||||
import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni")
|
||||
import("//test/xts/tools/build/suite.gni")
|
||||
|
||||
module_output_path = "hdf/sensor"
|
||||
|
||||
ohos_moduletest_suite("HatsHdfSensorbenchmarkTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [
|
||||
"//drivers/peripheral/sensor/interfaces",
|
||||
"//drivers/peripheral/sensor/interfaces/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"hdf_sensor_benchmark_test.cpp",
|
||||
"sensor_callback_impl.cpp",
|
||||
"sensor_callback_impl.h",
|
||||
]
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-fsigned-char",
|
||||
"-fno-common",
|
||||
"-fno-strict-aliasing",
|
||||
]
|
||||
deps = [
|
||||
"//third_party/benchmark",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
if (is_standard_system) {
|
||||
external_deps = [
|
||||
"hdf_core:libhdf_utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"sensor_device_driver_interface:libsensor_proxy_1.0",
|
||||
"utils_base:utils",
|
||||
]
|
||||
} else {
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
}
|
||||
external_deps += [ "ipc:ipc_single" ]
|
||||
}
|
18
hdf/sensor/sensorBenchmarkTest/Test.json
Normal file
18
hdf/sensor/sensorBenchmarkTest/Test.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"kits": [
|
||||
{
|
||||
"push": [
|
||||
"HatsHdfSensorbenchmarkTest->/data/local/tmp/HatsHdfSensorbenchmarkTest"
|
||||
],
|
||||
"type": "PushKit"
|
||||
}
|
||||
],
|
||||
"driver": {
|
||||
"native-test-timeout": "120000",
|
||||
"type": "CppTest",
|
||||
"module-name": "HatsHdfSensorbenchmarkTest",
|
||||
"runtime-hint": "1s",
|
||||
"native-test-device-path": "/data/local/tmp"
|
||||
},
|
||||
"description": "Configuration for HatsHdfSensorbenchmarkTest Tests"
|
||||
}
|
328
hdf/sensor/sensorBenchmarkTest/hdf_sensor_benchmark_test.cpp
Normal file
328
hdf/sensor/sensorBenchmarkTest/hdf_sensor_benchmark_test.cpp
Normal file
@ -0,0 +1,328 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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 <benchmark/benchmark.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <securec.h>
|
||||
#include "hdf_base.h"
|
||||
#include "osal_time.h"
|
||||
#include "v1_0/isensor_interface.h"
|
||||
#include "sensor_type.h"
|
||||
#include "sensor_callback_impl.h"
|
||||
|
||||
using namespace OHOS::HDI::Sensor::V1_0;
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
sptr<ISensorInterface> g_sensorInterface = nullptr;
|
||||
sptr<ISensorCallback> g_traditionalCallback = new SensorCallbackImpl();
|
||||
sptr<ISensorCallback> g_medicalCallback = new SensorCallbackImpl();
|
||||
std::vector<HdfSensorInformation> g_info;
|
||||
struct SensorValueRange {
|
||||
float highThreshold;
|
||||
float lowThreshold;
|
||||
};
|
||||
|
||||
struct SensorDevelopmentList {
|
||||
int32_t sensorTypeId;
|
||||
char sensorName[SENSOR_NAME_MAX_LEN];
|
||||
int32_t dataForm; // 0: fixed, 1: range
|
||||
int32_t dataDimension;
|
||||
struct SensorValueRange *valueRange;
|
||||
};
|
||||
|
||||
struct SensorValueRange g_testRange[] = {{1e5, 0}};
|
||||
struct SensorValueRange g_accelRange[] = {{78, -78}, {78, -78}, {78, -78}};
|
||||
struct SensorValueRange g_alsRange[] = {{10000, 0}};
|
||||
struct SensorValueRange g_pedometerRange[] = {{10000, 0}};
|
||||
struct SensorValueRange g_proximityRange[] = {{5, 0}};
|
||||
struct SensorValueRange g_hallRange[] = {{1, 0}};
|
||||
struct SensorValueRange g_barometerRange[] = {{1100, -1100}, {1100, -1100}};
|
||||
struct SensorValueRange g_magneticRange[] = {{2000, -2000}, {2000, -2000}, {2000, -2000}};
|
||||
struct SensorValueRange g_gyroscopeRange[] = {{35, -35}, {35, -35}, {35, -35}};
|
||||
struct SensorValueRange g_gravityRange[] = {{78, -78}, {78, -78}, {78, -78}};
|
||||
|
||||
struct SensorDevelopmentList g_sensorList[] = {
|
||||
{SENSOR_TYPE_NONE, "sensor_test", 1, 1, g_testRange},
|
||||
{SENSOR_TYPE_ACCELEROMETER, "accelerometer", 1, 3, g_accelRange},
|
||||
{SENSOR_TYPE_PEDOMETER, "pedometer", 1, 1, g_pedometerRange},
|
||||
{SENSOR_TYPE_PROXIMITY, "proximity", 0, 1, g_proximityRange},
|
||||
{SENSOR_TYPE_HALL, "hallrometer", 0, 1, g_hallRange},
|
||||
{SENSOR_TYPE_BAROMETER, "barometer", 1, 2, g_barometerRange},
|
||||
{SENSOR_TYPE_AMBIENT_LIGHT, "als", 1, 1, g_alsRange},
|
||||
{SENSOR_TYPE_MAGNETIC_FIELD, "magnetometer", 1, 3, g_magneticRange},
|
||||
{SENSOR_TYPE_GYROSCOPE, "gyroscope", 1, 3, g_gyroscopeRange},
|
||||
{SENSOR_TYPE_GRAVITY, "gravity", 1, 3, g_gravityRange}
|
||||
};
|
||||
|
||||
constexpr int g_listNum = sizeof(g_sensorList) / sizeof(g_sensorList[0]);
|
||||
constexpr int32_t SENSOR_INTERVAL1 = 20;
|
||||
constexpr int32_t SENSOR_INTERVAL2 = 2;
|
||||
constexpr int32_t SENSOR_POLL_TIME = 1;
|
||||
constexpr int32_t SENSOR_WAIT_TIME = 10;
|
||||
|
||||
class sensorBenchmarkTest : public benchmark::Fixture {
|
||||
public:
|
||||
void SetUp(const ::benchmark::State &state);
|
||||
void TearDown(const ::benchmark::State &state);
|
||||
};
|
||||
|
||||
void sensorBenchmarkTest::SetUp(const ::benchmark::State &state)
|
||||
{
|
||||
g_sensorInterface = ISensorInterface::Get();
|
||||
}
|
||||
|
||||
void sensorBenchmarkTest::TearDown(const ::benchmark::State &state)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetSensorList0001
|
||||
* @tc.desc: Obtains information about all sensors in the system.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
BENCHMARK_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0010)(benchmark::State &st)
|
||||
{
|
||||
if (g_sensorInterface == nullptr) {
|
||||
ASSERT_NE(nullptr, g_sensorInterface);
|
||||
return;
|
||||
}
|
||||
int32_t ret;
|
||||
for (auto _ : st) {
|
||||
ret = g_sensorInterface->GetAllSensorInfo(g_info);
|
||||
}
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
|
||||
for (auto iter : g_info) {
|
||||
for (int j =0; j < g_listNum; ++j) {
|
||||
if (iter.sensorId == g_sensorList[j].sensorTypeId) {
|
||||
EXPECT_GT(iter.sensorName.size(), 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0010)->
|
||||
Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterSensorDataCb0001
|
||||
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
BENCHMARK_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0020)(benchmark::State &st)
|
||||
{
|
||||
if (g_sensorInterface == nullptr) {
|
||||
ASSERT_NE(nullptr, g_sensorInterface);
|
||||
return;
|
||||
}
|
||||
int32_t ret;
|
||||
for (auto _ : st) {
|
||||
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_medicalCallback);
|
||||
}
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
ret = g_sensorInterface->Unregister(TRADITIONAL_SENSOR_TYPE, g_medicalCallback);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0020)->
|
||||
Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.name: UnRegisterSensorDataCb0001
|
||||
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
BENCHMARK_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0030)(benchmark::State &st)
|
||||
{
|
||||
if (g_sensorInterface == nullptr) {
|
||||
ASSERT_NE(nullptr, g_sensorInterface);
|
||||
return;
|
||||
}
|
||||
int32_t ret;
|
||||
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_medicalCallback);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
for (auto _ : st) {
|
||||
ret = g_sensorInterface->Unregister(TRADITIONAL_SENSOR_TYPE, g_medicalCallback);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0030)->
|
||||
Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.name: EnableSensor0001
|
||||
* @tc.desc: Enables the sensor unavailable in the sensor list based on the specified sensor ID.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
|
||||
BENCHMARK_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0040)(benchmark::State &st)
|
||||
{
|
||||
if (g_sensorInterface == nullptr) {
|
||||
ASSERT_NE(nullptr, g_sensorInterface);
|
||||
return;
|
||||
}
|
||||
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
|
||||
EXPECT_GT(g_info.size(), 0);
|
||||
|
||||
ret = g_sensorInterface->SetBatch(0, SENSOR_INTERVAL1, SENSOR_POLL_TIME);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
for (auto _ : st) {
|
||||
ret = g_sensorInterface->Enable(0);
|
||||
}
|
||||
OsalMSleep(SENSOR_POLL_TIME);
|
||||
ret = g_sensorInterface->Disable(0);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
ret = g_sensorInterface->Unregister(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
|
||||
EXPECT_EQ(SensorCallbackImpl::sensorDataFlag, 1);
|
||||
SensorCallbackImpl::sensorDataFlag = 1;
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0040)->
|
||||
Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.name: DisableSensor0001
|
||||
* @tc.desc: Enables the sensor unavailable in the sensor list based on the specified sensor ID.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
|
||||
BENCHMARK_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0050)(benchmark::State &st)
|
||||
{
|
||||
if (g_sensorInterface == nullptr) {
|
||||
ASSERT_NE(nullptr, g_sensorInterface);
|
||||
return;
|
||||
}
|
||||
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
|
||||
EXPECT_GT(g_info.size(), 0);
|
||||
|
||||
ret = g_sensorInterface->SetBatch(0, SENSOR_INTERVAL1, SENSOR_POLL_TIME);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
ret = g_sensorInterface->Enable(0);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
OsalMSleep(SENSOR_POLL_TIME);
|
||||
for (auto _ : st) {
|
||||
ret = g_sensorInterface->Disable(0);
|
||||
}
|
||||
ret = g_sensorInterface->Unregister(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
|
||||
EXPECT_EQ(SensorCallbackImpl::sensorDataFlag, 1);
|
||||
SensorCallbackImpl::sensorDataFlag = 1;
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0050)->
|
||||
Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.name: SetSensorBatch0001
|
||||
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
BENCHMARK_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0060)(benchmark::State &st)
|
||||
{
|
||||
if (g_sensorInterface == nullptr) {
|
||||
ASSERT_NE(nullptr, g_sensorInterface);
|
||||
return;
|
||||
}
|
||||
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
|
||||
for (auto _ : st) {
|
||||
ret = g_sensorInterface->SetBatch(0, SENSOR_INTERVAL2, SENSOR_POLL_TIME);
|
||||
}
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
ret = g_sensorInterface->Enable(0);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
OsalMSleep(SENSOR_WAIT_TIME);
|
||||
ret = g_sensorInterface->Disable(0);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
|
||||
ret = g_sensorInterface->Unregister(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
EXPECT_EQ(SensorCallbackImpl::sensorDataFlag, 1);
|
||||
SensorCallbackImpl::sensorDataFlag = 1;
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0060)->
|
||||
Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.name: SetSensorMode0001
|
||||
* @tc.desc: Sets the data reporting mode for the specified sensor.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
BENCHMARK_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0070)(benchmark::State &st)
|
||||
{
|
||||
if (g_sensorInterface == nullptr) {
|
||||
ASSERT_NE(nullptr, g_sensorInterface);
|
||||
return;
|
||||
}
|
||||
EXPECT_GT(g_info.size(), 0);
|
||||
int32_t ret ;
|
||||
ret = g_sensorInterface->SetBatch(0, SENSOR_INTERVAL1, SENSOR_POLL_TIME);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
for (auto _ : st) {
|
||||
if (0 == SENSOR_TYPE_HALL) {
|
||||
ret = g_sensorInterface->SetMode(0, SENSOR_MODE_ON_CHANGE);
|
||||
} else {
|
||||
ret = g_sensorInterface->SetMode(0, SENSOR_MODE_REALTIME);
|
||||
}
|
||||
}
|
||||
ret = g_sensorInterface->Enable(0);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
OsalMSleep(SENSOR_WAIT_TIME);
|
||||
ret = g_sensorInterface->Disable(0);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0070)->
|
||||
Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
|
||||
|
||||
/**
|
||||
* @tc.name: SetSensorOption0001
|
||||
* @tc.desc: Sets options for the specified sensor, including its measurement range and accuracy.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
BENCHMARK_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0080)(benchmark::State &st)
|
||||
{
|
||||
if (g_sensorInterface == nullptr) {
|
||||
ASSERT_NE(nullptr, g_sensorInterface);
|
||||
return;
|
||||
}
|
||||
EXPECT_GT(g_info.size(), 0);
|
||||
int32_t ret;
|
||||
|
||||
for (auto _ : st) {
|
||||
ret = g_sensorInterface->SetOption(0, 0);
|
||||
EXPECT_EQ(SENSOR_SUCCESS, ret);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(sensorBenchmarkTest, SUB_DriverSystem_SensorBenchmark_0080)->
|
||||
Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
|
||||
}
|
||||
|
||||
BENCHMARK_MAIN();
|
115
hdf/sensor/sensorBenchmarkTest/sensor_callback_impl.cpp
Normal file
115
hdf/sensor/sensorBenchmarkTest/sensor_callback_impl.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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 "sensor_callback_impl.h"
|
||||
#include "sensor_type.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace HDI {
|
||||
namespace Sensor {
|
||||
namespace V1_0 {
|
||||
uint32_t SensorCallbackImpl::sensorDataFlag = 1;
|
||||
namespace {
|
||||
struct SensorValueRange {
|
||||
float highThreshold;
|
||||
float lowThreshold;
|
||||
};
|
||||
|
||||
struct SensorDevelopmentList {
|
||||
int32_t sensorTypeId;
|
||||
char sensorName[SENSOR_NAME_MAX_LEN];
|
||||
int32_t dataForm; // 0: fixed, 1: range
|
||||
int32_t dataDimension;
|
||||
struct SensorValueRange *valueRange;
|
||||
};
|
||||
|
||||
struct SensorValueRange g_testRange[] = {{1e5, 0.0}};
|
||||
struct SensorValueRange g_accelRange[] = {{78.0, -78.0}, {78.0, -78.0}, {78.0, -78.0}};
|
||||
struct SensorValueRange g_alsRange[] = {{10000.0, 0.0}};
|
||||
struct SensorValueRange g_pedometerRange[] = {{10000.0, 0.0}};
|
||||
struct SensorValueRange g_proximityRange[] = {{5.0, 0.0}};
|
||||
struct SensorValueRange g_hallRange[] = {{1.0, 0.0}};
|
||||
struct SensorValueRange g_barometerRange[] = {{1100.0, -1100.0}, {1100.0, -1100.0}};
|
||||
struct SensorValueRange g_magneticRange[] = {{2000.0, -2000.0}, {2000.0, -2000.0}, {2000.0, -2000.0}};
|
||||
struct SensorValueRange g_gyroscopeRange[] = {{35.0, -35.0}, {35.0, -35.0}, {35.0, -35.0}};
|
||||
struct SensorValueRange g_gravityRange[] = {{78.0, -78.0}, {78.0, -78.0}, {78.0, -78.0}};
|
||||
|
||||
struct SensorDevelopmentList g_sensorList[] = {
|
||||
{SENSOR_TYPE_NONE, "sensor_test", 1, 1, g_testRange},
|
||||
{SENSOR_TYPE_ACCELEROMETER, "accelerometer", 1, 3, g_accelRange},
|
||||
{SENSOR_TYPE_PEDOMETER, "pedometer", 1, 1, g_pedometerRange},
|
||||
{SENSOR_TYPE_PROXIMITY, "proximity", 0, 1, g_proximityRange},
|
||||
{SENSOR_TYPE_HALL, "hallrometer", 0, 1, g_hallRange},
|
||||
{SENSOR_TYPE_BAROMETER, "barometer", 1, 2, g_barometerRange},
|
||||
{SENSOR_TYPE_AMBIENT_LIGHT, "als", 1, 1, g_alsRange},
|
||||
{SENSOR_TYPE_MAGNETIC_FIELD, "magnetometer", 1, 3, g_magneticRange},
|
||||
{SENSOR_TYPE_GYROSCOPE, "gyroscope", 1, 3, g_gyroscopeRange},
|
||||
{SENSOR_TYPE_GRAVITY, "gravity", 1, 3, g_gravityRange}
|
||||
};
|
||||
|
||||
constexpr int g_listNum = sizeof(g_sensorList) / sizeof(g_sensorList[0]);
|
||||
constexpr float EPSINON = 1e-6;
|
||||
|
||||
void SensorDataVerification(const float &data, const struct SensorDevelopmentList &sensorNode)
|
||||
{
|
||||
for (int32_t j = 0; j < sensorNode.dataDimension; ++j) {
|
||||
printf("sensor id :[%d], data[%d]: %f\n\r", sensorNode.sensorTypeId, j + 1, *(&data + j));
|
||||
if (sensorNode.dataForm == 0) {
|
||||
if (abs(*(&data + j) - sensorNode.valueRange[j].highThreshold) < EPSINON ||
|
||||
abs(*(&data + j) - sensorNode.valueRange[j].lowThreshold) < EPSINON) {
|
||||
SensorCallbackImpl::sensorDataFlag &= 1;
|
||||
} else {
|
||||
SensorCallbackImpl::sensorDataFlag = 0;
|
||||
printf("%s: %s Not expected\n\r", __func__, sensorNode.sensorName);
|
||||
}
|
||||
}
|
||||
|
||||
if (sensorNode.dataForm == 1) {
|
||||
if (*(&data + j) > sensorNode.valueRange[j].lowThreshold &&
|
||||
*(&data + j) < sensorNode.valueRange[j].highThreshold) {
|
||||
SensorCallbackImpl::sensorDataFlag &= 1;
|
||||
printf("sensorDataFlag = 1;");
|
||||
} else {
|
||||
SensorCallbackImpl::sensorDataFlag = 0;
|
||||
printf("%s: %s Not expected\n\r", __func__, sensorNode.sensorName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SensorCallbackImpl::OnDataEvent(const HdfSensorEvents& event)
|
||||
{
|
||||
void *origin = OsalMemCalloc(sizeof(uint8_t) * (event.dataLen));
|
||||
uint8_t *tmp = static_cast<uint8_t*>(origin);
|
||||
uint8_t *eventData = tmp;
|
||||
for (auto value : event.data) {
|
||||
*tmp++ = value;
|
||||
}
|
||||
|
||||
for (int i = 0; i < g_listNum; ++i) {
|
||||
if (event.sensorId == g_sensorList[i].sensorTypeId) {
|
||||
float *data = (float*)eventData;
|
||||
SensorDataVerification(*data, g_sensorList[i]);
|
||||
}
|
||||
}
|
||||
OsalMemFree(origin);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
} // V1_0
|
||||
} // Sensor
|
||||
} // HDI
|
||||
} // OHOS
|
38
hdf/sensor/sensorBenchmarkTest/sensor_callback_impl.h
Normal file
38
hdf/sensor/sensorBenchmarkTest/sensor_callback_impl.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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_SENSOR_V1_0_SENSORCALLBACKIMPL_H
|
||||
#define OHOS_HDI_SENSOR_V1_0_SENSORCALLBACKIMPL_H
|
||||
|
||||
#include <hdf_base.h>
|
||||
#include "v1_0/isensor_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace HDI {
|
||||
namespace Sensor {
|
||||
namespace V1_0 {
|
||||
class SensorCallbackImpl : public ISensorCallback {
|
||||
public:
|
||||
virtual ~SensorCallbackImpl() {}
|
||||
|
||||
int32_t OnDataEvent(const HdfSensorEvents& event) override;
|
||||
static uint32_t sensorDataFlag;
|
||||
};
|
||||
} // V1_0
|
||||
} // Sensor
|
||||
} // HDI
|
||||
} // OHOS
|
||||
|
||||
#endif // OHOS_HDI_SENSOR_V1_0_SENSORCALLBACKIMPL_H
|
Loading…
Reference in New Issue
Block a user