OSDN Git Service

test: add getFullTestName to i965 test fixture
[android-x86/hardware-intel-common-vaapi.git] / test / i965_test_fixture.cpp
1 /*
2  * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
3  *
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:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
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.
23  */
24
25 #include "i965_test_fixture.h"
26
27 #include <fcntl.h> // for O_RDWR
28 #include <unistd.h> // for close()
29 #include <va/va_drm.h>
30
31 I965TestFixture::I965TestFixture()
32     : ::testing::Test::Test()
33     , m_handle(-1)
34     , m_vaDisplay(NULL)
35 {
36     setenv("LIBVA_DRIVERS_PATH", TEST_VA_DRIVERS_PATH, 1);
37     setenv("LIBVA_DRIVER_NAME", "i965", 1);
38 }
39
40 I965TestFixture::~I965TestFixture()
41 {
42     if (m_handle >= 0)
43         close(m_handle);
44     m_handle = -1;
45     m_vaDisplay = NULL;
46 }
47
48 const std::string I965TestFixture::getFullTestName() const
49 {
50     const ::testing::TestInfo * const info =
51         ::testing::UnitTest::GetInstance()->current_test_info();
52     return std::string(info->test_case_name())
53         + std::string(".")
54         + std::string(info->name());
55 }
56
57 void I965TestFixture::initialize()
58 {
59     ASSERT_FALSE(NULL == (VADisplay)*this);
60
61     int major, minor;
62     ASSERT_STATUS(vaInitialize(*this, &major, &minor));
63
64     EXPECT_EQ(VA_MAJOR_VERSION, major);
65     EXPECT_EQ(VA_MINOR_VERSION, minor);
66
67     VADriverContextP context(*this);
68     ASSERT_PTR(context);
69
70     const std::string vendor(context->str_vendor);
71
72     ::testing::Test::RecordProperty("driver_vendor", vendor);
73     ::testing::Test::RecordProperty("vaapi_version", VA_VERSION_S);
74 }
75
76 void I965TestFixture::terminate()
77 {
78     if (m_vaDisplay)
79         EXPECT_STATUS(vaTerminate(m_vaDisplay));
80 }
81
82 I965TestFixture::operator VADisplay()
83 {
84     if (m_vaDisplay)
85         return m_vaDisplay;
86
87     m_handle = open("/dev/dri/renderD128", O_RDWR);
88     if (m_handle < 0)
89         m_handle = open("/dev/dri/card0", O_RDWR);
90
91     m_vaDisplay = vaGetDisplayDRM(m_handle);
92     if (!m_vaDisplay && m_handle >= 0) {
93         close(m_handle);
94         m_handle = -1;
95     }
96
97     return m_vaDisplay;
98 }
99
100 Surfaces I965TestFixture::createSurfaces(int w, int h, int format, size_t count)
101 {
102     Surfaces surfaces(count, VA_INVALID_ID);
103     EXPECT_STATUS(
104         i965_CreateSurfaces(
105             *this, w, h, format, surfaces.size(), surfaces.data()));
106
107     for (size_t i(0); i < count; ++i) {
108         EXPECT_ID(surfaces[i]);
109     }
110
111     return surfaces;
112 }
113
114 void I965TestFixture::destroySurfaces(Surfaces& surfaces)
115 {
116     EXPECT_STATUS(
117         i965_DestroySurfaces(*this, surfaces.data(), surfaces.size()));
118 }
119
120 VAConfigID I965TestFixture::createConfig(
121     VAProfile profile, VAEntrypoint entrypoint, ConfigAttribs& attribs)
122 {
123     VAConfigID id = VA_INVALID_ID;
124     EXPECT_STATUS(
125         i965_CreateConfig(
126             *this, profile, entrypoint, attribs.data(), attribs.size(), &id));
127     EXPECT_ID(id);
128
129     return id;
130 }
131
132 void I965TestFixture::destroyConfig(VAConfigID id)
133 {
134     EXPECT_STATUS(i965_DestroyConfig(*this, id));
135 }
136
137 VAContextID I965TestFixture::createContext(
138     VAConfigID config, int w, int h, int flags, Surfaces& targets)
139 {
140     VAContextID id = VA_INVALID_ID;
141     EXPECT_STATUS(
142         i965_CreateContext(
143             *this, config, w, h, flags, targets.data(), targets.size(), &id));
144     EXPECT_ID(id);
145
146     return id;
147 }
148
149 void I965TestFixture::destroyContext(VAContextID id)
150 {
151     EXPECT_STATUS(i965_DestroyContext(*this, id));
152 }
153
154 VABufferID I965TestFixture::createBuffer(
155     VAContextID context, VABufferType type,
156     unsigned size, unsigned num, const void *data)
157 {
158     VABufferID id;
159     EXPECT_STATUS(
160         i965_CreateBuffer(*this, context, type, size, num, (void*)data, &id));
161     EXPECT_ID(id);
162
163     return id;
164 }
165
166 void I965TestFixture::beginPicture(VAContextID context, VASurfaceID target)
167 {
168     EXPECT_STATUS(
169         i965_BeginPicture(*this, context, target));
170 }
171
172 void I965TestFixture::renderPicture(
173     VAContextID context, VABufferID *bufs, int num_bufs)
174 {
175     EXPECT_STATUS(
176         i965_RenderPicture(*this, context, bufs, num_bufs));
177 }
178
179 void I965TestFixture::endPicture(VAContextID context)
180 {
181     EXPECT_STATUS(
182         i965_EndPicture(*this, context));
183 }
184
185 void I965TestFixture::destroyBuffer(VABufferID id)
186 {
187     EXPECT_STATUS(
188         i965_DestroyBuffer(*this, id));
189 }
190
191 void I965TestFixture::deriveImage(VASurfaceID surface, VAImage &image)
192 {
193     EXPECT_STATUS(
194         i965_DeriveImage(*this, surface, &image));
195 }
196
197 void I965TestFixture::destroyImage(VAImage &image)
198 {
199     EXPECT_STATUS(
200         i965_DestroyImage(*this, image.image_id));
201 }
202
203 class I965TestFixtureTest
204     : public I965TestFixture
205 {
206 protected:
207     virtual void SetUp() { } // override I965TestFixture::SetUp
208     virtual void TearDown() { } // override I965TestFixture::TearDown
209 };
210
211 TEST_F(I965TestFixtureTest, Logic)
212 {
213     VADisplayContextP dispCtx(*this);
214     VADriverContextP drvCtx(*this);
215     struct i965_driver_data* i965(*this);
216     VADisplay display(*this);
217
218     EXPECT_PTR(display);
219     EXPECT_PTR(dispCtx);
220     EXPECT_PTR(drvCtx);
221     EXPECT_TRUE(NULL == i965);
222     EXPECT_TRUE(NULL == drvCtx->handle);
223
224     ASSERT_NO_FATAL_FAILURE(initialize());
225
226     i965 = *this;
227     EXPECT_PTR(i965);
228     EXPECT_PTR(drvCtx->handle);
229
230     terminate();
231 }