xref: /aosp_15_r20/external/deqp/executor/xeTestCaseListParser.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program Test Executor
3*35238bceSAndroid Build Coastguard Worker  * ------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Test case list parser.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "xeTestCaseListParser.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "deString.h"
26*35238bceSAndroid Build Coastguard Worker 
27*35238bceSAndroid Build Coastguard Worker using std::string;
28*35238bceSAndroid Build Coastguard Worker using std::vector;
29*35238bceSAndroid Build Coastguard Worker 
30*35238bceSAndroid Build Coastguard Worker namespace xe
31*35238bceSAndroid Build Coastguard Worker {
32*35238bceSAndroid Build Coastguard Worker 
getTestCaseType(const char * caseType)33*35238bceSAndroid Build Coastguard Worker static TestCaseType getTestCaseType(const char *caseType)
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker     // \todo [2012-06-11 pyry] Use hashes for speedup.
36*35238bceSAndroid Build Coastguard Worker     static const struct
37*35238bceSAndroid Build Coastguard Worker     {
38*35238bceSAndroid Build Coastguard Worker         const char *name;
39*35238bceSAndroid Build Coastguard Worker         TestCaseType caseType;
40*35238bceSAndroid Build Coastguard Worker     } s_caseTypeMap[] = {{"SelfValidate", TESTCASETYPE_SELF_VALIDATE},
41*35238bceSAndroid Build Coastguard Worker                          {"Capability", TESTCASETYPE_CAPABILITY},
42*35238bceSAndroid Build Coastguard Worker                          {"Accuracy", TESTCASETYPE_ACCURACY},
43*35238bceSAndroid Build Coastguard Worker                          {"Performance", TESTCASETYPE_PERFORMANCE}};
44*35238bceSAndroid Build Coastguard Worker 
45*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_caseTypeMap); ndx++)
46*35238bceSAndroid Build Coastguard Worker     {
47*35238bceSAndroid Build Coastguard Worker         if (deStringEqual(caseType, s_caseTypeMap[ndx].name))
48*35238bceSAndroid Build Coastguard Worker             return s_caseTypeMap[ndx].caseType;
49*35238bceSAndroid Build Coastguard Worker     }
50*35238bceSAndroid Build Coastguard Worker 
51*35238bceSAndroid Build Coastguard Worker     XE_FAIL((string("Unknown test case type '") + caseType + "'").c_str());
52*35238bceSAndroid Build Coastguard Worker }
53*35238bceSAndroid Build Coastguard Worker 
TestCaseListParser(void)54*35238bceSAndroid Build Coastguard Worker TestCaseListParser::TestCaseListParser(void) : m_root(DE_NULL)
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker }
57*35238bceSAndroid Build Coastguard Worker 
~TestCaseListParser(void)58*35238bceSAndroid Build Coastguard Worker TestCaseListParser::~TestCaseListParser(void)
59*35238bceSAndroid Build Coastguard Worker {
60*35238bceSAndroid Build Coastguard Worker }
61*35238bceSAndroid Build Coastguard Worker 
clear(void)62*35238bceSAndroid Build Coastguard Worker void TestCaseListParser::clear(void)
63*35238bceSAndroid Build Coastguard Worker {
64*35238bceSAndroid Build Coastguard Worker     m_xmlParser.clear();
65*35238bceSAndroid Build Coastguard Worker     m_nodeStack.clear();
66*35238bceSAndroid Build Coastguard Worker     m_root = DE_NULL;
67*35238bceSAndroid Build Coastguard Worker }
68*35238bceSAndroid Build Coastguard Worker 
init(TestGroup * rootGroup)69*35238bceSAndroid Build Coastguard Worker void TestCaseListParser::init(TestGroup *rootGroup)
70*35238bceSAndroid Build Coastguard Worker {
71*35238bceSAndroid Build Coastguard Worker     clear();
72*35238bceSAndroid Build Coastguard Worker     m_root = rootGroup;
73*35238bceSAndroid Build Coastguard Worker }
74*35238bceSAndroid Build Coastguard Worker 
parse(const uint8_t * bytes,int numBytes)75*35238bceSAndroid Build Coastguard Worker void TestCaseListParser::parse(const uint8_t *bytes, int numBytes)
76*35238bceSAndroid Build Coastguard Worker {
77*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_root);
78*35238bceSAndroid Build Coastguard Worker     m_xmlParser.feed(bytes, numBytes);
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker     for (;;)
81*35238bceSAndroid Build Coastguard Worker     {
82*35238bceSAndroid Build Coastguard Worker         xml::Element element = m_xmlParser.getElement();
83*35238bceSAndroid Build Coastguard Worker 
84*35238bceSAndroid Build Coastguard Worker         if (element == xml::ELEMENT_INCOMPLETE || element == xml::ELEMENT_END_OF_STRING)
85*35238bceSAndroid Build Coastguard Worker             break;
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker         if (element == xml::ELEMENT_START || element == xml::ELEMENT_END)
88*35238bceSAndroid Build Coastguard Worker         {
89*35238bceSAndroid Build Coastguard Worker             bool isStart         = element == xml::ELEMENT_START;
90*35238bceSAndroid Build Coastguard Worker             const char *elemName = m_xmlParser.getElementName();
91*35238bceSAndroid Build Coastguard Worker 
92*35238bceSAndroid Build Coastguard Worker             if (deStringEqual(elemName, "TestCase"))
93*35238bceSAndroid Build Coastguard Worker             {
94*35238bceSAndroid Build Coastguard Worker                 if (isStart)
95*35238bceSAndroid Build Coastguard Worker                 {
96*35238bceSAndroid Build Coastguard Worker                     XE_CHECK_MSG(!m_nodeStack.empty(), "<TestCase> outside of <TestCaseList>");
97*35238bceSAndroid Build Coastguard Worker 
98*35238bceSAndroid Build Coastguard Worker                     TestNode *parent = m_nodeStack.back();
99*35238bceSAndroid Build Coastguard Worker                     const char *name = m_xmlParser.hasAttribute("Name") ? m_xmlParser.getAttribute("Name") : DE_NULL;
100*35238bceSAndroid Build Coastguard Worker                     const char *description =
101*35238bceSAndroid Build Coastguard Worker                         m_xmlParser.hasAttribute("Description") ? m_xmlParser.getAttribute("Description") : DE_NULL;
102*35238bceSAndroid Build Coastguard Worker                     const char *caseType =
103*35238bceSAndroid Build Coastguard Worker                         m_xmlParser.hasAttribute("CaseType") ? m_xmlParser.getAttribute("CaseType") : DE_NULL;
104*35238bceSAndroid Build Coastguard Worker 
105*35238bceSAndroid Build Coastguard Worker                     XE_CHECK_MSG(name && description && caseType, "Missing attribute in <TestCase>");
106*35238bceSAndroid Build Coastguard Worker                     XE_CHECK_MSG(parent->getNodeType() == TESTNODETYPE_GROUP,
107*35238bceSAndroid Build Coastguard Worker                                  "Only TestGroups are allowed to have child nodes");
108*35238bceSAndroid Build Coastguard Worker 
109*35238bceSAndroid Build Coastguard Worker                     bool isGroup = deStringEqual(caseType, "TestGroup") == true;
110*35238bceSAndroid Build Coastguard Worker                     TestNode *node =
111*35238bceSAndroid Build Coastguard Worker                         isGroup ? static_cast<TestNode *>(static_cast<TestGroup *>(parent)->createGroup(name)) :
112*35238bceSAndroid Build Coastguard Worker                                   static_cast<TestNode *>(
113*35238bceSAndroid Build Coastguard Worker                                       static_cast<TestGroup *>(parent)->createCase(getTestCaseType(caseType), name));
114*35238bceSAndroid Build Coastguard Worker 
115*35238bceSAndroid Build Coastguard Worker                     m_nodeStack.push_back(node);
116*35238bceSAndroid Build Coastguard Worker                 }
117*35238bceSAndroid Build Coastguard Worker                 else
118*35238bceSAndroid Build Coastguard Worker                 {
119*35238bceSAndroid Build Coastguard Worker                     XE_CHECK_MSG(m_nodeStack.size() >= 2, "Unexpected </TestCase>");
120*35238bceSAndroid Build Coastguard Worker                     m_nodeStack.pop_back();
121*35238bceSAndroid Build Coastguard Worker                 }
122*35238bceSAndroid Build Coastguard Worker             }
123*35238bceSAndroid Build Coastguard Worker             else if (deStringEqual(elemName, "TestCaseList"))
124*35238bceSAndroid Build Coastguard Worker             {
125*35238bceSAndroid Build Coastguard Worker                 if (isStart)
126*35238bceSAndroid Build Coastguard Worker                 {
127*35238bceSAndroid Build Coastguard Worker                     XE_CHECK_MSG(m_nodeStack.empty(), "Unexpected <TestCaseList>");
128*35238bceSAndroid Build Coastguard Worker                     m_nodeStack.push_back(m_root);
129*35238bceSAndroid Build Coastguard Worker                 }
130*35238bceSAndroid Build Coastguard Worker                 else
131*35238bceSAndroid Build Coastguard Worker                 {
132*35238bceSAndroid Build Coastguard Worker                     XE_CHECK_MSG(m_nodeStack.size() == 1, "Unexpected </TestCaseList>");
133*35238bceSAndroid Build Coastguard Worker                     m_nodeStack.pop_back();
134*35238bceSAndroid Build Coastguard Worker                 }
135*35238bceSAndroid Build Coastguard Worker             }
136*35238bceSAndroid Build Coastguard Worker             else
137*35238bceSAndroid Build Coastguard Worker                 XE_FAIL((string("Unexpected <") + elemName + ">").c_str());
138*35238bceSAndroid Build Coastguard Worker         }
139*35238bceSAndroid Build Coastguard Worker         else if (element != xml::ELEMENT_DATA)
140*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(false); // \note Data elements are just ignored, they should be whitespace anyway.
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker         m_xmlParser.advance();
143*35238bceSAndroid Build Coastguard Worker     }
144*35238bceSAndroid Build Coastguard Worker }
145*35238bceSAndroid Build Coastguard Worker 
146*35238bceSAndroid Build Coastguard Worker } // namespace xe
147