1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Test Executor
3 * ------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Test case result parser.
22 *//*--------------------------------------------------------------------*/
24 #include "xeTestResultParser.hpp"
25 #include "xeTestCaseResult.hpp"
26 #include "xeBatchResult.hpp"
39 static inline int toInt (const char* str)
44 static inline double toDouble (const char* str)
49 static inline deInt64 toInt64 (const char* str)
51 std::istringstream s (str);
59 static inline bool toBool (const char* str)
61 return deStringEqual(str, "OK") || deStringEqual(str, "True");
64 static const char* stripLeadingWhitespace (const char* str)
66 int whitespaceCount = 0;
68 while (str[whitespaceCount] != 0 &&
69 (str[whitespaceCount] == ' ' ||
70 str[whitespaceCount] == '\t' ||
71 str[whitespaceCount] == '\r' ||
72 str[whitespaceCount] == '\n'))
75 return str + whitespaceCount;
85 static const EnumMapEntry s_statusCodeMap[] =
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 }
103 static const EnumMapEntry s_resultItemMap[] =
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 { 0x72863a54, "ShaderProgram", ri::TYPE_SHADERPROGRAM },
117 { 0xb4efc08d, "ShaderSource", ri::TYPE_SHADERSOURCE },
118 { 0xff265913, "InfoLog", ri::TYPE_INFOLOG },
119 { 0x84159b73, "EglConfig", ri::TYPE_EGLCONFIG },
120 { 0xdd34391f, "EglConfigSet", ri::TYPE_EGLCONFIGSET },
121 { 0xebbb3aba, "Section", ri::TYPE_SECTION },
122 { 0xa0f15677, "KernelSource", ri::TYPE_KERNELSOURCE },
123 { 0x1ee9083a, "CompileInfo", ri::TYPE_COMPILEINFO },
124 { 0xf1004023, "SampleList", ri::TYPE_SAMPLELIST },
125 { 0xf0feae93, "SampleInfo", ri::TYPE_SAMPLEINFO },
126 { 0x2aa6f14e, "ValueInfo", ri::TYPE_VALUEINFO },
127 { 0xd09429e7, "Sample", ri::TYPE_SAMPLE },
128 { 0x0e4a4722, "Value", ri::TYPE_SAMPLEVALUE },
131 static const EnumMapEntry s_imageFormatMap[] =
133 { 0xcc4ffac8, "RGB888", ri::Image::FORMAT_RGB888 },
134 { 0x20dcb0c1, "RGBA8888", ri::Image::FORMAT_RGBA8888 }
137 static const EnumMapEntry s_compressionMap[] =
139 { 0x7c89bbd5, "None", ri::Image::COMPRESSION_NONE },
140 { 0x0b88118a, "PNG", ri::Image::COMPRESSION_PNG }
143 static const EnumMapEntry s_shaderTypeFromTagMap[] =
145 { 0x1181fa5a, "VertexShader", ri::Shader::SHADERTYPE_VERTEX },
146 { 0xa93daef0, "FragmentShader", ri::Shader::SHADERTYPE_FRAGMENT },
147 { 0x8f066128, "GeometryShader", ri::Shader::SHADERTYPE_GEOMETRY },
148 { 0x235a931c, "TessControlShader", ri::Shader::SHADERTYPE_TESS_CONTROL },
149 { 0xa1bf7153, "TessEvaluationShader", ri::Shader::SHADERTYPE_TESS_EVALUATION },
150 { 0x6c1415d9, "ComputeShader", ri::Shader::SHADERTYPE_COMPUTE },
153 static const EnumMapEntry s_testTypeMap[] =
155 { 0x7fa80959, "SelfValidate", TESTCASETYPE_SELF_VALIDATE },
156 { 0xdb797567, "Capability", TESTCASETYPE_CAPABILITY },
157 { 0x2ca3ec10, "Accuracy", TESTCASETYPE_ACCURACY },
158 { 0xa48ac277, "Performance", TESTCASETYPE_PERFORMANCE }
161 static const EnumMapEntry s_logVersionMap[] =
163 { 0x0b7dac93, "0.2.0", TESTLOGVERSION_0_2_0 },
164 { 0x0b7db0d4, "0.3.0", TESTLOGVERSION_0_3_0 },
165 { 0x0b7db0d5, "0.3.1", TESTLOGVERSION_0_3_1 },
166 { 0x0b7db0d6, "0.3.2", TESTLOGVERSION_0_3_2 },
167 { 0x0b7db0d7, "0.3.3", TESTLOGVERSION_0_3_3 }
170 static const EnumMapEntry s_sampleValueTagMap[] =
172 { 0xddf2d0d1, "Predictor", ri::ValueInfo::VALUETAG_PREDICTOR },
173 { 0x9bee2c34, "Response", ri::ValueInfo::VALUETAG_RESPONSE },
176 #if defined(DE_DEBUG)
177 static void printHashes (const char* name, const EnumMapEntry* entries, int numEntries)
179 printf("%s:\n", name);
181 for (int ndx = 0; ndx < numEntries; ndx++)
182 printf("0x%08x\t%s\n", deStringHash(entries[ndx].name), entries[ndx].name);
187 #define PRINT_HASHES(MAP) printHashes(#MAP, MAP, DE_LENGTH_OF_ARRAY(MAP))
189 void TestResultParser_printHashes (void)
191 PRINT_HASHES(s_statusCodeMap);
192 PRINT_HASHES(s_resultItemMap);
193 PRINT_HASHES(s_imageFormatMap);
194 PRINT_HASHES(s_compressionMap);
195 PRINT_HASHES(s_shaderTypeFromTagMap);
196 PRINT_HASHES(s_testTypeMap);
197 PRINT_HASHES(s_logVersionMap);
198 PRINT_HASHES(s_sampleValueTagMap);
202 static inline int getEnumValue (const char* enumName, const EnumMapEntry* entries, int numEntries, const char* name)
204 deUint32 hash = deStringHash(name);
206 for (int ndx = 0; ndx < numEntries; ndx++)
208 if (entries[ndx].hash == hash && deStringEqual(entries[ndx].name, name))
209 return entries[ndx].value;
212 throw TestResultParseError(string("Could not map '") + name + "' to " + enumName);
215 TestStatusCode getTestStatusCode (const char* statusCode)
217 return (TestStatusCode)getEnumValue("status code", s_statusCodeMap, DE_LENGTH_OF_ARRAY(s_statusCodeMap), statusCode);
220 static ri::Type getResultItemType (const char* elemName)
222 return (ri::Type)getEnumValue("result item type", s_resultItemMap, DE_LENGTH_OF_ARRAY(s_resultItemMap), elemName);
225 static ri::Image::Format getImageFormat (const char* imageFormat)
227 return (ri::Image::Format)getEnumValue("image format", s_imageFormatMap, DE_LENGTH_OF_ARRAY(s_imageFormatMap), imageFormat);
230 static ri::Image::Compression getImageCompression (const char* compression)
232 return (ri::Image::Compression)getEnumValue("image compression", s_compressionMap, DE_LENGTH_OF_ARRAY(s_compressionMap), compression);
235 static ri::Shader::ShaderType getShaderTypeFromTagName (const char* shaderType)
237 return (ri::Shader::ShaderType)getEnumValue("shader type", s_shaderTypeFromTagMap, DE_LENGTH_OF_ARRAY(s_shaderTypeFromTagMap), shaderType);
240 static TestCaseType getTestCaseType (const char* caseType)
242 return (TestCaseType)getEnumValue("test case type", s_testTypeMap, DE_LENGTH_OF_ARRAY(s_testTypeMap), caseType);
245 static TestLogVersion getTestLogVersion (const char* logVersion)
247 return (TestLogVersion)getEnumValue("test log version", s_logVersionMap, DE_LENGTH_OF_ARRAY(s_logVersionMap), logVersion);
250 static ri::ValueInfo::ValueTag getSampleValueTag (const char* tag)
252 return (ri::ValueInfo::ValueTag)getEnumValue("sample value tag", s_sampleValueTagMap, DE_LENGTH_OF_ARRAY(s_sampleValueTagMap), tag);
255 static TestCaseType getTestCaseTypeFromPath (const char* casePath)
257 if (deStringBeginsWith(casePath, "dEQP-GLES2."))
259 const char* group = casePath+11;
260 if (deStringBeginsWith(group, "capability."))
261 return TESTCASETYPE_CAPABILITY;
262 else if (deStringBeginsWith(group, "accuracy."))
263 return TESTCASETYPE_ACCURACY;
264 else if (deStringBeginsWith(group, "performance."))
265 return TESTCASETYPE_PERFORMANCE;
268 return TESTCASETYPE_SELF_VALIDATE;
271 static ri::NumericValue getNumericValue (const std::string& value)
273 const bool isFloat = value.find('.') != std::string::npos || value.find('e') != std::string::npos;
277 const double num = toDouble(stripLeadingWhitespace(value.c_str()));
278 return ri::NumericValue(num);
282 const deInt64 num = toInt64(stripLeadingWhitespace(value.c_str()));
283 return ri::NumericValue(num);
287 TestResultParser::TestResultParser (void)
289 , m_state (STATE_NOT_INITIALIZED)
290 , m_logVersion (TESTLOGVERSION_LAST)
291 , m_curItemList (DE_NULL)
292 , m_base64DecodeOffset (0)
296 TestResultParser::~TestResultParser (void)
300 void TestResultParser::clear (void)
306 m_state = STATE_NOT_INITIALIZED;
307 m_logVersion = TESTLOGVERSION_LAST;
308 m_curItemList = DE_NULL;
309 m_base64DecodeOffset = 0;
310 m_curNumValue.clear();
313 void TestResultParser::init (TestCaseResult* dstResult)
316 m_result = dstResult;
317 m_state = STATE_INITIALIZED;
318 m_curItemList = &dstResult->resultItems;
321 TestResultParser::ParseResult TestResultParser::parse (const deUint8* bytes, int numBytes)
323 DE_ASSERT(m_result && m_state != STATE_NOT_INITIALIZED);
327 bool resultChanged = false;
329 m_xmlParser.feed(bytes, numBytes);
333 xml::Element curElement = m_xmlParser.getElement();
335 if (curElement == xml::ELEMENT_INCOMPLETE ||
336 curElement == xml::ELEMENT_END_OF_STRING)
341 case xml::ELEMENT_START: handleElementStart(); break;
342 case xml::ELEMENT_END: handleElementEnd(); break;
343 case xml::ELEMENT_DATA: handleData(); break;
349 resultChanged = true;
350 m_xmlParser.advance();
353 if (m_xmlParser.getElement() == xml::ELEMENT_END_OF_STRING)
355 if (m_state != STATE_TEST_CASE_RESULT_ENDED)
356 throw TestResultParseError("Unexpected end of log data");
358 return PARSERESULT_COMPLETE;
361 return resultChanged ? PARSERESULT_CHANGED
362 : PARSERESULT_NOT_CHANGED;
364 catch (const TestResultParseError& e)
366 // Set error code to result.
367 m_result->statusCode = TESTSTATUSCODE_INTERNAL_ERROR;
368 m_result->statusDetails = e.what();
370 return PARSERESULT_ERROR;
372 catch (const xml::ParseError& e)
374 // Set error code to result.
375 m_result->statusCode = TESTSTATUSCODE_INTERNAL_ERROR;
376 m_result->statusDetails = e.what();
378 return PARSERESULT_ERROR;
382 const char* TestResultParser::getAttribute (const char* name)
384 if (!m_xmlParser.hasAttribute(name))
385 throw TestResultParseError(string("Missing attribute '") + name + "' in <" + m_xmlParser.getElementName() + ">");
387 return m_xmlParser.getAttribute(name);
390 ri::Item* TestResultParser::getCurrentItem (void)
392 return !m_itemStack.empty() ? m_itemStack.back() : DE_NULL;
395 ri::List* TestResultParser::getCurrentItemList (void)
397 DE_ASSERT(m_curItemList);
398 return m_curItemList;
401 void TestResultParser::updateCurrentItemList (void)
403 m_curItemList = DE_NULL;
405 for (vector<ri::Item*>::reverse_iterator i = m_itemStack.rbegin(); i != m_itemStack.rend(); i++)
408 ri::Type type = item->getType();
410 if (type == ri::TYPE_IMAGESET)
411 m_curItemList = &static_cast<ri::ImageSet*>(item)->images;
412 else if (type == ri::TYPE_SECTION)
413 m_curItemList = &static_cast<ri::Section*>(item)->items;
414 else if (type == ri::TYPE_EGLCONFIGSET)
415 m_curItemList = &static_cast<ri::EglConfigSet*>(item)->configs;
416 else if (type == ri::TYPE_SHADERPROGRAM)
417 m_curItemList = &static_cast<ri::ShaderProgram*>(item)->shaders;
424 m_curItemList = &m_result->resultItems;
427 void TestResultParser::pushItem (ri::Item* item)
429 m_itemStack.push_back(item);
430 updateCurrentItemList();
433 void TestResultParser::popItem (void)
435 m_itemStack.pop_back();
436 updateCurrentItemList();
439 void TestResultParser::handleElementStart (void)
441 const char* elemName = m_xmlParser.getElementName();
443 if (m_state == STATE_INITIALIZED)
445 // Expect TestCaseResult.
446 if (!deStringEqual(elemName, "TestCaseResult"))
447 throw TestResultParseError(string("Expected <TestCaseResult>, got <") + elemName + ">");
449 const char* version = getAttribute("Version");
450 m_logVersion = getTestLogVersion(version);
451 // \note Currently assumed that all known log versions are supported.
453 m_result->casePath = getAttribute("CasePath");
454 m_result->caseType = TESTCASETYPE_SELF_VALIDATE;
456 if (m_xmlParser.hasAttribute("CaseType"))
457 m_result->caseType = getTestCaseType(m_xmlParser.getAttribute("CaseType"));
460 // Do guess based on path for legacy log files.
461 if (m_logVersion >= TESTLOGVERSION_0_3_2)
462 throw TestResultParseError("Missing CaseType attribute in <TestCaseResult>");
463 m_result->caseType = getTestCaseTypeFromPath(m_result->casePath.c_str());
466 m_state = STATE_IN_TEST_CASE_RESULT;
470 ri::List* curList = getCurrentItemList();
471 ri::Type itemType = getResultItemType(elemName);
472 ri::Item* item = DE_NULL;
473 ri::Item* parentItem = getCurrentItem();
474 ri::Type parentType = parentItem ? parentItem->getType() : ri::TYPE_LAST;
478 case ri::TYPE_RESULT:
480 ri::Result* result = curList->allocItem<ri::Result>();
481 result->statusCode = getTestStatusCode(getAttribute("StatusCode"));
487 item = curList->allocItem<ri::Text>();
490 case ri::TYPE_SECTION:
492 ri::Section* section = curList->allocItem<ri::Section>();
493 section->name = getAttribute("Name");
494 section->description = getAttribute("Description");
499 case ri::TYPE_NUMBER:
501 ri::Number* number = curList->allocItem<ri::Number>();
502 number->name = getAttribute("Name");
503 number->description = getAttribute("Description");
504 number->unit = getAttribute("Unit");
506 if (m_xmlParser.hasAttribute("Tag"))
507 number->tag = m_xmlParser.getAttribute("Tag");
511 m_curNumValue.clear();
515 case ri::TYPE_IMAGESET:
517 ri::ImageSet* imageSet = curList->allocItem<ri::ImageSet>();
518 imageSet->name = getAttribute("Name");
519 imageSet->description = getAttribute("Description");
526 ri::Image* image = curList->allocItem<ri::Image>();
527 image->name = getAttribute("Name");
528 image->description = getAttribute("Description");
529 image->width = toInt(getAttribute("Width"));
530 image->height = toInt(getAttribute("Height"));
531 image->format = getImageFormat(getAttribute("Format"));
532 image->compression = getImageCompression(getAttribute("CompressionMode"));
537 case ri::TYPE_SHADERPROGRAM:
539 ri::ShaderProgram* shaderProgram = curList->allocItem<ri::ShaderProgram>();
540 shaderProgram->linkStatus = toBool(getAttribute("LinkStatus"));
541 item = shaderProgram;
545 case ri::TYPE_SHADER:
547 if (parentType != ri::TYPE_SHADERPROGRAM)
548 throw TestResultParseError("<VertexShader> outside of <ShaderProgram>");
550 ri::Shader* shader = curList->allocItem<ri::Shader>();
552 shader->shaderType = getShaderTypeFromTagName(elemName);
553 shader->compileStatus = toBool(getAttribute("CompileStatus"));
559 case ri::TYPE_SHADERSOURCE:
560 if (parentType == ri::TYPE_SHADER)
561 item = &static_cast<ri::Shader*>(parentItem)->source;
563 throw TestResultParseError("Unexpected <ShaderSource>");
566 case ri::TYPE_INFOLOG:
567 if (parentType == ri::TYPE_SHADERPROGRAM)
568 item = &static_cast<ri::ShaderProgram*>(parentItem)->linkInfoLog;
569 else if (parentType == ri::TYPE_SHADER)
570 item = &static_cast<ri::Shader*>(parentItem)->infoLog;
571 else if (parentType == ri::TYPE_COMPILEINFO)
572 item = &static_cast<ri::CompileInfo*>(parentItem)->infoLog;
574 throw TestResultParseError("Unexpected <InfoLog>");
577 case ri::TYPE_KERNELSOURCE:
578 item = curList->allocItem<ri::KernelSource>();
581 case ri::TYPE_COMPILEINFO:
583 ri::CompileInfo* info = curList->allocItem<ri::CompileInfo>();
584 info->name = getAttribute("Name");
585 info->description = getAttribute("Description");
586 info->compileStatus = toBool(getAttribute("CompileStatus"));
591 case ri::TYPE_EGLCONFIGSET:
593 ri::EglConfigSet* set = curList->allocItem<ri::EglConfigSet>();
594 set->name = getAttribute("Name");
595 set->description = m_xmlParser.hasAttribute("Description") ? m_xmlParser.getAttribute("Description") : "";
600 case ri::TYPE_EGLCONFIG:
602 ri::EglConfig* config = curList->allocItem<ri::EglConfig>();
603 config->bufferSize = toInt(getAttribute("BufferSize"));
604 config->redSize = toInt(getAttribute("RedSize"));
605 config->greenSize = toInt(getAttribute("GreenSize"));
606 config->blueSize = toInt(getAttribute("BlueSize"));
607 config->luminanceSize = toInt(getAttribute("LuminanceSize"));
608 config->alphaSize = toInt(getAttribute("AlphaSize"));
609 config->alphaMaskSize = toInt(getAttribute("AlphaMaskSize"));
610 config->bindToTextureRGB = toBool(getAttribute("BindToTextureRGB"));
611 config->bindToTextureRGBA = toBool(getAttribute("BindToTextureRGBA"));
612 config->colorBufferType = getAttribute("ColorBufferType");
613 config->configCaveat = getAttribute("ConfigCaveat");
614 config->configID = toInt(getAttribute("ConfigID"));
615 config->conformant = getAttribute("Conformant");
616 config->depthSize = toInt(getAttribute("DepthSize"));
617 config->level = toInt(getAttribute("Level"));
618 config->maxPBufferWidth = toInt(getAttribute("MaxPBufferWidth"));
619 config->maxPBufferHeight = toInt(getAttribute("MaxPBufferHeight"));
620 config->maxPBufferPixels = toInt(getAttribute("MaxPBufferPixels"));
621 config->maxSwapInterval = toInt(getAttribute("MaxSwapInterval"));
622 config->minSwapInterval = toInt(getAttribute("MinSwapInterval"));
623 config->nativeRenderable = toBool(getAttribute("NativeRenderable"));
624 config->renderableType = getAttribute("RenderableType");
625 config->sampleBuffers = toInt(getAttribute("SampleBuffers"));
626 config->samples = toInt(getAttribute("Samples"));
627 config->stencilSize = toInt(getAttribute("StencilSize"));
628 config->surfaceTypes = getAttribute("SurfaceTypes");
629 config->transparentType = getAttribute("TransparentType");
630 config->transparentRedValue = toInt(getAttribute("TransparentRedValue"));
631 config->transparentGreenValue = toInt(getAttribute("TransparentGreenValue"));
632 config->transparentBlueValue = toInt(getAttribute("TransparentBlueValue"));
637 case ri::TYPE_SAMPLELIST:
639 ri::SampleList* list = curList->allocItem<ri::SampleList>();
640 list->name = getAttribute("Name");
641 list->description = getAttribute("Description");
646 case ri::TYPE_SAMPLEINFO:
648 if (parentType != ri::TYPE_SAMPLELIST)
649 throw TestResultParseError("<SampleInfo> outside of <SampleList>");
651 ri::SampleList* list = static_cast<ri::SampleList*>(parentItem);
652 ri::SampleInfo* info = &list->sampleInfo;
658 case ri::TYPE_VALUEINFO:
660 if (parentType != ri::TYPE_SAMPLEINFO)
661 throw TestResultParseError("<ValueInfo> outside of <SampleInfo>");
663 ri::SampleInfo* sampleInfo = static_cast<ri::SampleInfo*>(parentItem);
664 ri::ValueInfo* valueInfo = sampleInfo->valueInfos.allocItem<ri::ValueInfo>();
666 valueInfo->name = getAttribute("Name");
667 valueInfo->description = getAttribute("Description");
668 valueInfo->tag = getSampleValueTag(getAttribute("Tag"));
670 if (m_xmlParser.hasAttribute("Unit"))
671 valueInfo->unit = getAttribute("Unit");
677 case ri::TYPE_SAMPLE:
679 if (parentType != ri::TYPE_SAMPLELIST)
680 throw TestResultParseError("<Sample> outside of <SampleList>");
682 ri::SampleList* list = static_cast<ri::SampleList*>(parentItem);
683 ri::Sample* sample = list->samples.allocItem<ri::Sample>();
689 case ri::TYPE_SAMPLEVALUE:
691 if (parentType != ri::TYPE_SAMPLE)
692 throw TestResultParseError("<Value> outside of <Sample>");
694 ri::Sample* sample = static_cast<ri::Sample*>(parentItem);
695 ri::SampleValue* value = sample->values.allocItem<ri::SampleValue>();
702 throw TestResultParseError(string("Unsupported element '") + elemName + ("'"));
708 // Reset base64 decoding offset.
709 m_base64DecodeOffset = 0;
713 void TestResultParser::handleElementEnd (void)
715 const char* elemName = m_xmlParser.getElementName();
717 if (m_state != STATE_IN_TEST_CASE_RESULT)
718 throw TestResultParseError(string("Unexpected </") + elemName + "> outside of <TestCaseResult>");
720 if (deStringEqual(elemName, "TestCaseResult"))
722 // Logs from buggy test cases may contain invalid XML.
723 // DE_ASSERT(getCurrentItem() == DE_NULL);
724 // \todo [2012-11-22 pyry] Log warning.
726 m_state = STATE_TEST_CASE_RESULT_ENDED;
730 ri::Type itemType = getResultItemType(elemName);
731 ri::Item* curItem = getCurrentItem();
733 if (!curItem || itemType != curItem->getType())
734 throw TestResultParseError(string("Unexpected </") + elemName + ">");
736 if (itemType == ri::TYPE_RESULT)
738 ri::Result* result = static_cast<ri::Result*>(curItem);
739 m_result->statusCode = result->statusCode;
740 m_result->statusDetails = result->details;
742 else if (itemType == ri::TYPE_NUMBER)
744 // Parse value for number.
745 ri::Number* number = static_cast<ri::Number*>(curItem);
746 number->value = getNumericValue(m_curNumValue);
747 m_curNumValue.clear();
749 else if (itemType == ri::TYPE_SAMPLEVALUE)
751 ri::SampleValue* value = static_cast<ri::SampleValue*>(curItem);
752 value->value = getNumericValue(m_curNumValue);
753 m_curNumValue.clear();
760 void TestResultParser::handleData (void)
762 ri::Item* curItem = getCurrentItem();
763 ri::Type type = curItem ? curItem->getType() : ri::TYPE_LAST;
767 case ri::TYPE_RESULT:
768 m_xmlParser.appendDataStr(static_cast<ri::Result*>(curItem)->details);
772 m_xmlParser.appendDataStr(static_cast<ri::Text*>(curItem)->text);
775 case ri::TYPE_SHADERSOURCE:
776 m_xmlParser.appendDataStr(static_cast<ri::ShaderSource*>(curItem)->source);
779 case ri::TYPE_INFOLOG:
780 m_xmlParser.appendDataStr(static_cast<ri::InfoLog*>(curItem)->log);
783 case ri::TYPE_KERNELSOURCE:
784 m_xmlParser.appendDataStr(static_cast<ri::KernelSource*>(curItem)->source);
787 case ri::TYPE_NUMBER:
788 case ri::TYPE_SAMPLEVALUE:
789 m_xmlParser.appendDataStr(m_curNumValue);
794 ri::Image* image = static_cast<ri::Image*>(curItem);
797 int numBytesIn = m_xmlParser.getDataSize();
799 for (int inNdx = 0; inNdx < numBytesIn; inNdx++)
801 deUint8 byte = m_xmlParser.getDataByte(inNdx);
802 deUint8 decodedBits = 0;
804 if (de::inRange<deInt8>(byte, 'A', 'Z'))
805 decodedBits = (deUint8)(byte - 'A');
806 else if (de::inRange<deInt8>(byte, 'a', 'z'))
807 decodedBits = (deUint8)(('Z'-'A'+1) + (byte-'a'));
808 else if (de::inRange<deInt8>(byte, '0', '9'))
809 decodedBits = (deUint8)(('Z'-'A'+1) + ('z'-'a'+1) + (byte-'0'));
810 else if (byte == '+')
811 decodedBits = ('Z'-'A'+1) + ('z'-'a'+1) + ('9'-'0'+1);
812 else if (byte == '/')
813 decodedBits = ('Z'-'A'+1) + ('z'-'a'+1) + ('9'-'0'+2);
814 else if (byte == '=')
816 // Padding at end - remove last byte.
817 if (image->data.empty())
818 throw TestResultParseError("Malformed base64 data");
819 image->data.pop_back();
823 continue; // Not an B64 input character.
825 int phase = m_base64DecodeOffset % 4;
828 image->data.resize(image->data.size()+3, 0);
830 if ((int)image->data.size() < (m_base64DecodeOffset>>2)*3 + 3)
831 throw TestResultParseError("Malformed base64 data");
832 deUint8* outPtr = &image->data[(m_base64DecodeOffset>>2)*3];
836 case 0: outPtr[0] |= (deUint8)(decodedBits<<2); break;
837 case 1: outPtr[0] |= (deUint8)(decodedBits>>4); outPtr[1] |= (deUint8)((decodedBits&0xF)<<4); break;
838 case 2: outPtr[1] |= (deUint8)(decodedBits>>2); outPtr[2] |= (deUint8)((decodedBits&0x3)<<6); break;
839 case 3: outPtr[2] |= decodedBits; break;
844 m_base64DecodeOffset += 1;
856 //! Helper for parsing TestCaseResult from TestCaseResultData.
857 void parseTestCaseResultFromData (TestResultParser* parser, TestCaseResult* result, const TestCaseResultData& data)
859 DE_ASSERT(result->resultItems.getNumItems() == 0);
861 // Initialize status codes etc. from data.
862 result->casePath = data.getTestCasePath();
863 result->caseType = TESTCASETYPE_SELF_VALIDATE;
864 result->statusCode = data.getStatusCode();
865 result->statusDetails = data.getStatusDetails();
867 if (data.getDataSize() > 0)
869 parser->init(result);
871 const TestResultParser::ParseResult parseResult = parser->parse(data.getData(), data.getDataSize());
873 if (result->statusCode == TESTSTATUSCODE_LAST)
875 result->statusCode = TESTSTATUSCODE_INTERNAL_ERROR;
877 if (parseResult == TestResultParser::PARSERESULT_ERROR)
878 result->statusDetails = "Test case result parsing failed";
879 else if (parseResult != TestResultParser::PARSERESULT_COMPLETE)
880 result->statusDetails = "Incomplete test case result";
882 result->statusDetails = "Test case result is missing <Result> item";
885 else if (result->statusCode == TESTSTATUSCODE_LAST)
887 result->statusCode = TESTSTATUSCODE_TERMINATED;
888 result->statusDetails = "Empty test case result";
891 if (result->casePath.empty())
892 throw Error("Empty test case path in result");
894 if (result->caseType == TESTCASETYPE_LAST)
895 throw Error("Invalid test case type in result");
897 DE_ASSERT(result->statusCode != TESTSTATUSCODE_LAST);