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 result parser.
22 *//*--------------------------------------------------------------------*/
23
24 #include "xeTestResultParser.hpp"
25 #include "xeTestCaseResult.hpp"
26 #include "xeBatchResult.hpp"
27 #include "deString.h"
28 #include "deInt32.h"
29
30 #include <sstream>
31 #include <stdlib.h>
32
33 using std::string;
34 using std::vector;
35
36 namespace xe
37 {
38
toInt(const char * str)39 static inline int toInt (const char* str)
40 {
41 return atoi(str);
42 }
43
toDouble(const char * str)44 static inline double toDouble (const char* str)
45 {
46 return atof(str);
47 }
48
toInt64(const char * str)49 static inline deInt64 toInt64 (const char* str)
50 {
51 std::istringstream s (str);
52 deInt64 val;
53
54 s >> val;
55
56 return val;
57 }
58
toBool(const char * str)59 static inline bool toBool (const char* str)
60 {
61 return deStringEqual(str, "OK") || deStringEqual(str, "True");
62 }
63
stripLeadingWhitespace(const char * str)64 static const char* stripLeadingWhitespace (const char* str)
65 {
66 int whitespaceCount = 0;
67
68 while (str[whitespaceCount] != 0 &&
69 (str[whitespaceCount] == ' ' ||
70 str[whitespaceCount] == '\t' ||
71 str[whitespaceCount] == '\r' ||
72 str[whitespaceCount] == '\n'))
73 whitespaceCount += 1;
74
75 return str + whitespaceCount;
76 }
77
78 struct EnumMapEntry
79 {
80 deUint32 hash;
81 const char* name;
82 int value;
83 };
84
85 static const EnumMapEntry s_statusCodeMap[] =
86 {
87 { 0x7c8a99bc, "Pass", TESTSTATUSCODE_PASS },
88 { 0x7c851ca1, "Fail", TESTSTATUSCODE_FAIL },
89 { 0x10ecd324, "QualityWarning", TESTSTATUSCODE_QUALITY_WARNING },
90 { 0x341ae835, "CompatibilityWarning", TESTSTATUSCODE_COMPATIBILITY_WARNING },
91 { 0x058acbca, "Pending", TESTSTATUSCODE_PENDING },
92 { 0xc4d74b26, "Running", TESTSTATUSCODE_RUNNING },
93 { 0x6409f93c, "NotSupported", TESTSTATUSCODE_NOT_SUPPORTED },
94 { 0xfa5a9ab7, "ResourceError", TESTSTATUSCODE_RESOURCE_ERROR },
95 { 0xad6793ec, "InternalError", TESTSTATUSCODE_INTERNAL_ERROR },
96 { 0x838f3034, "Canceled", TESTSTATUSCODE_CANCELED },
97 { 0x42b6efac, "Timeout", TESTSTATUSCODE_TIMEOUT },
98 { 0x0cfb98f6, "Crash", TESTSTATUSCODE_CRASH },
99 { 0xe326e01d, "Disabled", TESTSTATUSCODE_DISABLED },
100 { 0x77061af2, "Terminated", TESTSTATUSCODE_TERMINATED },
101 { 0xd9e6b393, "Waiver", TESTSTATUSCODE_WAIVER }
102 };
103
104 static const EnumMapEntry s_resultItemMap[] =
105 {
106 { 0xce8ac2e4, "Result", ri::TYPE_RESULT },
107 { 0x7c8cdcea, "Text", ri::TYPE_TEXT },
108 { 0xc6540c6e, "Number", ri::TYPE_NUMBER },
109 { 0x0d656c88, "Image", ri::TYPE_IMAGE },
110 { 0x8ac9ee14, "ImageSet", ri::TYPE_IMAGESET },
111 { 0x1181fa5a, "VertexShader", ri::TYPE_SHADER },
112 { 0xa93daef0, "FragmentShader", ri::TYPE_SHADER },
113 { 0x8f066128, "GeometryShader", ri::TYPE_SHADER },
114 { 0x235a931c, "TessControlShader", ri::TYPE_SHADER },
115 { 0xa1bf7153, "TessEvaluationShader", ri::TYPE_SHADER },
116 { 0x6c1415d9, "ComputeShader", ri::TYPE_SHADER },
117 { 0x68738b22, "RaygenShader", ri::TYPE_SHADER },
118 { 0x51d29ce9, "AnyHitShader", ri::TYPE_SHADER },
119 { 0x8c64a6be, "ClosestHitShader", ri::TYPE_SHADER },
120 { 0xb30ed398, "MissShader", ri::TYPE_SHADER },
121 { 0x26150e53, "IntersectionShader", ri::TYPE_SHADER },
122 { 0x7e50944c, "CallableShader", ri::TYPE_SHADER },
123 { 0x72863a54, "ShaderProgram", ri::TYPE_SHADERPROGRAM },
124 { 0xb4efc08d, "ShaderSource", ri::TYPE_SHADERSOURCE },
125 { 0xaee4380a, "SpirVAssemblySource", ri::TYPE_SPIRVSOURCE },
126 { 0xff265913, "InfoLog", ri::TYPE_INFOLOG },
127 { 0x84159b73, "EglConfig", ri::TYPE_EGLCONFIG },
128 { 0xdd34391f, "EglConfigSet", ri::TYPE_EGLCONFIGSET },
129 { 0xebbb3aba, "Section", ri::TYPE_SECTION },
130 { 0xa0f15677, "KernelSource", ri::TYPE_KERNELSOURCE },
131 { 0x1ee9083a, "CompileInfo", ri::TYPE_COMPILEINFO },
132 { 0xf1004023, "SampleList", ri::TYPE_SAMPLELIST },
133 { 0xf0feae93, "SampleInfo", ri::TYPE_SAMPLEINFO },
134 { 0x2aa6f14e, "ValueInfo", ri::TYPE_VALUEINFO },
135 { 0xd09429e7, "Sample", ri::TYPE_SAMPLE },
136 { 0x0e4a4722, "Value", ri::TYPE_SAMPLEVALUE }
137 };
138
139 static const EnumMapEntry s_imageFormatMap[] =
140 {
141 { 0xcc4ffac8, "RGB888", ri::Image::FORMAT_RGB888 },
142 { 0x20dcb0c1, "RGBA8888", ri::Image::FORMAT_RGBA8888 }
143 };
144
145 static const EnumMapEntry s_compressionMap[] =
146 {
147 { 0x7c89bbd5, "None", ri::Image::COMPRESSION_NONE },
148 { 0x0b88118a, "PNG", ri::Image::COMPRESSION_PNG }
149 };
150
151 static const EnumMapEntry s_shaderTypeFromTagMap[] =
152 {
153 { 0x1181fa5a, "VertexShader", ri::Shader::SHADERTYPE_VERTEX },
154 { 0xa93daef0, "FragmentShader", ri::Shader::SHADERTYPE_FRAGMENT },
155 { 0x8f066128, "GeometryShader", ri::Shader::SHADERTYPE_GEOMETRY },
156 { 0x235a931c, "TessControlShader", ri::Shader::SHADERTYPE_TESS_CONTROL },
157 { 0xa1bf7153, "TessEvaluationShader", ri::Shader::SHADERTYPE_TESS_EVALUATION },
158 { 0x6c1415d9, "ComputeShader", ri::Shader::SHADERTYPE_COMPUTE },
159 { 0x68738b22, "RaygenShader", ri::Shader::SHADERTYPE_RAYGEN },
160 { 0x51d29ce9, "AnyHitShader", ri::Shader::SHADERTYPE_ANY_HIT },
161 { 0x8c64a6be, "ClosestHitShader", ri::Shader::SHADERTYPE_CLOSEST_HIT },
162 { 0xb30ed398, "MissShader", ri::Shader::SHADERTYPE_MISS },
163 { 0x26150e53, "IntersectionShader", ri::Shader::SHADERTYPE_INTERSECTION },
164 { 0x7e50944c, "CallableShader", ri::Shader::SHADERTYPE_CALLABLE },
165 { 0xc3a35d6f, "TaskShader", ri::Shader::SHADERTYPE_TASK },
166 { 0x925c7349, "MeshShader", ri::Shader::SHADERTYPE_MESH },
167 };
168
169 static const EnumMapEntry s_testTypeMap[] =
170 {
171 { 0x7fa80959, "SelfValidate", TESTCASETYPE_SELF_VALIDATE },
172 { 0xdb797567, "Capability", TESTCASETYPE_CAPABILITY },
173 { 0x2ca3ec10, "Accuracy", TESTCASETYPE_ACCURACY },
174 { 0xa48ac277, "Performance", TESTCASETYPE_PERFORMANCE }
175 };
176
177 static const EnumMapEntry s_logVersionMap[] =
178 {
179 { 0x0b7dac93, "0.2.0", TESTLOGVERSION_0_2_0 },
180 { 0x0b7db0d4, "0.3.0", TESTLOGVERSION_0_3_0 },
181 { 0x0b7db0d5, "0.3.1", TESTLOGVERSION_0_3_1 },
182 { 0x0b7db0d6, "0.3.2", TESTLOGVERSION_0_3_2 },
183 { 0x0b7db0d7, "0.3.3", TESTLOGVERSION_0_3_3 },
184 { 0x0b7db0d8, "0.3.4", TESTLOGVERSION_0_3_4 }
185 };
186
187 static const EnumMapEntry s_sampleValueTagMap[] =
188 {
189 { 0xddf2d0d1, "Predictor", ri::ValueInfo::VALUETAG_PREDICTOR },
190 { 0x9bee2c34, "Response", ri::ValueInfo::VALUETAG_RESPONSE },
191 };
192
193 #if defined(DE_DEBUG)
printHashes(const char * name,const EnumMapEntry * entries,int numEntries)194 static void printHashes (const char* name, const EnumMapEntry* entries, int numEntries)
195 {
196 printf("%s:\n", name);
197
198 for (int ndx = 0; ndx < numEntries; ndx++)
199 printf("0x%08x\t%s\n", deStringHash(entries[ndx].name), entries[ndx].name);
200
201 printf("\n");
202 }
203
204 #define PRINT_HASHES(MAP) printHashes(#MAP, MAP, DE_LENGTH_OF_ARRAY(MAP))
205
TestResultParser_printHashes(void)206 void TestResultParser_printHashes (void)
207 {
208 PRINT_HASHES(s_statusCodeMap);
209 PRINT_HASHES(s_resultItemMap);
210 PRINT_HASHES(s_imageFormatMap);
211 PRINT_HASHES(s_compressionMap);
212 PRINT_HASHES(s_shaderTypeFromTagMap);
213 PRINT_HASHES(s_testTypeMap);
214 PRINT_HASHES(s_logVersionMap);
215 PRINT_HASHES(s_sampleValueTagMap);
216 }
217 #endif
218
getEnumValue(const char * enumName,const EnumMapEntry * entries,int numEntries,const char * name)219 static inline int getEnumValue (const char* enumName, const EnumMapEntry* entries, int numEntries, const char* name)
220 {
221 deUint32 hash = deStringHash(name);
222
223 for (int ndx = 0; ndx < numEntries; ndx++)
224 {
225 if (entries[ndx].hash == hash && deStringEqual(entries[ndx].name, name))
226 return entries[ndx].value;
227 }
228
229 throw TestResultParseError(string("Could not map '") + name + "' to " + enumName);
230 }
231
getTestStatusCode(const char * statusCode)232 TestStatusCode getTestStatusCode (const char* statusCode)
233 {
234 return (TestStatusCode)getEnumValue("status code", s_statusCodeMap, DE_LENGTH_OF_ARRAY(s_statusCodeMap), statusCode);
235 }
236
getResultItemType(const char * elemName)237 static ri::Type getResultItemType (const char* elemName)
238 {
239 return (ri::Type)getEnumValue("result item type", s_resultItemMap, DE_LENGTH_OF_ARRAY(s_resultItemMap), elemName);
240 }
241
getImageFormat(const char * imageFormat)242 static ri::Image::Format getImageFormat (const char* imageFormat)
243 {
244 return (ri::Image::Format)getEnumValue("image format", s_imageFormatMap, DE_LENGTH_OF_ARRAY(s_imageFormatMap), imageFormat);
245 }
246
getImageCompression(const char * compression)247 static ri::Image::Compression getImageCompression (const char* compression)
248 {
249 return (ri::Image::Compression)getEnumValue("image compression", s_compressionMap, DE_LENGTH_OF_ARRAY(s_compressionMap), compression);
250 }
251
getShaderTypeFromTagName(const char * shaderType)252 static ri::Shader::ShaderType getShaderTypeFromTagName (const char* shaderType)
253 {
254 return (ri::Shader::ShaderType)getEnumValue("shader type", s_shaderTypeFromTagMap, DE_LENGTH_OF_ARRAY(s_shaderTypeFromTagMap), shaderType);
255 }
256
getTestCaseType(const char * caseType)257 static TestCaseType getTestCaseType (const char* caseType)
258 {
259 return (TestCaseType)getEnumValue("test case type", s_testTypeMap, DE_LENGTH_OF_ARRAY(s_testTypeMap), caseType);
260 }
261
getTestLogVersion(const char * logVersion)262 static TestLogVersion getTestLogVersion (const char* logVersion)
263 {
264 return (TestLogVersion)getEnumValue("test log version", s_logVersionMap, DE_LENGTH_OF_ARRAY(s_logVersionMap), logVersion);
265 }
266
getSampleValueTag(const char * tag)267 static ri::ValueInfo::ValueTag getSampleValueTag (const char* tag)
268 {
269 return (ri::ValueInfo::ValueTag)getEnumValue("sample value tag", s_sampleValueTagMap, DE_LENGTH_OF_ARRAY(s_sampleValueTagMap), tag);
270 }
271
getTestCaseTypeFromPath(const char * casePath)272 static TestCaseType getTestCaseTypeFromPath (const char* casePath)
273 {
274 if (deStringBeginsWith(casePath, "dEQP-GLES2."))
275 {
276 const char* group = casePath+11;
277 if (deStringBeginsWith(group, "capability."))
278 return TESTCASETYPE_CAPABILITY;
279 else if (deStringBeginsWith(group, "accuracy."))
280 return TESTCASETYPE_ACCURACY;
281 else if (deStringBeginsWith(group, "performance."))
282 return TESTCASETYPE_PERFORMANCE;
283 }
284
285 return TESTCASETYPE_SELF_VALIDATE;
286 }
287
getNumericValue(const std::string & value)288 static ri::NumericValue getNumericValue (const std::string& value)
289 {
290 const bool isFloat = value.find('.') != std::string::npos || value.find('e') != std::string::npos;
291
292 if (isFloat)
293 {
294 const double num = toDouble(stripLeadingWhitespace(value.c_str()));
295 return ri::NumericValue(num);
296 }
297 else
298 {
299 const deInt64 num = toInt64(stripLeadingWhitespace(value.c_str()));
300 return ri::NumericValue(num);
301 }
302 }
303
TestResultParser(void)304 TestResultParser::TestResultParser (void)
305 : m_result (DE_NULL)
306 , m_state (STATE_NOT_INITIALIZED)
307 , m_logVersion (TESTLOGVERSION_LAST)
308 , m_curItemList (DE_NULL)
309 , m_base64DecodeOffset (0)
310 {
311 }
312
~TestResultParser(void)313 TestResultParser::~TestResultParser (void)
314 {
315 }
316
clear(void)317 void TestResultParser::clear (void)
318 {
319 m_xmlParser.clear();
320 m_itemStack.clear();
321
322 m_result = DE_NULL;
323 m_state = STATE_NOT_INITIALIZED;
324 m_logVersion = TESTLOGVERSION_LAST;
325 m_curItemList = DE_NULL;
326 m_base64DecodeOffset = 0;
327 m_curNumValue.clear();
328 }
329
init(TestCaseResult * dstResult)330 void TestResultParser::init (TestCaseResult* dstResult)
331 {
332 clear();
333 m_result = dstResult;
334 m_state = STATE_INITIALIZED;
335 m_curItemList = &dstResult->resultItems;
336 }
337
parse(const deUint8 * bytes,int numBytes)338 TestResultParser::ParseResult TestResultParser::parse (const deUint8* bytes, int numBytes)
339 {
340 DE_ASSERT(m_result && m_state != STATE_NOT_INITIALIZED);
341
342 try
343 {
344 bool resultChanged = false;
345
346 m_xmlParser.feed(bytes, numBytes);
347
348 for (;;)
349 {
350 xml::Element curElement = m_xmlParser.getElement();
351
352 if (curElement == xml::ELEMENT_INCOMPLETE ||
353 curElement == xml::ELEMENT_END_OF_STRING)
354 break;
355
356 switch (curElement)
357 {
358 case xml::ELEMENT_START: handleElementStart(); break;
359 case xml::ELEMENT_END: handleElementEnd(); break;
360 case xml::ELEMENT_DATA: handleData(); break;
361
362 default:
363 DE_ASSERT(false);
364 }
365
366 resultChanged = true;
367 m_xmlParser.advance();
368 }
369
370 if (m_xmlParser.getElement() == xml::ELEMENT_END_OF_STRING)
371 {
372 if (m_state != STATE_TEST_CASE_RESULT_ENDED)
373 throw TestResultParseError("Unexpected end of log data");
374
375 return PARSERESULT_COMPLETE;
376 }
377 else
378 return resultChanged ? PARSERESULT_CHANGED
379 : PARSERESULT_NOT_CHANGED;
380 }
381 catch (const TestResultParseError& e)
382 {
383 // Set error code to result.
384 m_result->statusCode = TESTSTATUSCODE_INTERNAL_ERROR;
385 m_result->statusDetails = e.what();
386
387 return PARSERESULT_ERROR;
388 }
389 catch (const xml::ParseError& e)
390 {
391 // Set error code to result.
392 m_result->statusCode = TESTSTATUSCODE_INTERNAL_ERROR;
393 m_result->statusDetails = e.what();
394
395 return PARSERESULT_ERROR;
396 }
397 }
398
getAttribute(const char * name)399 const char* TestResultParser::getAttribute (const char* name)
400 {
401 if (!m_xmlParser.hasAttribute(name))
402 throw TestResultParseError(string("Missing attribute '") + name + "' in <" + m_xmlParser.getElementName() + ">");
403
404 return m_xmlParser.getAttribute(name);
405 }
406
getCurrentItem(void)407 ri::Item* TestResultParser::getCurrentItem (void)
408 {
409 return !m_itemStack.empty() ? m_itemStack.back() : DE_NULL;
410 }
411
getCurrentItemList(void)412 ri::List* TestResultParser::getCurrentItemList (void)
413 {
414 DE_ASSERT(m_curItemList);
415 return m_curItemList;
416 }
417
updateCurrentItemList(void)418 void TestResultParser::updateCurrentItemList (void)
419 {
420 m_curItemList = DE_NULL;
421
422 for (vector<ri::Item*>::reverse_iterator i = m_itemStack.rbegin(); i != m_itemStack.rend(); i++)
423 {
424 ri::Item* item = *i;
425 ri::Type type = item->getType();
426
427 if (type == ri::TYPE_IMAGESET)
428 m_curItemList = &static_cast<ri::ImageSet*>(item)->images;
429 else if (type == ri::TYPE_SECTION)
430 m_curItemList = &static_cast<ri::Section*>(item)->items;
431 else if (type == ri::TYPE_EGLCONFIGSET)
432 m_curItemList = &static_cast<ri::EglConfigSet*>(item)->configs;
433 else if (type == ri::TYPE_SHADERPROGRAM)
434 m_curItemList = &static_cast<ri::ShaderProgram*>(item)->shaders;
435
436 if (m_curItemList)
437 break;
438 }
439
440 if (!m_curItemList)
441 m_curItemList = &m_result->resultItems;
442 }
443
pushItem(ri::Item * item)444 void TestResultParser::pushItem (ri::Item* item)
445 {
446 m_itemStack.push_back(item);
447 updateCurrentItemList();
448 }
449
popItem(void)450 void TestResultParser::popItem (void)
451 {
452 m_itemStack.pop_back();
453 updateCurrentItemList();
454 }
455
handleElementStart(void)456 void TestResultParser::handleElementStart (void)
457 {
458 const char* elemName = m_xmlParser.getElementName();
459
460 if (m_state == STATE_INITIALIZED)
461 {
462 // Expect TestCaseResult.
463 if (!deStringEqual(elemName, "TestCaseResult"))
464 throw TestResultParseError(string("Expected <TestCaseResult>, got <") + elemName + ">");
465
466 const char* version = getAttribute("Version");
467 m_logVersion = getTestLogVersion(version);
468 // \note Currently assumed that all known log versions are supported.
469
470 m_result->casePath = getAttribute("CasePath");
471 m_result->caseType = TESTCASETYPE_SELF_VALIDATE;
472
473 if (m_xmlParser.hasAttribute("CaseType"))
474 m_result->caseType = getTestCaseType(m_xmlParser.getAttribute("CaseType"));
475 else
476 {
477 // Do guess based on path for legacy log files.
478 if (m_logVersion >= TESTLOGVERSION_0_3_2)
479 throw TestResultParseError("Missing CaseType attribute in <TestCaseResult>");
480 m_result->caseType = getTestCaseTypeFromPath(m_result->casePath.c_str());
481 }
482
483 m_state = STATE_IN_TEST_CASE_RESULT;
484 }
485 else
486 {
487 ri::List* curList = getCurrentItemList();
488 ri::Type itemType = getResultItemType(elemName);
489 ri::Item* item = DE_NULL;
490 ri::Item* parentItem = getCurrentItem();
491 ri::Type parentType = parentItem ? parentItem->getType() : ri::TYPE_LAST;
492
493 switch (itemType)
494 {
495 case ri::TYPE_RESULT:
496 {
497 ri::Result* result = curList->allocItem<ri::Result>();
498 result->statusCode = getTestStatusCode(getAttribute("StatusCode"));
499 item = result;
500 break;
501 }
502
503 case ri::TYPE_TEXT:
504 item = curList->allocItem<ri::Text>();
505 break;
506
507 case ri::TYPE_SECTION:
508 {
509 ri::Section* section = curList->allocItem<ri::Section>();
510 section->name = getAttribute("Name");
511 section->description = getAttribute("Description");
512 item = section;
513 break;
514 }
515
516 case ri::TYPE_NUMBER:
517 {
518 ri::Number* number = curList->allocItem<ri::Number>();
519 number->name = getAttribute("Name");
520 number->description = getAttribute("Description");
521 number->unit = getAttribute("Unit");
522
523 if (m_xmlParser.hasAttribute("Tag"))
524 number->tag = m_xmlParser.getAttribute("Tag");
525
526 item = number;
527
528 m_curNumValue.clear();
529 break;
530 }
531
532 case ri::TYPE_IMAGESET:
533 {
534 ri::ImageSet* imageSet = curList->allocItem<ri::ImageSet>();
535 imageSet->name = getAttribute("Name");
536 imageSet->description = getAttribute("Description");
537 item = imageSet;
538 break;
539 }
540
541 case ri::TYPE_IMAGE:
542 {
543 ri::Image* image = curList->allocItem<ri::Image>();
544 image->name = getAttribute("Name");
545 image->description = getAttribute("Description");
546 image->width = toInt(getAttribute("Width"));
547 image->height = toInt(getAttribute("Height"));
548 image->format = getImageFormat(getAttribute("Format"));
549 image->compression = getImageCompression(getAttribute("CompressionMode"));
550 item = image;
551 break;
552 }
553
554 case ri::TYPE_SHADERPROGRAM:
555 {
556 ri::ShaderProgram* shaderProgram = curList->allocItem<ri::ShaderProgram>();
557 shaderProgram->linkStatus = toBool(getAttribute("LinkStatus"));
558 item = shaderProgram;
559 break;
560 }
561
562 case ri::TYPE_SHADER:
563 {
564 if (parentType != ri::TYPE_SHADERPROGRAM)
565 throw TestResultParseError(string("<") + elemName + "> outside of <ShaderProgram>");
566
567 ri::Shader* shader = curList->allocItem<ri::Shader>();
568
569 shader->shaderType = getShaderTypeFromTagName(elemName);
570 shader->compileStatus = toBool(getAttribute("CompileStatus"));
571
572 item = shader;
573 break;
574 }
575
576 case ri::TYPE_SPIRVSOURCE:
577 {
578 if (parentType != ri::TYPE_SHADERPROGRAM)
579 throw TestResultParseError(string("<") + elemName + "> outside of <ShaderProgram>");
580 item = curList->allocItem<ri::SpirVSource>();
581 break;
582 }
583
584 case ri::TYPE_SHADERSOURCE:
585 if (parentType == ri::TYPE_SHADER)
586 item = &static_cast<ri::Shader*>(parentItem)->source;
587 else
588 throw TestResultParseError("Unexpected <ShaderSource>");
589 break;
590
591 case ri::TYPE_INFOLOG:
592 if (parentType == ri::TYPE_SHADERPROGRAM)
593 item = &static_cast<ri::ShaderProgram*>(parentItem)->linkInfoLog;
594 else if (parentType == ri::TYPE_SHADER)
595 item = &static_cast<ri::Shader*>(parentItem)->infoLog;
596 else if (parentType == ri::TYPE_COMPILEINFO)
597 item = &static_cast<ri::CompileInfo*>(parentItem)->infoLog;
598 else
599 throw TestResultParseError("Unexpected <InfoLog>");
600 break;
601
602 case ri::TYPE_KERNELSOURCE:
603 item = curList->allocItem<ri::KernelSource>();
604 break;
605
606 case ri::TYPE_COMPILEINFO:
607 {
608 ri::CompileInfo* info = curList->allocItem<ri::CompileInfo>();
609 info->name = getAttribute("Name");
610 info->description = getAttribute("Description");
611 info->compileStatus = toBool(getAttribute("CompileStatus"));
612 item = info;
613 break;
614 }
615
616 case ri::TYPE_EGLCONFIGSET:
617 {
618 ri::EglConfigSet* set = curList->allocItem<ri::EglConfigSet>();
619 set->name = getAttribute("Name");
620 set->description = m_xmlParser.hasAttribute("Description") ? m_xmlParser.getAttribute("Description") : "";
621 item = set;
622 break;
623 }
624
625 case ri::TYPE_EGLCONFIG:
626 {
627 ri::EglConfig* config = curList->allocItem<ri::EglConfig>();
628 config->bufferSize = toInt(getAttribute("BufferSize"));
629 config->redSize = toInt(getAttribute("RedSize"));
630 config->greenSize = toInt(getAttribute("GreenSize"));
631 config->blueSize = toInt(getAttribute("BlueSize"));
632 config->luminanceSize = toInt(getAttribute("LuminanceSize"));
633 config->alphaSize = toInt(getAttribute("AlphaSize"));
634 config->alphaMaskSize = toInt(getAttribute("AlphaMaskSize"));
635 config->bindToTextureRGB = toBool(getAttribute("BindToTextureRGB"));
636 config->bindToTextureRGBA = toBool(getAttribute("BindToTextureRGBA"));
637 config->colorBufferType = getAttribute("ColorBufferType");
638 config->configCaveat = getAttribute("ConfigCaveat");
639 config->configID = toInt(getAttribute("ConfigID"));
640 config->conformant = getAttribute("Conformant");
641 config->depthSize = toInt(getAttribute("DepthSize"));
642 config->level = toInt(getAttribute("Level"));
643 config->maxPBufferWidth = toInt(getAttribute("MaxPBufferWidth"));
644 config->maxPBufferHeight = toInt(getAttribute("MaxPBufferHeight"));
645 config->maxPBufferPixels = toInt(getAttribute("MaxPBufferPixels"));
646 config->maxSwapInterval = toInt(getAttribute("MaxSwapInterval"));
647 config->minSwapInterval = toInt(getAttribute("MinSwapInterval"));
648 config->nativeRenderable = toBool(getAttribute("NativeRenderable"));
649 config->renderableType = getAttribute("RenderableType");
650 config->sampleBuffers = toInt(getAttribute("SampleBuffers"));
651 config->samples = toInt(getAttribute("Samples"));
652 config->stencilSize = toInt(getAttribute("StencilSize"));
653 config->surfaceTypes = getAttribute("SurfaceTypes");
654 config->transparentType = getAttribute("TransparentType");
655 config->transparentRedValue = toInt(getAttribute("TransparentRedValue"));
656 config->transparentGreenValue = toInt(getAttribute("TransparentGreenValue"));
657 config->transparentBlueValue = toInt(getAttribute("TransparentBlueValue"));
658 item = config;
659 break;
660 }
661
662 case ri::TYPE_SAMPLELIST:
663 {
664 ri::SampleList* list = curList->allocItem<ri::SampleList>();
665 list->name = getAttribute("Name");
666 list->description = getAttribute("Description");
667 item = list;
668 break;
669 }
670
671 case ri::TYPE_SAMPLEINFO:
672 {
673 if (parentType != ri::TYPE_SAMPLELIST)
674 throw TestResultParseError("<SampleInfo> outside of <SampleList>");
675
676 ri::SampleList* list = static_cast<ri::SampleList*>(parentItem);
677 ri::SampleInfo* info = &list->sampleInfo;
678
679 item = info;
680 break;
681 }
682
683 case ri::TYPE_VALUEINFO:
684 {
685 if (parentType != ri::TYPE_SAMPLEINFO)
686 throw TestResultParseError("<ValueInfo> outside of <SampleInfo>");
687
688 ri::SampleInfo* sampleInfo = static_cast<ri::SampleInfo*>(parentItem);
689 ri::ValueInfo* valueInfo = sampleInfo->valueInfos.allocItem<ri::ValueInfo>();
690
691 valueInfo->name = getAttribute("Name");
692 valueInfo->description = getAttribute("Description");
693 valueInfo->tag = getSampleValueTag(getAttribute("Tag"));
694
695 if (m_xmlParser.hasAttribute("Unit"))
696 valueInfo->unit = getAttribute("Unit");
697
698 item = valueInfo;
699 break;
700 }
701
702 case ri::TYPE_SAMPLE:
703 {
704 if (parentType != ri::TYPE_SAMPLELIST)
705 throw TestResultParseError("<Sample> outside of <SampleList>");
706
707 ri::SampleList* list = static_cast<ri::SampleList*>(parentItem);
708 ri::Sample* sample = list->samples.allocItem<ri::Sample>();
709
710 item = sample;
711 break;
712 }
713
714 case ri::TYPE_SAMPLEVALUE:
715 {
716 if (parentType != ri::TYPE_SAMPLE)
717 throw TestResultParseError("<Value> outside of <Sample>");
718
719 ri::Sample* sample = static_cast<ri::Sample*>(parentItem);
720 ri::SampleValue* value = sample->values.allocItem<ri::SampleValue>();
721
722 item = value;
723 break;
724 }
725
726 default:
727 throw TestResultParseError(string("Unsupported element '") + elemName + ("'"));
728 }
729
730 DE_ASSERT(item);
731 pushItem(item);
732
733 // Reset base64 decoding offset.
734 m_base64DecodeOffset = 0;
735 }
736 }
737
handleElementEnd(void)738 void TestResultParser::handleElementEnd (void)
739 {
740 const char* elemName = m_xmlParser.getElementName();
741
742 if (m_state != STATE_IN_TEST_CASE_RESULT)
743 throw TestResultParseError(string("Unexpected </") + elemName + "> outside of <TestCaseResult>");
744
745 if (deStringEqual(elemName, "TestCaseResult"))
746 {
747 // Logs from buggy test cases may contain invalid XML.
748 // DE_ASSERT(getCurrentItem() == DE_NULL);
749 // \todo [2012-11-22 pyry] Log warning.
750
751 m_state = STATE_TEST_CASE_RESULT_ENDED;
752 }
753 else
754 {
755 ri::Type itemType = getResultItemType(elemName);
756 ri::Item* curItem = getCurrentItem();
757
758 if (!curItem || itemType != curItem->getType())
759 throw TestResultParseError(string("Unexpected </") + elemName + ">");
760
761 if (itemType == ri::TYPE_RESULT)
762 {
763 ri::Result* result = static_cast<ri::Result*>(curItem);
764 m_result->statusCode = result->statusCode;
765 m_result->statusDetails = result->details;
766 }
767 else if (itemType == ri::TYPE_NUMBER)
768 {
769 // Parse value for number.
770 ri::Number* number = static_cast<ri::Number*>(curItem);
771 number->value = getNumericValue(m_curNumValue);
772 m_curNumValue.clear();
773 }
774 else if (itemType == ri::TYPE_SAMPLEVALUE)
775 {
776 ri::SampleValue* value = static_cast<ri::SampleValue*>(curItem);
777 value->value = getNumericValue(m_curNumValue);
778 m_curNumValue.clear();
779 }
780
781 popItem();
782 }
783 }
784
handleData(void)785 void TestResultParser::handleData (void)
786 {
787 ri::Item* curItem = getCurrentItem();
788 ri::Type type = curItem ? curItem->getType() : ri::TYPE_LAST;
789
790 switch (type)
791 {
792 case ri::TYPE_RESULT:
793 m_xmlParser.appendDataStr(static_cast<ri::Result*>(curItem)->details);
794 break;
795
796 case ri::TYPE_TEXT:
797 m_xmlParser.appendDataStr(static_cast<ri::Text*>(curItem)->text);
798 break;
799
800 case ri::TYPE_SHADERSOURCE:
801 m_xmlParser.appendDataStr(static_cast<ri::ShaderSource*>(curItem)->source);
802 break;
803
804 case ri::TYPE_SPIRVSOURCE:
805 m_xmlParser.appendDataStr(static_cast<ri::SpirVSource*>(curItem)->source);
806 break;
807
808 case ri::TYPE_INFOLOG:
809 m_xmlParser.appendDataStr(static_cast<ri::InfoLog*>(curItem)->log);
810 break;
811
812 case ri::TYPE_KERNELSOURCE:
813 m_xmlParser.appendDataStr(static_cast<ri::KernelSource*>(curItem)->source);
814 break;
815
816 case ri::TYPE_NUMBER:
817 case ri::TYPE_SAMPLEVALUE:
818 m_xmlParser.appendDataStr(m_curNumValue);
819 break;
820
821 case ri::TYPE_IMAGE:
822 {
823 ri::Image* image = static_cast<ri::Image*>(curItem);
824
825 // Base64 decode.
826 int numBytesIn = m_xmlParser.getDataSize();
827
828 for (int inNdx = 0; inNdx < numBytesIn; inNdx++)
829 {
830 deUint8 byte = m_xmlParser.getDataByte(inNdx);
831 deUint8 decodedBits = 0;
832
833 if (de::inRange<deInt8>(byte, 'A', 'Z'))
834 decodedBits = (deUint8)(byte - 'A');
835 else if (de::inRange<deInt8>(byte, 'a', 'z'))
836 decodedBits = (deUint8)(('Z'-'A'+1) + (byte-'a'));
837 else if (de::inRange<deInt8>(byte, '0', '9'))
838 decodedBits = (deUint8)(('Z'-'A'+1) + ('z'-'a'+1) + (byte-'0'));
839 else if (byte == '+')
840 decodedBits = ('Z'-'A'+1) + ('z'-'a'+1) + ('9'-'0'+1);
841 else if (byte == '/')
842 decodedBits = ('Z'-'A'+1) + ('z'-'a'+1) + ('9'-'0'+2);
843 else if (byte == '=')
844 {
845 // Padding at end - remove last byte.
846 if (image->data.empty())
847 throw TestResultParseError("Malformed base64 data");
848 image->data.pop_back();
849 continue;
850 }
851 else
852 continue; // Not an B64 input character.
853
854 int phase = m_base64DecodeOffset % 4;
855
856 if (phase == 0)
857 image->data.resize(image->data.size()+3, 0);
858
859 if ((int)image->data.size() < (m_base64DecodeOffset>>2)*3 + 3)
860 throw TestResultParseError("Malformed base64 data");
861 deUint8* outPtr = &image->data[(m_base64DecodeOffset>>2)*3];
862
863 switch (phase)
864 {
865 case 0: outPtr[0] |= (deUint8)(decodedBits<<2); break;
866 case 1: outPtr[0] = (deUint8)(outPtr[0] | (deUint8)(decodedBits>>4)); outPtr[1] = (deUint8)(outPtr[1] | (deUint8)((decodedBits&0xF)<<4)); break;
867 case 2: outPtr[1] = (deUint8)(outPtr[1] | (deUint8)(decodedBits>>2)); outPtr[2] = (deUint8)(outPtr[2] | (deUint8)((decodedBits&0x3)<<6)); break;
868 case 3: outPtr[2] |= decodedBits; break;
869 default:
870 DE_ASSERT(false);
871 }
872
873 m_base64DecodeOffset += 1;
874 }
875
876 break;
877 }
878
879 default:
880 // Just ignore data.
881 break;
882 }
883 }
884
885 //! Helper for parsing TestCaseResult from TestCaseResultData.
parseTestCaseResultFromData(TestResultParser * parser,TestCaseResult * result,const TestCaseResultData & data)886 void parseTestCaseResultFromData (TestResultParser* parser, TestCaseResult* result, const TestCaseResultData& data)
887 {
888 DE_ASSERT(result->resultItems.getNumItems() == 0);
889
890 // Initialize status codes etc. from data.
891 result->casePath = data.getTestCasePath();
892 result->caseType = TESTCASETYPE_SELF_VALIDATE;
893 result->statusCode = data.getStatusCode();
894 result->statusDetails = data.getStatusDetails();
895
896 if (data.getDataSize() > 0)
897 {
898 parser->init(result);
899
900 const TestResultParser::ParseResult parseResult = parser->parse(data.getData(), data.getDataSize());
901
902 if (result->statusCode == TESTSTATUSCODE_LAST)
903 {
904 result->statusCode = TESTSTATUSCODE_INTERNAL_ERROR;
905
906 if (parseResult == TestResultParser::PARSERESULT_ERROR)
907 result->statusDetails = "Test case result parsing failed";
908 else if (parseResult != TestResultParser::PARSERESULT_COMPLETE)
909 result->statusDetails = "Incomplete test case result";
910 else
911 result->statusDetails = "Test case result is missing <Result> item";
912 }
913 }
914 else if (result->statusCode == TESTSTATUSCODE_LAST)
915 {
916 result->statusCode = TESTSTATUSCODE_TERMINATED;
917 result->statusDetails = "Empty test case result";
918 }
919
920 if (result->casePath.empty())
921 throw Error("Empty test case path in result");
922
923 if (result->caseType == TESTCASETYPE_LAST)
924 throw Error("Invalid test case type in result");
925
926 DE_ASSERT(result->statusCode != TESTSTATUSCODE_LAST);
927 }
928
929 } // xe
930