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