Fail Power HAL benchmarks on failed result
This cl adds ranges to benchmark tests to cover all existing power
Boost, Mode and Hint values. It also fails the benchmark when a HAL
result is fail, and skip AIDL unsupported operations.
Checking the hardware::Return status prevents the benchmark execution
crash, which was causing the json output to be clipped and unable to
be parsed and uploaded to any metric dashboard.
Also adding more error logs printing HAL result from within wrappers.
Sample output:
https://paste.googleplex.com/5185928966438912
Fix: b/160972434
Test: atest libpowermanager_benchmarks
Change-Id: I63733baaf7d04428a9a5425a25c5ffe8c72249e1
diff --git a/services/powermanager/benchmarks/PowerHalAidlBenchmarks.cpp b/services/powermanager/benchmarks/PowerHalAidlBenchmarks.cpp
index a6dad51..1004828 100644
--- a/services/powermanager/benchmarks/PowerHalAidlBenchmarks.cpp
+++ b/services/powermanager/benchmarks/PowerHalAidlBenchmarks.cpp
@@ -19,50 +19,78 @@
#include <android/hardware/power/Boost.h>
#include <android/hardware/power/IPower.h>
#include <android/hardware/power/Mode.h>
-
#include <benchmark/benchmark.h>
-
#include <binder/IServiceManager.h>
+#include <testUtil.h>
+#include <chrono>
using android::hardware::power::Boost;
using android::hardware::power::IPower;
using android::hardware::power::Mode;
+using std::chrono::microseconds;
using namespace android;
+using namespace std::chrono_literals;
+
+// Values from Boost.aidl and Mode.aidl.
+static constexpr int64_t FIRST_BOOST = static_cast<int64_t>(Boost::INTERACTION);
+static constexpr int64_t LAST_BOOST = static_cast<int64_t>(Boost::CAMERA_SHOT);
+static constexpr int64_t FIRST_MODE = static_cast<int64_t>(Mode::DOUBLE_TAP_TO_WAKE);
+static constexpr int64_t LAST_MODE = static_cast<int64_t>(Mode::CAMERA_STREAMING_HIGH);
+
+// Delay between oneway method calls to avoid overflowing the binder buffers.
+static constexpr microseconds ONEWAY_API_DELAY = 100us;
template <class R, class... Args0, class... Args1>
-static void runBenchmark(benchmark::State& state, R (IPower::*fn)(Args0...), Args1&&... args1) {
+static void runBenchmark(benchmark::State& state, microseconds delay, R (IPower::*fn)(Args0...),
+ Args1&&... args1) {
sp<IPower> hal = waitForVintfService<IPower>();
if (hal == nullptr) {
- ALOGI("Power HAL AIDL not available, skipping test...");
+ ALOGI("Power HAL not available, skipping test...");
+ return;
+ }
+
+ binder::Status ret = (*hal.*fn)(std::forward<Args1>(args1)...);
+ if (ret.exceptionCode() == binder::Status::Exception::EX_UNSUPPORTED_OPERATION) {
+ ALOGI("Power HAL does not support this operation, skipping test...");
return;
}
while (state.KeepRunning()) {
- (*hal.*fn)(std::forward<Args1>(args1)...);
+ ret = (*hal.*fn)(std::forward<Args1>(args1)...);
+ state.PauseTiming();
+ if (!ret.isOk()) state.SkipWithError(ret.toString8().c_str());
+ if (delay > 0us) {
+ testDelaySpin(std::chrono::duration_cast<std::chrono::duration<float>>(delay).count());
+ }
+ state.ResumeTiming();
}
}
static void BM_PowerHalAidlBenchmarks_isBoostSupported(benchmark::State& state) {
bool isSupported;
- runBenchmark(state, &IPower::isBoostSupported, Boost::INTERACTION, &isSupported);
+ Boost boost = static_cast<Boost>(state.range(0));
+ runBenchmark(state, 0us, &IPower::isBoostSupported, boost, &isSupported);
}
static void BM_PowerHalAidlBenchmarks_isModeSupported(benchmark::State& state) {
bool isSupported;
- runBenchmark(state, &IPower::isModeSupported, Mode::INTERACTIVE, &isSupported);
+ Mode mode = static_cast<Mode>(state.range(0));
+ runBenchmark(state, 0us, &IPower::isModeSupported, mode, &isSupported);
}
static void BM_PowerHalAidlBenchmarks_setBoost(benchmark::State& state) {
- runBenchmark(state, &IPower::setBoost, Boost::INTERACTION, 0);
+ Boost boost = static_cast<Boost>(state.range(0));
+ runBenchmark(state, ONEWAY_API_DELAY, &IPower::setBoost, boost, 1);
}
static void BM_PowerHalAidlBenchmarks_setMode(benchmark::State& state) {
- runBenchmark(state, &IPower::setMode, Mode::INTERACTIVE, false);
+ Mode mode = static_cast<Mode>(state.range(0));
+ runBenchmark(state, ONEWAY_API_DELAY, &IPower::setMode, mode, false);
}
-BENCHMARK(BM_PowerHalAidlBenchmarks_isBoostSupported);
-BENCHMARK(BM_PowerHalAidlBenchmarks_isModeSupported);
-BENCHMARK(BM_PowerHalAidlBenchmarks_setBoost);
-BENCHMARK(BM_PowerHalAidlBenchmarks_setMode);
+BENCHMARK(BM_PowerHalAidlBenchmarks_isBoostSupported)->DenseRange(FIRST_BOOST, LAST_BOOST, 1);
+BENCHMARK(BM_PowerHalAidlBenchmarks_isModeSupported)->DenseRange(FIRST_MODE, LAST_MODE, 1);
+BENCHMARK(BM_PowerHalAidlBenchmarks_setBoost)->DenseRange(FIRST_BOOST, LAST_BOOST, 1);
+BENCHMARK(BM_PowerHalAidlBenchmarks_setMode)->DenseRange(FIRST_MODE, LAST_MODE, 1);