[Libva] [PATCH RFC intel-driver 06/11] test: add i965 test fixture
U. Artie Eoff
ullysses.a.eoff at intel.com
Thu Sep 1 19:59:40 UTC 2016
Add an i965 test fixture class which creates a va drm display
for driver testing and initializes/terminates va. It also
provides some conversion operators for converting to various
driver data types. Various driver wrapper functions are
provided, too, for convenience.
Signed-off-by: U. Artie Eoff <ullysses.a.eoff at intel.com>
---
test/Makefile.am | 4 +
test/i965_internal_decl.h | 71 ++++++++++++++
test/i965_test_fixture.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++
test/i965_test_fixture.h | 237 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 535 insertions(+)
create mode 100644 test/i965_internal_decl.h
create mode 100644 test/i965_test_fixture.cpp
create mode 100644 test/i965_test_fixture.h
diff --git a/test/Makefile.am b/test/Makefile.am
index f309de202559..7521a3772e11 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -11,6 +11,7 @@ AM_CPPFLAGS = \
-DGTEST_HAS_TR1_TUPLE=1 \
-DPTHREADS \
-DVA_DRIVERS_PATH="\"$(LIBVA_DRIVERS_PATH)\"" \
+ -DTEST_VA_DRIVERS_PATH="\"$(abs_top_srcdir)/src/.libs\"" \
-std=c++11 \
$(NULL)
@@ -43,10 +44,13 @@ EXTRA_DIST = \
# test_i965_drv_video
noinst_PROGRAMS = test_i965_drv_video
noinst_HEADERS = \
+ i965_internal_decl.h \
+ i965_test_fixture.h \
test.h \
$(NULL)
test_i965_drv_video_SOURCES = \
+ i965_test_fixture.cpp \
test_main.cpp \
$(NULL)
diff --git a/test/i965_internal_decl.h b/test/i965_internal_decl.h
new file mode 100644
index 000000000000..ceaa1d3a8e39
--- /dev/null
+++ b/test/i965_internal_decl.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef I965_INTERNAL_DECL_H
+#define I965_INTERNAL_DECL_H
+
+extern "C" {
+ #include "sysdeps.h"
+ #include "i965_drv_video.h"
+
+ extern VAStatus i965_CreateConfig(
+ VADriverContextP, VAProfile, VAEntrypoint,
+ VAConfigAttrib *, int, VAConfigID *);
+
+ extern VAStatus i965_DestroyConfig(
+ VADriverContextP, VAConfigID);
+
+ extern VAStatus i965_CreateContext(
+ VADriverContextP, VAConfigID, int, int,
+ int, VASurfaceID *, int, VAContextID *);
+
+ extern VAStatus i965_DestroyContext(
+ VADriverContextP, VAContextID);
+
+ extern VAStatus i965_CreateBuffer(
+ VADriverContextP, VAContextID, VABufferType,
+ unsigned, unsigned, void *, VABufferID *);
+
+ extern VAStatus i965_DestroyBuffer(
+ VADriverContextP, VABufferID);
+
+ extern VAStatus i965_BeginPicture(
+ VADriverContextP, VAContextID, VASurfaceID);
+
+ extern VAStatus i965_RenderPicture(
+ VADriverContextP, VAContextID,
+ VABufferID *, int);
+
+ extern VAStatus i965_EndPicture(
+ VADriverContextP, VAContextID);
+
+ extern VAStatus i965_DeriveImage(
+ VADriverContextP, VASurfaceID, VAImage *);
+
+ extern VAStatus i965_DestroyImage(
+ VADriverContextP, VAImageID);
+
+} // extern "C"
+
+#endif
diff --git a/test/i965_test_fixture.cpp b/test/i965_test_fixture.cpp
new file mode 100644
index 000000000000..1cf48a11ee83
--- /dev/null
+++ b/test/i965_test_fixture.cpp
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "i965_test_fixture.h"
+
+#include <fcntl.h> // for O_RDWR
+#include <unistd.h> // for close()
+#include <va/va_drm.h>
+
+I965TestFixture::I965TestFixture()
+ : ::testing::Test::Test()
+ , m_handle(-1)
+ , m_vaDisplay(NULL)
+{
+ setenv("LIBVA_DRIVERS_PATH", TEST_VA_DRIVERS_PATH, 1);
+ setenv("LIBVA_DRIVER_NAME", "i965", 1);
+}
+
+I965TestFixture::~I965TestFixture()
+{
+ if (m_handle >= 0)
+ close(m_handle);
+ m_handle = -1;
+ m_vaDisplay = NULL;
+}
+
+void I965TestFixture::initialize()
+{
+ ASSERT_FALSE(NULL == (VADisplay)*this);
+
+ int major, minor;
+ ASSERT_STATUS(vaInitialize(*this, &major, &minor));
+
+ EXPECT_EQ(VA_MAJOR_VERSION, major);
+ EXPECT_EQ(VA_MINOR_VERSION, minor);
+
+ VADriverContextP context(*this);
+ ASSERT_PTR(context);
+
+ const std::string vendor(context->str_vendor);
+
+ ::testing::Test::RecordProperty("driver_vendor", vendor);
+ ::testing::Test::RecordProperty("vaapi_version", VA_VERSION_S);
+}
+
+void I965TestFixture::terminate()
+{
+ if (m_vaDisplay)
+ EXPECT_STATUS(vaTerminate(m_vaDisplay));
+}
+
+I965TestFixture::operator VADisplay()
+{
+ if (m_vaDisplay)
+ return m_vaDisplay;
+
+ m_handle = open("/dev/dri/renderD128", O_RDWR);
+ if (m_handle < 0)
+ m_handle = open("/dev/dri/card0", O_RDWR);
+
+ m_vaDisplay = vaGetDisplayDRM(m_handle);
+ if (!m_vaDisplay && m_handle >= 0) {
+ close(m_handle);
+ m_handle = -1;
+ }
+
+ return m_vaDisplay;
+}
+
+Surfaces I965TestFixture::createSurfaces(int w, int h, int format, size_t count)
+{
+ Surfaces surfaces(count, VA_INVALID_ID);
+ EXPECT_STATUS(
+ i965_CreateSurfaces(
+ *this, w, h, format, surfaces.size(), surfaces.data()));
+
+ for (size_t i(0); i < count; ++i) {
+ EXPECT_ID(surfaces[i]);
+ }
+
+ return surfaces;
+}
+
+void I965TestFixture::destroySurfaces(Surfaces& surfaces)
+{
+ EXPECT_STATUS(
+ i965_DestroySurfaces(*this, surfaces.data(), surfaces.size()));
+}
+
+VAConfigID I965TestFixture::createConfig(
+ VAProfile profile, VAEntrypoint entrypoint, ConfigAttribs& attribs)
+{
+ VAConfigID id = VA_INVALID_ID;
+ EXPECT_STATUS(
+ i965_CreateConfig(
+ *this, profile, entrypoint, attribs.data(), attribs.size(), &id));
+ EXPECT_ID(id);
+
+ return id;
+}
+
+void I965TestFixture::destroyConfig(VAConfigID id)
+{
+ EXPECT_STATUS(i965_DestroyConfig(*this, id));
+}
+
+VAContextID I965TestFixture::createContext(
+ VAConfigID config, int w, int h, int flags, Surfaces& targets)
+{
+ VAContextID id = VA_INVALID_ID;
+ EXPECT_STATUS(
+ i965_CreateContext(
+ *this, config, w, h, flags, targets.data(), targets.size(), &id));
+ EXPECT_ID(id);
+
+ return id;
+}
+
+void I965TestFixture::destroyContext(VAContextID id)
+{
+ EXPECT_STATUS(i965_DestroyContext(*this, id));
+}
+
+VABufferID I965TestFixture::createBuffer(
+ VAContextID context, VABufferType type,
+ unsigned size, unsigned num, const void *data)
+{
+ VABufferID id;
+ EXPECT_STATUS(
+ i965_CreateBuffer(*this, context, type, size, num, (void*)data, &id));
+ EXPECT_ID(id);
+
+ return id;
+}
+
+void I965TestFixture::beginPicture(VAContextID context, VASurfaceID target)
+{
+ EXPECT_STATUS(
+ i965_BeginPicture(*this, context, target));
+}
+
+void I965TestFixture::renderPicture(
+ VAContextID context, VABufferID *bufs, int num_bufs)
+{
+ EXPECT_STATUS(
+ i965_RenderPicture(*this, context, bufs, num_bufs));
+}
+
+void I965TestFixture::endPicture(VAContextID context)
+{
+ EXPECT_STATUS(
+ i965_EndPicture(*this, context));
+}
+
+void I965TestFixture::destroyBuffer(VABufferID id)
+{
+ EXPECT_STATUS(
+ i965_DestroyBuffer(*this, id));
+}
+
+void I965TestFixture::deriveImage(VASurfaceID surface, VAImage &image)
+{
+ EXPECT_STATUS(
+ i965_DeriveImage(*this, surface, &image));
+}
+
+void I965TestFixture::destroyImage(VAImage &image)
+{
+ EXPECT_STATUS(
+ i965_DestroyImage(*this, image.image_id));
+}
+
+class I965TestFixtureTest
+ : public I965TestFixture
+{
+protected:
+ virtual void SetUp() { } // override I965TestFixture::SetUp
+ virtual void TearDown() { } // override I965TestFixture::TearDown
+};
+
+TEST_F(I965TestFixtureTest, Logic)
+{
+ VADisplayContextP dispCtx(*this);
+ VADriverContextP drvCtx(*this);
+ struct i965_driver_data* i965(*this);
+ VADisplay display(*this);
+
+ EXPECT_PTR(display);
+ EXPECT_PTR(dispCtx);
+ EXPECT_PTR(drvCtx);
+ EXPECT_TRUE(NULL == i965);
+ EXPECT_TRUE(NULL == drvCtx->handle);
+
+ ASSERT_NO_FATAL_FAILURE(initialize());
+
+ i965 = *this;
+ EXPECT_PTR(i965);
+ EXPECT_PTR(drvCtx->handle);
+
+ terminate();
+}
+
diff --git a/test/i965_test_fixture.h b/test/i965_test_fixture.h
new file mode 100644
index 000000000000..f80384810410
--- /dev/null
+++ b/test/i965_test_fixture.h
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef I965_TEST_FIXTURE_H
+#define I965_TEST_FIXTURE_H
+
+#include "test.h"
+#include "i965_internal_decl.h"
+
+#include <vector>
+
+typedef std::vector<VASurfaceID> Surfaces;
+typedef std::vector<VAConfigAttrib> ConfigAttribs;
+
+/**
+ * This test fixture handles initialization and termination of the i965 driver
+ * and display. It defines various operators to make it implicitly convertible
+ * to a VADriverContextP, VADisplay, VADisplayContextP, and i965_driver_data*.
+ * Other operators may be defined, too. These operators allow an instance of
+ * the test fixture to be passed to various driver functions that take one of
+ * those parameter types. Various driver functions are also wrapped by this
+ * test fixture to simplify writing test cases.
+ *
+ * Test cases that wish to use this fixture should define their own test
+ * fixture class that derives from this one. The derived test fixture may
+ * override the SetUp() and TearDown() methods. These two methods are invoked
+ * by gtest before and after a TEST_F test body is executed, respectively. The
+ * derived test fixture should be sure to call the I965TestFixture::SetUp() and
+ * I965TestFixture::TearDown() methods when they are overridden to ensure
+ * proper initialization and termination of the driver and display.
+ *
+ * See the "Test Fixtures" section in gtest/docs/Primer.md for more details
+ * on how test fixtures are used.
+ */
+class I965TestFixture
+ : public ::testing::Test
+{
+public:
+ I965TestFixture();
+ virtual ~I965TestFixture();
+
+protected:
+ /**
+ * This is invoked by gtest before the test body is executed. Gtest will
+ * not run the test body if this method generates a fatal test assertion
+ * failure.
+ */
+ virtual void SetUp()
+ {
+ ASSERT_NO_FATAL_FAILURE(initialize());
+ }
+
+ /**
+ * This is invoked by gtest after the test body is executed... even if the
+ * test body generates a fatal or non-fatal test assertion failure. If
+ * SetUp() generates a fatal test assertion, this is also invoked by gtest
+ * afterwards.
+ */
+ virtual void TearDown()
+ {
+ terminate();
+ }
+
+public:
+ /**
+ * Initializes the i965 driver and display. May generate a fatal or
+ * non-fatal test assertion failure.
+ */
+ void initialize();
+
+ /**
+ * Terminates the i965 driver and display. May generate a non-fatal
+ * test assertion failure.
+ */
+ void terminate();
+
+ /**
+ * Convenience wrapper for i965_CreateSurfaces. May generate a non-fatal
+ * test assertion failure.
+ */
+ Surfaces createSurfaces(int w, int h, int format, size_t count = 1);
+
+ /**
+ * Convenience wrapper for i965_DestroySurfaces. May generate a non-fatal
+ * test assertion failure.
+ */
+ void destroySurfaces(Surfaces&);
+
+ /**
+ * Convenience wrapper for i965_CreateConfig. May generate a non-fatal
+ * test assertion failure.
+ */
+ VAConfigID createConfig(VAProfile, VAEntrypoint, ConfigAttribs&);
+
+ /**
+ * Convenience wrapper for i965_DestroyConfig. May generate a non-fatal
+ * test assertion failure.
+ */
+ void destroyConfig(VAConfigID);
+
+ /**
+ * Convenience wrapper for i965_CreateContext. May generate a non-fatal
+ * test assertion failure.
+ */
+ VAContextID createContext(VAConfigID, int, int, int, Surfaces&);
+
+ /**
+ * Convenience wrapper for i965_DestroyContext. May generate a non-fatal
+ * test assertion failure.
+ */
+ void destroyContext(VAContextID);
+
+ /**
+ * Convenience wrapper for i965_CreateBuffer. May generate a non-fatal
+ * test assertion failure.
+ */
+ VABufferID createBuffer(
+ VAContextID, VABufferType, unsigned, unsigned = 1, const void * = NULL);
+
+ /**
+ * Convenience wrapper for i965_DestroyBuffer. May generate a non-fatal
+ * test assertion failure.
+ */
+ void destroyBuffer(VABufferID);
+
+ /**
+ * Convenience wrapper for i965_MapBuffer. May generate a non-fatal
+ * test assertion failure.
+ */
+ template<typename T>
+ T* mapBuffer(VABufferID id)
+ {
+ T* data = NULL;
+ EXPECT_STATUS(
+ i965_MapBuffer(*this, id, (void**)&data));
+ EXPECT_PTR(data);
+ return data;
+ }
+
+ /**
+ * Convenience Wrapper for i965_UnmapBuffer. May generate a non-fatal
+ * test assertion failure.
+ */
+ void unmapBuffer(VABufferID id)
+ {
+ EXPECT_STATUS(
+ i965_UnmapBuffer(*this, id));
+ }
+
+ /**
+ * Convenience wrapper for i965_BeginPicture. May generate a non-fatal
+ * test assertion failure.
+ */
+ void beginPicture(VAContextID, VASurfaceID);
+
+ /**
+ * Convenience wrapper for i965_RenderPicture. May generate a non-fatal
+ * test assertion failure.
+ */
+ void renderPicture(VAContextID, VABufferID *, int = 1);
+
+ /**
+ * Convenience wrapper for i965_EndPicture. May generate a non-fatal
+ * test assertion failure.
+ */
+ void endPicture(VAContextID);
+
+ /**
+ * Convenience wrapper for i965_DeriveImage. May generate a non-fatal
+ * test assertion failure.
+ */
+ void deriveImage(VASurfaceID, VAImage &);
+
+ /**
+ * Convenience wrapper for i965_DestroyImage. May generate a non-fatal
+ * test assertion failure.
+ */
+ void destroyImage(VAImage &);
+
+ /**
+ * VADisplay implicit and explicit conversion operator.
+ */
+ operator VADisplay();
+
+ /**
+ * VADisplayContextP implict and explicit conversion operator.
+ */
+ inline operator VADisplayContextP()
+ {
+ return (VADisplayContextP)((VADisplay)*this);
+ }
+
+ /**
+ * VADriverContextP implict and explicit conversion operator.
+ */
+ inline operator VADriverContextP()
+ {
+ VADisplayContextP dctx(*this);
+ return dctx ? dctx->pDriverContext : NULL;
+ }
+
+ /**
+ * i965_driver_data * implict and explicit conversion operator.
+ */
+ inline operator struct i965_driver_data *()
+ {
+ VADriverContextP ctx(*this);
+ return ctx ? i965_driver_data(ctx) : NULL;
+ }
+
+private:
+ int m_handle; /* current native display handle */
+ VADisplay m_vaDisplay; /* current VADisplay handle */
+};
+
+#endif
--
2.4.11
More information about the Libva
mailing list