xref: /aosp_15_r20/external/deqp/framework/common/tcuTestPackage.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Base class for a test case.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "tcuTestPackage.hpp"
25 #include "tcuPlatform.hpp"
26 
27 #include "deString.h"
28 
29 using std::vector;
30 
31 namespace tcu
32 {
33 
34 // TestPackage
35 
TestPackage(TestContext & testCtx,const char * name,const char * description)36 TestPackage::TestPackage(TestContext &testCtx, const char *name, const char *description)
37     : TestNode(testCtx, NODETYPE_PACKAGE, name)
38     , m_caseListFilter(nullptr)
39 {
40     DE_UNREF(description);
41 }
42 
~TestPackage(void)43 TestPackage::~TestPackage(void)
44 {
45 }
46 
setCaseListFilter(const CaseListFilter * caseListFilter)47 void TestPackage::setCaseListFilter(const CaseListFilter *caseListFilter)
48 {
49     m_caseListFilter = caseListFilter;
50 }
51 
iterate(void)52 TestNode::IterateResult TestPackage::iterate(void)
53 {
54     DE_ASSERT(false); // should never be here!
55     throw InternalError("TestPackage::iterate() called!", "", __FILE__, __LINE__);
56 }
57 
58 // TestPackageRegistry
59 
TestPackageRegistry(void)60 TestPackageRegistry::TestPackageRegistry(void)
61 {
62 }
63 
~TestPackageRegistry(void)64 TestPackageRegistry::~TestPackageRegistry(void)
65 {
66     for (int i = 0; i < (int)m_packageInfos.size(); i++)
67         delete m_packageInfos[i];
68 }
69 
getSingleton(void)70 TestPackageRegistry *TestPackageRegistry::getSingleton(void)
71 {
72     return TestPackageRegistry::getOrDestroy(true);
73 }
74 
destroy(void)75 void TestPackageRegistry::destroy(void)
76 {
77     TestPackageRegistry::getOrDestroy(false);
78 }
79 
getOrDestroy(bool isCreate)80 TestPackageRegistry *TestPackageRegistry::getOrDestroy(bool isCreate)
81 {
82     static TestPackageRegistry *s_ptr = DE_NULL;
83 
84     if (isCreate)
85     {
86         if (!s_ptr)
87             s_ptr = new TestPackageRegistry();
88 
89         return s_ptr;
90     }
91     else
92     {
93         if (s_ptr)
94         {
95             delete s_ptr;
96             s_ptr = DE_NULL;
97         }
98 
99         return DE_NULL;
100     }
101 }
102 
registerPackage(const char * name,TestPackageCreateFunc createFunc)103 void TestPackageRegistry::registerPackage(const char *name, TestPackageCreateFunc createFunc)
104 {
105     DE_ASSERT(getPackageInfoByName(name) == DE_NULL);
106     m_packageInfos.push_back(new PackageInfo(name, createFunc));
107 }
108 
getPackageInfos(void) const109 const std::vector<TestPackageRegistry::PackageInfo *> &TestPackageRegistry::getPackageInfos(void) const
110 {
111     return m_packageInfos;
112 }
113 
getPackageInfoByName(const char * packageName) const114 TestPackageRegistry::PackageInfo *TestPackageRegistry::getPackageInfoByName(const char *packageName) const
115 {
116     for (int i = 0; i < (int)m_packageInfos.size(); i++)
117     {
118         if (m_packageInfos[i]->name == packageName)
119             return m_packageInfos[i];
120     }
121 
122     return DE_NULL;
123 }
124 
createPackage(const char * name,TestContext & testCtx) const125 TestPackage *TestPackageRegistry::createPackage(const char *name, TestContext &testCtx) const
126 {
127     PackageInfo *info = getPackageInfoByName(name);
128     return info ? info->createFunc(testCtx) : DE_NULL;
129 }
130 
131 // TestPackageDescriptor
132 
TestPackageDescriptor(const char * name,TestPackageCreateFunc createFunc)133 TestPackageDescriptor::TestPackageDescriptor(const char *name, TestPackageCreateFunc createFunc)
134 {
135     TestPackageRegistry::getSingleton()->registerPackage(name, createFunc);
136 }
137 
~TestPackageDescriptor(void)138 TestPackageDescriptor::~TestPackageDescriptor(void)
139 {
140     TestPackageRegistry::destroy();
141 }
142 
143 // TestPackageRoot
144 
TestPackageRoot(TestContext & testCtx)145 TestPackageRoot::TestPackageRoot(TestContext &testCtx) : TestNode(testCtx, NODETYPE_ROOT, "")
146 {
147 }
148 
TestPackageRoot(TestContext & testCtx,const vector<TestNode * > & children)149 TestPackageRoot::TestPackageRoot(TestContext &testCtx, const vector<TestNode *> &children)
150     : TestNode(testCtx, NODETYPE_ROOT, "", children)
151 {
152 }
153 
TestPackageRoot(TestContext & testCtx,const TestPackageRegistry * packageRegistry)154 TestPackageRoot::TestPackageRoot(TestContext &testCtx, const TestPackageRegistry *packageRegistry)
155     : TestNode(testCtx, NODETYPE_ROOT, "")
156 {
157     const vector<TestPackageRegistry::PackageInfo *> &packageInfos = packageRegistry->getPackageInfos();
158 
159     for (int i = 0; i < (int)packageInfos.size(); i++)
160         addChild(packageInfos[i]->createFunc(testCtx));
161 }
162 
~TestPackageRoot(void)163 TestPackageRoot::~TestPackageRoot(void)
164 {
165 }
166 
iterate(void)167 TestCase::IterateResult TestPackageRoot::iterate(void)
168 {
169     DE_ASSERT(false); // should never be here!
170     throw InternalError("TestPackageRoot::iterate() called!", "", __FILE__, __LINE__);
171 }
172 
173 } // namespace tcu
174