2 * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "i965_test_fixture.h"
27 #include <fcntl.h> // for O_RDWR
28 #include <unistd.h> // for close()
29 #include <va/va_drm.h>
31 I965TestFixture::I965TestFixture()
32 : ::testing::Test::Test()
36 setenv("LIBVA_DRIVERS_PATH", TEST_VA_DRIVERS_PATH, 1);
37 setenv("LIBVA_DRIVER_NAME", "i965", 1);
40 I965TestFixture::~I965TestFixture()
48 const std::string I965TestFixture::getFullTestName() const
50 const ::testing::TestInfo * const info =
51 ::testing::UnitTest::GetInstance()->current_test_info();
52 return std::string(info->test_case_name())
54 + std::string(info->name());
57 void I965TestFixture::initialize()
59 ASSERT_FALSE(NULL == (VADisplay)*this);
62 ASSERT_STATUS(vaInitialize(*this, &major, &minor));
64 EXPECT_EQ(VA_MAJOR_VERSION, major);
65 EXPECT_EQ(VA_MINOR_VERSION, minor);
67 VADriverContextP context(*this);
70 const std::string vendor(context->str_vendor);
72 ::testing::Test::RecordProperty("driver_vendor", vendor);
73 ::testing::Test::RecordProperty("vaapi_version", VA_VERSION_S);
76 void I965TestFixture::terminate()
79 EXPECT_STATUS(vaTerminate(m_vaDisplay));
82 I965TestFixture::operator VADisplay()
87 m_handle = open("/dev/dri/renderD128", O_RDWR);
89 m_handle = open("/dev/dri/card0", O_RDWR);
91 m_vaDisplay = vaGetDisplayDRM(m_handle);
92 if (!m_vaDisplay && m_handle >= 0) {
100 Surfaces I965TestFixture::createSurfaces(int w, int h, int format, size_t count)
102 Surfaces surfaces(count, VA_INVALID_ID);
105 *this, w, h, format, surfaces.size(), surfaces.data()));
107 for (size_t i(0); i < count; ++i) {
108 EXPECT_ID(surfaces[i]);
114 void I965TestFixture::destroySurfaces(Surfaces& surfaces)
117 i965_DestroySurfaces(*this, surfaces.data(), surfaces.size()));
120 VAConfigID I965TestFixture::createConfig(
121 VAProfile profile, VAEntrypoint entrypoint, ConfigAttribs& attribs)
123 VAConfigID id = VA_INVALID_ID;
126 *this, profile, entrypoint, attribs.data(), attribs.size(), &id));
132 void I965TestFixture::destroyConfig(VAConfigID id)
134 EXPECT_STATUS(i965_DestroyConfig(*this, id));
137 VAContextID I965TestFixture::createContext(
138 VAConfigID config, int w, int h, int flags, Surfaces& targets)
140 VAContextID id = VA_INVALID_ID;
143 *this, config, w, h, flags, targets.data(), targets.size(), &id));
149 void I965TestFixture::destroyContext(VAContextID id)
151 EXPECT_STATUS(i965_DestroyContext(*this, id));
154 VABufferID I965TestFixture::createBuffer(
155 VAContextID context, VABufferType type,
156 unsigned size, unsigned num, const void *data)
160 i965_CreateBuffer(*this, context, type, size, num, (void*)data, &id));
166 void I965TestFixture::beginPicture(VAContextID context, VASurfaceID target)
169 i965_BeginPicture(*this, context, target));
172 void I965TestFixture::renderPicture(
173 VAContextID context, VABufferID *bufs, int num_bufs)
176 i965_RenderPicture(*this, context, bufs, num_bufs));
179 void I965TestFixture::endPicture(VAContextID context)
182 i965_EndPicture(*this, context));
185 void I965TestFixture::destroyBuffer(VABufferID id)
188 i965_DestroyBuffer(*this, id));
191 void I965TestFixture::deriveImage(VASurfaceID surface, VAImage &image)
194 i965_DeriveImage(*this, surface, &image));
197 void I965TestFixture::destroyImage(VAImage &image)
200 i965_DestroyImage(*this, image.image_id));
203 class I965TestFixtureTest
204 : public I965TestFixture
207 virtual void SetUp() { } // override I965TestFixture::SetUp
208 virtual void TearDown() { } // override I965TestFixture::TearDown
211 TEST_F(I965TestFixtureTest, Logic)
213 VADisplayContextP dispCtx(*this);
214 VADriverContextP drvCtx(*this);
215 struct i965_driver_data* i965(*this);
216 VADisplay display(*this);
221 EXPECT_TRUE(NULL == i965);
222 EXPECT_TRUE(NULL == drvCtx->handle);
224 ASSERT_NO_FATAL_FAILURE(initialize());
228 EXPECT_PTR(drvCtx->handle);