Merge "[vts-core] add VtsHalVibratorV1_*TargetTest to vts-core"
This commit is contained in:
commit
48141f00ab
8 changed files with 66 additions and 142 deletions
|
@ -19,6 +19,6 @@ cc_test {
|
|||
defaults: ["VtsHalTargetTestDefaults"],
|
||||
srcs: ["VtsHalVibratorV1_0TargetTest.cpp"],
|
||||
static_libs: ["android.hardware.vibrator@1.0"],
|
||||
test_suites: ["general-tests"],
|
||||
test_suites: ["general-tests", "vts-core"],
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,9 @@
|
|||
#include <android/hardware/vibrator/1.0/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
#include <VtsHalHidlTargetTestEnvBase.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <hidl/GtestPrinter.h>
|
||||
#include <hidl/ServiceManagement.h>
|
||||
|
||||
using ::android::sp;
|
||||
using ::android::hardware::hidl_enum_range;
|
||||
|
@ -35,27 +36,11 @@ using ::android::hardware::vibrator::V1_0::Status;
|
|||
|
||||
#define EXPECT_OK(ret) EXPECT_TRUE((ret).isOk())
|
||||
|
||||
// Test environment for Vibrator HIDL HAL.
|
||||
class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
|
||||
public:
|
||||
// get the test environment singleton
|
||||
static VibratorHidlEnvironment* Instance() {
|
||||
static VibratorHidlEnvironment* instance = new VibratorHidlEnvironment;
|
||||
return instance;
|
||||
}
|
||||
|
||||
virtual void registerTestServices() override { registerTestService<IVibrator>(); }
|
||||
|
||||
private:
|
||||
VibratorHidlEnvironment() {}
|
||||
};
|
||||
|
||||
// The main test class for VIBRATOR HIDL HAL.
|
||||
class VibratorHidlTest : public ::testing::VtsHalHidlTargetTestBase {
|
||||
class VibratorHidlTest : public ::testing::TestWithParam<std::string> {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>(
|
||||
VibratorHidlEnvironment::Instance()->getServiceName<IVibrator>());
|
||||
vibrator = IVibrator::getService(GetParam());
|
||||
ASSERT_NE(vibrator, nullptr);
|
||||
}
|
||||
|
||||
|
@ -79,13 +64,13 @@ static void validatePerformEffectBadInput(Status status, uint32_t lengthMs) {
|
|||
<< "Effects that return UNSUPPORTED_OPERATION must have a duration of zero";
|
||||
}
|
||||
|
||||
TEST_F(VibratorHidlTest, OnThenOffBeforeTimeout) {
|
||||
TEST_P(VibratorHidlTest, OnThenOffBeforeTimeout) {
|
||||
EXPECT_EQ(Status::OK, vibrator->on(2000));
|
||||
sleep(1);
|
||||
EXPECT_EQ(Status::OK, vibrator->off());
|
||||
}
|
||||
|
||||
TEST_F(VibratorHidlTest, PerformEffect) {
|
||||
TEST_P(VibratorHidlTest, PerformEffect) {
|
||||
vibrator->perform(Effect::CLICK, EffectStrength::MEDIUM, validatePerformEffect);
|
||||
vibrator->perform(Effect::DOUBLE_CLICK, EffectStrength::LIGHT, validatePerformEffect);
|
||||
}
|
||||
|
@ -93,7 +78,7 @@ TEST_F(VibratorHidlTest, PerformEffect) {
|
|||
/*
|
||||
* Test to make sure effect values above the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest, PerformEffect_BadEffects_AboveValidRange) {
|
||||
TEST_P(VibratorHidlTest, PerformEffect_BadEffects_AboveValidRange) {
|
||||
Effect effect = *std::prev(hidl_enum_range<Effect>().end());
|
||||
Effect badEffect = static_cast<Effect>(static_cast<int32_t>(effect) + 1);
|
||||
EXPECT_OK(vibrator->perform(badEffect, EffectStrength::LIGHT, validatePerformEffectBadInput));
|
||||
|
@ -102,7 +87,7 @@ TEST_F(VibratorHidlTest, PerformEffect_BadEffects_AboveValidRange) {
|
|||
/*
|
||||
* Test to make sure effect values below the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest, PerformEffect_BadEffects_BelowValidRange) {
|
||||
TEST_P(VibratorHidlTest, PerformEffect_BadEffects_BelowValidRange) {
|
||||
Effect effect = *hidl_enum_range<Effect>().begin();
|
||||
Effect badEffect = static_cast<Effect>(static_cast<int32_t>(effect) - 1);
|
||||
EXPECT_OK(vibrator->perform(badEffect, EffectStrength::LIGHT, validatePerformEffectBadInput));
|
||||
|
@ -111,7 +96,7 @@ TEST_F(VibratorHidlTest, PerformEffect_BadEffects_BelowValidRange) {
|
|||
/*
|
||||
* Test to make sure strength values above the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest, PerformEffect_BadStrength_AboveValidRange) {
|
||||
TEST_P(VibratorHidlTest, PerformEffect_BadStrength_AboveValidRange) {
|
||||
EffectStrength strength = *std::prev(hidl_enum_range<EffectStrength>().end());
|
||||
EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) + 1);
|
||||
EXPECT_OK(vibrator->perform(Effect::CLICK, badStrength, validatePerformEffectBadInput));
|
||||
|
@ -120,13 +105,13 @@ TEST_F(VibratorHidlTest, PerformEffect_BadStrength_AboveValidRange) {
|
|||
/*
|
||||
* Test to make sure strength values below the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest, PerformEffect_BadStrength_BelowValidRange) {
|
||||
TEST_P(VibratorHidlTest, PerformEffect_BadStrength_BelowValidRange) {
|
||||
EffectStrength strength = *hidl_enum_range<EffectStrength>().begin();
|
||||
EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) - 1);
|
||||
EXPECT_OK(vibrator->perform(Effect::CLICK, badStrength, validatePerformEffectBadInput));
|
||||
}
|
||||
|
||||
TEST_F(VibratorHidlTest, ChangeVibrationalAmplitude) {
|
||||
TEST_P(VibratorHidlTest, ChangeVibrationalAmplitude) {
|
||||
if (vibrator->supportsAmplitudeControl()) {
|
||||
EXPECT_EQ(Status::OK, vibrator->setAmplitude(1));
|
||||
EXPECT_EQ(Status::OK, vibrator->on(2000));
|
||||
|
@ -137,23 +122,19 @@ TEST_F(VibratorHidlTest, ChangeVibrationalAmplitude) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(VibratorHidlTest, AmplitudeOutsideRangeFails) {
|
||||
TEST_P(VibratorHidlTest, AmplitudeOutsideRangeFails) {
|
||||
if (vibrator->supportsAmplitudeControl()) {
|
||||
EXPECT_EQ(Status::BAD_VALUE, vibrator->setAmplitude(0));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(VibratorHidlTest, SetAmplitudeReturnUnsupportedOperationIfNotSupported) {
|
||||
TEST_P(VibratorHidlTest, SetAmplitudeReturnUnsupportedOperationIfNotSupported) {
|
||||
if (!vibrator->supportsAmplitudeControl()) {
|
||||
EXPECT_EQ(Status::UNSUPPORTED_OPERATION, vibrator->setAmplitude(1));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance());
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
VibratorHidlEnvironment::Instance()->init(&argc, argv);
|
||||
int status = RUN_ALL_TESTS();
|
||||
LOG(INFO) << "Test result = " << status;
|
||||
return status;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
PerInstance, VibratorHidlTest,
|
||||
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IVibrator::descriptor)),
|
||||
android::hardware::PrintInstanceNameToString);
|
||||
|
|
|
@ -22,6 +22,6 @@ cc_test {
|
|||
"android.hardware.vibrator@1.0",
|
||||
"android.hardware.vibrator@1.1",
|
||||
],
|
||||
test_suites: ["general-tests"],
|
||||
test_suites: ["general-tests", "vts-core"],
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
|
||||
#define LOG_TAG "vibrator_hidl_hal_test"
|
||||
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
#include <VtsHalHidlTargetTestEnvBase.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android/hardware/vibrator/1.1/IVibrator.h>
|
||||
#include <android/hardware/vibrator/1.1/types.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <hidl/GtestPrinter.h>
|
||||
#include <hidl/ServiceManagement.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using ::android::sp;
|
||||
|
@ -34,27 +35,11 @@ using ::android::hardware::vibrator::V1_1::IVibrator;
|
|||
|
||||
#define EXPECT_OK(ret) EXPECT_TRUE((ret).isOk())
|
||||
|
||||
// Test environment for Vibrator HIDL HAL.
|
||||
class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
|
||||
public:
|
||||
// get the test environment singleton
|
||||
static VibratorHidlEnvironment* Instance() {
|
||||
static VibratorHidlEnvironment* instance = new VibratorHidlEnvironment;
|
||||
return instance;
|
||||
}
|
||||
|
||||
virtual void registerTestServices() override { registerTestService<IVibrator>(); }
|
||||
|
||||
private:
|
||||
VibratorHidlEnvironment() {}
|
||||
};
|
||||
|
||||
// The main test class for VIBRATOR HIDL HAL 1.1.
|
||||
class VibratorHidlTest_1_1 : public ::testing::VtsHalHidlTargetTestBase {
|
||||
class VibratorHidlTest_1_1 : public ::testing::TestWithParam<std::string> {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>(
|
||||
VibratorHidlEnvironment::Instance()->getServiceName<IVibrator>());
|
||||
vibrator = IVibrator::getService(GetParam());
|
||||
ASSERT_NE(vibrator, nullptr);
|
||||
}
|
||||
|
||||
|
@ -80,7 +65,7 @@ static void validatePerformEffectBadInput(Status status, uint32_t lengthMs) {
|
|||
<< "Effects that return UNSUPPORTED_OPERATION must have a duration of zero";
|
||||
}
|
||||
|
||||
TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1) {
|
||||
TEST_P(VibratorHidlTest_1_1, PerformEffect_1_1) {
|
||||
vibrator->perform_1_1(Effect_1_1::CLICK, EffectStrength::MEDIUM, validatePerformEffect);
|
||||
vibrator->perform_1_1(Effect_1_1::TICK, EffectStrength::STRONG, validatePerformEffect);
|
||||
}
|
||||
|
@ -88,7 +73,7 @@ TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1) {
|
|||
/*
|
||||
* Test to make sure effect values above the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1_BadEffects_AboveValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_1, PerformEffect_1_1_BadEffects_AboveValidRange) {
|
||||
Effect_1_1 effect = *std::prev(hidl_enum_range<Effect_1_1>().end());
|
||||
Effect_1_1 badEffect = static_cast<Effect_1_1>(static_cast<int32_t>(effect) + 1);
|
||||
EXPECT_OK(
|
||||
|
@ -98,7 +83,7 @@ TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1_BadEffects_AboveValidRange) {
|
|||
/*
|
||||
* Test to make sure effect values below the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1_BadEffects_BelowValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_1, PerformEffect_1_1_BadEffects_BelowValidRange) {
|
||||
Effect_1_1 effect = *hidl_enum_range<Effect_1_1>().begin();
|
||||
Effect_1_1 badEffect = static_cast<Effect_1_1>(static_cast<int32_t>(effect) - 1);
|
||||
EXPECT_OK(
|
||||
|
@ -108,7 +93,7 @@ TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1_BadEffects_BelowValidRange) {
|
|||
/*
|
||||
* Test to make sure strength values above the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1_BadStrength_AboveValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_1, PerformEffect_1_1_BadStrength_AboveValidRange) {
|
||||
EffectStrength strength = *std::prev(hidl_enum_range<EffectStrength>().end());
|
||||
EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) + 1);
|
||||
EXPECT_OK(vibrator->perform_1_1(Effect_1_1::CLICK, badStrength, validatePerformEffectBadInput));
|
||||
|
@ -117,17 +102,13 @@ TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1_BadStrength_AboveValidRange) {
|
|||
/*
|
||||
* Test to make sure strength values below the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1_BadStrength_BelowValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_1, PerformEffect_1_1_BadStrength_BelowValidRange) {
|
||||
EffectStrength strength = *hidl_enum_range<EffectStrength>().begin();
|
||||
EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) - 1);
|
||||
EXPECT_OK(vibrator->perform_1_1(Effect_1_1::CLICK, badStrength, validatePerformEffectBadInput));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance());
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
VibratorHidlEnvironment::Instance()->init(&argc, argv);
|
||||
int status = RUN_ALL_TESTS();
|
||||
LOG(INFO) << "Test result = " << status;
|
||||
return status;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
PerInstance, VibratorHidlTest_1_1,
|
||||
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IVibrator::descriptor)),
|
||||
android::hardware::PrintInstanceNameToString);
|
||||
|
|
|
@ -23,6 +23,6 @@ cc_test {
|
|||
"android.hardware.vibrator@1.1",
|
||||
"android.hardware.vibrator@1.2",
|
||||
],
|
||||
test_suites: ["general-tests"],
|
||||
test_suites: ["general-tests", "vts-core"],
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,13 @@
|
|||
|
||||
#define LOG_TAG "vibrator_hidl_hal_test"
|
||||
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
#include <VtsHalHidlTargetTestEnvBase.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android/hardware/vibrator/1.0/types.h>
|
||||
#include <android/hardware/vibrator/1.2/IVibrator.h>
|
||||
#include <android/hardware/vibrator/1.2/types.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <hidl/GtestPrinter.h>
|
||||
#include <hidl/ServiceManagement.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using ::android::hardware::vibrator::V1_0::Status;
|
||||
|
@ -35,27 +36,11 @@ using ::android::sp;
|
|||
|
||||
#define EXPECT_OK(ret) ASSERT_TRUE((ret).isOk())
|
||||
|
||||
// Test environment for Vibrator HIDL HAL.
|
||||
class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
|
||||
public:
|
||||
// get the test environment singleton
|
||||
static VibratorHidlEnvironment* Instance() {
|
||||
static VibratorHidlEnvironment* instance = new VibratorHidlEnvironment;
|
||||
return instance;
|
||||
}
|
||||
|
||||
virtual void registerTestServices() override { registerTestService<IVibrator>(); }
|
||||
|
||||
private:
|
||||
VibratorHidlEnvironment() {}
|
||||
};
|
||||
|
||||
// The main test class for VIBRATOR HIDL HAL 1.2.
|
||||
class VibratorHidlTest_1_2 : public ::testing::VtsHalHidlTargetTestBase {
|
||||
class VibratorHidlTest_1_2 : public ::testing::TestWithParam<std::string> {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>(
|
||||
VibratorHidlEnvironment::Instance()->getServiceName<IVibrator>());
|
||||
vibrator = IVibrator::getService(GetParam());
|
||||
ASSERT_NE(vibrator, nullptr);
|
||||
}
|
||||
|
||||
|
@ -85,7 +70,7 @@ static void validatePerformEffectBadInput(Status status, uint32_t lengthMs) {
|
|||
* Test to make sure effects within the valid range return are either supported and return OK with
|
||||
* a valid duration, or are unsupported and return UNSUPPORTED_OPERATION with a duration of 0.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2) {
|
||||
TEST_P(VibratorHidlTest_1_2, PerformEffect_1_2) {
|
||||
for (const auto& effect : hidl_enum_range<Effect>()) {
|
||||
for (const auto& strength : hidl_enum_range<EffectStrength>()) {
|
||||
EXPECT_OK(vibrator->perform_1_2(effect, strength, validatePerformEffect));
|
||||
|
@ -96,7 +81,7 @@ TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2) {
|
|||
/*
|
||||
* Test to make sure effect values above the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadEffects_AboveValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_2, PerformEffect_1_2_BadEffects_AboveValidRange) {
|
||||
Effect effect = *std::prev(hidl_enum_range<Effect>().end());
|
||||
Effect badEffect = static_cast<Effect>(static_cast<int32_t>(effect) + 1);
|
||||
EXPECT_OK(
|
||||
|
@ -106,7 +91,7 @@ TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadEffects_AboveValidRange) {
|
|||
/*
|
||||
* Test to make sure effect values below the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadEffects_BelowValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_2, PerformEffect_1_2_BadEffects_BelowValidRange) {
|
||||
Effect effect = *hidl_enum_range<Effect>().begin();
|
||||
Effect badEffect = static_cast<Effect>(static_cast<int32_t>(effect) - 1);
|
||||
EXPECT_OK(
|
||||
|
@ -116,7 +101,7 @@ TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadEffects_BelowValidRange) {
|
|||
/*
|
||||
* Test to make sure strength values above the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadStrength_AboveValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_2, PerformEffect_1_2_BadStrength_AboveValidRange) {
|
||||
EffectStrength strength = *std::prev(hidl_enum_range<EffectStrength>().end());
|
||||
EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) + 1);
|
||||
EXPECT_OK(vibrator->perform_1_2(Effect::THUD, badStrength, validatePerformEffectBadInput));
|
||||
|
@ -125,17 +110,13 @@ TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadStrength_AboveValidRange) {
|
|||
/*
|
||||
* Test to make sure strength values below the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2_BadStrength_BelowValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_2, PerformEffect_1_2_BadStrength_BelowValidRange) {
|
||||
EffectStrength strength = *hidl_enum_range<EffectStrength>().begin();
|
||||
EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) - 1);
|
||||
EXPECT_OK(vibrator->perform_1_2(Effect::THUD, badStrength, validatePerformEffectBadInput));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance());
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
VibratorHidlEnvironment::Instance()->init(&argc, argv);
|
||||
int status = RUN_ALL_TESTS();
|
||||
LOG(INFO) << "Test result = " << status;
|
||||
return status;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
PerInstance, VibratorHidlTest_1_2,
|
||||
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IVibrator::descriptor)),
|
||||
android::hardware::PrintInstanceNameToString);
|
||||
|
|
|
@ -24,6 +24,6 @@ cc_test {
|
|||
"android.hardware.vibrator@1.2",
|
||||
"android.hardware.vibrator@1.3",
|
||||
],
|
||||
test_suites: ["general-tests"],
|
||||
test_suites: ["general-tests", "vts-core"],
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
|
||||
#define LOG_TAG "vibrator_hidl_hal_test"
|
||||
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
#include <VtsHalHidlTargetTestEnvBase.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android/hardware/vibrator/1.0/types.h>
|
||||
#include <android/hardware/vibrator/1.3/IVibrator.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <hidl/GtestPrinter.h>
|
||||
#include <hidl/ServiceManagement.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using ::android::sp;
|
||||
|
@ -34,27 +35,11 @@ using ::android::hardware::vibrator::V1_3::IVibrator;
|
|||
|
||||
#define EXPECT_OK(ret) ASSERT_TRUE((ret).isOk())
|
||||
|
||||
// Test environment for Vibrator HIDL HAL.
|
||||
class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
|
||||
public:
|
||||
// get the test environment singleton
|
||||
static VibratorHidlEnvironment* Instance() {
|
||||
static VibratorHidlEnvironment* instance = new VibratorHidlEnvironment;
|
||||
return instance;
|
||||
}
|
||||
|
||||
virtual void registerTestServices() override { registerTestService<IVibrator>(); }
|
||||
|
||||
private:
|
||||
VibratorHidlEnvironment() {}
|
||||
};
|
||||
|
||||
// The main test class for VIBRATOR HIDL HAL 1.3.
|
||||
class VibratorHidlTest_1_3 : public ::testing::VtsHalHidlTargetTestBase {
|
||||
class VibratorHidlTest_1_3 : public ::testing::TestWithParam<std::string> {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>(
|
||||
VibratorHidlEnvironment::Instance()->getServiceName<IVibrator>());
|
||||
vibrator = IVibrator::getService(GetParam());
|
||||
ASSERT_NE(vibrator, nullptr);
|
||||
}
|
||||
|
||||
|
@ -63,7 +48,7 @@ class VibratorHidlTest_1_3 : public ::testing::VtsHalHidlTargetTestBase {
|
|||
sp<IVibrator> vibrator;
|
||||
};
|
||||
|
||||
TEST_F(VibratorHidlTest_1_3, ChangeVibrationalExternalControl) {
|
||||
TEST_P(VibratorHidlTest_1_3, ChangeVibrationalExternalControl) {
|
||||
if (vibrator->supportsExternalControl()) {
|
||||
EXPECT_EQ(Status::OK, vibrator->setExternalControl(true));
|
||||
sleep(1);
|
||||
|
@ -72,7 +57,7 @@ TEST_F(VibratorHidlTest_1_3, ChangeVibrationalExternalControl) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(VibratorHidlTest_1_3, SetExternalControlReturnUnsupportedOperationIfNotSupported) {
|
||||
TEST_P(VibratorHidlTest_1_3, SetExternalControlReturnUnsupportedOperationIfNotSupported) {
|
||||
if (!vibrator->supportsExternalControl()) {
|
||||
EXPECT_EQ(Status::UNSUPPORTED_OPERATION, vibrator->setExternalControl(true));
|
||||
}
|
||||
|
@ -98,7 +83,7 @@ static void validatePerformEffect(Status status, uint32_t lengthMs) {
|
|||
* Test to make sure effects within the valid range return are either supported and return OK with
|
||||
* a valid duration, or are unsupported and return UNSUPPORTED_OPERATION with a duration of 0.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3) {
|
||||
TEST_P(VibratorHidlTest_1_3, PerformEffect_1_3) {
|
||||
for (const auto& effect : hidl_enum_range<Effect>()) {
|
||||
for (const auto& strength : hidl_enum_range<EffectStrength>()) {
|
||||
EXPECT_OK(vibrator->perform_1_3(effect, strength, validatePerformEffect));
|
||||
|
@ -109,7 +94,7 @@ TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3) {
|
|||
/*
|
||||
* Test to make sure effect values above the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3_BadEffects_AboveValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_3, PerformEffect_1_3_BadEffects_AboveValidRange) {
|
||||
Effect effect = *std::prev(hidl_enum_range<Effect>().end());
|
||||
Effect badEffect = static_cast<Effect>(static_cast<int32_t>(effect) + 1);
|
||||
EXPECT_OK(vibrator->perform_1_3(badEffect, EffectStrength::LIGHT,
|
||||
|
@ -119,7 +104,7 @@ TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3_BadEffects_AboveValidRange) {
|
|||
/*
|
||||
* Test to make sure effect values below the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3_BadEffects_BelowValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_3, PerformEffect_1_3_BadEffects_BelowValidRange) {
|
||||
Effect effect = *hidl_enum_range<Effect>().begin();
|
||||
Effect badEffect = static_cast<Effect>(static_cast<int32_t>(effect) - 1);
|
||||
EXPECT_OK(vibrator->perform_1_3(badEffect, EffectStrength::LIGHT,
|
||||
|
@ -129,7 +114,7 @@ TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3_BadEffects_BelowValidRange) {
|
|||
/*
|
||||
* Test to make sure strength values above the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3_BadStrength_AboveValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_3, PerformEffect_1_3_BadStrength_AboveValidRange) {
|
||||
EffectStrength strength = *std::prev(hidl_enum_range<EffectStrength>().end());
|
||||
EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) + 1);
|
||||
EXPECT_OK(vibrator->perform_1_3(Effect::THUD, badStrength,
|
||||
|
@ -139,18 +124,14 @@ TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3_BadStrength_AboveValidRange) {
|
|||
/*
|
||||
* Test to make sure strength values below the valid range are rejected.
|
||||
*/
|
||||
TEST_F(VibratorHidlTest_1_3, PerformEffect_1_3_BadStrength_BelowValidRange) {
|
||||
TEST_P(VibratorHidlTest_1_3, PerformEffect_1_3_BadStrength_BelowValidRange) {
|
||||
EffectStrength strength = *hidl_enum_range<EffectStrength>().begin();
|
||||
EffectStrength badStrength = static_cast<EffectStrength>(static_cast<int32_t>(strength) - 1);
|
||||
EXPECT_OK(vibrator->perform_1_3(Effect::THUD, badStrength,
|
||||
validatePerformEffectUnsupportedOperation));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance());
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
VibratorHidlEnvironment::Instance()->init(&argc, argv);
|
||||
int status = RUN_ALL_TESTS();
|
||||
LOG(INFO) << "Test result = " << status;
|
||||
return status;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
PerInstance, VibratorHidlTest_1_3,
|
||||
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IVibrator::descriptor)),
|
||||
android::hardware::PrintInstanceNameToString);
|
||||
|
|
Loading…
Reference in a new issue