Debian Codegraph @

media_driver/linux/ult/ult_app/ddi_test_caps.cpp

raw
1 /*
2 * Copyright (c) 2018, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 #include <algorithm>
23 #include <string>
24 #include "ddi_test_caps.h"
25
26 using namespace std;
27
28 bool CompareFeatureIDTable(vector<FeatureID> &currentTable, vector<FeatureID> &refTable)
29 {
30 if (currentTable.size() != refTable.size())
31 {
32 return false;
33 }
34
35 sort(currentTable.begin(), currentTable.end());
36 sort(refTable.begin() , refTable.end());
37
38 return equal(currentTable.begin(), currentTable.end(), refTable.begin());
39 }
40
41 int Test_QueryConfigProfiles(VADriverContextP ctx, vector<FeatureID> &queriedFeatureIDTable)
42 {
43 VAProfile profile;
44 VAEntrypoint entrypoints[10];
45 int num_profiles;
46 int num_entrypoint;
47 int max_num_profiles = ctx->max_profiles;
48 VAProfile *profile_list = nullptr;
49
50 profile_list = (VAProfile *)malloc(max_num_profiles * sizeof(VAProfile));
51 if (profile_list == nullptr)
52 {
53 return -1;
54 }
55
56 int ret = ctx->vtable->vaQueryConfigProfiles(ctx, profile_list, &num_profiles);
57 if (ret)
58 {
59 free(profile_list);
60 return -1;
61 }
62
63 for (int i = 0; i < num_profiles; i++)
64 {
65 profile = profile_list[i];
66 ret = ctx->vtable->vaQueryConfigEntrypoints(ctx, profile, entrypoints, &num_entrypoint);
67
68 if (ret == VA_STATUS_ERROR_UNSUPPORTED_PROFILE)
69 {
70 continue;
71 }
72 else if (ret)
73 {
74 free(profile_list);
75 return -1;
76 }
77 else
78 {
79 for (int j = 0; j < num_entrypoint; j++)
80 {
81 queriedFeatureIDTable.push_back({profile, entrypoints[j]});
82 }
83 }
84 }
85
86 free(profile_list);
87
88 return ret;
89 }
90
91 TEST_F(MediaCapsDdiTest, DecodeEncodeProfile)
92 {
93 vector<Platform_t> platforms = m_driverLoader.GetPlatforms();
94
95 for (int i = 0; i < m_driverLoader.GetPlatformNum(); i++)
96 {
97 vector<FeatureID> queriedFeatureIDTable;
98 vector<FeatureID> refFeatureIDTable = m_capsData.GetRefFeatureIDTable(DeviceConfigTable[platforms[i]]);
99
100 // So far we still use DeviceConfigTable to find the platform, as the libdrm mock use this.
101 // If we want to use vector Platforms, we would use vector in libdrm too.
102 int ret = m_driverLoader.InitDriver(platforms[i]);
103 EXPECT_EQ(VA_STATUS_SUCCESS , ret) << "Platform = " << g_platformName[platforms[i]]
104 << ", Failed function = m_driverLoader.InitDriver" << endl;
105
106 ret = Test_QueryConfigProfiles(&m_driverLoader.m_ctx, queriedFeatureIDTable);
107 EXPECT_EQ(VA_STATUS_SUCCESS , ret) << "Platform = " << g_platformName[platforms[i]]
108 << ", Failed function = Test_QueryConfigProfiles" << endl;
109
110 EXPECT_TRUE((CompareFeatureIDTable(queriedFeatureIDTable, refFeatureIDTable))) << "Platform = "
111 << g_platformName[platforms[i]] << ", Failed function = CompareFeatureIDTable" << endl;
112
113 ret = m_driverLoader.CloseDriver();
114 EXPECT_EQ (VA_STATUS_SUCCESS , ret) << "Platform = " << g_platformName[platforms[i]]
115 << ", Failed function = m_driverLoader.CloseDriver" << endl;
116 }
117 }
118
119 int testfunction(int a)
120 {
121 return a + 1;
122 }
123
124 TEST_F(MediaCapsDdiTest, TraceInterfaceTest)
125 {
126 //EXPECT_EQ(0, _TR_COUNT()); //compiler dependent behavior
127 EXPECT_EQ(1, _TR_COUNT(1));
128 EXPECT_EQ(2, _TR_COUNT(1, 2));
129 EXPECT_EQ(10, _TR_COUNT(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
130
131 int i = 1;
132 char b = 2;
133 uint64_t l = 3;
134 char a[] = {1, 2};
135
136 {
137 TR_FILL_PARAM(i, b);
138 EXPECT_EQ(5, sizeof(_buf));
139 EXPECT_EQ(1, *(int *)_buf);
140 }
141 {
142 TR_FILL_PARAM(b, l);
143 EXPECT_EQ(9, sizeof(_buf));
144 EXPECT_EQ(2, *(char *)_buf);
145 }
146 {
147 TR_FILL_PARAM(l, a);
148 EXPECT_EQ(10, sizeof(_buf));
149 EXPECT_EQ(3, *(uint64_t *)_buf);
150 }
151 {
152 TR_FILL_PARAM(b, (int)l);
153 EXPECT_EQ(5, sizeof(_buf));
154 EXPECT_EQ(3, *(int *)(_buf + 1));
155 }
156 {
157 TR_FILL_PARAM(b, *(short *)a);
158 EXPECT_EQ(3, sizeof(_buf));
159 EXPECT_EQ(0x201, *(short *)(_buf + 1));
160 }
161 {
162 TR_FILL_PARAM(b, testfunction(2));
163 EXPECT_EQ(5, sizeof(_buf));
164 EXPECT_EQ(3, *(int *)(_buf + 1));
165 }
166 }