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

Commit 7ea777f0 authored by Igor Murashkin's avatar Igor Murashkin
Browse files

gui: Add tests for IGraphicBufferProducer

* Basic tests only. Needs more complicated queue/dequeue tests.
* Also needs consumer-side tests to really be thorough.

Change-Id: I1099dd56d65b6e9dfa15377726d6054ce657c0ca
parent 4be18a35
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public:
    //
    // This will fail if the producer has dequeued any buffers, or if
    // bufferCount is invalid.  bufferCount must generally be a value
    // between the minimum undequeued buffer count and NUM_BUFFER_SLOTS
    // between the minimum undequeued buffer count (exclusive) and NUM_BUFFER_SLOTS
    // (inclusive).  It may also be set to zero (the default) to indicate
    // that the producer does not wish to set a value.  The minimum value
    // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
+8 −3
Original line number Diff line number Diff line
@@ -84,9 +84,13 @@ public:
    // This function should not be called when there are any dequeued buffer
    // slots, doing so will result in a BAD_VALUE error returned.
    //
    // The buffer count should be at most NUM_BUFFER_SLOTS, but at least
    // the minimum undequeued buffer count (inclusive). The minimum value
    // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS);
    // The buffer count should be at most NUM_BUFFER_SLOTS (inclusive), but at least
    // the minimum undequeued buffer count (exclusive). The minimum value
    // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS).
    // In particular the range is (minUndequeudBuffers, NUM_BUFFER_SLOTS].
    //
    // The buffer count may also be set to 0 (the default), to indicate that
    // the producer does not wish to set a value.
    //
    // Return of a value other than NO_ERROR means an error has occurred:
    // * NO_INIT - the buffer queue has been abandoned.
@@ -315,6 +319,7 @@ public:
    // * BAD_VALUE - one of the following has occurred:
    //             * the producer is already connected
    //             * api was out of range (see above).
    //             * output was NULL.
    // * DEAD_OBJECT - the token is hosted by an already-dead process
    //
    // Additional negative errors may be returned by the internals, they
+12 −2
Original line number Diff line number Diff line
@@ -195,6 +195,11 @@ int BufferQueue::query(int what, int* outValue)
    ATRACE_CALL();
    Mutex::Autolock lock(mMutex);

    if (outValue == NULL) {
        ST_LOGE("query: outValue was NULL");
        return BAD_VALUE;
    }

    if (mAbandoned) {
        ST_LOGE("query: BufferQueue has been abandoned!");
        return NO_INIT;
@@ -654,10 +659,15 @@ retry:
        return NO_INIT;
    }

    if (output == NULL) {
        ST_LOGE("connect: output was NULL");
        return BAD_VALUE;
    }

    if (mConnectedApi != NO_CONNECTED_API) {
        ST_LOGE("connect: already connected (cur=%d, req=%d)",
                mConnectedApi, api);
        return -EINVAL;
        return BAD_VALUE;
    }

    // If we disconnect and reconnect quickly, we can be in a state where our slots are
@@ -693,7 +703,7 @@ retry:
            }
            break;
        default:
            err = -EINVAL;
            err = BAD_VALUE;
            break;
    }

+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ LOCAL_MODULE_TAGS := tests
LOCAL_SRC_FILES := \
    BufferQueue_test.cpp \
    CpuConsumer_test.cpp \
    IGraphicBufferProducer_test.cpp \
    SurfaceTextureClient_test.cpp \
    SurfaceTexture_test.cpp \
    Surface_test.cpp \
+21 −7
Original line number Diff line number Diff line
@@ -52,6 +52,12 @@ protected:
                testInfo->name());
    }

    void GetMinUndequeuedBufferCount(int* bufferCount) {
        ASSERT_NE((void*)NULL, bufferCount);
        ASSERT_EQ(OK, mBQ->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, bufferCount));
        ASSERT_LE(0, *bufferCount); // non-negative
    }

    sp<BufferQueue> mBQ;
};

@@ -97,20 +103,28 @@ TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithIllegalValues_ReturnsError)
    sp<DummyConsumer> dc(new DummyConsumer);
    mBQ->consumerConnect(dc, false);

    ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(0));
    ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(-3));
    ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(
    int minBufferCount;
    ASSERT_NO_FATAL_FAILURE(GetMinUndequeuedBufferCount(&minBufferCount));
    EXPECT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(minBufferCount - 1));

    EXPECT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(0));
    EXPECT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(-3));
    EXPECT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(
            BufferQueue::MAX_MAX_ACQUIRED_BUFFERS+1));
    ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(100));
    EXPECT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(100));
}

TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithLegalValues_Succeeds) {
    sp<DummyConsumer> dc(new DummyConsumer);
    mBQ->consumerConnect(dc, false);

    ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(1));
    ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(2));
    ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(
    int minBufferCount;
    ASSERT_NO_FATAL_FAILURE(GetMinUndequeuedBufferCount(&minBufferCount));

    EXPECT_EQ(OK, mBQ->setMaxAcquiredBufferCount(1));
    EXPECT_EQ(OK, mBQ->setMaxAcquiredBufferCount(2));
    EXPECT_EQ(OK, mBQ->setMaxAcquiredBufferCount(minBufferCount));
    EXPECT_EQ(OK, mBQ->setMaxAcquiredBufferCount(
            BufferQueue::MAX_MAX_ACQUIRED_BUFFERS));
}

Loading