mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:23:37 +00:00
Avoid NPD when re-initializing HAL fails
If the sensors HAL crashes or errors out during a test where we manually re-run the environment setup function (e.g. CleanupConnectionsOnInitialize), the pointer to the interface will become null. Avoid dereferencing it by checking for nullness in the per-test setup function and after each manual setup call. Also add a death recipient to help identify instances where the HAL crashes during a test. Bug: 135638664 Test: run VTS on device where HAL crashes during above mentioned test Change-Id: Iff7aa159c6b859272cfd18e7efb3ca431ea214fc
This commit is contained in:
@@ -38,6 +38,13 @@ constexpr typename std::underlying_type<EnumType>::type asBaseType(EnumType valu
|
||||
|
||||
constexpr size_t SensorsHidlEnvironmentV2_0::MAX_RECEIVE_BUFFER_EVENT_COUNT;
|
||||
|
||||
void SensorsHalDeathRecipient::serviceDied(
|
||||
uint64_t /* cookie */,
|
||||
const ::android::wp<::android::hidl::base::V1_0::IBase>& /* service */) {
|
||||
ALOGE("Sensors HAL died (likely crashed) during test");
|
||||
FAIL() << "Sensors HAL died during test";
|
||||
}
|
||||
|
||||
struct SensorsCallback : ISensorsCallback {
|
||||
Return<void> onDynamicSensorsConnected(const hidl_vec<SensorInfo>& /* sensorInfos */) {
|
||||
return Return<void>();
|
||||
@@ -56,6 +63,7 @@ bool SensorsHidlEnvironmentV2_0::resetHal() {
|
||||
if (mSensors == nullptr) {
|
||||
break;
|
||||
}
|
||||
mSensors->linkToDeath(mDeathRecipient, 0 /* cookie */);
|
||||
|
||||
// Initialize FMQs
|
||||
mEventQueue = std::make_unique<EventMessageQueue>(MAX_RECEIVE_BUFFER_EVENT_COUNT,
|
||||
|
||||
@@ -32,6 +32,13 @@ using ::android::sp;
|
||||
using ::android::hardware::MessageQueue;
|
||||
|
||||
class SensorsHidlTest;
|
||||
|
||||
class SensorsHalDeathRecipient : public ::android::hardware::hidl_death_recipient {
|
||||
virtual void serviceDied(
|
||||
uint64_t cookie,
|
||||
const ::android::wp<::android::hidl::base::V1_0::IBase>& service) override;
|
||||
};
|
||||
|
||||
class SensorsHidlEnvironmentV2_0 : public SensorsHidlEnvironmentBase {
|
||||
public:
|
||||
using Event = ::android::hardware::sensors::V1_0::Event;
|
||||
@@ -83,6 +90,11 @@ class SensorsHidlEnvironmentV2_0 : public SensorsHidlEnvironmentBase {
|
||||
*/
|
||||
sp<android::hardware::sensors::V2_0::ISensors> mSensors;
|
||||
|
||||
/**
|
||||
* Monitors the HAL for crashes, triggering test failure if seen
|
||||
*/
|
||||
sp<SensorsHalDeathRecipient> mDeathRecipient = new SensorsHalDeathRecipient();
|
||||
|
||||
/**
|
||||
* Type used to simplify the creation of the Event FMQ
|
||||
*/
|
||||
|
||||
@@ -115,7 +115,13 @@ class EventCallback : public IEventCallback {
|
||||
// The main test class for SENSORS HIDL HAL.
|
||||
|
||||
class SensorsHidlTest : public SensorsHidlTestBase {
|
||||
protected:
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
// Ensure that we have a valid environment before performing tests
|
||||
ASSERT_NE(getSensors(), nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
SensorInfo defaultSensorByType(SensorType type) override;
|
||||
std::vector<SensorInfo> getSensorsList();
|
||||
// implementation wrapper
|
||||
@@ -612,6 +618,9 @@ TEST_F(SensorsHidlTest, CallInitializeTwice) {
|
||||
std::unique_ptr<SensorsHidlEnvironmentTest> newEnv =
|
||||
std::make_unique<SensorsHidlEnvironmentTest>();
|
||||
newEnv->HidlSetUp();
|
||||
if (HasFatalFailure()) {
|
||||
return; // Exit early if setting up the new environment failed
|
||||
}
|
||||
|
||||
activateAllSensors(true);
|
||||
// Verify that the old environment does not receive any events
|
||||
@@ -624,8 +633,11 @@ TEST_F(SensorsHidlTest, CallInitializeTwice) {
|
||||
newEnv->HidlTearDown();
|
||||
|
||||
// Restore the test environment for future tests
|
||||
SensorsHidlEnvironmentV2_0::Instance()->HidlTearDown();
|
||||
SensorsHidlEnvironmentV2_0::Instance()->HidlSetUp();
|
||||
getEnvironment()->HidlTearDown();
|
||||
getEnvironment()->HidlSetUp();
|
||||
if (HasFatalFailure()) {
|
||||
return; // Exit early if resetting the environment failed
|
||||
}
|
||||
|
||||
// Ensure that the original environment is receiving events
|
||||
activateAllSensors(true);
|
||||
@@ -644,8 +656,11 @@ TEST_F(SensorsHidlTest, CleanupConnectionsOnInitialize) {
|
||||
// Clear the active sensor handles so they are not disabled during TearDown
|
||||
auto handles = mSensorHandles;
|
||||
mSensorHandles.clear();
|
||||
getEnvironment()->TearDown();
|
||||
getEnvironment()->SetUp();
|
||||
getEnvironment()->HidlTearDown();
|
||||
getEnvironment()->HidlSetUp();
|
||||
if (HasFatalFailure()) {
|
||||
return; // Exit early if resetting the environment failed
|
||||
}
|
||||
|
||||
// Verify no events are received until sensors are re-activated
|
||||
ASSERT_EQ(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), 0);
|
||||
@@ -1023,8 +1038,11 @@ TEST_F(SensorsHidlTest, CleanupDirectConnectionOnInitialize) {
|
||||
// Clear the active direct connections so they are not stopped during TearDown
|
||||
auto handles = mDirectChannelHandles;
|
||||
mDirectChannelHandles.clear();
|
||||
getEnvironment()->TearDown();
|
||||
getEnvironment()->SetUp();
|
||||
getEnvironment()->HidlTearDown();
|
||||
getEnvironment()->HidlSetUp();
|
||||
if (HasFatalFailure()) {
|
||||
return; // Exit early if resetting the environment failed
|
||||
}
|
||||
|
||||
// Attempt to configure the direct channel and expect it to fail
|
||||
configDirectReport(
|
||||
|
||||
Reference in New Issue
Block a user