xref: /aosp_15_r20/external/deqp/framework/common/tcuTestHierarchyIterator.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _TCUTESTHIERARCHYITERATOR_HPP
2*35238bceSAndroid Build Coastguard Worker #define _TCUTESTHIERARCHYITERATOR_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program Tester Core
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 hierarchy iterator.
24*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "tcuDefs.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuTestContext.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuTestCase.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuTestPackage.hpp"
30*35238bceSAndroid Build Coastguard Worker 
31*35238bceSAndroid Build Coastguard Worker #include <vector>
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker namespace tcu
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker class CaseListFilter;
37*35238bceSAndroid Build Coastguard Worker 
38*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
39*35238bceSAndroid Build Coastguard Worker  * \brief Test hierarchy inflater
40*35238bceSAndroid Build Coastguard Worker  *
41*35238bceSAndroid Build Coastguard Worker  * This interface is used by TestHierarchyIterator to materialize, and clean
42*35238bceSAndroid Build Coastguard Worker  * up, test hierarchy on-demand while walking through it.
43*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
44*35238bceSAndroid Build Coastguard Worker class TestHierarchyInflater
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker public:
47*35238bceSAndroid Build Coastguard Worker     TestHierarchyInflater(void);
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker     virtual void enterTestPackage(TestPackage *testPackage, std::vector<TestNode *> &children) = 0;
50*35238bceSAndroid Build Coastguard Worker     virtual void leaveTestPackage(TestPackage *testPackage)                                    = 0;
51*35238bceSAndroid Build Coastguard Worker 
52*35238bceSAndroid Build Coastguard Worker     virtual void enterGroupNode(TestCaseGroup *testGroup, std::vector<TestNode *> &children) = 0;
53*35238bceSAndroid Build Coastguard Worker     virtual void leaveGroupNode(TestCaseGroup *testGroup)                                    = 0;
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker protected:
56*35238bceSAndroid Build Coastguard Worker     ~TestHierarchyInflater(void);
57*35238bceSAndroid Build Coastguard Worker };
58*35238bceSAndroid Build Coastguard Worker 
59*35238bceSAndroid Build Coastguard Worker // \todo [2015-02-26 pyry] Hierarchy traversal should not depend on TestContext
60*35238bceSAndroid Build Coastguard Worker class DefaultHierarchyInflater : public TestHierarchyInflater
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker public:
63*35238bceSAndroid Build Coastguard Worker     DefaultHierarchyInflater(TestContext &testCtx);
64*35238bceSAndroid Build Coastguard Worker     ~DefaultHierarchyInflater(void);
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker     virtual void enterTestPackage(TestPackage *testPackage, std::vector<TestNode *> &children);
67*35238bceSAndroid Build Coastguard Worker     virtual void leaveTestPackage(TestPackage *testPackage);
68*35238bceSAndroid Build Coastguard Worker 
69*35238bceSAndroid Build Coastguard Worker     virtual void enterGroupNode(TestCaseGroup *testGroup, std::vector<TestNode *> &children);
70*35238bceSAndroid Build Coastguard Worker     virtual void leaveGroupNode(TestCaseGroup *testGroup);
71*35238bceSAndroid Build Coastguard Worker 
72*35238bceSAndroid Build Coastguard Worker protected:
73*35238bceSAndroid Build Coastguard Worker     TestContext &m_testCtx;
74*35238bceSAndroid Build Coastguard Worker };
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
77*35238bceSAndroid Build Coastguard Worker  * \brief Test hierarchy iterator
78*35238bceSAndroid Build Coastguard Worker  *
79*35238bceSAndroid Build Coastguard Worker  * Test hierarchy iterator allows walking test case hierarchy in depth-first
80*35238bceSAndroid Build Coastguard Worker  * order. The walked sub-tree is limited by command line parameters.
81*35238bceSAndroid Build Coastguard Worker  *
82*35238bceSAndroid Build Coastguard Worker  * Iterator signals current state with getState(), which initally, and after
83*35238bceSAndroid Build Coastguard Worker  * each increment (next()) may report one of the following:
84*35238bceSAndroid Build Coastguard Worker  *
85*35238bceSAndroid Build Coastguard Worker  * STATE_ENTER_NODE: A test node has been entered to for the first time.
86*35238bceSAndroid Build Coastguard Worker  *   Node can be queried with getNode() and its full path with getNodePath().
87*35238bceSAndroid Build Coastguard Worker  *   For group nodes the iterator will next enter first matching child node.
88*35238bceSAndroid Build Coastguard Worker  *   For executable (test case) nodes STATE_LEAVE_NODE will always be reported
89*35238bceSAndroid Build Coastguard Worker  *   immediately after entering that node.
90*35238bceSAndroid Build Coastguard Worker  *
91*35238bceSAndroid Build Coastguard Worker  * STATE_LEAVE_NODE: Iterator is leaving a node. In case of group nodes this
92*35238bceSAndroid Build Coastguard Worker  *   means that all child nodes and their children have been processed. For
93*35238bceSAndroid Build Coastguard Worker  *   executable nodes the iterator will either move on to the next sibling,
94*35238bceSAndroid Build Coastguard Worker  *   or leave the parent group if the reported node was last child of that
95*35238bceSAndroid Build Coastguard Worker  *   group.
96*35238bceSAndroid Build Coastguard Worker  *
97*35238bceSAndroid Build Coastguard Worker  * Root node is never reported, but instead iteration will start on first
98*35238bceSAndroid Build Coastguard Worker  * matching test package node, if there is any.
99*35238bceSAndroid Build Coastguard Worker  *
100*35238bceSAndroid Build Coastguard Worker  * Test hierarchy is created on demand with help of TestHierarchyInflater.
101*35238bceSAndroid Build Coastguard Worker  * Upon entering a group node, after STATE_ENTER_NODE has been signaled,
102*35238bceSAndroid Build Coastguard Worker  * inflater is called to construct the list of child nodes for that group.
103*35238bceSAndroid Build Coastguard Worker  * Upon exiting a group node, before STATE_LEAVE_NODE is called, inflater
104*35238bceSAndroid Build Coastguard Worker  * is asked to clean up any resources by calling leaveGroupNode() or
105*35238bceSAndroid Build Coastguard Worker  * leaveTestPackage() depending on the type of the node.
106*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
107*35238bceSAndroid Build Coastguard Worker class TestHierarchyIterator
108*35238bceSAndroid Build Coastguard Worker {
109*35238bceSAndroid Build Coastguard Worker public:
110*35238bceSAndroid Build Coastguard Worker     TestHierarchyIterator(TestPackageRoot &rootNode, TestHierarchyInflater &inflater,
111*35238bceSAndroid Build Coastguard Worker                           const CaseListFilter &caseListFilter);
112*35238bceSAndroid Build Coastguard Worker     ~TestHierarchyIterator(void);
113*35238bceSAndroid Build Coastguard Worker 
114*35238bceSAndroid Build Coastguard Worker     enum State
115*35238bceSAndroid Build Coastguard Worker     {
116*35238bceSAndroid Build Coastguard Worker         STATE_ENTER_NODE = 0,
117*35238bceSAndroid Build Coastguard Worker         STATE_LEAVE_NODE,
118*35238bceSAndroid Build Coastguard Worker         STATE_FINISHED,
119*35238bceSAndroid Build Coastguard Worker 
120*35238bceSAndroid Build Coastguard Worker         STATE_LAST
121*35238bceSAndroid Build Coastguard Worker     };
122*35238bceSAndroid Build Coastguard Worker 
123*35238bceSAndroid Build Coastguard Worker     State getState(void) const;
124*35238bceSAndroid Build Coastguard Worker 
125*35238bceSAndroid Build Coastguard Worker     TestNode *getNode(void) const;
126*35238bceSAndroid Build Coastguard Worker     const std::string &getNodePath(void) const;
127*35238bceSAndroid Build Coastguard Worker 
128*35238bceSAndroid Build Coastguard Worker     void next(void);
129*35238bceSAndroid Build Coastguard Worker 
130*35238bceSAndroid Build Coastguard Worker private:
131*35238bceSAndroid Build Coastguard Worker     struct NodeIter
132*35238bceSAndroid Build Coastguard Worker     {
133*35238bceSAndroid Build Coastguard Worker         enum State
134*35238bceSAndroid Build Coastguard Worker         {
135*35238bceSAndroid Build Coastguard Worker             NISTATE_INIT = 0,
136*35238bceSAndroid Build Coastguard Worker             NISTATE_ENTER,
137*35238bceSAndroid Build Coastguard Worker             NISTATE_TRAVERSE_CHILDREN,
138*35238bceSAndroid Build Coastguard Worker             NISTATE_LEAVE,
139*35238bceSAndroid Build Coastguard Worker 
140*35238bceSAndroid Build Coastguard Worker             NISTATE_LAST
141*35238bceSAndroid Build Coastguard Worker         };
142*35238bceSAndroid Build Coastguard Worker 
NodeItertcu::TestHierarchyIterator::NodeIter143*35238bceSAndroid Build Coastguard Worker         NodeIter(void) : node(DE_NULL), curChildNdx(-1), m_state(NISTATE_LAST)
144*35238bceSAndroid Build Coastguard Worker         {
145*35238bceSAndroid Build Coastguard Worker         }
146*35238bceSAndroid Build Coastguard Worker 
NodeItertcu::TestHierarchyIterator::NodeIter147*35238bceSAndroid Build Coastguard Worker         NodeIter(TestNode *node_) : node(node_), curChildNdx(-1), m_state(NISTATE_INIT)
148*35238bceSAndroid Build Coastguard Worker         {
149*35238bceSAndroid Build Coastguard Worker         }
150*35238bceSAndroid Build Coastguard Worker 
getStatetcu::TestHierarchyIterator::NodeIter151*35238bceSAndroid Build Coastguard Worker         State getState(void) const
152*35238bceSAndroid Build Coastguard Worker         {
153*35238bceSAndroid Build Coastguard Worker             return m_state;
154*35238bceSAndroid Build Coastguard Worker         }
155*35238bceSAndroid Build Coastguard Worker 
setStatetcu::TestHierarchyIterator::NodeIter156*35238bceSAndroid Build Coastguard Worker         void setState(State newState)
157*35238bceSAndroid Build Coastguard Worker         {
158*35238bceSAndroid Build Coastguard Worker             switch (newState)
159*35238bceSAndroid Build Coastguard Worker             {
160*35238bceSAndroid Build Coastguard Worker             case NISTATE_TRAVERSE_CHILDREN:
161*35238bceSAndroid Build Coastguard Worker                 curChildNdx = -1;
162*35238bceSAndroid Build Coastguard Worker                 break;
163*35238bceSAndroid Build Coastguard Worker 
164*35238bceSAndroid Build Coastguard Worker             default:
165*35238bceSAndroid Build Coastguard Worker                 break;
166*35238bceSAndroid Build Coastguard Worker             }
167*35238bceSAndroid Build Coastguard Worker 
168*35238bceSAndroid Build Coastguard Worker             m_state = newState;
169*35238bceSAndroid Build Coastguard Worker         }
170*35238bceSAndroid Build Coastguard Worker 
171*35238bceSAndroid Build Coastguard Worker         TestNode *node;
172*35238bceSAndroid Build Coastguard Worker         std::vector<TestNode *> children;
173*35238bceSAndroid Build Coastguard Worker         int curChildNdx;
174*35238bceSAndroid Build Coastguard Worker 
175*35238bceSAndroid Build Coastguard Worker     private:
176*35238bceSAndroid Build Coastguard Worker         State m_state;
177*35238bceSAndroid Build Coastguard Worker     };
178*35238bceSAndroid Build Coastguard Worker 
179*35238bceSAndroid Build Coastguard Worker     TestHierarchyIterator(const TestHierarchyIterator &);            // not allowed!
180*35238bceSAndroid Build Coastguard Worker     TestHierarchyIterator &operator=(const TestHierarchyIterator &); // not allowed!
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker     bool matchFolderName(const std::string &folderName) const;
183*35238bceSAndroid Build Coastguard Worker     bool matchCaseName(const std::string &caseName) const;
184*35238bceSAndroid Build Coastguard Worker 
185*35238bceSAndroid Build Coastguard Worker     static std::string buildNodePath(const std::vector<NodeIter> &nodeStack);
186*35238bceSAndroid Build Coastguard Worker 
187*35238bceSAndroid Build Coastguard Worker     TestHierarchyInflater &m_inflater;
188*35238bceSAndroid Build Coastguard Worker     const CaseListFilter &m_caseListFilter;
189*35238bceSAndroid Build Coastguard Worker 
190*35238bceSAndroid Build Coastguard Worker     // Current session state.
191*35238bceSAndroid Build Coastguard Worker     std::vector<NodeIter> m_sessionStack;
192*35238bceSAndroid Build Coastguard Worker     std::string m_nodePath;
193*35238bceSAndroid Build Coastguard Worker 
194*35238bceSAndroid Build Coastguard Worker     // Counter that increments by one for each bottom-level test group
195*35238bceSAndroid Build Coastguard Worker     int m_groupNumber;
196*35238bceSAndroid Build Coastguard Worker };
197*35238bceSAndroid Build Coastguard Worker 
198*35238bceSAndroid Build Coastguard Worker } // namespace tcu
199*35238bceSAndroid Build Coastguard Worker 
200*35238bceSAndroid Build Coastguard Worker #endif // _TCUTESTHIERARCHYITERATOR_HPP
201