Loading sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp +54 −26 Original line number Diff line number Diff line Loading @@ -182,14 +182,15 @@ class SensorsHidlTest : public SensorsHidlTestBase { int32_t getInvalidSensorHandle(); bool getDirectChannelSensor(SensorInfo* sensor, SharedMemType* memType, RateLevel* rate); void verifyDirectChannel(SharedMemType memType); void verifyRegisterDirectChannel(const SensorInfo& sensor, SharedMemType memType, std::shared_ptr<SensorsTestSharedMemory> mem, int32_t* directChannelHandle); void verifyRegisterDirectChannel(std::shared_ptr<SensorsTestSharedMemory> mem, int32_t* directChannelHandle, bool supportsSharedMemType, bool supportsAnyDirectChannel); void verifyConfigure(const SensorInfo& sensor, SharedMemType memType, int32_t directChannelHandle); void verifyUnregisterDirectChannel(const SensorInfo& sensor, SharedMemType memType, int32_t directChannelHandle); int32_t directChannelHandle, bool directChannelSupported); void verifyUnregisterDirectChannel(int32_t directChannelHandle, bool directChannelSupported); void checkRateLevel(const SensorInfo& sensor, int32_t directChannelHandle, RateLevel rateLevel); void queryDirectChannelSupport(SharedMemType memType, bool* supportsSharedMemType, bool* supportsAnyDirectChannel); }; Return<Result> SensorsHidlTest::activate(int32_t sensorHandle, bool enabled) { Loading Loading @@ -917,14 +918,34 @@ void SensorsHidlTest::checkRateLevel(const SensorInfo& sensor, int32_t directCha }); } void SensorsHidlTest::verifyRegisterDirectChannel(const SensorInfo& sensor, SharedMemType memType, std::shared_ptr<SensorsTestSharedMemory> mem, int32_t* directChannelHandle) { void SensorsHidlTest::queryDirectChannelSupport(SharedMemType memType, bool* supportsSharedMemType, bool* supportsAnyDirectChannel) { *supportsSharedMemType = false; *supportsAnyDirectChannel = false; for (const SensorInfo& curSensor : getSensorsList()) { if (isDirectChannelTypeSupported(curSensor, memType)) { *supportsSharedMemType = true; } if (isDirectChannelTypeSupported(curSensor, SharedMemType::ASHMEM) || isDirectChannelTypeSupported(curSensor, SharedMemType::GRALLOC)) { *supportsAnyDirectChannel = true; } if (*supportsSharedMemType && *supportsAnyDirectChannel) { break; } } } void SensorsHidlTest::verifyRegisterDirectChannel(std::shared_ptr<SensorsTestSharedMemory> mem, int32_t* directChannelHandle, bool supportsSharedMemType, bool supportsAnyDirectChannel) { char* buffer = mem->getBuffer(); memset(buffer, 0xff, mem->getSize()); registerDirectChannel(mem->getSharedMemInfo(), [&](Result result, int32_t channelHandle) { if (isDirectChannelTypeSupported(sensor, memType)) { if (supportsSharedMemType) { ASSERT_EQ(result, Result::OK); ASSERT_GT(channelHandle, 0); Loading @@ -933,7 +954,9 @@ void SensorsHidlTest::verifyRegisterDirectChannel(const SensorInfo& sensor, Shar ASSERT_EQ(buffer[i], 0x00); } } else { ASSERT_EQ(result, Result::INVALID_OPERATION); Result expectedResult = supportsAnyDirectChannel ? Result::BAD_VALUE : Result::INVALID_OPERATION; ASSERT_EQ(result, expectedResult); ASSERT_EQ(channelHandle, -1); } *directChannelHandle = channelHandle; Loading @@ -941,7 +964,7 @@ void SensorsHidlTest::verifyRegisterDirectChannel(const SensorInfo& sensor, Shar } void SensorsHidlTest::verifyConfigure(const SensorInfo& sensor, SharedMemType memType, int32_t directChannelHandle) { int32_t directChannelHandle, bool supportsAnyDirectChannel) { if (isDirectChannelTypeSupported(sensor, memType)) { // Verify that each rate level is properly supported checkRateLevel(sensor, directChannelHandle, RateLevel::NORMAL); Loading @@ -957,22 +980,22 @@ void SensorsHidlTest::verifyConfigure(const SensorInfo& sensor, SharedMemType me -1 /* sensorHandle */, directChannelHandle, RateLevel::STOP, [](Result result, int32_t /* reportToken */) { ASSERT_EQ(result, Result::OK); }); } else { // Direct channel is not supported for this SharedMemType // directChannelHandle will be -1 here, HAL should either reject it as a bad value if there // is some level of direct channel report, otherwise return INVALID_OPERATION if direct // channel is not supported at all Result expectedResult = supportsAnyDirectChannel ? Result::BAD_VALUE : Result::INVALID_OPERATION; configDirectReport(sensor.sensorHandle, directChannelHandle, RateLevel::NORMAL, [](Result result, int32_t /* reportToken */) { ASSERT_EQ(result, Result::INVALID_OPERATION); [expectedResult](Result result, int32_t /* reportToken */) { ASSERT_EQ(result, expectedResult); }); } } void SensorsHidlTest::verifyUnregisterDirectChannel(const SensorInfo& sensor, SharedMemType memType, int32_t directChannelHandle) { Result result = unregisterDirectChannel(directChannelHandle); if (isDirectChannelTypeSupported(sensor, memType)) { ASSERT_EQ(result, Result::OK); } else { ASSERT_EQ(result, Result::INVALID_OPERATION); } void SensorsHidlTest::verifyUnregisterDirectChannel(int32_t directChannelHandle, bool supportsAnyDirectChannel) { Result expectedResult = supportsAnyDirectChannel ? Result::OK : Result::INVALID_OPERATION; ASSERT_EQ(unregisterDirectChannel(directChannelHandle), expectedResult); } void SensorsHidlTest::verifyDirectChannel(SharedMemType memType) { Loading @@ -983,11 +1006,16 @@ void SensorsHidlTest::verifyDirectChannel(SharedMemType memType) { SensorsTestSharedMemory::create(memType, kMemSize)); ASSERT_NE(mem, nullptr); bool supportsSharedMemType; bool supportsAnyDirectChannel; queryDirectChannelSupport(memType, &supportsSharedMemType, &supportsAnyDirectChannel); for (const SensorInfo& sensor : getSensorsList()) { int32_t directChannelHandle = 0; verifyRegisterDirectChannel(sensor, memType, mem, &directChannelHandle); verifyConfigure(sensor, memType, directChannelHandle); verifyUnregisterDirectChannel(sensor, memType, directChannelHandle); verifyRegisterDirectChannel(mem, &directChannelHandle, supportsSharedMemType, supportsAnyDirectChannel); verifyConfigure(sensor, memType, directChannelHandle, supportsAnyDirectChannel); verifyUnregisterDirectChannel(directChannelHandle, supportsAnyDirectChannel); } } Loading Loading
sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp +54 −26 Original line number Diff line number Diff line Loading @@ -182,14 +182,15 @@ class SensorsHidlTest : public SensorsHidlTestBase { int32_t getInvalidSensorHandle(); bool getDirectChannelSensor(SensorInfo* sensor, SharedMemType* memType, RateLevel* rate); void verifyDirectChannel(SharedMemType memType); void verifyRegisterDirectChannel(const SensorInfo& sensor, SharedMemType memType, std::shared_ptr<SensorsTestSharedMemory> mem, int32_t* directChannelHandle); void verifyRegisterDirectChannel(std::shared_ptr<SensorsTestSharedMemory> mem, int32_t* directChannelHandle, bool supportsSharedMemType, bool supportsAnyDirectChannel); void verifyConfigure(const SensorInfo& sensor, SharedMemType memType, int32_t directChannelHandle); void verifyUnregisterDirectChannel(const SensorInfo& sensor, SharedMemType memType, int32_t directChannelHandle); int32_t directChannelHandle, bool directChannelSupported); void verifyUnregisterDirectChannel(int32_t directChannelHandle, bool directChannelSupported); void checkRateLevel(const SensorInfo& sensor, int32_t directChannelHandle, RateLevel rateLevel); void queryDirectChannelSupport(SharedMemType memType, bool* supportsSharedMemType, bool* supportsAnyDirectChannel); }; Return<Result> SensorsHidlTest::activate(int32_t sensorHandle, bool enabled) { Loading Loading @@ -917,14 +918,34 @@ void SensorsHidlTest::checkRateLevel(const SensorInfo& sensor, int32_t directCha }); } void SensorsHidlTest::verifyRegisterDirectChannel(const SensorInfo& sensor, SharedMemType memType, std::shared_ptr<SensorsTestSharedMemory> mem, int32_t* directChannelHandle) { void SensorsHidlTest::queryDirectChannelSupport(SharedMemType memType, bool* supportsSharedMemType, bool* supportsAnyDirectChannel) { *supportsSharedMemType = false; *supportsAnyDirectChannel = false; for (const SensorInfo& curSensor : getSensorsList()) { if (isDirectChannelTypeSupported(curSensor, memType)) { *supportsSharedMemType = true; } if (isDirectChannelTypeSupported(curSensor, SharedMemType::ASHMEM) || isDirectChannelTypeSupported(curSensor, SharedMemType::GRALLOC)) { *supportsAnyDirectChannel = true; } if (*supportsSharedMemType && *supportsAnyDirectChannel) { break; } } } void SensorsHidlTest::verifyRegisterDirectChannel(std::shared_ptr<SensorsTestSharedMemory> mem, int32_t* directChannelHandle, bool supportsSharedMemType, bool supportsAnyDirectChannel) { char* buffer = mem->getBuffer(); memset(buffer, 0xff, mem->getSize()); registerDirectChannel(mem->getSharedMemInfo(), [&](Result result, int32_t channelHandle) { if (isDirectChannelTypeSupported(sensor, memType)) { if (supportsSharedMemType) { ASSERT_EQ(result, Result::OK); ASSERT_GT(channelHandle, 0); Loading @@ -933,7 +954,9 @@ void SensorsHidlTest::verifyRegisterDirectChannel(const SensorInfo& sensor, Shar ASSERT_EQ(buffer[i], 0x00); } } else { ASSERT_EQ(result, Result::INVALID_OPERATION); Result expectedResult = supportsAnyDirectChannel ? Result::BAD_VALUE : Result::INVALID_OPERATION; ASSERT_EQ(result, expectedResult); ASSERT_EQ(channelHandle, -1); } *directChannelHandle = channelHandle; Loading @@ -941,7 +964,7 @@ void SensorsHidlTest::verifyRegisterDirectChannel(const SensorInfo& sensor, Shar } void SensorsHidlTest::verifyConfigure(const SensorInfo& sensor, SharedMemType memType, int32_t directChannelHandle) { int32_t directChannelHandle, bool supportsAnyDirectChannel) { if (isDirectChannelTypeSupported(sensor, memType)) { // Verify that each rate level is properly supported checkRateLevel(sensor, directChannelHandle, RateLevel::NORMAL); Loading @@ -957,22 +980,22 @@ void SensorsHidlTest::verifyConfigure(const SensorInfo& sensor, SharedMemType me -1 /* sensorHandle */, directChannelHandle, RateLevel::STOP, [](Result result, int32_t /* reportToken */) { ASSERT_EQ(result, Result::OK); }); } else { // Direct channel is not supported for this SharedMemType // directChannelHandle will be -1 here, HAL should either reject it as a bad value if there // is some level of direct channel report, otherwise return INVALID_OPERATION if direct // channel is not supported at all Result expectedResult = supportsAnyDirectChannel ? Result::BAD_VALUE : Result::INVALID_OPERATION; configDirectReport(sensor.sensorHandle, directChannelHandle, RateLevel::NORMAL, [](Result result, int32_t /* reportToken */) { ASSERT_EQ(result, Result::INVALID_OPERATION); [expectedResult](Result result, int32_t /* reportToken */) { ASSERT_EQ(result, expectedResult); }); } } void SensorsHidlTest::verifyUnregisterDirectChannel(const SensorInfo& sensor, SharedMemType memType, int32_t directChannelHandle) { Result result = unregisterDirectChannel(directChannelHandle); if (isDirectChannelTypeSupported(sensor, memType)) { ASSERT_EQ(result, Result::OK); } else { ASSERT_EQ(result, Result::INVALID_OPERATION); } void SensorsHidlTest::verifyUnregisterDirectChannel(int32_t directChannelHandle, bool supportsAnyDirectChannel) { Result expectedResult = supportsAnyDirectChannel ? Result::OK : Result::INVALID_OPERATION; ASSERT_EQ(unregisterDirectChannel(directChannelHandle), expectedResult); } void SensorsHidlTest::verifyDirectChannel(SharedMemType memType) { Loading @@ -983,11 +1006,16 @@ void SensorsHidlTest::verifyDirectChannel(SharedMemType memType) { SensorsTestSharedMemory::create(memType, kMemSize)); ASSERT_NE(mem, nullptr); bool supportsSharedMemType; bool supportsAnyDirectChannel; queryDirectChannelSupport(memType, &supportsSharedMemType, &supportsAnyDirectChannel); for (const SensorInfo& sensor : getSensorsList()) { int32_t directChannelHandle = 0; verifyRegisterDirectChannel(sensor, memType, mem, &directChannelHandle); verifyConfigure(sensor, memType, directChannelHandle); verifyUnregisterDirectChannel(sensor, memType, directChannelHandle); verifyRegisterDirectChannel(mem, &directChannelHandle, supportsSharedMemType, supportsAnyDirectChannel); verifyConfigure(sensor, memType, directChannelHandle, supportsAnyDirectChannel); verifyUnregisterDirectChannel(directChannelHandle, supportsAnyDirectChannel); } } Loading