OSDN Git Service

test: add common test utils
[android-x86/hardware-intel-common-vaapi.git] / test / i965_test_fixture.h
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 #ifndef I965_TEST_FIXTURE_H
26 #define I965_TEST_FIXTURE_H
27
28 #include "test.h"
29 #include "i965_internal_decl.h"
30 #include "i965_streamable.h"
31
32 #include <string>
33 #include <vector>
34
35 typedef std::vector<VASurfaceID> Surfaces;
36 typedef std::vector<VASurfaceAttrib> SurfaceAttribs;
37 typedef std::vector<VAConfigAttrib> ConfigAttribs;
38
39 /**
40  * This test fixture handles initialization and termination of the i965 driver
41  * and display. It defines various operators to make it implicitly convertible
42  * to a VADriverContextP, VADisplay, VADisplayContextP, and i965_driver_data*.
43  * Other operators may be defined, too.  These operators allow an instance of
44  * the test fixture to be passed to various driver functions that take one of
45  * those parameter types.  Various driver functions are also wrapped by this
46  * test fixture to simplify writing test cases.
47  *
48  * Test cases that wish to use this fixture should define their own test
49  * fixture class that derives from this one.  The derived test fixture may
50  * override the SetUp() and TearDown() methods.  These two methods are invoked
51  * by gtest before and after a TEST_F test body is executed, respectively.  The
52  * derived test fixture should be sure to call the I965TestFixture::SetUp() and
53  * I965TestFixture::TearDown() methods when they are overridden to ensure
54  * proper initialization and termination of the driver and display.
55  *
56  * See the "Test Fixtures" section in gtest/docs/Primer.md for more details
57  * on how test fixtures are used.
58  */
59 class I965TestFixture
60     : public ::testing::Test
61 {
62 public:
63     I965TestFixture();
64     virtual ~I965TestFixture();
65
66 protected:
67     /**
68      * This is invoked by gtest before the test body is executed.  Gtest will
69      * not run the test body if this method generates a fatal test assertion
70      * failure.
71      */
72     virtual void SetUp()
73     {
74         ASSERT_NO_FATAL_FAILURE(initialize());
75     }
76
77     /**
78      * This is invoked by gtest after the test body is executed... even if the
79      * test body generates a fatal or non-fatal test assertion failure.  If
80      * SetUp() generates a fatal test assertion, this is also invoked by gtest
81      * afterwards.
82      */
83     virtual void TearDown()
84     {
85         terminate();
86     }
87
88     const std::string getFullTestName() const;
89
90 public:
91     /**
92      * Initializes the i965 driver and display.  May generate a fatal or
93      * non-fatal test assertion failure.
94      */
95     void initialize();
96
97     /**
98      * Terminates the i965 driver and display.  May generate a non-fatal
99      * test assertion failure.
100      */
101     void terminate();
102
103     /**
104      * Convenience wrapper for i965_CreateSurfaces or i965_CreateSurfaces2.
105      * If SurfaceAttribs are specified then i965_CreateSurfaces2 is used,
106      * otherwise i965_CreateSurfaces is used. May generate a non-fatal test
107      * assertion failure.
108      */
109     Surfaces createSurfaces(int w, int h, int format, size_t count = 1,
110         const SurfaceAttribs& = SurfaceAttribs());
111
112     /**
113      * Convenience wrapper for i965_DestroySurfaces.  May generate a non-fatal
114      * test assertion failure.
115      */
116     void destroySurfaces(Surfaces&);
117
118     /**
119      * Convenience wrapper for i965_CreateConfig.  May generate a non-fatal
120      * test assertion failure.
121      */
122     VAConfigID createConfig(VAProfile, VAEntrypoint, ConfigAttribs&);
123
124     /**
125      * Convenience wrapper for i965_DestroyConfig.  May generate a non-fatal
126      * test assertion failure.
127      */
128     void destroyConfig(VAConfigID);
129
130     /**
131      * Convenience wrapper for i965_CreateContext.  May generate a non-fatal
132      * test assertion failure.
133      */
134     VAContextID createContext(VAConfigID, int, int, int, Surfaces&);
135
136     /**
137      * Convenience wrapper for i965_DestroyContext.  May generate a non-fatal
138      * test assertion failure.
139      */
140     void destroyContext(VAContextID);
141
142     /**
143      * Convenience wrapper for i965_CreateBuffer.  May generate a non-fatal
144      * test assertion failure.
145      */
146     VABufferID createBuffer(
147         VAContextID, VABufferType, unsigned, unsigned = 1, const void * = NULL);
148
149     /**
150      * Convenience wrapper for i965_DestroyBuffer.  May generate a non-fatal
151      * test assertion failure.
152      */
153     void destroyBuffer(VABufferID);
154
155     /**
156      * Convenience wrapper for i965_MapBuffer.  May generate a non-fatal
157      * test assertion failure.
158      */
159     template<typename T>
160     T* mapBuffer(VABufferID id)
161     {
162         T* data = NULL;
163         EXPECT_STATUS(
164             i965_MapBuffer(*this, id, (void**)&data));
165         EXPECT_PTR(data);
166         return data;
167     }
168
169     /**
170      * Convenience Wrapper for i965_UnmapBuffer.  May generate a non-fatal
171      * test assertion failure.
172      */
173     void unmapBuffer(VABufferID id)
174     {
175         EXPECT_STATUS(
176             i965_UnmapBuffer(*this, id));
177     }
178
179     /**
180      * Convenience wrapper for i965_BeginPicture.  May generate a non-fatal
181      * test assertion failure.
182      */
183     void beginPicture(VAContextID, VASurfaceID);
184
185     /**
186      * Convenience wrapper for i965_RenderPicture.  May generate a non-fatal
187      * test assertion failure.
188      */
189     void renderPicture(VAContextID, VABufferID *, int = 1);
190
191     /**
192      * Convenience wrapper for i965_EndPicture.  May generate a non-fatal
193      * test assertion failure.
194      */
195     void endPicture(VAContextID);
196
197     /**
198      * Convenience wrapper for i965_DeriveImage.  May generate a non-fatal
199      * test assertion failure.
200      */
201     void deriveImage(VASurfaceID, VAImage &);
202
203     /**
204      * Convenience wrapper for i965_DestroyImage.  May generate a non-fatal
205      * test assertion failure.
206      */
207     void destroyImage(VAImage &);
208
209     /**
210      * Convenience wrapper for i965_SyncSurface.  May generate a non-fatal
211      * test assertion failure.
212      */
213     void syncSurface(VASurfaceID);
214
215     /**
216      * VADisplay implicit and explicit conversion operator.
217      */
218     operator VADisplay();
219
220     /**
221      * VADisplayContextP implict and explicit conversion operator.
222      */
223     inline operator VADisplayContextP()
224     {
225         return (VADisplayContextP)((VADisplay)*this);
226     }
227
228     /**
229      * VADriverContextP implict and explicit conversion operator.
230      */
231     inline operator VADriverContextP()
232     {
233         VADisplayContextP dctx(*this);
234         return dctx ? dctx->pDriverContext : NULL;
235     }
236
237     /**
238      * i965_driver_data * implict and explicit conversion operator.
239      */
240     inline operator struct i965_driver_data *()
241     {
242         VADriverContextP ctx(*this);
243         return ctx ? i965_driver_data(ctx) : NULL;
244     }
245
246 private:
247     int m_handle; /* current native display handle */
248     VADisplay m_vaDisplay; /* current VADisplay handle */
249 };
250
251 #endif