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

Commit 45bce64a authored by android-build-team Robot's avatar android-build-team Robot
Browse files

release-request-ad401328-e365-4073-9b7c-44f7fc79185b-for-git_oc-mr1-release-43...

release-request-ad401328-e365-4073-9b7c-44f7fc79185b-for-git_oc-mr1-release-4329935 snap-temp-L86100000101558881

Change-Id: I78cc62fbfbdd0c27ba2adb31eb30cd288a56f4fd
parents 8850f4cc 2b395216
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -162,12 +162,29 @@ StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) {
    return StatusCode::OK;
}

static bool isDiagnosticProperty(VehiclePropConfig propConfig) {
    switch (propConfig.prop) {
        case OBD2_LIVE_FRAME:
        case OBD2_FREEZE_FRAME:
        case OBD2_FREEZE_FRAME_CLEAR:
        case OBD2_FREEZE_FRAME_INFO:
            return true;
    }
    return false;
}

// Parse supported properties list and generate vector of property values to hold current values.
void EmulatedVehicleHal::onCreate() {
    for (auto& it : kVehicleProperties) {
        VehiclePropConfig cfg = it.config;
        int32_t supportedAreas = cfg.supportedAreas;

        if (isDiagnosticProperty(cfg)) {
            // do not write an initial empty value for the diagnostic properties
            // as we will initialize those separately.
            continue;
        }

        //  A global property will have supportedAreas = 0
        if (isGlobalProp(cfg.prop)) {
            supportedAreas = 0;
+61 −0
Original line number Diff line number Diff line
@@ -583,6 +583,67 @@ TEST_F(ComponentHidlTest, Flush) {
                            kPortIndexInput, kPortIndexOutput);
}

// test port mode configuration when the component is in various states
TEST_F(ComponentHidlTest, PortModeConfig) {
    description("Test Port Mode Configuration");
    if (disableTest) return;
    android::hardware::media::omx::V1_0::Status status;
    uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
    Message msg;

    status = setRole(omxNode, gEnv->getRole().c_str());
    ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
    OMX_PORT_PARAM_TYPE params;
    if (compClass == audio_decoder || compClass == audio_encoder) {
        status = getParam(omxNode, OMX_IndexParamAudioInit, &params);
    } else {
        status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
    }
    if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
        ASSERT_EQ(params.nPorts, 2U);
        kPortIndexInput = params.nStartPortNumber;
        kPortIndexOutput = kPortIndexInput + 1;
    }

    android::Vector<BufferInfo> iBuffer, oBuffer;

    // set port mode
    PortMode portMode[2];
    initPortMode(portMode, isSecure, compClass);
    status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
    EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
    status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
    EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);

    // set state to idle
    changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
                            kPortIndexInput, kPortIndexOutput, portMode);
    // Only Allow Port Mode configuration in loaded state
    status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
    EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
    status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
    EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);

    // set state to executing
    changeStateIdletoExecute(omxNode, observer);
    // Only Allow Port Mode configuration in loaded state
    status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
    EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);
    status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
    EXPECT_NE(status, ::android::hardware::media::omx::V1_0::Status::OK);

    // set state to idle
    changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer);
    // set state to loaded
    changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer,
                            kPortIndexInput, kPortIndexOutput);

    status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
    EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
    status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
    EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
}

// state transitions test
TEST_F(ComponentHidlTest, StateTransitions) {
    description("Test State Transitions Loaded<->Idle<->Execute");
+21 −3
Original line number Diff line number Diff line
@@ -10,9 +10,15 @@ namespace implementation {
Event::Event() : mStatus(Status::WAITING) {}

Event::~Event() {
    if (mThread.joinable()) {
        mThread.join();
    }
    // Note that we cannot call Event::join_thread from here: Event is
    // intended to be reference counted, and it is possible that the
    // reference count drops to zero in the bound thread, causing the
    // bound thread to call this destructor. If a thread tries to join
    // itself, it throws an exception, producing a message like the
    // following:
    //
    //     terminating with uncaught exception of type std::__1::system_error:
    //     thread::join failed: Resource deadlock would occur
}

Return<void> Event::notify(ReturnedStatus status) {
@@ -38,6 +44,7 @@ Event::Status Event::poll() {
Event::Status Event::wait() {
    std::unique_lock<std::mutex> lock(mMutex);
    mCondition.wait(lock, [this]{return mStatus != Status::WAITING;});
    join_thread_locked();
    return mStatus;
}

@@ -69,6 +76,17 @@ bool Event::bind_thread(std::thread&& asyncThread) {
    return true;
}

void Event::join_thread() {
    std::lock_guard<std::mutex> lock(mMutex);
    join_thread_locked();
}

void Event::join_thread_locked() {
    if (mThread.joinable()) {
        mThread.join();
    }
}

}  // namespace implementation
}  // namespace V1_0
}  // namespace neuralnetworks
+31 −5
Original line number Diff line number Diff line
@@ -139,9 +139,18 @@ struct Event : public IEvent {
    bool on_finish(std::function<bool(void)> callback);

    /**
     * Event::bind_thread binds a thread to the event ensuring that the thread
     * has fully finished and cleaned its resources before the event is
     * destroyed. The thread should be bound using std::move.
     * Event::bind_thread binds a thread to the event for later use by
     * Event::join_thread.
     *
     * The thread must be passed using std::move.
     *
     * Once a thread is bound with Event::bind_thread, the client code
     * should ensure that one of the following occurs before the event is
     * destroyed:
     * - Event::join_thread has been called.
     * - Event::wait has been called.
     * - Event::wait_for has been called and returned other than TIMEOUT.
     * - Event::wait_until has been called and returned other than TIMEOUT.
     *
     * The bound thread shall not call any Event method with the exception of
     * IEvent::notify, which it will call when the thread has finished its
@@ -156,7 +165,18 @@ struct Event : public IEvent {
     */
    bool bind_thread(std::thread&& asyncThread);

    /**
     * Event::join_thread ensures that the thread (if any) bound to
     * this event with Event::bind_thread has fully finished and
     * cleaned its resources. It is legal to call this function
     * multiple times, concurrently or sequentially.
     */
    void join_thread();

 private:
    // Same as Event::join_thread but assumes we already hold a lock on mMutex.
    void join_thread_locked();

    Status                    mStatus;
    std::mutex                mMutex;
    std::condition_variable   mCondition;
@@ -172,6 +192,9 @@ Event::Status Event::wait_for(const std::chrono::duration<Rep,Period>& timeout_d
    std::unique_lock<std::mutex> lock(mMutex);
    std::cv_status status = mCondition.wait_for(lock, timeout_duration,
                                                [this]{return mStatus != Status::WAITING;});
    if (status != std::cv_status::timeout) {
        join_thread_locked();
    }
    return status != std::cv_status::timeout ? mStatus : Status::TIMEOUT;
}

@@ -180,6 +203,9 @@ Event::Status Event::wait_until(const std::chrono::time_point<Clock,Duration>& t
    std::unique_lock<std::mutex> lock(mMutex);
    std::cv_status status = mCondition.wait_until(lock, timeout_time,
                                                  [this]{return mStatus != Status::WAITING;});
    if (status != std::cv_status::timeout) {
        join_thread_locked();
    }
    return status != std::cv_status::timeout ? mStatus : Status::TIMEOUT;
}