summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lais Andrade <lsandrade@google.com> 2020-11-09 15:25:07 +0000
committer Lais Andrade <lsandrade@google.com> 2020-11-09 16:35:56 +0000
commit1cd65e88f64636a96723c469b8533ebdc1e12993 (patch)
treeccc39b115292a53b18d0cf52ba64642c5a7c9a63
parent9febda8e05bbd924d14682454fdc7a846c38f954 (diff)
Fix assert error on vibrator benchmarks
The benchmark Args are generated dynamically with the supported effects/primitives, and they can be an empty list on some devices. The benchmark.h has a range(size_t) method to retrive arguments, which asserts on the args size, but does not expose a way to check if the args are empty. Fix: 171192316 Test: atest libvibratorservice_benchmarks Change-Id: Ida67e81bdf1066a055a6cafbb3b1ef3bdbe23e41
-rw-r--r--services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp b/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp
index 6589f74d9a..0acff065e8 100644
--- a/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp
+++ b/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp
@@ -302,11 +302,13 @@ public:
}
std::vector<hardware::vibrator::Effect> supported = effectsResult.value();
+ b->ArgNames({"Effect", "Strength"});
+
if (supported.empty()) {
+ b->Args({static_cast<long>(-1), static_cast<long>(-1)});
return;
}
- b->ArgNames({"Effect", "Strength"});
for (const auto& effect : enum_range<hardware::vibrator::Effect>()) {
if (std::find(supported.begin(), supported.end(), effect) == supported.end()) {
continue;
@@ -318,6 +320,8 @@ public:
}
protected:
+ bool hasArgs(const State& state) const { return this->getOtherArg(state, 0) >= 0; }
+
auto getEffect(const State& state) const {
return static_cast<hardware::vibrator::Effect>(this->getOtherArg(state, 0));
}
@@ -333,6 +337,9 @@ BENCHMARK_WRAPPER(VibratorEffectsBench, alwaysOnEnable, {
if (!hasCapabilities(result, vibrator::Capabilities::ALWAYS_ON_CONTROL, state)) {
return;
}
+ if (!hasArgs(state)) {
+ return;
+ }
int32_t id = 1;
auto effect = getEffect(state);
@@ -354,6 +361,9 @@ BENCHMARK_WRAPPER(VibratorEffectsBench, alwaysOnDisable, {
if (!hasCapabilities(result, vibrator::Capabilities::ALWAYS_ON_CONTROL, state)) {
return;
}
+ if (!hasArgs(state)) {
+ return;
+ }
int32_t id = 1;
auto effect = getEffect(state);
@@ -370,6 +380,10 @@ BENCHMARK_WRAPPER(VibratorEffectsBench, alwaysOnDisable, {
});
BENCHMARK_WRAPPER(VibratorEffectsBench, performEffect, {
+ if (!hasArgs(state)) {
+ return;
+ }
+
auto effect = getEffect(state);
auto strength = getStrength(state);
auto callback = []() {};
@@ -394,11 +408,13 @@ public:
}
std::vector<hardware::vibrator::CompositePrimitive> supported = primitivesResult.value();
+ b->ArgNames({"Primitive"});
+
if (supported.empty()) {
+ b->Args({static_cast<long>(-1)});
return;
}
- b->ArgNames({"Primitive"});
for (const auto& primitive : enum_range<hardware::vibrator::CompositePrimitive>()) {
if (std::find(supported.begin(), supported.end(), primitive) == supported.end()) {
continue;
@@ -411,6 +427,8 @@ public:
}
protected:
+ bool hasArgs(const State& state) const { return this->getOtherArg(state, 0) >= 0; }
+
auto getPrimitive(const State& state) const {
return static_cast<hardware::vibrator::CompositePrimitive>(this->getOtherArg(state, 0));
}
@@ -422,6 +440,9 @@ BENCHMARK_WRAPPER(VibratorPrimitivesBench, performComposedEffect, {
if (!hasCapabilities(result, vibrator::Capabilities::COMPOSE_EFFECTS, state)) {
return;
}
+ if (!hasArgs(state)) {
+ return;
+ }
hardware::vibrator::CompositeEffect effect;
effect.primitive = getPrimitive(state);