xref: /aosp_15_r20/external/deqp/executor/xeTestCaseListParser.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Test Executor
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 Test case list parser.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "xeTestCaseListParser.hpp"
25 #include "deString.h"
26 
27 using std::string;
28 using std::vector;
29 
30 namespace xe
31 {
32 
getTestCaseType(const char * caseType)33 static TestCaseType getTestCaseType(const char *caseType)
34 {
35     // \todo [2012-06-11 pyry] Use hashes for speedup.
36     static const struct
37     {
38         const char *name;
39         TestCaseType caseType;
40     } s_caseTypeMap[] = {{"SelfValidate", TESTCASETYPE_SELF_VALIDATE},
41                          {"Capability", TESTCASETYPE_CAPABILITY},
42                          {"Accuracy", TESTCASETYPE_ACCURACY},
43                          {"Performance", TESTCASETYPE_PERFORMANCE}};
44 
45     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_caseTypeMap); ndx++)
46     {
47         if (deStringEqual(caseType, s_caseTypeMap[ndx].name))
48             return s_caseTypeMap[ndx].caseType;
49     }
50 
51     XE_FAIL((string("Unknown test case type '") + caseType + "'").c_str());
52 }
53 
TestCaseListParser(void)54 TestCaseListParser::TestCaseListParser(void) : m_root(DE_NULL)
55 {
56 }
57 
~TestCaseListParser(void)58 TestCaseListParser::~TestCaseListParser(void)
59 {
60 }
61 
clear(void)62 void TestCaseListParser::clear(void)
63 {
64     m_xmlParser.clear();
65     m_nodeStack.clear();
66     m_root = DE_NULL;
67 }
68 
init(TestGroup * rootGroup)69 void TestCaseListParser::init(TestGroup *rootGroup)
70 {
71     clear();
72     m_root = rootGroup;
73 }
74 
parse(const uint8_t * bytes,int numBytes)75 void TestCaseListParser::parse(const uint8_t *bytes, int numBytes)
76 {
77     DE_ASSERT(m_root);
78     m_xmlParser.feed(bytes, numBytes);
79 
80     for (;;)
81     {
82         xml::Element element = m_xmlParser.getElement();
83 
84         if (element == xml::ELEMENT_INCOMPLETE || element == xml::ELEMENT_END_OF_STRING)
85             break;
86 
87         if (element == xml::ELEMENT_START || element == xml::ELEMENT_END)
88         {
89             bool isStart         = element == xml::ELEMENT_START;
90             const char *elemName = m_xmlParser.getElementName();
91 
92             if (deStringEqual(elemName, "TestCase"))
93             {
94                 if (isStart)
95                 {
96                     XE_CHECK_MSG(!m_nodeStack.empty(), "<TestCase> outside of <TestCaseList>");
97 
98                     TestNode *parent = m_nodeStack.back();
99                     const char *name = m_xmlParser.hasAttribute("Name") ? m_xmlParser.getAttribute("Name") : DE_NULL;
100                     const char *description =
101                         m_xmlParser.hasAttribute("Description") ? m_xmlParser.getAttribute("Description") : DE_NULL;
102                     const char *caseType =
103                         m_xmlParser.hasAttribute("CaseType") ? m_xmlParser.getAttribute("CaseType") : DE_NULL;
104 
105                     XE_CHECK_MSG(name && description && caseType, "Missing attribute in <TestCase>");
106                     XE_CHECK_MSG(parent->getNodeType() == TESTNODETYPE_GROUP,
107                                  "Only TestGroups are allowed to have child nodes");
108 
109                     bool isGroup = deStringEqual(caseType, "TestGroup") == true;
110                     TestNode *node =
111                         isGroup ? static_cast<TestNode *>(static_cast<TestGroup *>(parent)->createGroup(name)) :
112                                   static_cast<TestNode *>(
113                                       static_cast<TestGroup *>(parent)->createCase(getTestCaseType(caseType), name));
114 
115                     m_nodeStack.push_back(node);
116                 }
117                 else
118                 {
119                     XE_CHECK_MSG(m_nodeStack.size() >= 2, "Unexpected </TestCase>");
120                     m_nodeStack.pop_back();
121                 }
122             }
123             else if (deStringEqual(elemName, "TestCaseList"))
124             {
125                 if (isStart)
126                 {
127                     XE_CHECK_MSG(m_nodeStack.empty(), "Unexpected <TestCaseList>");
128                     m_nodeStack.push_back(m_root);
129                 }
130                 else
131                 {
132                     XE_CHECK_MSG(m_nodeStack.size() == 1, "Unexpected </TestCaseList>");
133                     m_nodeStack.pop_back();
134                 }
135             }
136             else
137                 XE_FAIL((string("Unexpected <") + elemName + ">").c_str());
138         }
139         else if (element != xml::ELEMENT_DATA)
140             DE_ASSERT(false); // \note Data elements are just ignored, they should be whitespace anyway.
141 
142         m_xmlParser.advance();
143     }
144 }
145 
146 } // namespace xe
147