Merge "Remove dependency on VtsHalHidlTargetTestEnvBase" into rvc-dev
diff --git a/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp b/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
index 5c8d0d8..0689919 100644
--- a/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
+++ b/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
@@ -1865,13 +1865,15 @@
*/
TEST_P(GraphicsMapperHidlTest, GetFromBufferDescriptorInfoPlaneLayouts) {
hidl_vec<uint8_t> vec;
- ASSERT_EQ(Error::NONE,
- mGralloc->getFromBufferDescriptorInfo(mDummyDescriptorInfo,
- gralloc4::MetadataType_PlaneLayouts, &vec));
-
- std::vector<PlaneLayout> planeLayouts;
- ASSERT_EQ(NO_ERROR, gralloc4::decodePlaneLayouts(vec, &planeLayouts));
- ASSERT_NO_FATAL_FAILURE(verifyDummyDescriptorInfoPlaneLayouts(planeLayouts));
+ const auto ret = mGralloc->getFromBufferDescriptorInfo(
+ mDummyDescriptorInfo, gralloc4::MetadataType_PlaneLayouts, &vec);
+ if (ret == Error::NONE) {
+ std::vector<PlaneLayout> planeLayouts;
+ ASSERT_EQ(NO_ERROR, gralloc4::decodePlaneLayouts(vec, &planeLayouts));
+ ASSERT_NO_FATAL_FAILURE(verifyDummyDescriptorInfoPlaneLayouts(planeLayouts));
+ } else {
+ ASSERT_EQ(Error::UNSUPPORTED, ret);
+ }
}
/**
diff --git a/input/classifier/1.0/vts/functional/Android.bp b/input/classifier/1.0/vts/functional/Android.bp
index ef49d70..4db1398 100644
--- a/input/classifier/1.0/vts/functional/Android.bp
+++ b/input/classifier/1.0/vts/functional/Android.bp
@@ -22,6 +22,8 @@
"android.hardware.input.classifier@1.0",
"android.hardware.input.common@1.0",
],
- test_suites: ["general-tests"],
+ test_suites: [
+ "general-tests",
+ "vts-core",
+ ],
}
-
diff --git a/input/classifier/1.0/vts/functional/VtsHalInputClassifierV1_0TargetTest.cpp b/input/classifier/1.0/vts/functional/VtsHalInputClassifierV1_0TargetTest.cpp
index f033c2a..ee529c7 100644
--- a/input/classifier/1.0/vts/functional/VtsHalInputClassifierV1_0TargetTest.cpp
+++ b/input/classifier/1.0/vts/functional/VtsHalInputClassifierV1_0TargetTest.cpp
@@ -16,11 +16,12 @@
#define LOG_TAG "input_classifier_hal_test"
-#include <VtsHalHidlTargetTestBase.h>
-#include <VtsHalHidlTargetTestEnvBase.h>
#include <android-base/logging.h>
#include <android/hardware/input/classifier/1.0/IInputClassifier.h>
#include <android/hardware/input/common/1.0/types.h>
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
#include <input/InputDevice.h>
#include <unistd.h>
@@ -72,27 +73,11 @@
return event;
}
-// Test environment for Input Classifier HIDL HAL.
-class InputClassifierHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
- public:
- // get the test environment singleton
- static InputClassifierHidlEnvironment* Instance() {
- static InputClassifierHidlEnvironment* instance = new InputClassifierHidlEnvironment;
- return instance;
- }
-
- virtual void registerTestServices() override { registerTestService<IInputClassifier>(); }
-
- private:
- InputClassifierHidlEnvironment() {}
-};
-
// The main test class for INPUT CLASSIFIER HIDL HAL 1.0.
-class InputClassifierHidlTest_1_0 : public ::testing::VtsHalHidlTargetTestBase {
+class InputClassifierHidlTest_1_0 : public ::testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
- classifier = ::testing::VtsHalHidlTargetTestBase::getService<IInputClassifier>(
- InputClassifierHidlEnvironment::Instance()->getServiceName<IInputClassifier>());
+ classifier = IInputClassifier::getService(GetParam());
ASSERT_NE(classifier, nullptr);
}
@@ -105,7 +90,7 @@
* Call resetDevice(..) for a few common device id values, and make sure that the HAL
* can handle the resets gracefully.
*/
-TEST_F(InputClassifierHidlTest_1_0, ResetDevice) {
+TEST_P(InputClassifierHidlTest_1_0, ResetDevice) {
EXPECT_TRUE(classifier->resetDevice(ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID).isOk());
EXPECT_TRUE(classifier->resetDevice(ReservedInputDeviceId::BUILT_IN_KEYBOARD_ID).isOk());
EXPECT_TRUE(classifier->resetDevice(1).isOk());
@@ -115,14 +100,14 @@
/**
* Call reset() on the HAL to ensure no fatal failure there.
*/
-TEST_F(InputClassifierHidlTest_1_0, ResetHal) {
+TEST_P(InputClassifierHidlTest_1_0, ResetHal) {
EXPECT_TRUE(classifier->reset().isOk());
}
/**
* Classify an event without any video frames.
*/
-TEST_F(InputClassifierHidlTest_1_0, Classify_NoVideoFrame) {
+TEST_P(InputClassifierHidlTest_1_0, Classify_NoVideoFrame) {
// Create a MotionEvent that does not have any video data
MotionEvent event = getSimpleMotionEvent();
@@ -137,7 +122,7 @@
/**
* Classify an event with one video frame. Should be the most common scenario.
*/
-TEST_F(InputClassifierHidlTest_1_0, Classify_OneVideoFrame) {
+TEST_P(InputClassifierHidlTest_1_0, Classify_OneVideoFrame) {
MotionEvent event = getSimpleMotionEvent();
VideoFrame frame;
frame.data = {1, 2, 3, 4};
@@ -163,7 +148,7 @@
* monotonically increasing timestamps. Still, we provide consistent timestamps here since that
* is the most realistic mode of operation.
*/
-TEST_F(InputClassifierHidlTest_1_0, Classify_TwoVideoFrames) {
+TEST_P(InputClassifierHidlTest_1_0, Classify_TwoVideoFrames) {
MotionEvent event = getSimpleMotionEvent();
VideoFrame frame1;
frame1.data = {1, 2, 3, 4};
@@ -183,11 +168,7 @@
classifier->reset();
}
-int main(int argc, char** argv) {
- ::testing::AddGlobalTestEnvironment(InputClassifierHidlEnvironment::Instance());
- ::testing::InitGoogleTest(&argc, argv);
- InputClassifierHidlEnvironment::Instance()->init(&argc, argv);
- int status = RUN_ALL_TESTS();
- LOG(INFO) << "Test result = " << status;
- return status;
-}
+INSTANTIATE_TEST_SUITE_P(
+ PerInstance, InputClassifierHidlTest_1_0,
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(IInputClassifier::descriptor)),
+ android::hardware::PrintInstanceNameToString);
diff --git a/radio/1.0/vts/functional/radio_hidl_hal_icc.cpp b/radio/1.0/vts/functional/radio_hidl_hal_icc.cpp
index 60cb2fe..9568524 100644
--- a/radio/1.0/vts/functional/radio_hidl_hal_icc.cpp
+++ b/radio/1.0/vts/functional/radio_hidl_hal_icc.cpp
@@ -177,9 +177,11 @@
}
/*
+ * The following test is disabled due to b/109889468
+ *
* Test IRadio.getImsiForApp() for the response returned.
*/
-TEST_P(RadioHidlTest, getImsiForApp) {
+TEST_P(RadioHidlTest, DISABLED_getImsiForApp) {
serial = GetRandomSerialNumber();
// Check success returned while getting imsi for 3GPP and 3GPP2 apps only
diff --git a/radio/1.0/vts/functional/radio_hidl_hal_misc.cpp b/radio/1.0/vts/functional/radio_hidl_hal_misc.cpp
index 9b6cc96..7228fb0 100644
--- a/radio/1.0/vts/functional/radio_hidl_hal_misc.cpp
+++ b/radio/1.0/vts/functional/radio_hidl_hal_misc.cpp
@@ -629,9 +629,11 @@
}
/*
+ * The following test is disabled due to b/64734869
+ *
* Test IRadio.requestShutdown() for the response returned.
*/
-TEST_P(RadioHidlTest, requestShutdown) {
+TEST_P(RadioHidlTest, DISABLED_requestShutdown) {
serial = GetRandomSerialNumber();
radio->requestShutdown(serial);
@@ -756,9 +758,11 @@
}
/*
+ * The following test is disabled due to b/79930549
+ *
* Test IRadio.setAllowedCarriers() for the response returned.
*/
-TEST_P(RadioHidlTest, setAllowedCarriers) {
+TEST_P(RadioHidlTest, DISABLED_setAllowedCarriers) {
serial = GetRandomSerialNumber();
CarrierRestrictions carriers;
memset(&carriers, 0, sizeof(carriers));
diff --git a/radio/1.2/vts/functional/radio_hidl_hal_api.cpp b/radio/1.2/vts/functional/radio_hidl_hal_api.cpp
index 7464307..c81a8d9 100644
--- a/radio/1.2/vts/functional/radio_hidl_hal_api.cpp
+++ b/radio/1.2/vts/functional/radio_hidl_hal_api.cpp
@@ -299,9 +299,11 @@
}
/*
+ * The following test is disabled due to b/112206766
+ *
* Test IRadio.startNetworkScan() with valid periodicity
*/
-TEST_P(RadioHidlTest_v1_2, startNetworkScan_GoodRequest1) {
+TEST_P(RadioHidlTest_v1_2, DISABLED_startNetworkScan_GoodRequest1) {
serial = GetRandomSerialNumber();
::android::hardware::radio::V1_2::NetworkScanRequest request = {
@@ -333,9 +335,11 @@
}
/*
+ * The following test is disabled due to b/112206766
+ *
* Test IRadio.startNetworkScan() with valid periodicity and plmns
*/
-TEST_P(RadioHidlTest_v1_2, startNetworkScan_GoodRequest2) {
+TEST_P(RadioHidlTest_v1_2, DISABLED_startNetworkScan_GoodRequest2) {
serial = GetRandomSerialNumber();
::android::hardware::radio::V1_2::NetworkScanRequest request = {
diff --git a/soundtrigger/2.0/vts/functional/VtsHalSoundtriggerV2_0TargetTest.cpp b/soundtrigger/2.0/vts/functional/VtsHalSoundtriggerV2_0TargetTest.cpp
index d7a7d08..63edec5 100644
--- a/soundtrigger/2.0/vts/functional/VtsHalSoundtriggerV2_0TargetTest.cpp
+++ b/soundtrigger/2.0/vts/functional/VtsHalSoundtriggerV2_0TargetTest.cpp
@@ -293,22 +293,6 @@
EXPECT_NE(0, hidlReturn);
}
-/**
- * Test ISoundTriggerHw::stopAllRecognitions() method
- *
- * Verifies that:
- * - the implementation implements this optional method or indicates it is not support by
- * returning -ENOSYS
- */
-TEST_P(SoundTriggerHidlTest, stopAllRecognitions) {
- Return<int32_t> hidlReturn(0);
-
- hidlReturn = mSoundTriggerHal->stopAllRecognitions();
-
- EXPECT_TRUE(hidlReturn.isOk());
- EXPECT_TRUE(hidlReturn == 0 || hidlReturn == -ENOSYS);
-}
-
INSTANTIATE_TEST_SUITE_P(
PerInstance, SoundTriggerHidlTest,
testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)),
diff --git a/soundtrigger/2.1/vts/functional/VtsHalSoundtriggerV2_1TargetTest.cpp b/soundtrigger/2.1/vts/functional/VtsHalSoundtriggerV2_1TargetTest.cpp
index 7f06ed9..392679d 100644
--- a/soundtrigger/2.1/vts/functional/VtsHalSoundtriggerV2_1TargetTest.cpp
+++ b/soundtrigger/2.1/vts/functional/VtsHalSoundtriggerV2_1TargetTest.cpp
@@ -172,61 +172,6 @@
};
/**
- * Test ISoundTriggerHw::getProperties() method
- *
- * Verifies that:
- * - the implementation implements the method
- * - the method returns 0 (no error)
- * - the implementation supports at least one sound model and one key phrase
- * - the implementation supports at least VOICE_TRIGGER recognition mode
- */
-TEST_P(SoundTriggerHidlTest, GetProperties) {
- ISoundTriggerHw::Properties halProperties;
- Return<void> hidlReturn;
- int ret = -ENODEV;
-
- hidlReturn = mSoundTriggerHal->getProperties([&](int rc, auto res) {
- ret = rc;
- halProperties = res;
- });
-
- EXPECT_TRUE(hidlReturn.isOk());
- EXPECT_EQ(0, ret);
- EXPECT_GT(halProperties.maxSoundModels, 0u);
- EXPECT_GT(halProperties.maxKeyPhrases, 0u);
- EXPECT_NE(0u, (halProperties.recognitionModes & (uint32_t)RecognitionMode::VOICE_TRIGGER));
-}
-
-/**
- * Test ISoundTriggerHw::loadPhraseSoundModel() method
- *
- * Verifies that:
- * - the implementation implements the method
- * - the implementation returns an error when passed a malformed sound model
- *
- * There is no way to verify that implementation actually can load a sound model because each
- * sound model is vendor specific.
- */
-TEST_P(SoundTriggerHidlTest, LoadInvalidModelFail) {
- Return<void> hidlReturn;
- int ret = -ENODEV;
- V2_0_ISoundTriggerHw::PhraseSoundModel model;
- SoundModelHandle handle;
-
- model.common.type = SoundModelType::UNKNOWN;
-
- hidlReturn =
- mSoundTriggerHal->loadPhraseSoundModel(model, mCallback, 0, [&](int32_t retval, auto res) {
- ret = retval;
- handle = res;
- });
-
- EXPECT_TRUE(hidlReturn.isOk());
- EXPECT_NE(0, ret);
- EXPECT_FALSE(monitor.wait(SHORT_TIMEOUT_PERIOD));
-}
-
-/**
* Test ISoundTriggerHw::loadPhraseSoundModel_2_1() method
*
* Verifies that:
@@ -280,34 +225,6 @@
}
/**
- * Test ISoundTriggerHw::loadSoundModel() method
- *
- * Verifies that:
- * - the implementation returns error when passed a sound model with random data.
- */
-TEST_P(SoundTriggerHidlTest, LoadGenericSoundModelFail) {
- int ret = -ENODEV;
- V2_0_ISoundTriggerHw::SoundModel model;
- SoundModelHandle handle = 0;
-
- model.type = SoundModelType::GENERIC;
- model.data.resize(100);
- for (auto& d : model.data) {
- d = rand();
- }
-
- Return<void> loadReturn =
- mSoundTriggerHal->loadSoundModel(model, mCallback, 0, [&](int32_t retval, auto res) {
- ret = retval;
- handle = res;
- });
-
- EXPECT_TRUE(loadReturn.isOk());
- EXPECT_NE(0, ret);
- EXPECT_FALSE(monitor.wait(SHORT_TIMEOUT_PERIOD));
-}
-
-/**
* Test ISoundTriggerHw::loadSoundModel_2_1() method
*
* Verifies that:
@@ -371,54 +288,6 @@
}
/**
- * Test ISoundTriggerHw::unloadSoundModel() method
- *
- * Verifies that:
- * - the implementation implements the method
- * - the implementation returns an error when called without a valid loaded sound model
- *
- */
-TEST_P(SoundTriggerHidlTest, UnloadModelNoModelFail) {
- Return<int32_t> hidlReturn(0);
- SoundModelHandle halHandle = 0;
-
- hidlReturn = mSoundTriggerHal->unloadSoundModel(halHandle);
-
- EXPECT_TRUE(hidlReturn.isOk());
- EXPECT_NE(0, hidlReturn);
-}
-
-/**
- * Test ISoundTriggerHw::startRecognition() method
- *
- * Verifies that:
- * - the implementation implements the method
- * - the implementation returns an error when called without a valid loaded sound model
- *
- * There is no way to verify that implementation actually starts recognition because no model can
- * be loaded.
- */
-TEST_P(SoundTriggerHidlTest, StartRecognitionNoModelFail) {
- Return<int32_t> hidlReturn(0);
- SoundModelHandle handle = 0;
- PhraseRecognitionExtra phrase;
- V2_0_ISoundTriggerHw::RecognitionConfig config;
-
- config.captureHandle = 0;
- config.captureDevice = AudioDevice::IN_BUILTIN_MIC;
- phrase.id = 0;
- phrase.recognitionModes = (uint32_t)RecognitionMode::VOICE_TRIGGER;
- phrase.confidenceLevel = 0;
-
- config.phrases.setToExternal(&phrase, 1);
-
- hidlReturn = mSoundTriggerHal->startRecognition(handle, config, mCallback, 0);
-
- EXPECT_TRUE(hidlReturn.isOk());
- EXPECT_NE(0, hidlReturn);
-}
-
-/**
* Test ISoundTriggerHw::startRecognition_2_1() method
*
* Verifies that:
@@ -448,40 +317,6 @@
EXPECT_NE(0, hidlReturn);
}
-/**
- * Test ISoundTriggerHw::stopRecognition() method
- *
- * Verifies that:
- * - the implementation implements the method
- * - the implementation returns an error when called without an active recognition running
- *
- */
-TEST_P(SoundTriggerHidlTest, StopRecognitionNoAStartFail) {
- Return<int32_t> hidlReturn(0);
- SoundModelHandle handle = 0;
-
- hidlReturn = mSoundTriggerHal->stopRecognition(handle);
-
- EXPECT_TRUE(hidlReturn.isOk());
- EXPECT_NE(0, hidlReturn);
-}
-
-/**
- * Test ISoundTriggerHw::stopAllRecognitions() method
- *
- * Verifies that:
- * - the implementation implements this optional method or indicates it is not supported by
- * returning -ENOSYS
- */
-TEST_P(SoundTriggerHidlTest, stopAllRecognitions) {
- Return<int32_t> hidlReturn(0);
-
- hidlReturn = mSoundTriggerHal->stopAllRecognitions();
-
- EXPECT_TRUE(hidlReturn.isOk());
- EXPECT_TRUE(hidlReturn == 0 || hidlReturn == -ENOSYS);
-}
-
INSTANTIATE_TEST_SUITE_P(
PerInstance, SoundTriggerHidlTest,
testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)),
diff --git a/tv/input/1.0/vts/functional/Android.bp b/tv/input/1.0/vts/functional/Android.bp
index 29181b0..5d20bce 100644
--- a/tv/input/1.0/vts/functional/Android.bp
+++ b/tv/input/1.0/vts/functional/Android.bp
@@ -19,6 +19,9 @@
defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalTvInputV1_0TargetTest.cpp"],
static_libs: ["android.hardware.tv.input@1.0"],
- test_suites: ["general-tests"],
+ test_suites: [
+ "general-tests",
+ "vts-core",
+ ],
+ require_root: true,
}
-
diff --git a/tv/input/1.0/vts/functional/VtsHalTvInputV1_0TargetTest.cpp b/tv/input/1.0/vts/functional/VtsHalTvInputV1_0TargetTest.cpp
index 573a1d6..59c70eb 100644
--- a/tv/input/1.0/vts/functional/VtsHalTvInputV1_0TargetTest.cpp
+++ b/tv/input/1.0/vts/functional/VtsHalTvInputV1_0TargetTest.cpp
@@ -17,11 +17,12 @@
#define LOG_TAG "tv_input_hidl_hal_test"
#include <android-base/logging.h>
-#include <android/hardware/tv/input/1.0/types.h>
#include <android/hardware/tv/input/1.0/ITvInput.h>
#include <android/hardware/tv/input/1.0/ITvInputCallback.h>
-
-#include <VtsHalHidlTargetTestBase.h>
+#include <android/hardware/tv/input/1.0/types.h>
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
#include <utils/KeyedVector.h>
#include <mutex>
#include <vector>
@@ -42,179 +43,161 @@
#define WAIT_FOR_EVENT_TIMEOUT 5
#define DEFAULT_ID INT32_MIN
-// Test environment for TvInput HIDL HAL.
-class TvInputHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
- public:
- // get the test environment singleton
- static TvInputHidlEnvironment* Instance() {
- static TvInputHidlEnvironment* instance = new TvInputHidlEnvironment;
- return instance;
- }
-
- virtual void registerTestServices() override { registerTestService<ITvInput>(); }
-
- private:
- TvInputHidlEnvironment() {}
-};
-
/* The main test class for TV Input HIDL HAL. */
-class TvInputHidlTest : public ::testing::VtsHalHidlTargetTestBase {
- public:
- virtual void SetUp() override {
- tv_input_ = ::testing::VtsHalHidlTargetTestBase::getService<ITvInput>(
- TvInputHidlEnvironment::Instance()->getServiceName<ITvInput>());
- ASSERT_NE(tv_input_, nullptr);
- tv_input_callback_ = new TvInputCallback(*this);
- ASSERT_NE(tv_input_callback_, nullptr);
- tv_input_->setCallback(tv_input_callback_);
- // All events received within the timeout should be handled.
- sleep(WAIT_FOR_EVENT_TIMEOUT);
- }
-
- virtual void TearDown() override {}
-
- /* Called when a DEVICE_AVAILABLE event is received. */
- void onDeviceAvailable(const TvInputDeviceInfo& deviceInfo) {
- device_info_.add(deviceInfo.deviceId, deviceInfo);
- }
-
- /* Called when a DEVICE_UNAVAILABLE event is received. */
- void onDeviceUnavailable(int32_t deviceId) {
- device_info_.removeItem(deviceId);
- }
-
- /* Called when a DEVICE_CONFIGURATIONS_CHANGED event is received. */
- Result onStreamConfigurationsChanged(int32_t deviceId) {
- return updateStreamConfigurations(deviceId);
- }
-
- /* Gets and updates the stream configurations for a device. */
- Result updateStreamConfigurations(int32_t deviceId) {
- stream_config_.removeItem(deviceId);
- Result result = Result::UNKNOWN;
- hidl_vec<TvStreamConfig> list;
- tv_input_->getStreamConfigurations(deviceId,
- [&result, &list](Result res, hidl_vec<TvStreamConfig> configs) {
- result = res;
- if (res == Result::OK) {
- list = configs;
- }
- });
- if (result == Result::OK) {
- stream_config_.add(deviceId, list);
- }
- return result;
- }
-
- /* Gets and updates the stream configurations for all existing devices. */
- void updateAllStreamConfigurations() {
- for (size_t i = 0; i < device_info_.size(); i++) {
- int32_t device_id = device_info_.keyAt(i);
- updateStreamConfigurations(device_id);
- }
- }
-
- /* Returns a list of indices of stream_config_ whose corresponding values are not empty. */
- std::vector<size_t> getConfigIndices() {
- std::vector<size_t> indices;
- for (size_t i = 0; i < stream_config_.size(); i++) {
- if (stream_config_.valueAt(i).size() != 0) {
- indices.push_back(i);
- }
- }
- return indices;
- }
-
- /*
- * Returns DEFAULT_ID if there is no missing integer in the range [0, the size of nums).
- * Otherwise, returns the smallest missing non-negative integer.
- */
- int32_t getNumNotIn(std::vector<int32_t>& nums) {
- int32_t result = DEFAULT_ID;
- int32_t size = static_cast<int32_t>(nums.size());
- for (int32_t i = 0; i < size; i++) {
- // Put every element to its target position, if possible.
- int32_t target_pos = nums[i];
- while (target_pos >= 0 && target_pos < size && i != target_pos && nums[i] != nums[target_pos]) {
- std::swap(nums[i], nums[target_pos]);
- target_pos = nums[i];
- }
+class TvInputHidlTest : public testing::TestWithParam<std::string> {
+ public:
+ virtual void SetUp() override {
+ tv_input_ = ITvInput::getService(GetParam());
+ tv_input_callback_ = new TvInputCallback(*this);
+ ASSERT_NE(tv_input_callback_, nullptr);
+ tv_input_->setCallback(tv_input_callback_);
+ // All events received within the timeout should be handled.
+ sleep(WAIT_FOR_EVENT_TIMEOUT);
}
- for (int32_t i = 0; i < size; i++) {
- if (nums[i] != i) {
- return i;
- }
+ virtual void TearDown() override {}
+
+ /* Called when a DEVICE_AVAILABLE event is received. */
+ void onDeviceAvailable(const TvInputDeviceInfo& deviceInfo) {
+ device_info_.add(deviceInfo.deviceId, deviceInfo);
}
- return result;
- }
- /* A simple test implementation of TvInputCallback for TV Input Events. */
- class TvInputCallback : public ITvInputCallback {
- public:
- TvInputCallback(TvInputHidlTest& parent) : parent_(parent){};
+ /* Called when a DEVICE_UNAVAILABLE event is received. */
+ void onDeviceUnavailable(int32_t deviceId) { device_info_.removeItem(deviceId); }
- virtual ~TvInputCallback() = default;
+ /* Called when a DEVICE_CONFIGURATIONS_CHANGED event is received. */
+ Result onStreamConfigurationsChanged(int32_t deviceId) {
+ return updateStreamConfigurations(deviceId);
+ }
- /*
- * Notifies the client that an event has occured. For possible event types,
- * check TvInputEventType.
- */
- Return<void> notify(const TvInputEvent& event) override {
- std::unique_lock<std::mutex> lock(parent_.mutex_);
- switch(event.type) {
- case TvInputEventType::DEVICE_AVAILABLE:
- parent_.onDeviceAvailable(event.deviceInfo);
- break;
- case TvInputEventType::DEVICE_UNAVAILABLE:
- parent_.onDeviceUnavailable(event.deviceInfo.deviceId);
- break;
- case TvInputEventType::STREAM_CONFIGURATIONS_CHANGED:
- parent_.onStreamConfigurationsChanged(event.deviceInfo.deviceId);
- break;
- }
- return Void();
- };
- private:
- /* The test contains this callback instance. */
- TvInputHidlTest& parent_;
- };
+ /* Gets and updates the stream configurations for a device. */
+ Result updateStreamConfigurations(int32_t deviceId) {
+ stream_config_.removeItem(deviceId);
+ Result result = Result::UNKNOWN;
+ hidl_vec<TvStreamConfig> list;
+ tv_input_->getStreamConfigurations(
+ deviceId, [&result, &list](Result res, hidl_vec<TvStreamConfig> configs) {
+ result = res;
+ if (res == Result::OK) {
+ list = configs;
+ }
+ });
+ if (result == Result::OK) {
+ stream_config_.add(deviceId, list);
+ }
+ return result;
+ }
- /* The TvInput used for the test. */
- sp<ITvInput> tv_input_;
+ /* Gets and updates the stream configurations for all existing devices. */
+ void updateAllStreamConfigurations() {
+ for (size_t i = 0; i < device_info_.size(); i++) {
+ int32_t device_id = device_info_.keyAt(i);
+ updateStreamConfigurations(device_id);
+ }
+ }
- /* The TvInputCallback used for the test. */
- sp<ITvInputCallback> tv_input_callback_;
+ /* Returns a list of indices of stream_config_ whose corresponding values are not empty. */
+ std::vector<size_t> getConfigIndices() {
+ std::vector<size_t> indices;
+ for (size_t i = 0; i < stream_config_.size(); i++) {
+ if (stream_config_.valueAt(i).size() != 0) {
+ indices.push_back(i);
+ }
+ }
+ return indices;
+ }
- /*
- * A KeyedVector stores device information of every available device.
- * A key is a device ID and the corresponding value is the TvInputDeviceInfo.
- */
- android::KeyedVector<int32_t, TvInputDeviceInfo> device_info_;
+ /*
+ * Returns DEFAULT_ID if there is no missing integer in the range [0, the size of nums).
+ * Otherwise, returns the smallest missing non-negative integer.
+ */
+ int32_t getNumNotIn(std::vector<int32_t>& nums) {
+ int32_t result = DEFAULT_ID;
+ int32_t size = static_cast<int32_t>(nums.size());
+ for (int32_t i = 0; i < size; i++) {
+ // Put every element to its target position, if possible.
+ int32_t target_pos = nums[i];
+ while (target_pos >= 0 && target_pos < size && i != target_pos &&
+ nums[i] != nums[target_pos]) {
+ std::swap(nums[i], nums[target_pos]);
+ target_pos = nums[i];
+ }
+ }
- /*
- * A KeyedVector stores a list of stream configurations of every available device.
- * A key is a device ID and the corresponding value is the stream configuration list.
- */
- android::KeyedVector<int32_t, hidl_vec<TvStreamConfig>> stream_config_;
+ for (int32_t i = 0; i < size; i++) {
+ if (nums[i] != i) {
+ return i;
+ }
+ }
+ return result;
+ }
- /* The mutex controls the access of shared data. */
- std::mutex mutex_;
+ /* A simple test implementation of TvInputCallback for TV Input Events. */
+ class TvInputCallback : public ITvInputCallback {
+ public:
+ TvInputCallback(TvInputHidlTest& parent) : parent_(parent){};
+
+ virtual ~TvInputCallback() = default;
+
+ /*
+ * Notifies the client that an event has occurred. For possible event types,
+ * check TvInputEventType.
+ */
+ Return<void> notify(const TvInputEvent& event) override {
+ std::unique_lock<std::mutex> lock(parent_.mutex_);
+ switch (event.type) {
+ case TvInputEventType::DEVICE_AVAILABLE:
+ parent_.onDeviceAvailable(event.deviceInfo);
+ break;
+ case TvInputEventType::DEVICE_UNAVAILABLE:
+ parent_.onDeviceUnavailable(event.deviceInfo.deviceId);
+ break;
+ case TvInputEventType::STREAM_CONFIGURATIONS_CHANGED:
+ parent_.onStreamConfigurationsChanged(event.deviceInfo.deviceId);
+ break;
+ }
+ return Void();
+ };
+
+ private:
+ /* The test contains this callback instance. */
+ TvInputHidlTest& parent_;
+ };
+
+ /* The TvInput used for the test. */
+ sp<ITvInput> tv_input_;
+
+ /* The TvInputCallback used for the test. */
+ sp<ITvInputCallback> tv_input_callback_;
+
+ /*
+ * A KeyedVector stores device information of every available device.
+ * A key is a device ID and the corresponding value is the TvInputDeviceInfo.
+ */
+ android::KeyedVector<int32_t, TvInputDeviceInfo> device_info_;
+
+ /*
+ * A KeyedVector stores a list of stream configurations of every available device.
+ * A key is a device ID and the corresponding value is the stream configuration list.
+ */
+ android::KeyedVector<int32_t, hidl_vec<TvStreamConfig>> stream_config_;
+
+ /* The mutex controls the access of shared data. */
+ std::mutex mutex_;
};
-
/*
* GetStreamConfigTest:
* Calls updateStreamConfigurations() for each existing device
* Checks returned results
*/
-TEST_F(TvInputHidlTest, GetStreamConfigTest) {
- std::unique_lock<std::mutex> lock(mutex_);
- for (size_t i = 0; i < device_info_.size(); i++) {
- int32_t device_id = device_info_.keyAt(i);
- Result result = updateStreamConfigurations(device_id);
- EXPECT_EQ(Result::OK, result);
- }
+TEST_P(TvInputHidlTest, GetStreamConfigTest) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ for (size_t i = 0; i < device_info_.size(); i++) {
+ int32_t device_id = device_info_.keyAt(i);
+ Result result = updateStreamConfigurations(device_id);
+ EXPECT_EQ(Result::OK, result);
+ }
}
/*
@@ -222,26 +205,24 @@
* Calls openStream() and then closeStream() for each existing stream
* Checks returned results
*/
-TEST_F(TvInputHidlTest, OpenAndCloseStreamTest) {
- std::unique_lock<std::mutex> lock(mutex_);
- updateAllStreamConfigurations();
- for (size_t j = 0; j < stream_config_.size(); j++) {
- int32_t device_id = stream_config_.keyAt(j);
- hidl_vec<TvStreamConfig> config = stream_config_.valueAt(j);
- for (size_t i = 0; i < config.size(); i++) {
- Result result = Result::UNKNOWN;
- int32_t stream_id = config[i].streamId;
- tv_input_->openStream(device_id, stream_id,
- [&result](Result res, const native_handle_t*) {
- result = res;
- });
- EXPECT_EQ(Result::OK, result);
+TEST_P(TvInputHidlTest, OpenAndCloseStreamTest) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ updateAllStreamConfigurations();
+ for (size_t j = 0; j < stream_config_.size(); j++) {
+ int32_t device_id = stream_config_.keyAt(j);
+ hidl_vec<TvStreamConfig> config = stream_config_.valueAt(j);
+ for (size_t i = 0; i < config.size(); i++) {
+ Result result = Result::UNKNOWN;
+ int32_t stream_id = config[i].streamId;
+ tv_input_->openStream(device_id, stream_id,
+ [&result](Result res, const native_handle_t*) { result = res; });
+ EXPECT_EQ(Result::OK, result);
- result = Result::UNKNOWN;
- result = tv_input_->closeStream(device_id, stream_id);
- EXPECT_EQ(Result::OK, result);
+ result = Result::UNKNOWN;
+ result = tv_input_->closeStream(device_id, stream_id);
+ EXPECT_EQ(Result::OK, result);
+ }
}
- }
}
/*
@@ -251,28 +232,26 @@
* Checks returned results
* The results should be Result::INVALID_ARGUMENTS
*/
-TEST_F(TvInputHidlTest, InvalidDeviceIdTest) {
- std::unique_lock<std::mutex> lock(mutex_);
+TEST_P(TvInputHidlTest, InvalidDeviceIdTest) {
+ std::unique_lock<std::mutex> lock(mutex_);
- std::vector<int32_t> device_ids;
- for (size_t i = 0; i < device_info_.size(); i++) {
- device_ids.push_back(device_info_.keyAt(i));
- }
- // Get a non-existing device ID.
- int32_t id = getNumNotIn(device_ids);
- EXPECT_EQ(Result::INVALID_ARGUMENTS, updateStreamConfigurations(id));
+ std::vector<int32_t> device_ids;
+ for (size_t i = 0; i < device_info_.size(); i++) {
+ device_ids.push_back(device_info_.keyAt(i));
+ }
+ // Get a non-existing device ID.
+ int32_t id = getNumNotIn(device_ids);
+ EXPECT_EQ(Result::INVALID_ARGUMENTS, updateStreamConfigurations(id));
- Result result = Result::UNKNOWN;
- int32_t stream_id = 0;
- tv_input_->openStream(id, stream_id,
- [&result](Result res, const native_handle_t*) {
- result = res;
- });
- EXPECT_EQ(Result::INVALID_ARGUMENTS, result);
+ Result result = Result::UNKNOWN;
+ int32_t stream_id = 0;
+ tv_input_->openStream(id, stream_id,
+ [&result](Result res, const native_handle_t*) { result = res; });
+ EXPECT_EQ(Result::INVALID_ARGUMENTS, result);
- result = Result::UNKNOWN;
- result = tv_input_->closeStream(id, stream_id);
- EXPECT_EQ(Result::INVALID_ARGUMENTS, result);
+ result = Result::UNKNOWN;
+ result = tv_input_->closeStream(id, stream_id);
+ EXPECT_EQ(Result::INVALID_ARGUMENTS, result);
}
/*
@@ -281,35 +260,33 @@
* Checks returned results
* The results should be Result::INVALID_ARGUMENTS
*/
-TEST_F(TvInputHidlTest, InvalidStreamIdTest) {
- std::unique_lock<std::mutex> lock(mutex_);
- if (device_info_.isEmpty()) {
- return;
- }
- updateAllStreamConfigurations();
-
- int32_t device_id = device_info_.keyAt(0);
- // Get a non-existing stream ID.
- int32_t id = DEFAULT_ID;
- if (stream_config_.indexOfKey(device_id) >= 0) {
- std::vector<int32_t> stream_ids;
- hidl_vec<TvStreamConfig> config = stream_config_.valueFor(device_id);
- for (size_t i = 0; i < config.size(); i++) {
- stream_ids.push_back(config[i].streamId);
+TEST_P(TvInputHidlTest, InvalidStreamIdTest) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ if (device_info_.isEmpty()) {
+ return;
}
- id = getNumNotIn(stream_ids);
- }
+ updateAllStreamConfigurations();
- Result result = Result::UNKNOWN;
- tv_input_->openStream(device_id, id,
- [&result](Result res, const native_handle_t*) {
- result = res;
- });
- EXPECT_EQ(Result::INVALID_ARGUMENTS, result);
+ int32_t device_id = device_info_.keyAt(0);
+ // Get a non-existing stream ID.
+ int32_t id = DEFAULT_ID;
+ if (stream_config_.indexOfKey(device_id) >= 0) {
+ std::vector<int32_t> stream_ids;
+ hidl_vec<TvStreamConfig> config = stream_config_.valueFor(device_id);
+ for (size_t i = 0; i < config.size(); i++) {
+ stream_ids.push_back(config[i].streamId);
+ }
+ id = getNumNotIn(stream_ids);
+ }
- result = Result::UNKNOWN;
- result = tv_input_->closeStream(device_id, id);
- EXPECT_EQ(Result::INVALID_ARGUMENTS, result);
+ Result result = Result::UNKNOWN;
+ tv_input_->openStream(device_id, id,
+ [&result](Result res, const native_handle_t*) { result = res; });
+ EXPECT_EQ(Result::INVALID_ARGUMENTS, result);
+
+ result = Result::UNKNOWN;
+ result = tv_input_->closeStream(device_id, id);
+ EXPECT_EQ(Result::INVALID_ARGUMENTS, result);
}
/*
@@ -318,28 +295,24 @@
* Checks returned results
* The result of the second call should be Result::INVALID_STATE
*/
-TEST_F(TvInputHidlTest, OpenAnOpenedStreamsTest) {
- std::unique_lock<std::mutex> lock(mutex_);
- updateAllStreamConfigurations();
- std::vector<size_t> indices = getConfigIndices();
- if (indices.empty()) {
- return;
- }
- int32_t device_id = stream_config_.keyAt(indices[0]);
- int32_t stream_id = stream_config_.valueAt(indices[0])[0].streamId;
+TEST_P(TvInputHidlTest, OpenAnOpenedStreamsTest) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ updateAllStreamConfigurations();
+ std::vector<size_t> indices = getConfigIndices();
+ if (indices.empty()) {
+ return;
+ }
+ int32_t device_id = stream_config_.keyAt(indices[0]);
+ int32_t stream_id = stream_config_.valueAt(indices[0])[0].streamId;
- Result result = Result::UNKNOWN;
- tv_input_->openStream(device_id, stream_id,
- [&result](Result res, const native_handle_t*) {
- result = res;
- });
- EXPECT_EQ(Result::OK, result);
+ Result result = Result::UNKNOWN;
+ tv_input_->openStream(device_id, stream_id,
+ [&result](Result res, const native_handle_t*) { result = res; });
+ EXPECT_EQ(Result::OK, result);
- tv_input_->openStream(device_id, stream_id,
- [&result](Result res, const native_handle_t*) {
- result = res;
- });
- EXPECT_EQ(Result::INVALID_STATE, result);
+ tv_input_->openStream(device_id, stream_id,
+ [&result](Result res, const native_handle_t*) { result = res; });
+ EXPECT_EQ(Result::INVALID_STATE, result);
}
/*
@@ -348,24 +321,19 @@
* Checks the returned result
* The result should be Result::INVALID_STATE
*/
-TEST_F(TvInputHidlTest, CloseStreamBeforeOpenTest) {
- std::unique_lock<std::mutex> lock(mutex_);
- updateAllStreamConfigurations();
- std::vector<size_t> indices = getConfigIndices();
- if (indices.empty()) {
- return;
- }
- int32_t device_id = stream_config_.keyAt(indices[0]);
- int32_t stream_id = stream_config_.valueAt(indices[0])[0].streamId;
- EXPECT_EQ(Result::INVALID_STATE, tv_input_->closeStream(device_id, stream_id));
+TEST_P(TvInputHidlTest, CloseStreamBeforeOpenTest) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ updateAllStreamConfigurations();
+ std::vector<size_t> indices = getConfigIndices();
+ if (indices.empty()) {
+ return;
+ }
+ int32_t device_id = stream_config_.keyAt(indices[0]);
+ int32_t stream_id = stream_config_.valueAt(indices[0])[0].streamId;
+ EXPECT_EQ(Result::INVALID_STATE, tv_input_->closeStream(device_id, stream_id));
}
-int main(int argc, char **argv) {
- ::testing::AddGlobalTestEnvironment(TvInputHidlEnvironment::Instance());
- ::testing::InitGoogleTest(&argc, argv);
- TvInputHidlEnvironment::Instance()->init(&argc, argv);
- int status = RUN_ALL_TESTS();
- ALOGI("Test result = %d", status);
- return status;
-}
-
+INSTANTIATE_TEST_SUITE_P(
+ PerInstance, TvInputHidlTest,
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(ITvInput::descriptor)),
+ android::hardware::PrintInstanceNameToString);