xref: /aosp_15_r20/external/deqp/executor/xeTestCase.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _XETESTCASE_HPP
2*35238bceSAndroid Build Coastguard Worker #define _XETESTCASE_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program Test Executor
5*35238bceSAndroid Build Coastguard Worker  * ------------------------------------------
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
8*35238bceSAndroid Build Coastguard Worker  *
9*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker  *
15*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
20*35238bceSAndroid Build Coastguard Worker  *
21*35238bceSAndroid Build Coastguard Worker  *//*!
22*35238bceSAndroid Build Coastguard Worker  * \file
23*35238bceSAndroid Build Coastguard Worker  * \brief Test case.
24*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "xeDefs.hpp"
27*35238bceSAndroid Build Coastguard Worker 
28*35238bceSAndroid Build Coastguard Worker #include <string>
29*35238bceSAndroid Build Coastguard Worker #include <vector>
30*35238bceSAndroid Build Coastguard Worker #include <set>
31*35238bceSAndroid Build Coastguard Worker #include <map>
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker namespace xe
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker enum TestCaseType
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker     TESTCASETYPE_SELF_VALIDATE,
39*35238bceSAndroid Build Coastguard Worker     TESTCASETYPE_CAPABILITY,
40*35238bceSAndroid Build Coastguard Worker     TESTCASETYPE_ACCURACY,
41*35238bceSAndroid Build Coastguard Worker     TESTCASETYPE_PERFORMANCE,
42*35238bceSAndroid Build Coastguard Worker 
43*35238bceSAndroid Build Coastguard Worker     TESTCASETYPE_LAST
44*35238bceSAndroid Build Coastguard Worker };
45*35238bceSAndroid Build Coastguard Worker 
46*35238bceSAndroid Build Coastguard Worker const char *getTestCaseTypeName(TestCaseType caseType);
47*35238bceSAndroid Build Coastguard Worker 
48*35238bceSAndroid Build Coastguard Worker enum TestNodeType
49*35238bceSAndroid Build Coastguard Worker {
50*35238bceSAndroid Build Coastguard Worker     TESTNODETYPE_ROOT,
51*35238bceSAndroid Build Coastguard Worker     TESTNODETYPE_GROUP,
52*35238bceSAndroid Build Coastguard Worker     TESTNODETYPE_TEST_CASE,
53*35238bceSAndroid Build Coastguard Worker 
54*35238bceSAndroid Build Coastguard Worker     TESTNODETYPE_LAST
55*35238bceSAndroid Build Coastguard Worker };
56*35238bceSAndroid Build Coastguard Worker 
57*35238bceSAndroid Build Coastguard Worker class TestGroup;
58*35238bceSAndroid Build Coastguard Worker class TestCase;
59*35238bceSAndroid Build Coastguard Worker 
60*35238bceSAndroid Build Coastguard Worker class TestNode
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker public:
~TestNode(void)63*35238bceSAndroid Build Coastguard Worker     virtual ~TestNode(void)
64*35238bceSAndroid Build Coastguard Worker     {
65*35238bceSAndroid Build Coastguard Worker     }
66*35238bceSAndroid Build Coastguard Worker 
getNodeType(void) const67*35238bceSAndroid Build Coastguard Worker     TestNodeType getNodeType(void) const
68*35238bceSAndroid Build Coastguard Worker     {
69*35238bceSAndroid Build Coastguard Worker         return m_nodeType;
70*35238bceSAndroid Build Coastguard Worker     }
getName(void) const71*35238bceSAndroid Build Coastguard Worker     const char *getName(void) const
72*35238bceSAndroid Build Coastguard Worker     {
73*35238bceSAndroid Build Coastguard Worker         return m_name.c_str();
74*35238bceSAndroid Build Coastguard Worker     }
getParent(void) const75*35238bceSAndroid Build Coastguard Worker     const TestGroup *getParent(void) const
76*35238bceSAndroid Build Coastguard Worker     {
77*35238bceSAndroid Build Coastguard Worker         return m_parent;
78*35238bceSAndroid Build Coastguard Worker     }
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker     void getFullPath(std::string &path) const;
getFullPath(void) const81*35238bceSAndroid Build Coastguard Worker     std::string getFullPath(void) const
82*35238bceSAndroid Build Coastguard Worker     {
83*35238bceSAndroid Build Coastguard Worker         std::string str;
84*35238bceSAndroid Build Coastguard Worker         getFullPath(str);
85*35238bceSAndroid Build Coastguard Worker         return str;
86*35238bceSAndroid Build Coastguard Worker     }
87*35238bceSAndroid Build Coastguard Worker 
88*35238bceSAndroid Build Coastguard Worker     const TestNode *find(const char *path) const;
89*35238bceSAndroid Build Coastguard Worker     TestNode *find(const char *path);
90*35238bceSAndroid Build Coastguard Worker 
91*35238bceSAndroid Build Coastguard Worker protected:
92*35238bceSAndroid Build Coastguard Worker     TestNode(TestGroup *parent, TestNodeType nodeType, const char *name);
93*35238bceSAndroid Build Coastguard Worker 
94*35238bceSAndroid Build Coastguard Worker private:
95*35238bceSAndroid Build Coastguard Worker     TestNode(const TestNode &other);
96*35238bceSAndroid Build Coastguard Worker     TestNode &operator=(const TestNode &other);
97*35238bceSAndroid Build Coastguard Worker 
98*35238bceSAndroid Build Coastguard Worker     TestGroup *m_parent;
99*35238bceSAndroid Build Coastguard Worker     TestNodeType m_nodeType;
100*35238bceSAndroid Build Coastguard Worker     std::string m_name;
101*35238bceSAndroid Build Coastguard Worker     std::string m_description;
102*35238bceSAndroid Build Coastguard Worker };
103*35238bceSAndroid Build Coastguard Worker 
104*35238bceSAndroid Build Coastguard Worker class TestGroup : public TestNode
105*35238bceSAndroid Build Coastguard Worker {
106*35238bceSAndroid Build Coastguard Worker public:
107*35238bceSAndroid Build Coastguard Worker     ~TestGroup(void);
108*35238bceSAndroid Build Coastguard Worker 
getNumChildren(void) const109*35238bceSAndroid Build Coastguard Worker     int getNumChildren(void) const
110*35238bceSAndroid Build Coastguard Worker     {
111*35238bceSAndroid Build Coastguard Worker         return (int)m_children.size();
112*35238bceSAndroid Build Coastguard Worker     }
getChild(int ndx)113*35238bceSAndroid Build Coastguard Worker     TestNode *getChild(int ndx)
114*35238bceSAndroid Build Coastguard Worker     {
115*35238bceSAndroid Build Coastguard Worker         return m_children[ndx];
116*35238bceSAndroid Build Coastguard Worker     }
getChild(int ndx) const117*35238bceSAndroid Build Coastguard Worker     const TestNode *getChild(int ndx) const
118*35238bceSAndroid Build Coastguard Worker     {
119*35238bceSAndroid Build Coastguard Worker         return m_children[ndx];
120*35238bceSAndroid Build Coastguard Worker     }
121*35238bceSAndroid Build Coastguard Worker 
122*35238bceSAndroid Build Coastguard Worker     TestNode *findChildNode(const char *path);
123*35238bceSAndroid Build Coastguard Worker     const TestNode *findChildNode(const char *path) const;
124*35238bceSAndroid Build Coastguard Worker 
125*35238bceSAndroid Build Coastguard Worker     TestGroup *createGroup(const char *name);
126*35238bceSAndroid Build Coastguard Worker     TestCase *createCase(TestCaseType caseType, const char *name);
127*35238bceSAndroid Build Coastguard Worker 
128*35238bceSAndroid Build Coastguard Worker protected:
129*35238bceSAndroid Build Coastguard Worker     TestGroup(TestGroup *parent, TestNodeType nodeType, const char *name);
130*35238bceSAndroid Build Coastguard Worker 
131*35238bceSAndroid Build Coastguard Worker private:
132*35238bceSAndroid Build Coastguard Worker     std::vector<TestNode *> m_children;
133*35238bceSAndroid Build Coastguard Worker     std::set<std::string> m_childNames; //!< Used for checking for duplicate test case names.
134*35238bceSAndroid Build Coastguard Worker 
135*35238bceSAndroid Build Coastguard Worker     // For adding TestCase to m_children. \todo [2012-06-15 pyry] Is the API broken perhaps?
136*35238bceSAndroid Build Coastguard Worker     friend class TestNode;
137*35238bceSAndroid Build Coastguard Worker };
138*35238bceSAndroid Build Coastguard Worker 
139*35238bceSAndroid Build Coastguard Worker class TestRoot : public TestGroup
140*35238bceSAndroid Build Coastguard Worker {
141*35238bceSAndroid Build Coastguard Worker public:
142*35238bceSAndroid Build Coastguard Worker     TestRoot(void);
143*35238bceSAndroid Build Coastguard Worker };
144*35238bceSAndroid Build Coastguard Worker 
145*35238bceSAndroid Build Coastguard Worker class TestCase : public TestNode
146*35238bceSAndroid Build Coastguard Worker {
147*35238bceSAndroid Build Coastguard Worker public:
148*35238bceSAndroid Build Coastguard Worker     ~TestCase(void);
149*35238bceSAndroid Build Coastguard Worker 
getCaseType(void) const150*35238bceSAndroid Build Coastguard Worker     TestCaseType getCaseType(void) const
151*35238bceSAndroid Build Coastguard Worker     {
152*35238bceSAndroid Build Coastguard Worker         return m_caseType;
153*35238bceSAndroid Build Coastguard Worker     }
154*35238bceSAndroid Build Coastguard Worker 
155*35238bceSAndroid Build Coastguard Worker     static TestCase *createAsChild(TestGroup *parent, TestCaseType caseType, const char *name);
156*35238bceSAndroid Build Coastguard Worker 
157*35238bceSAndroid Build Coastguard Worker protected:
158*35238bceSAndroid Build Coastguard Worker     TestCase(TestGroup *parent, TestCaseType caseType, const char *name);
159*35238bceSAndroid Build Coastguard Worker 
160*35238bceSAndroid Build Coastguard Worker private:
161*35238bceSAndroid Build Coastguard Worker     TestCaseType m_caseType;
162*35238bceSAndroid Build Coastguard Worker };
163*35238bceSAndroid Build Coastguard Worker 
164*35238bceSAndroid Build Coastguard Worker // Helper class for efficiently constructing TestCase hierarchy from test case list.
165*35238bceSAndroid Build Coastguard Worker class TestHierarchyBuilder
166*35238bceSAndroid Build Coastguard Worker {
167*35238bceSAndroid Build Coastguard Worker public:
168*35238bceSAndroid Build Coastguard Worker     TestHierarchyBuilder(TestRoot *root);
169*35238bceSAndroid Build Coastguard Worker     ~TestHierarchyBuilder(void);
170*35238bceSAndroid Build Coastguard Worker 
171*35238bceSAndroid Build Coastguard Worker     TestCase *createCase(const char *path, TestCaseType caseType);
172*35238bceSAndroid Build Coastguard Worker 
173*35238bceSAndroid Build Coastguard Worker private:
174*35238bceSAndroid Build Coastguard Worker     TestHierarchyBuilder(const TestHierarchyBuilder &other);
175*35238bceSAndroid Build Coastguard Worker     TestHierarchyBuilder &operator=(const TestHierarchyBuilder &other);
176*35238bceSAndroid Build Coastguard Worker 
177*35238bceSAndroid Build Coastguard Worker     TestRoot *m_root;
178*35238bceSAndroid Build Coastguard Worker     std::map<std::string, TestGroup *> m_groupMap;
179*35238bceSAndroid Build Coastguard Worker };
180*35238bceSAndroid Build Coastguard Worker 
181*35238bceSAndroid Build Coastguard Worker // Helper class for computing and iterating test sets.
182*35238bceSAndroid Build Coastguard Worker class TestSet
183*35238bceSAndroid Build Coastguard Worker {
184*35238bceSAndroid Build Coastguard Worker public:
TestSet(void)185*35238bceSAndroid Build Coastguard Worker     TestSet(void)
186*35238bceSAndroid Build Coastguard Worker     {
187*35238bceSAndroid Build Coastguard Worker     }
~TestSet(void)188*35238bceSAndroid Build Coastguard Worker     ~TestSet(void)
189*35238bceSAndroid Build Coastguard Worker     {
190*35238bceSAndroid Build Coastguard Worker     }
191*35238bceSAndroid Build Coastguard Worker 
empty(void) const192*35238bceSAndroid Build Coastguard Worker     bool empty(void) const
193*35238bceSAndroid Build Coastguard Worker     {
194*35238bceSAndroid Build Coastguard Worker         return m_set.empty();
195*35238bceSAndroid Build Coastguard Worker     }
196*35238bceSAndroid Build Coastguard Worker 
197*35238bceSAndroid Build Coastguard Worker     void add(const TestNode *node);
198*35238bceSAndroid Build Coastguard Worker     void addCase(const TestCase *testCase);
199*35238bceSAndroid Build Coastguard Worker     void addGroup(const TestGroup *testGroup);
200*35238bceSAndroid Build Coastguard Worker 
201*35238bceSAndroid Build Coastguard Worker     void remove(const TestNode *node);
202*35238bceSAndroid Build Coastguard Worker     void removeCase(const TestCase *testCase);
203*35238bceSAndroid Build Coastguard Worker     void removeGroup(const TestGroup *testGroup);
204*35238bceSAndroid Build Coastguard Worker 
hasNode(const TestNode * node) const205*35238bceSAndroid Build Coastguard Worker     bool hasNode(const TestNode *node) const
206*35238bceSAndroid Build Coastguard Worker     {
207*35238bceSAndroid Build Coastguard Worker         return m_set.find(node) != m_set.end();
208*35238bceSAndroid Build Coastguard Worker     }
209*35238bceSAndroid Build Coastguard Worker 
210*35238bceSAndroid Build Coastguard Worker private:
211*35238bceSAndroid Build Coastguard Worker     std::set<const TestNode *> m_set;
212*35238bceSAndroid Build Coastguard Worker };
213*35238bceSAndroid Build Coastguard Worker 
214*35238bceSAndroid Build Coastguard Worker class ConstTestNodeIterator
215*35238bceSAndroid Build Coastguard Worker {
216*35238bceSAndroid Build Coastguard Worker public:
217*35238bceSAndroid Build Coastguard Worker     static ConstTestNodeIterator begin(const TestNode *root);
218*35238bceSAndroid Build Coastguard Worker     static ConstTestNodeIterator end(const TestNode *root);
219*35238bceSAndroid Build Coastguard Worker 
220*35238bceSAndroid Build Coastguard Worker     ConstTestNodeIterator &operator++(void);
221*35238bceSAndroid Build Coastguard Worker     ConstTestNodeIterator operator++(int);
222*35238bceSAndroid Build Coastguard Worker 
223*35238bceSAndroid Build Coastguard Worker     const TestNode *operator*(void) const;
224*35238bceSAndroid Build Coastguard Worker 
225*35238bceSAndroid Build Coastguard Worker     bool operator!=(const ConstTestNodeIterator &other) const;
226*35238bceSAndroid Build Coastguard Worker 
227*35238bceSAndroid Build Coastguard Worker protected:
228*35238bceSAndroid Build Coastguard Worker     ConstTestNodeIterator(const TestNode *root);
229*35238bceSAndroid Build Coastguard Worker 
230*35238bceSAndroid Build Coastguard Worker private:
231*35238bceSAndroid Build Coastguard Worker     struct GroupState
232*35238bceSAndroid Build Coastguard Worker     {
GroupStatexe::ConstTestNodeIterator::GroupState233*35238bceSAndroid Build Coastguard Worker         GroupState(const TestGroup *group_) : group(group_), childNdx(0)
234*35238bceSAndroid Build Coastguard Worker         {
235*35238bceSAndroid Build Coastguard Worker         }
236*35238bceSAndroid Build Coastguard Worker 
237*35238bceSAndroid Build Coastguard Worker         const TestGroup *group;
238*35238bceSAndroid Build Coastguard Worker         int childNdx;
239*35238bceSAndroid Build Coastguard Worker 
operator !=xe::ConstTestNodeIterator::GroupState240*35238bceSAndroid Build Coastguard Worker         bool operator!=(const GroupState &other) const
241*35238bceSAndroid Build Coastguard Worker         {
242*35238bceSAndroid Build Coastguard Worker             return group != other.group || childNdx != other.childNdx;
243*35238bceSAndroid Build Coastguard Worker         }
244*35238bceSAndroid Build Coastguard Worker 
operator ==xe::ConstTestNodeIterator::GroupState245*35238bceSAndroid Build Coastguard Worker         bool operator==(const GroupState &other) const
246*35238bceSAndroid Build Coastguard Worker         {
247*35238bceSAndroid Build Coastguard Worker             return group == other.group && childNdx == other.childNdx;
248*35238bceSAndroid Build Coastguard Worker         }
249*35238bceSAndroid Build Coastguard Worker     };
250*35238bceSAndroid Build Coastguard Worker 
251*35238bceSAndroid Build Coastguard Worker     const TestNode *m_root;
252*35238bceSAndroid Build Coastguard Worker     std::vector<GroupState> m_iterStack;
253*35238bceSAndroid Build Coastguard Worker };
254*35238bceSAndroid Build Coastguard Worker 
255*35238bceSAndroid Build Coastguard Worker // \todo [2012-06-19 pyry] Implement following iterators:
256*35238bceSAndroid Build Coastguard Worker //  - TestNodeIterator
257*35238bceSAndroid Build Coastguard Worker //  - ConstTestSetIterator
258*35238bceSAndroid Build Coastguard Worker //  - TestSetIterator
259*35238bceSAndroid Build Coastguard Worker 
260*35238bceSAndroid Build Coastguard Worker } // namespace xe
261*35238bceSAndroid Build Coastguard Worker 
262*35238bceSAndroid Build Coastguard Worker #endif // _XETESTCASE_HPP
263