mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-02 20:24:19 +00:00
Set up shell to use for unit tests
Sets up a unit test file that can be used to unit test the HalProxy. The unit tests will eventually end up containing code that injects the fake SensorsSubHal implementation into the HalProxy and verifies various parts of the implementation. This will likely require some modifications to the SensorsSubHal class to modify it during test execution, but it's better that the same implementation is shared between unit / manual integration testing. Test: Run atest android.hardware.sensors@2.0-halproxy-unit-tests Bug: 136511617 Change-Id: I7b6865564ea41ab3c58f77d3168366c95e3289e5
This commit is contained in:
@@ -13,18 +13,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.sensors@2.0-service.multihal",
|
||||
defaults: ["hidl_defaults"],
|
||||
vendor: true,
|
||||
relative_install_path: "hw",
|
||||
srcs: [
|
||||
"service.cpp",
|
||||
"HalProxy.cpp",
|
||||
],
|
||||
init_rc: ["android.hardware.sensors@2.0-service-multihal.rc"],
|
||||
cc_defaults {
|
||||
name: "android.hardware.sensors@2.0-multihal-defaults",
|
||||
header_libs: [
|
||||
"android.hardware.sensors@2.0-subhal.header",
|
||||
"android.hardware.sensors@2.0-multihal.header",
|
||||
],
|
||||
shared_libs: [
|
||||
"android.hardware.sensors@1.0",
|
||||
@@ -37,11 +29,39 @@ cc_binary {
|
||||
"libpower",
|
||||
"libutils",
|
||||
],
|
||||
}
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.sensors@2.0-service.multihal",
|
||||
defaults: [
|
||||
"hidl_defaults",
|
||||
"android.hardware.sensors@2.0-multihal-defaults",
|
||||
],
|
||||
vendor: true,
|
||||
relative_install_path: "hw",
|
||||
srcs: [
|
||||
"service.cpp",
|
||||
"HalProxy.cpp",
|
||||
],
|
||||
init_rc: ["android.hardware.sensors@2.0-service-multihal.rc"],
|
||||
vintf_fragments: ["android.hardware.sensors@2.0-multihal.xml"],
|
||||
}
|
||||
|
||||
cc_library_headers {
|
||||
name: "android.hardware.sensors@2.0-subhal.header",
|
||||
vendor: true,
|
||||
name: "android.hardware.sensors@2.0-multihal.header",
|
||||
vendor_available: true,
|
||||
export_include_dirs: ["include"],
|
||||
}
|
||||
|
||||
// The below targets should only be used for testing.
|
||||
cc_test_library {
|
||||
name: "android.hardware.sensors@2.0-HalProxy",
|
||||
defaults: ["android.hardware.sensors@2.0-multihal-defaults"],
|
||||
vendor_available: true,
|
||||
srcs: [
|
||||
"HalProxy.cpp",
|
||||
],
|
||||
export_header_lib_headers: [
|
||||
"android.hardware.sensors@2.0-multihal.header",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -104,6 +104,10 @@ HalProxy::HalProxy() {
|
||||
// TODO: Discover sensors
|
||||
}
|
||||
|
||||
HalProxy::HalProxy(std::vector<ISensorsSubHal*>& subHalList) : mSubHalList(subHalList) {
|
||||
// TODO: Perform the same steps as the empty constructor.
|
||||
}
|
||||
|
||||
HalProxy::~HalProxy() {
|
||||
// TODO: Join any running threads and clean up FMQs and any other allocated
|
||||
// state.
|
||||
|
||||
@@ -46,7 +46,9 @@ struct HalProxy : public ISensors {
|
||||
using Result = ::android::hardware::sensors::V1_0::Result;
|
||||
using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
|
||||
|
||||
HalProxy();
|
||||
explicit HalProxy();
|
||||
// Test only constructor.
|
||||
explicit HalProxy(std::vector<ISensorsSubHal*>& subHalList);
|
||||
~HalProxy();
|
||||
|
||||
// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
|
||||
@@ -78,7 +80,7 @@ struct HalProxy : public ISensors {
|
||||
|
||||
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override;
|
||||
|
||||
// Below methods from ::android::hardware::sensors::V2_0::ISensorsCaback with a minor change
|
||||
// Below methods from ::android::hardware::sensors::V2_0::ISensorsCallback with a minor change
|
||||
// to pass in the sub-HAL index. While the above methods are invoked from the sensors framework
|
||||
// via the binder, these methods are invoked from a callback provided to sub-HALs inside the
|
||||
// same process as the HalProxy, but potentially running on different threads.
|
||||
@@ -15,14 +15,13 @@
|
||||
|
||||
cc_defaults {
|
||||
name: "android.hardware.sensors@2.0-fakesubhal-defaults",
|
||||
vendor: true,
|
||||
srcs: [
|
||||
"Sensor.cpp",
|
||||
"SensorsSubHal.cpp",
|
||||
"fake_subhal/*.cpp",
|
||||
],
|
||||
header_libs: [
|
||||
"android.hardware.sensors@2.0-subhal.header",
|
||||
"android.hardware.sensors@2.0-multihal.header",
|
||||
],
|
||||
export_include_dirs: ["fake_subhal"],
|
||||
shared_libs: [
|
||||
"android.hardware.sensors@1.0",
|
||||
"android.hardware.sensors@2.0",
|
||||
@@ -38,6 +37,7 @@ cc_defaults {
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.sensors@2.0-fakesubhal-config1",
|
||||
vendor: true,
|
||||
defaults: ["android.hardware.sensors@2.0-fakesubhal-defaults"],
|
||||
cflags: [
|
||||
"-DSUPPORT_CONTINUOUS_SENSORS",
|
||||
@@ -47,9 +47,43 @@ cc_library {
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.sensors@2.0-fakesubhal-config2",
|
||||
vendor: true,
|
||||
defaults: ["android.hardware.sensors@2.0-fakesubhal-defaults"],
|
||||
cflags: [
|
||||
"-DSUPPORT_ON_CHANGE_SENSORS",
|
||||
"-DSUB_HAL_NAME=\"FakeSubHal-OnChange\"",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test_library {
|
||||
name: "android.hardware.sensors@2.0-fakesubhal-unittest",
|
||||
vendor_available: true,
|
||||
defaults: ["android.hardware.sensors@2.0-fakesubhal-defaults"],
|
||||
cflags: [
|
||||
"-DSUPPORT_ON_CHANGE_SENSORS",
|
||||
"-DSUPPORT_CONTINUOUS_SENSORS",
|
||||
"-DSUB_HAL_NAME=\"FakeSubHal-Test\"",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test {
|
||||
name: "android.hardware.sensors@2.0-halproxy-unit-tests",
|
||||
srcs: ["HalProxy_test.cpp"],
|
||||
vendor: true,
|
||||
static_libs: [
|
||||
"android.hardware.sensors@2.0-HalProxy",
|
||||
"android.hardware.sensors@2.0-fakesubhal-unittest",
|
||||
],
|
||||
shared_libs: [
|
||||
"android.hardware.sensors@1.0",
|
||||
"android.hardware.sensors@2.0",
|
||||
"libcutils",
|
||||
"libfmq",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"liblog",
|
||||
"libpower",
|
||||
"libutils",
|
||||
],
|
||||
test_suites: ["device-tests"],
|
||||
}
|
||||
39
sensors/2.0/multihal/tests/HalProxy_test.cpp
Normal file
39
sensors/2.0/multihal/tests/HalProxy_test.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Copyright (C) 2019 The Android Open Source Project
|
||||
//
|
||||
// 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 <gtest/gtest.h>
|
||||
|
||||
#include "HalProxy.h"
|
||||
#include "SensorsSubHal.h"
|
||||
|
||||
using ::android::hardware::sensors::V2_0::implementation::HalProxy;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::SensorsSubHal;
|
||||
|
||||
// TODO: Add more interesting tests such as
|
||||
// - verify setOperationMode invokes all subhals
|
||||
// - verify if a subhal fails to change operation mode, that state is reset properly
|
||||
// - Available sensors are obtained during initialization
|
||||
//
|
||||
// You can run this suite using "atest android.hardware.sensors@2.0-halproxy-unit-tests".
|
||||
//
|
||||
// See https://source.android.com/compatibility/tests/development/native-func-e2e.md for more info
|
||||
// on how tests are set up and for information on the gtest framework itself.
|
||||
TEST(HalProxyTest, ExampleTest) {
|
||||
SensorsSubHal subHal;
|
||||
std::vector<ISensorsSubHal*> fakeSubHals;
|
||||
fakeSubHals.push_back(&subHal);
|
||||
|
||||
HalProxy proxy(fakeSubHals);
|
||||
}
|
||||
@@ -43,11 +43,14 @@ Sensor::Sensor(ISensorsEventCallback* callback)
|
||||
}
|
||||
|
||||
Sensor::~Sensor() {
|
||||
std::unique_lock<std::mutex> lock(mRunMutex);
|
||||
mStopThread = true;
|
||||
mIsEnabled = false;
|
||||
mWaitCV.notify_all();
|
||||
lock.release();
|
||||
// Ensure that lock is unlocked before calling mRunThread.join() or a
|
||||
// deadlock will occur.
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mRunMutex);
|
||||
mStopThread = true;
|
||||
mIsEnabled = false;
|
||||
mWaitCV.notify_all();
|
||||
}
|
||||
mRunThread.join();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user