Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cd65e88 authored by Lais Andrade's avatar Lais Andrade
Browse files

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
parent 9febda8e
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -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);