From 0a51242abcf658f84d62bb97ccdfb4f623c03326 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Mon, 30 Mar 2020 17:17:21 -0700 Subject: [PATCH] Convert InputClassifierTest to parametrized test The test is currently based on old vts harness and not in vts suite. Bug: 150383004 Test: atest VtsHalInputClassifierV1_0TargetTest Change-Id: I5df4eff845fd49b8663d1589c5314d5acf4b5057 Merged-In: I5df4eff845fd49b8663d1589c5314d5acf4b5057 (cherry picked from commit 25a866eecc75058be54a837fe5c00df496e626ca) --- .../classifier/1.0/vts/functional/Android.bp | 6 ++- .../VtsHalInputClassifierV1_0TargetTest.cpp | 47 ++++++------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/input/classifier/1.0/vts/functional/Android.bp b/input/classifier/1.0/vts/functional/Android.bp index ef49d70dfb..4db1398778 100644 --- a/input/classifier/1.0/vts/functional/Android.bp +++ b/input/classifier/1.0/vts/functional/Android.bp @@ -22,6 +22,8 @@ cc_test { "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 f033c2a102..ee529c73b0 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 -#include #include #include #include +#include +#include +#include #include #include @@ -72,27 +73,11 @@ static MotionEvent getSimpleMotionEvent() { 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(); } - - 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 { public: virtual void SetUp() override { - classifier = ::testing::VtsHalHidlTargetTestBase::getService( - InputClassifierHidlEnvironment::Instance()->getServiceName()); + classifier = IInputClassifier::getService(GetParam()); ASSERT_NE(classifier, nullptr); } @@ -105,7 +90,7 @@ class InputClassifierHidlTest_1_0 : public ::testing::VtsHalHidlTargetTestBase { * 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 @@ TEST_F(InputClassifierHidlTest_1_0, ResetDevice) { /** * 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 @@ TEST_F(InputClassifierHidlTest_1_0, Classify_NoVideoFrame) { /** * 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 @@ TEST_F(InputClassifierHidlTest_1_0, Classify_OneVideoFrame) { * 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 @@ TEST_F(InputClassifierHidlTest_1_0, Classify_TwoVideoFrames) { 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);