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

Commit f213eca9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add flush test" into oc-mr1-dev

parents f11a1ef8 3ca3988e
Loading
Loading
Loading
Loading
+103 −0
Original line number Diff line number Diff line
@@ -591,6 +591,109 @@ TEST_F(ComponentHidlTest, Flush) {
                            kPortIndexInput, kPortIndexOutput);
}

// Flush test - monkeying
TEST_F(ComponentHidlTest, Flush_M) {
    description("Test Flush monkeying");
    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);

    //    // Flush all ports ; receive error OMX_ErrorIncorrectStateOperation
    //    status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
    //    OMX_ALL);
    //    ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);

    // set state to idle
    changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
                            kPortIndexInput, kPortIndexOutput, portMode);

    //    // Flush all ports ; receive error OMX_ErrorIncorrectStateOperation
    //    status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
    //    OMX_ALL);
    //    ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);

    // set state to executing
    changeStateIdletoExecute(omxNode, observer);
    // dispatch buffers
    for (size_t i = 0; i < oBuffer.size(); i++) {
        dispatchOutputBuffer(omxNode, &oBuffer, i, portMode[1]);
    }

    //    // flush invalid port, expecting OMX_ErrorBadPortIndex
    //    status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush),
    //                                  RANDOM_INDEX);
    //    ASSERT_NE(status, android::hardware::media::omx::V1_0::Status::OK);

    // Flush all ports
    status = omxNode->sendCommand(toRawCommandType(OMX_CommandFlush), OMX_ALL);
    ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);

    for (int j = 0; j < 2; j++) {
        status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, &iBuffer,
                                          &oBuffer);
        ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
        ASSERT_EQ(msg.type, Message::Type::EVENT);
        ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
        ASSERT_EQ(msg.data.eventData.data1, OMX_CommandFlush);
        if (msg.data.eventData.data2 == kPortIndexInput) {
            // test if client got all its buffers back
            for (size_t i = 0; i < iBuffer.size(); ++i) {
                EXPECT_EQ(iBuffer[i].owner, client);
            }
        } else if (msg.data.eventData.data2 == kPortIndexOutput) {
            // test if client got all its buffers back
            for (size_t i = 0; i < oBuffer.size(); ++i) {
                EXPECT_EQ(oBuffer[i].owner, client);
            }
        } else {
            EXPECT_TRUE(false) << "Bad port Index";
        }
    }

    // SPECIAL CASE: When OMX_ALL is used as argument, Android OMX Core sends
    // an additional flush event with argument OMX_ALL. This we believe is
    // not recognized by OMX-IL Spec. So read this event and ignore it
    status =
        observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_PE, &iBuffer, &oBuffer);
    if (status == android::hardware::media::omx::V1_0::Status::OK) {
        ASSERT_EQ(msg.type, Message::Type::EVENT);
        ASSERT_EQ(msg.data.eventData.event, OMX_EventCmdComplete);
        ASSERT_EQ(msg.data.eventData.data1, OMX_CommandFlush);
        ASSERT_EQ(msg.data.eventData.data2, OMX_ALL);
    }

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

// test port mode configuration when the component is in various states
TEST_F(ComponentHidlTest, PortModeConfig) {
    description("Test Port Mode Configuration");