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 "test_va_api_fixture.h"
26
27 #include <sstream>
28
29 namespace VAAPI
30 {
31
32 class VAAPIGetCreateConfig
33 : public VAAPIFixture
34 , public ::testing::WithParamInterface<std::tuple<VAProfile, VAEntrypoint> >
35 {
36 public:
VAAPIGetCreateConfig()37 VAAPIGetCreateConfig()
38 : profile(::testing::get<0>(GetParam()))
39 , entrypoint(::testing::get<1>(GetParam()))
40 { }
41
42 protected:
43 const VAProfile& profile;
44 const VAEntrypoint& entrypoint;
45
SetUp()46 virtual void SetUp()
47 {
48 VAAPIFixture::SetUp();
49 doInitialize();
50 ASSERT_FALSE(HasFailure());
51 }
52
TearDown()53 virtual void TearDown()
54 {
55 doTerminate();
56 VAAPIFixture::TearDown();
57 }
58 };
59
TEST_P(VAAPIGetCreateConfig,CreateConfigWithAttributes)60 TEST_P(VAAPIGetCreateConfig, CreateConfigWithAttributes)
61 {
62 const VAStatus expectedStatus = getSupportStatus(profile, entrypoint);
63
64 if (VA_STATUS_SUCCESS != expectedStatus) {
65 createConfig(profile, entrypoint, ConfigAttributes(), expectedStatus);
66 destroyConfig(VA_STATUS_ERROR_INVALID_CONFIG);
67 return;
68 }
69
70 // profile and entrypoint are supported
71 ConfigAttributes attribs;
72 getConfigAttributes(profile, entrypoint, attribs);
73
74 // create config with each individual supported attribute
75 for (const auto& attrib : attribs) {
76 const auto match = g_vaConfigAttribBitMasks.find(attrib.type);
77 if (match != g_vaConfigAttribBitMasks.end()) {
78 // it's a bitfield attribute
79 uint32_t bitfield(0);
80 const BitMasks& masks = match->second;
81 for (const auto mask : masks) { // for all bitmasks
82 const bool isSet((attrib.value & mask) == mask);
83
84 std::ostringstream oss;
85 oss << std::hex << "0x" << attrib.type
86 << ":0x" << attrib.value
87 << ":0x" << mask << ":" << isSet;
88 SCOPED_TRACE(oss.str());
89
90 if (isSet) {
91 // supported value
92 bitfield |= mask;
93 createConfig(profile, entrypoint,
94 ConfigAttributes(
95 1, {/*type :*/ attrib.type, /*value :*/ mask }));
96 destroyConfig();
97 } else {
98 // unsupported value
99 const VAStatus expectation(
100 (attrib.type == VAConfigAttribRTFormat) ?
101 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT :
102 VA_STATUS_ERROR_INVALID_VALUE);
103 createConfig(profile, entrypoint,
104 ConfigAttributes(
105 1, {/*type :*/ attrib.type, /*value :*/ mask}),
106 expectation);
107 destroyConfig(VA_STATUS_ERROR_INVALID_CONFIG);
108 }
109 }
110 // ensure we processed all supported values
111 EXPECT_EQ(bitfield, attrib.value);
112 } else {
113 // it's a standard attribute
114 std::ostringstream oss;
115 oss << std::hex << "0x" << attrib.type
116 << ":0x" << attrib.value;
117 SCOPED_TRACE(oss.str());
118
119 createConfig(profile, entrypoint, ConfigAttributes(1, attrib));
120 destroyConfig();
121 }
122 }
123 }
124
TEST_P(VAAPIGetCreateConfig,CreateConfigNoAttributes)125 TEST_P(VAAPIGetCreateConfig, CreateConfigNoAttributes)
126 {
127 const VAStatus expectedStatus = getSupportStatus(profile, entrypoint);
128
129 if (VA_STATUS_SUCCESS != expectedStatus) {
130 createConfig(profile, entrypoint, ConfigAttributes(), expectedStatus);
131 destroyConfig(VA_STATUS_ERROR_INVALID_CONFIG);
132 return;
133 }
134
135 // profile and entrypoint are supported
136 createConfig(profile, entrypoint);
137 destroyConfig();
138 }
139
TEST_P(VAAPIGetCreateConfig,CreateConfigPackedHeaders)140 TEST_P(VAAPIGetCreateConfig, CreateConfigPackedHeaders)
141 {
142 if (!isSupported(profile, entrypoint)) {
143 skipTest(profile, entrypoint);
144 return;
145 }
146
147 ConfigAttributes packedHeaders{{/*.type = */VAConfigAttribEncPackedHeaders}};
148 getConfigAttributes(profile, entrypoint, packedHeaders);
149
150 for (uint32_t v(0x00); v < 0xff; ++v) {
151 ConfigAttributes attribs = {{
152 /*.type = */VAConfigAttribEncPackedHeaders,
153 /*.value = */v
154 }
155 };
156 if ((VA_ATTRIB_NOT_SUPPORTED == packedHeaders.front().value)
157 || (v & ~packedHeaders.front().value)) {
158 // Creating a config should fail if attribute is not supported
159 // or for values that are not in the set of supported values.
160 createConfig(
161 profile, entrypoint, attribs, VA_STATUS_ERROR_INVALID_VALUE);
162 destroyConfig(VA_STATUS_ERROR_INVALID_CONFIG);
163 } else {
164 // Creating a config should succeed for any value within the set of
165 // supported values, including 0x0 (i.e. VA_ENC_PACKED_HEADER_NONE).
166 createConfig(profile, entrypoint, attribs, VA_STATUS_SUCCESS);
167 destroyConfig(VA_STATUS_SUCCESS);
168 }
169 }
170 }
171
172 INSTANTIATE_TEST_SUITE_P(
173 GetCreateConfig, VAAPIGetCreateConfig,
174 ::testing::Combine(::testing::ValuesIn(g_vaProfiles),
175 ::testing::ValuesIn(g_vaEntrypoints)));
176
177 } // namespace VAAPI
178