vibrator: vts: Validate Primitive Duration
Bug: 148496381 Test: Ran on Pixel 4 Signed-off-by: Harpreet \"Eli\" Sangha <eliptus@google.com> Change-Id: Ie74f9458b881a51746539f61526fbe4898485b00
This commit is contained in:
parent
c2e1f3baef
commit
b075a6a599
2 changed files with 48 additions and 17 deletions
|
@ -163,6 +163,10 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi
|
|||
}
|
||||
LOG(INFO) << "triggering primitive " << static_cast<int>(e.primitive) << " @ scale "
|
||||
<< e.scale;
|
||||
|
||||
int32_t durationMs;
|
||||
getPrimitiveDuration(e.primitive, &durationMs);
|
||||
usleep(durationMs * 1000);
|
||||
}
|
||||
|
||||
if (callback != nullptr) {
|
||||
|
|
|
@ -33,6 +33,7 @@ using android::hardware::vibrator::CompositePrimitive;
|
|||
using android::hardware::vibrator::Effect;
|
||||
using android::hardware::vibrator::EffectStrength;
|
||||
using android::hardware::vibrator::IVibrator;
|
||||
using std::chrono::high_resolution_clock;
|
||||
|
||||
const std::vector<Effect> kEffects{android::enum_range<Effect>().begin(),
|
||||
android::enum_range<Effect>().end()};
|
||||
|
@ -381,26 +382,52 @@ TEST_P(VibratorAidl, CompseSizeBoundary) {
|
|||
}
|
||||
|
||||
TEST_P(VibratorAidl, ComposeCallback) {
|
||||
constexpr std::chrono::milliseconds allowedLatency{10};
|
||||
|
||||
if (capabilities & IVibrator::CAP_COMPOSE_EFFECTS) {
|
||||
std::promise<void> completionPromise;
|
||||
std::future<void> completionFuture{completionPromise.get_future()};
|
||||
sp<CompletionCallback> callback =
|
||||
new CompletionCallback([&completionPromise] { completionPromise.set_value(); });
|
||||
CompositePrimitive primitive = CompositePrimitive::CLICK;
|
||||
CompositeEffect effect;
|
||||
std::vector<CompositeEffect> composite;
|
||||
int32_t duration;
|
||||
std::vector<CompositePrimitive> supported;
|
||||
|
||||
effect.delayMs = 0;
|
||||
effect.primitive = primitive;
|
||||
effect.scale = 1.0f;
|
||||
composite.emplace_back(effect);
|
||||
ASSERT_TRUE(vibrator->getSupportedPrimitives(&supported).isOk());
|
||||
|
||||
EXPECT_EQ(Status::EX_NONE,
|
||||
vibrator->getPrimitiveDuration(primitive, &duration).exceptionCode());
|
||||
EXPECT_EQ(Status::EX_NONE, vibrator->compose(composite, callback).exceptionCode());
|
||||
EXPECT_EQ(completionFuture.wait_for(std::chrono::milliseconds(duration * 2)),
|
||||
std::future_status::ready);
|
||||
for (auto primitive : supported) {
|
||||
if (primitive == CompositePrimitive::NOOP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::promise<void> completionPromise;
|
||||
std::future<void> completionFuture{completionPromise.get_future()};
|
||||
sp<CompletionCallback> callback =
|
||||
new CompletionCallback([&completionPromise] { completionPromise.set_value(); });
|
||||
CompositeEffect effect;
|
||||
std::vector<CompositeEffect> composite;
|
||||
int32_t durationMs;
|
||||
std::chrono::milliseconds duration;
|
||||
std::chrono::time_point<high_resolution_clock> start, end;
|
||||
std::chrono::milliseconds elapsed;
|
||||
|
||||
effect.delayMs = 0;
|
||||
effect.primitive = primitive;
|
||||
effect.scale = 1.0f;
|
||||
composite.emplace_back(effect);
|
||||
|
||||
EXPECT_EQ(Status::EX_NONE,
|
||||
vibrator->getPrimitiveDuration(primitive, &durationMs).exceptionCode())
|
||||
<< toString(primitive);
|
||||
duration = std::chrono::milliseconds(durationMs);
|
||||
|
||||
EXPECT_EQ(Status::EX_NONE, vibrator->compose(composite, callback).exceptionCode())
|
||||
<< toString(primitive);
|
||||
start = high_resolution_clock::now();
|
||||
|
||||
EXPECT_EQ(completionFuture.wait_for(duration + allowedLatency),
|
||||
std::future_status::ready)
|
||||
<< toString(primitive);
|
||||
end = high_resolution_clock::now();
|
||||
|
||||
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
EXPECT_LE(elapsed.count(), (duration + allowedLatency).count()) << toString(primitive);
|
||||
EXPECT_GE(elapsed.count(), (duration - allowedLatency).count()) << toString(primitive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue