vibrator: fix VTS for effects

A few issues were causing effects tests to fail:
- invalid effects were not actually invalid
- test for invalid effects improved to consider invalid effects and
  strengths separately
- test sleeps for appropriate amount of time after requesting effect to
  be performed
- logging used to diagnose issues left in place for convenience

Bug: 141828236
Test: atest VtsHalVibratorTargetTest (on device which suffers from these
  issues that cf did not hit)

Change-Id: Id220d36c27d85f068dce6b8961f705eef8dc6a4f
diff --git a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
index aeb9b70..a8e1fe4 100644
--- a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
+++ b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
@@ -46,13 +46,13 @@
                                                       EffectStrength::STRONG};
 
 const std::vector<Effect> kInvalidEffects = {
-        static_cast<Effect>(static_cast<int32_t>(*kEffects.begin()) - 1),
-        static_cast<Effect>(static_cast<int32_t>(*kEffects.end()) + 1),
+        static_cast<Effect>(static_cast<int32_t>(kEffects.front()) - 1),
+        static_cast<Effect>(static_cast<int32_t>(kEffects.back()) + 1),
 };
 
 const std::vector<EffectStrength> kInvalidEffectStrengths = {
-        static_cast<EffectStrength>(static_cast<int8_t>(*kEffectStrengths.begin()) - 1),
-        static_cast<EffectStrength>(static_cast<int8_t>(*kEffectStrengths.end()) + 1),
+        static_cast<EffectStrength>(static_cast<int8_t>(kEffectStrengths.front()) - 1),
+        static_cast<EffectStrength>(static_cast<int8_t>(kEffectStrengths.back()) + 1),
 };
 
 class CompletionCallback : public BnVibratorCallback {
@@ -119,10 +119,13 @@
             Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs);
 
             if (isEffectSupported) {
-                EXPECT_TRUE(status.isOk());
+                EXPECT_TRUE(status.isOk())
+                        << static_cast<int>(effect) << " " << static_cast<int>(strength);
                 EXPECT_GT(lengthMs, 0);
+                usleep(lengthMs * 1000);
             } else {
-                EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION);
+                EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION)
+                        << static_cast<int>(effect) << " " << static_cast<int>(strength);
                 EXPECT_EQ(lengthMs, 0);
             }
         }
@@ -179,10 +182,19 @@
 
 TEST_P(VibratorAidl, InvalidEffectsUnsupported) {
     for (Effect effect : kInvalidEffects) {
+        for (EffectStrength strength : kEffectStrengths) {
+            int32_t lengthMs;
+            Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs);
+            EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION)
+                    << static_cast<int>(effect) << " " << static_cast<int>(strength);
+        }
+    }
+    for (Effect effect : kEffects) {
         for (EffectStrength strength : kInvalidEffectStrengths) {
             int32_t lengthMs;
             Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs);
-            EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION);
+            EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION)
+                    << static_cast<int>(effect) << " " << static_cast<int>(strength);
         }
     }
 }