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

Commit fb317fdd authored by Shunkai Yao's avatar Shunkai Yao Committed by Automerger Merge Worker
Browse files

Effect AIDL: Add VTS test cases cleanup in TearDown am: cb0fc410 am: 7213f6dd am: dec53195

parents 98098642 dec53195
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -53,9 +53,10 @@ class EqualizerSwContext final : public EffectContext {
                LOG(ERROR) << __func__ << " index illegal, skip: " << it.index << " - "
                           << it.levelMb;
                ret = RetCode::ERROR_ILLEGAL_PARAMETER;
            }
            } else {
                mBandLevels[it.index] = it.levelMb;
            }
        }
        return ret;
    }

+1 −3
Original line number Diff line number Diff line
@@ -72,13 +72,11 @@ class EffectContext {

    float* getWorkBuffer() { return static_cast<float*>(mWorkBuffer.data()); }

    // reset buffer status by abandon all data and status in FMQ
    // reset buffer status by abandon input data in FMQ
    void resetBuffer() {
        auto buffer = static_cast<float*>(mWorkBuffer.data());
        std::vector<IEffect::Status> status(mStatusMQ->availableToRead());
        mInputMQ->read(buffer, mInputMQ->availableToRead());
        mOutputMQ->read(buffer, mOutputMQ->availableToRead());
        mStatusMQ->read(status.data(), mStatusMQ->availableToRead());
    }

    void dupeFmq(IEffect::OpenEffectReturn* effectRet) {
+5 −6
Original line number Diff line number Diff line
@@ -49,11 +49,11 @@ class EffectFactoryHelper {

    std::shared_ptr<IFactory> GetFactory() const { return mEffectFactory; }

    static std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>>
    getAllEffectDescriptors(std::string serviceName, std::optional<AudioUuid> type = std::nullopt) {
    static std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> getAllEffectDescriptors(
            std::string serviceName, std::optional<AudioUuid> type = std::nullopt) {
        AudioHalBinderServiceUtil util;
        auto names = android::getAidlHalInstanceNames(serviceName);
        std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>> result;
        std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> result;

        for (const auto& name : names) {
            auto factory = IFactory::fromBinder(util.connectToService(name));
@@ -62,11 +62,10 @@ class EffectFactoryHelper {
                    factory->queryEffects(std::nullopt, std::nullopt, std::nullopt, &descs)
                            .isOk()) {
                    for (const auto& desc : descs) {
                        const auto& id = desc.common.id;
                        if (type.has_value() && id.type != type.value()) {
                        if (type.has_value() && desc.common.id.type != type.value()) {
                            continue;
                        }
                        result.emplace_back(factory, id);
                        result.emplace_back(factory, desc);
                    }
                }
            }
+37 −19
Original line number Diff line number Diff line
@@ -58,26 +58,34 @@ typedef ::android::AidlMessageQueue<float,
class EffectHelper {
  public:
    static void create(std::shared_ptr<IFactory> factory, std::shared_ptr<IEffect>& effect,
                       Descriptor::Identity id, binder_status_t status = EX_NONE) {
                       Descriptor& desc, binder_status_t status = EX_NONE) {
        ASSERT_NE(factory, nullptr);
        EXPECT_STATUS(status, factory->createEffect(id.uuid, &effect));
        auto& id = desc.common.id;
        ASSERT_STATUS(status, factory->createEffect(id.uuid, &effect));
        if (status == EX_NONE) {
            ASSERT_NE(effect, nullptr) << id.uuid.toString();
        }
    }

    static void destroyIgnoreRet(std::shared_ptr<IFactory> factory,
                                 std::shared_ptr<IEffect> effect) {
        if (factory && effect) {
            factory->destroyEffect(effect);
        }
    }

    static void destroy(std::shared_ptr<IFactory> factory, std::shared_ptr<IEffect> effect,
                        binder_status_t status = EX_NONE) {
        ASSERT_NE(factory, nullptr);
        ASSERT_NE(effect, nullptr);
        EXPECT_STATUS(status, factory->destroyEffect(effect));
        ASSERT_STATUS(status, factory->destroyEffect(effect));
    }

    static void open(std::shared_ptr<IEffect> effect, const Parameter::Common& common,
                     const std::optional<Parameter::Specific>& specific,
                     IEffect::OpenEffectReturn* ret, binder_status_t status = EX_NONE) {
        ASSERT_NE(effect, nullptr);
        EXPECT_STATUS(status, effect->open(common, specific, ret));
        ASSERT_STATUS(status, effect->open(common, specific, ret));
    }

    static void open(std::shared_ptr<IEffect> effect, int session = 0,
@@ -85,30 +93,40 @@ class EffectHelper {
        ASSERT_NE(effect, nullptr);
        Parameter::Common common = EffectHelper::createParamCommon(session);
        IEffect::OpenEffectReturn ret;
        open(effect, common, std::nullopt /* specific */, &ret, status);
        ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, status));
    }

    static void closeIgnoreRet(std::shared_ptr<IEffect> effect) {
        if (effect) {
            effect->close();
        }
    }
    static void close(std::shared_ptr<IEffect> effect, binder_status_t status = EX_NONE) {
        if (effect) {
            EXPECT_STATUS(status, effect->close());
            ASSERT_STATUS(status, effect->close());
        }
    }
    static void getDescriptor(std::shared_ptr<IEffect> effect, Descriptor& desc,
                              binder_status_t status = EX_NONE) {
        ASSERT_NE(effect, nullptr);
        EXPECT_STATUS(status, effect->getDescriptor(&desc));
        ASSERT_STATUS(status, effect->getDescriptor(&desc));
    }
    static void expectState(std::shared_ptr<IEffect> effect, State expectState,
                            binder_status_t status = EX_NONE) {
        ASSERT_NE(effect, nullptr);
        State state;
        EXPECT_STATUS(status, effect->getState(&state));
        EXPECT_EQ(expectState, state);
        ASSERT_STATUS(status, effect->getState(&state));
        ASSERT_EQ(expectState, state);
    }
    static void commandIgnoreRet(std::shared_ptr<IEffect> effect, CommandId command) {
        if (effect) {
            effect->command(command);
        }
    }
    static void command(std::shared_ptr<IEffect> effect, CommandId command,
                        binder_status_t status = EX_NONE) {
        ASSERT_NE(effect, nullptr);
        EXPECT_STATUS(status, effect->command(command));
        ASSERT_STATUS(status, effect->command(command));
    }
    static void allocateInputData(const Parameter::Common common, std::unique_ptr<DataMQ>& mq,
                                  std::vector<float>& buffer) {
@@ -116,29 +134,29 @@ class EffectHelper {
        auto frameSize = android::hardware::audio::common::getFrameSizeInBytes(
                common.input.base.format, common.input.base.channelMask);
        const size_t floatsToWrite = mq->availableToWrite();
        EXPECT_NE(0UL, floatsToWrite);
        EXPECT_EQ(frameSize * common.input.frameCount, floatsToWrite * sizeof(float));
        ASSERT_NE(0UL, floatsToWrite);
        ASSERT_EQ(frameSize * common.input.frameCount, floatsToWrite * sizeof(float));
        buffer.resize(floatsToWrite);
        std::fill(buffer.begin(), buffer.end(), 0x5a);
    }
    static void writeToFmq(std::unique_ptr<DataMQ>& mq, const std::vector<float>& buffer) {
        const size_t available = mq->availableToWrite();
        EXPECT_NE(0Ul, available);
        ASSERT_NE(0Ul, available);
        auto bufferFloats = buffer.size();
        auto floatsToWrite = std::min(available, bufferFloats);
        EXPECT_TRUE(mq->write(buffer.data(), floatsToWrite));
        ASSERT_TRUE(mq->write(buffer.data(), floatsToWrite));
    }
    static void readFromFmq(std::unique_ptr<StatusMQ>& statusMq, size_t statusNum,
                            std::unique_ptr<DataMQ>& dataMq, size_t expectFloats,
                            std::vector<float>& buffer) {
        IEffect::Status status{};
        EXPECT_TRUE(statusMq->readBlocking(&status, statusNum));
        EXPECT_EQ(STATUS_OK, status.status);
        ASSERT_TRUE(statusMq->readBlocking(&status, statusNum));
        ASSERT_EQ(STATUS_OK, status.status);
        if (statusNum != 0) {
            EXPECT_EQ(expectFloats, (unsigned)status.fmqProduced);
            EXPECT_EQ(expectFloats, dataMq->availableToRead());
            ASSERT_EQ(expectFloats, (unsigned)status.fmqProduced);
            ASSERT_EQ(expectFloats, dataMq->availableToRead());
            if (expectFloats != 0) {
                EXPECT_TRUE(dataMq->read(buffer.data(), expectFloats));
                ASSERT_TRUE(dataMq->read(buffer.data(), expectFloats));
            }
        }
    }
+310 −297

File changed.

Preview size limit exceeded, changes collapsed.

Loading