xref: /aosp_15_r20/external/deqp/framework/common/tcuTestPackage.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _TCUTESTPACKAGE_HPP
2 #define _TCUTESTPACKAGE_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Base class for a test case.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 #include <map>
29 
30 namespace tcu
31 {
32 
33 //! Test run summary.
34 class TestRunStatus
35 {
36 public:
TestRunStatus(void)37     TestRunStatus(void)
38     {
39         clear();
40     }
41 
clear(void)42     void clear(void)
43     {
44         numExecuted     = 0;
45         numPassed       = 0;
46         numFailed       = 0;
47         numDeviceLost   = 0;
48         numNotSupported = 0;
49         numWarnings     = 0;
50         numWaived       = 0;
51         isComplete      = false;
52     }
53 
54     int numExecuted;     //!< Total number of cases executed.
55     int numPassed;       //!< Number of cases passed.
56     int numFailed;       //!< Number of cases failed.
57     int numNotSupported; //!< Number of cases not supported.
58     int numWarnings;     //!< Number of QualityWarning / CompatibilityWarning results.
59     int numWaived;       //!< Number of waived tests.
60     int numDeviceLost;   //!< Number of cases that caused a device lost
61     bool isComplete;     //!< Is run complete.
62 };
63 
64 /*--------------------------------------------------------------------*//*!
65  * \brief Test case execution interface.
66  *
67  * TestCaseExecutor provides package-specific resources & initialization
68  * for test cases.
69  *
70  * \todo [2015-03-18 pyry] Replace with following API:
71  *
72  * class TestInstance
73  * {
74  * public:
75  *     TestInstance (TestContext& testCtx);
76  *     tcu::TestResult iterate (void);
77  * };
78  *
79  * class TestInstanceFactory (???)
80  * {
81  * public:
82  *     TestInstance* createInstance (const TestCase* testCase, const std::string& path);
83  * };
84  *//*--------------------------------------------------------------------*/
85 class TestCaseExecutor
86 {
87 public:
~TestCaseExecutor(void)88     virtual ~TestCaseExecutor(void)
89     {
90     }
91 
92     virtual void init(TestCase *testCase, const std::string &path) = 0;
93     virtual void deinit(TestCase *testCase)                        = 0;
94     virtual TestNode::IterateResult iterate(TestCase *testCase)    = 0;
deinitTestPackage(TestContext & testCtx)95     virtual void deinitTestPackage(TestContext &testCtx)
96     {
97         DE_UNREF(testCtx);
98     };
usesLocalStatus()99     virtual bool usesLocalStatus()
100     {
101         return false;
102     }
updateGlobalStatus(tcu::TestRunStatus & status)103     virtual void updateGlobalStatus(tcu::TestRunStatus &status)
104     {
105         DE_UNREF(status);
106     }
reportDurations(tcu::TestContext & testCtx,const std::string & packageName,const int64_t & duration,const std::map<std::string,uint64_t> & groupsDurationTime)107     virtual void reportDurations(tcu::TestContext &testCtx, const std::string &packageName, const int64_t &duration,
108                                  const std::map<std::string, uint64_t> &groupsDurationTime)
109     {
110         DE_UNREF(testCtx);
111         DE_UNREF(packageName);
112         DE_UNREF(duration);
113         DE_UNREF(groupsDurationTime);
114     }
115 };
116 
117 /*--------------------------------------------------------------------*//*!
118  * \brief Base class for test packages.
119  *
120  * Test packages are root-level test groups. They also provide package-
121  * specific test case executor, see TestCaseExecutor.
122  *//*--------------------------------------------------------------------*/
123 class TestPackage : public TestNode
124 {
125 public:
126     TestPackage(TestContext &testCtx, const char *name, const char *description);
127     virtual ~TestPackage(void);
128 
129     virtual TestCaseExecutor *createExecutor(void) const = 0;
130 
131     // Deprecated
getArchive(void)132     virtual Archive *getArchive(void)
133     {
134         return DE_NULL;
135     }
136 
137     virtual IterateResult iterate(void);
138 
139     void setCaseListFilter(const CaseListFilter *caseListFilter);
140 
141 protected:
142     const CaseListFilter *m_caseListFilter;
143 };
144 
145 // TestPackageRegistry
146 
147 typedef TestPackage *(*TestPackageCreateFunc)(TestContext &testCtx);
148 
149 class TestPackageRegistry
150 {
151 public:
152     struct PackageInfo
153     {
PackageInfotcu::TestPackageRegistry::PackageInfo154         PackageInfo(std::string name_, TestPackageCreateFunc createFunc_) : name(name_), createFunc(createFunc_)
155         {
156         }
157 
158         std::string name;
159         TestPackageCreateFunc createFunc;
160     };
161 
162     static TestPackageRegistry *getSingleton(void);
163     static void destroy(void);
164 
165     void registerPackage(const char *name, TestPackageCreateFunc createFunc);
166     const std::vector<PackageInfo *> &getPackageInfos(void) const;
167     PackageInfo *getPackageInfoByName(const char *name) const;
168     TestPackage *createPackage(const char *name, TestContext &testCtx) const;
169 
170 private:
171     TestPackageRegistry(void);
172     ~TestPackageRegistry(void);
173 
174     static TestPackageRegistry *getOrDestroy(bool isCreate);
175 
176     // Member variables.
177     std::vector<PackageInfo *> m_packageInfos;
178 };
179 
180 // TestPackageDescriptor
181 
182 class TestPackageDescriptor
183 {
184 public:
185     TestPackageDescriptor(const char *name, TestPackageCreateFunc createFunc);
186     ~TestPackageDescriptor(void);
187 };
188 
189 // TestPackageRoot
190 
191 class TestPackageRoot : public TestNode
192 {
193 public:
194     TestPackageRoot(TestContext &testCtx);
195     TestPackageRoot(TestContext &testCtx, const std::vector<TestNode *> &children);
196     TestPackageRoot(TestContext &testCtx, const TestPackageRegistry *packageRegistry);
197     virtual ~TestPackageRoot(void);
198 
199     virtual IterateResult iterate(void);
200 };
201 
202 } // namespace tcu
203 
204 #endif // _TCUTESTPACKAGE_HPP
205