1 /*-------------------------------------------------------------------------
2 * drawElements TestLog Library
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 logging
22 *//*--------------------------------------------------------------------*/
23
24 #include "qpTestLog.h"
25 #include "qpXmlWriter.h"
26 #include "qpInfo.h"
27 #include "qpDebugOut.h"
28
29 #include "deMemory.h"
30 #include "deInt32.h"
31 #include "deString.h"
32
33 #include "deMutex.h"
34
35 #if defined(QP_SUPPORT_PNG)
36 # include <png.h>
37 #endif
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <stdarg.h>
42
43 #if (DE_OS == DE_OS_WIN32)
44 # include <windows.h>
45 # include <io.h>
46 #endif
47
48 #if defined(DE_DEBUG)
49
50 /* Utils for verifying container (Section, ImageSet, EglConfigSet) usage in debug builds. */
51
52 typedef enum ContainerType_e
53 {
54 CONTAINERTYPE_SECTION = 0,
55 CONTAINERTYPE_IMAGESET,
56 CONTAINERTYPE_EGLCONFIGSET,
57 CONTAINERTYPE_SHADERPROGRAM,
58 CONTAINERTYPE_SAMPLELIST,
59 CONTAINERTYPE_SAMPLEINFO,
60 CONTAINERTYPE_SAMPLE,
61
62 CONTAINERTYPE_LAST
63 } ContainerType;
64
childContainersOk(ContainerType type)65 DE_INLINE deBool childContainersOk (ContainerType type)
66 {
67 return type == CONTAINERTYPE_SECTION || type == CONTAINERTYPE_SAMPLELIST;
68 }
69
70 enum
71 {
72 MAX_CONTAINER_STACK_DEPTH = 32
73 };
74
75 typedef struct ContainerStack_s
76 {
77 int numElements;
78 ContainerType elements[MAX_CONTAINER_STACK_DEPTH];
79 } ContainerStack;
80
ContainerStack_reset(ContainerStack * stack)81 DE_INLINE void ContainerStack_reset (ContainerStack* stack)
82 {
83 deMemset(stack, 0, sizeof(ContainerStack));
84 }
85
ContainerStack_isEmpty(const ContainerStack * stack)86 DE_INLINE deBool ContainerStack_isEmpty (const ContainerStack* stack)
87 {
88 return stack->numElements == 0;
89 }
90
ContainerStack_push(ContainerStack * stack,ContainerType type)91 DE_INLINE deBool ContainerStack_push (ContainerStack* stack, ContainerType type)
92 {
93 if (stack->numElements == MAX_CONTAINER_STACK_DEPTH)
94 return DE_FALSE;
95
96 if (stack->numElements > 0 && !childContainersOk(stack->elements[stack->numElements-1]))
97 return DE_FALSE;
98
99 stack->elements[stack->numElements] = type;
100 stack->numElements += 1;
101
102 return DE_TRUE;
103 }
104
ContainerStack_pop(ContainerStack * stack)105 DE_INLINE ContainerType ContainerStack_pop (ContainerStack* stack)
106 {
107 DE_ASSERT(stack->numElements > 0);
108 stack->numElements -= 1;
109 return stack->elements[stack->numElements];
110 }
111
ContainerStack_getTop(const ContainerStack * stack)112 DE_INLINE ContainerType ContainerStack_getTop (const ContainerStack* stack)
113 {
114 if (stack->numElements > 0)
115 return stack->elements[stack->numElements-1];
116 else
117 return CONTAINERTYPE_LAST;
118 }
119
120 #endif
121
122 /* qpTestLog instance */
123 struct qpTestLog_s
124 {
125 deUint32 flags; /*!< Logging flags. */
126
127 deMutex lock; /*!< Lock for mutable state below. */
128
129 /* State protected by lock. */
130 FILE* outputFile;
131 qpXmlWriter* writer;
132 deBool isSessionOpen;
133 deBool isCaseOpen;
134
135 #if defined(DE_DEBUG)
136 ContainerStack containerStack; /*!< For container usage verification. */
137 #endif
138 };
139
140 /* Maps integer to string. */
141 typedef struct qpKeyStringMap_s
142 {
143 int key;
144 char* string;
145 } qpKeyStringMap;
146
147 static const char* LOG_FORMAT_VERSION = "0.3.4";
148
149 /* Mapping enum to above strings... */
150 static const qpKeyStringMap s_qpTestTypeMap[] =
151 {
152 { QP_TEST_CASE_TYPE_SELF_VALIDATE, "SelfValidate" },
153 { QP_TEST_CASE_TYPE_PERFORMANCE, "Performance" },
154 { QP_TEST_CASE_TYPE_CAPABILITY, "Capability" },
155 { QP_TEST_CASE_TYPE_ACCURACY, "Accuracy" },
156
157 { QP_TEST_CASE_TYPE_LAST, DE_NULL }
158 };
159
160 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qpTestTypeMap) == QP_TEST_CASE_TYPE_LAST + 1);
161
162 static const qpKeyStringMap s_qpTestResultMap[] =
163 {
164 { QP_TEST_RESULT_PASS, "Pass" },
165 { QP_TEST_RESULT_FAIL, "Fail" },
166 { QP_TEST_RESULT_QUALITY_WARNING, "QualityWarning" },
167 { QP_TEST_RESULT_COMPATIBILITY_WARNING, "CompatibilityWarning" },
168 { QP_TEST_RESULT_PENDING, "Pending" }, /* should not be needed here */
169 { QP_TEST_RESULT_NOT_SUPPORTED, "NotSupported" },
170 { QP_TEST_RESULT_RESOURCE_ERROR, "ResourceError" },
171 { QP_TEST_RESULT_INTERNAL_ERROR, "InternalError" },
172 { QP_TEST_RESULT_CRASH, "Crash" },
173 { QP_TEST_RESULT_TIMEOUT, "Timeout" },
174
175 /* Add new values here if needed, remember to update qpTestResult enumeration. */
176
177 { QP_TEST_RESULT_LAST, DE_NULL }
178 };
179
180 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qpTestResultMap) == QP_TEST_RESULT_LAST + 1);
181
182 /* Key tag to string mapping. */
183
184 static const qpKeyStringMap s_qpTagMap[] =
185 {
186 { QP_KEY_TAG_NONE, DE_NULL },
187 { QP_KEY_TAG_PERFORMANCE, "Performance" },
188 { QP_KEY_TAG_QUALITY, "Quality" },
189 { QP_KEY_TAG_PRECISION, "Precision" },
190 { QP_KEY_TAG_TIME, "Time" },
191
192 { QP_KEY_TAG_LAST, DE_NULL }
193 };
194
195 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qpTagMap) == QP_KEY_TAG_LAST + 1);
196
197 /* Sample value tag to string mapping. */
198
199 static const qpKeyStringMap s_qpSampleValueTagMap[] =
200 {
201 { QP_SAMPLE_VALUE_TAG_PREDICTOR, "Predictor" },
202 { QP_SAMPLE_VALUE_TAG_RESPONSE, "Response" },
203
204 { QP_SAMPLE_VALUE_TAG_LAST, DE_NULL }
205 };
206
207 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qpSampleValueTagMap) == QP_SAMPLE_VALUE_TAG_LAST + 1);
208
209 /* Image compression mode to string mapping. */
210
211 static const qpKeyStringMap s_qpImageCompressionModeMap[] =
212 {
213 { QP_IMAGE_COMPRESSION_MODE_NONE, "None" },
214 { QP_IMAGE_COMPRESSION_MODE_PNG, "PNG" },
215
216 { QP_IMAGE_COMPRESSION_MODE_BEST, DE_NULL }, /* not allowed to be written! */
217
218 { QP_IMAGE_COMPRESSION_MODE_LAST, DE_NULL }
219 };
220
221 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qpImageCompressionModeMap) == QP_IMAGE_COMPRESSION_MODE_LAST + 1);
222
223 /* Image format to string mapping. */
224
225 static const qpKeyStringMap s_qpImageFormatMap[] =
226 {
227 { QP_IMAGE_FORMAT_RGB888, "RGB888" },
228 { QP_IMAGE_FORMAT_RGBA8888, "RGBA8888" },
229
230 { QP_IMAGE_FORMAT_LAST, DE_NULL }
231 };
232
233 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qpImageFormatMap) == QP_IMAGE_FORMAT_LAST + 1);
234
235 /* Shader type to string mapping. */
236
237 static const qpKeyStringMap s_qpShaderTypeMap[] =
238 {
239 { QP_SHADER_TYPE_VERTEX, "VertexShader" },
240 { QP_SHADER_TYPE_FRAGMENT, "FragmentShader" },
241 { QP_SHADER_TYPE_GEOMETRY, "GeometryShader" },
242 { QP_SHADER_TYPE_TESS_CONTROL, "TessControlShader" },
243 { QP_SHADER_TYPE_TESS_EVALUATION, "TessEvaluationShader" },
244 { QP_SHADER_TYPE_COMPUTE, "ComputeShader" },
245
246 { QP_SHADER_TYPE_LAST, DE_NULL }
247 };
248
249 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qpShaderTypeMap) == QP_SHADER_TYPE_LAST + 1);
250
qpTestLog_flushFile(qpTestLog * log)251 static void qpTestLog_flushFile (qpTestLog* log)
252 {
253 DE_ASSERT(log && log->outputFile);
254 fflush(log->outputFile);
255 #if (DE_OS == DE_OS_WIN32) && (DE_COMPILER == DE_COMPILER_MSC)
256 /* \todo [petri] Is this really necessary? */
257 FlushFileBuffers((HANDLE)_get_osfhandle(_fileno(log->outputFile)));
258 #endif
259 }
260
261 #define QP_LOOKUP_STRING(KEYMAP, KEY) qpLookupString(KEYMAP, DE_LENGTH_OF_ARRAY(KEYMAP), (int)(KEY))
262
qpLookupString(const qpKeyStringMap * keyMap,int keyMapSize,int key)263 static const char* qpLookupString (const qpKeyStringMap* keyMap, int keyMapSize, int key)
264 {
265 DE_ASSERT(keyMap);
266 DE_ASSERT(deInBounds32(key, 0, keyMapSize));
267 DE_ASSERT(keyMap[key].key == key);
268 DE_UNREF(keyMapSize); /* for asserting only */
269 return keyMap[key].string;
270 }
271
int32ToString(int val,char buf[32])272 DE_INLINE void int32ToString (int val, char buf[32])
273 {
274 deSprintf(&buf[0], 32, "%d", val);
275 }
276
int64ToString(deInt64 val,char buf[32])277 DE_INLINE void int64ToString (deInt64 val, char buf[32])
278 {
279 deSprintf(&buf[0], 32, "%lld", (long long int)val);
280 }
281
floatToString(float value,char * buf,size_t bufSize)282 DE_INLINE void floatToString (float value, char* buf, size_t bufSize)
283 {
284 deSprintf(buf, bufSize, "%f", value);
285 }
286
doubleToString(double value,char * buf,size_t bufSize)287 DE_INLINE void doubleToString (double value, char* buf, size_t bufSize)
288 {
289 deSprintf(buf, bufSize, "%f", value);
290 }
291
beginSession(qpTestLog * log)292 static deBool beginSession (qpTestLog* log)
293 {
294 DE_ASSERT(log && !log->isSessionOpen);
295
296 /* Write session info. */
297 fprintf(log->outputFile, "#sessionInfo releaseName %s\n", qpGetReleaseName());
298 fprintf(log->outputFile, "#sessionInfo releaseId 0x%08x\n", qpGetReleaseId());
299 fprintf(log->outputFile, "#sessionInfo targetName \"%s\"\n", qpGetTargetName());
300
301 /* Write out #beginSession. */
302 fprintf(log->outputFile, "#beginSession\n");
303 qpTestLog_flushFile(log);
304
305 log->isSessionOpen = DE_TRUE;
306
307 return DE_TRUE;
308 }
309
endSession(qpTestLog * log)310 static deBool endSession (qpTestLog* log)
311 {
312 DE_ASSERT(log && log->isSessionOpen);
313
314 /* Make sure xml is flushed. */
315 qpXmlWriter_flush(log->writer);
316
317 /* Write out #endSession. */
318 fprintf(log->outputFile, "\n#endSession\n");
319 qpTestLog_flushFile(log);
320
321 log->isSessionOpen = DE_FALSE;
322
323 return DE_TRUE;
324 }
325
326 /*--------------------------------------------------------------------*//*!
327 * \brief Create a file based logger instance
328 * \param fileName Name of the file where to put logs
329 * \return qpTestLog instance, or DE_NULL if cannot create file
330 *//*--------------------------------------------------------------------*/
qpTestLog_createFileLog(const char * fileName,deUint32 flags)331 qpTestLog* qpTestLog_createFileLog (const char* fileName, deUint32 flags)
332 {
333 qpTestLog* log = (qpTestLog*)deCalloc(sizeof(qpTestLog));
334 if (!log)
335 return DE_NULL;
336
337 DE_ASSERT(fileName && fileName[0]); /* must have filename. */
338
339 #if defined(DE_DEBUG)
340 ContainerStack_reset(&log->containerStack);
341 #endif
342
343 qpPrintf("Writing test log into %s\n", fileName);
344
345 /* Create output file. */
346 log->outputFile = fopen(fileName, "wb");
347 if (!log->outputFile)
348 {
349 qpPrintf("ERROR: Unable to open test log output file '%s'.\n", fileName);
350 qpTestLog_destroy(log);
351 return DE_NULL;
352 }
353
354 log->flags = flags;
355 log->writer = qpXmlWriter_createFileWriter(log->outputFile, 0, !(flags & QP_TEST_LOG_NO_FLUSH));
356 log->lock = deMutex_create(DE_NULL);
357 log->isSessionOpen = DE_FALSE;
358 log->isCaseOpen = DE_FALSE;
359
360 if (!log->writer)
361 {
362 qpPrintf("ERROR: Unable to create output XML writer to file '%s'.\n", fileName);
363 qpTestLog_destroy(log);
364 return DE_NULL;
365 }
366
367 if (!log->lock)
368 {
369 qpPrintf("ERROR: Unable to create mutex.\n");
370 qpTestLog_destroy(log);
371 return DE_NULL;
372 }
373
374 beginSession(log);
375
376 return log;
377 }
378
379 /*--------------------------------------------------------------------*//*!
380 * \brief Destroy a logger instance
381 * \param a qpTestLog instance
382 *//*--------------------------------------------------------------------*/
qpTestLog_destroy(qpTestLog * log)383 void qpTestLog_destroy (qpTestLog* log)
384 {
385 DE_ASSERT(log);
386
387 if (log->isSessionOpen)
388 endSession(log);
389
390 if (log->writer)
391 qpXmlWriter_destroy(log->writer);
392
393 if (log->outputFile)
394 fclose(log->outputFile);
395
396 if (log->lock)
397 deMutex_destroy(log->lock);
398
399 deFree(log);
400 }
401
402 /*--------------------------------------------------------------------*//*!
403 * \brief Log start of test case
404 * \param log qpTestLog instance
405 * \param testCasePath Full test case path (as seen in Candy).
406 * \param testCaseType Test case type
407 * \return true if ok, false otherwise
408 *//*--------------------------------------------------------------------*/
qpTestLog_startCase(qpTestLog * log,const char * testCasePath,qpTestCaseType testCaseType)409 deBool qpTestLog_startCase (qpTestLog* log, const char* testCasePath, qpTestCaseType testCaseType)
410 {
411 const char* typeStr = QP_LOOKUP_STRING(s_qpTestTypeMap, testCaseType);
412 int numResultAttribs = 0;
413 qpXmlAttribute resultAttribs[8];
414
415 DE_ASSERT(log && testCasePath && (testCasePath[0] != 0));
416 deMutex_lock(log->lock);
417
418 DE_ASSERT(!log->isCaseOpen);
419 DE_ASSERT(ContainerStack_isEmpty(&log->containerStack));
420
421 /* Flush XML and write out #beginTestCaseResult. */
422 qpXmlWriter_flush(log->writer);
423 fprintf(log->outputFile, "\n#beginTestCaseResult %s\n", testCasePath);
424 if (!(log->flags & QP_TEST_LOG_NO_FLUSH))
425 qpTestLog_flushFile(log);
426
427 log->isCaseOpen = DE_TRUE;
428
429 /* Fill in attributes. */
430 resultAttribs[numResultAttribs++] = qpSetStringAttrib("Version", LOG_FORMAT_VERSION);
431 resultAttribs[numResultAttribs++] = qpSetStringAttrib("CasePath", testCasePath);
432 resultAttribs[numResultAttribs++] = qpSetStringAttrib("CaseType", typeStr);
433
434 if (!qpXmlWriter_startDocument(log->writer) ||
435 !qpXmlWriter_startElement(log->writer, "TestCaseResult", numResultAttribs, resultAttribs))
436 {
437 qpPrintf("qpTestLog_startCase(): Writing XML failed\n");
438 deMutex_unlock(log->lock);
439 return DE_FALSE;
440 }
441
442 deMutex_unlock(log->lock);
443 return DE_TRUE;
444 }
445
446 /*--------------------------------------------------------------------*//*!
447 * \brief Log end of test case
448 * \param log qpTestLog instance
449 * \param result Test result
450 * \param description Description of a problem in case of error
451 * \return true if ok, false otherwise
452 *//*--------------------------------------------------------------------*/
qpTestLog_endCase(qpTestLog * log,qpTestResult result,const char * resultDetails)453 deBool qpTestLog_endCase (qpTestLog* log, qpTestResult result, const char* resultDetails)
454 {
455 const char* statusStr = QP_LOOKUP_STRING(s_qpTestResultMap, result);
456 qpXmlAttribute statusAttrib = qpSetStringAttrib("StatusCode", statusStr);
457
458 deMutex_lock(log->lock);
459
460 DE_ASSERT(log->isCaseOpen);
461 DE_ASSERT(ContainerStack_isEmpty(&log->containerStack));
462
463 /* <Result StatusCode="Pass">Result details</Result>
464 * </TestCaseResult>
465 */
466 if (!qpXmlWriter_startElement(log->writer, "Result", 1, &statusAttrib) ||
467 (resultDetails && !qpXmlWriter_writeString(log->writer, resultDetails)) ||
468 !qpXmlWriter_endElement(log->writer, "Result") ||
469 !qpXmlWriter_endElement(log->writer, "TestCaseResult") ||
470 !qpXmlWriter_endDocument(log->writer)) /* Close any XML elements still open */
471 {
472 qpPrintf("qpTestLog_endCase(): Writing XML failed\n");
473 deMutex_unlock(log->lock);
474 return DE_FALSE;
475 }
476
477 /* Flush XML and write #endTestCaseResult. */
478 qpXmlWriter_flush(log->writer);
479 fprintf(log->outputFile, "\n#endTestCaseResult\n");
480 if (!(log->flags & QP_TEST_LOG_NO_FLUSH))
481 qpTestLog_flushFile(log);
482
483 log->isCaseOpen = DE_FALSE;
484
485 deMutex_unlock(log->lock);
486 return DE_TRUE;
487 }
488
489 /*--------------------------------------------------------------------*//*!
490 * \brief Abrupt termination of logging.
491 * \param log qpTestLog instance
492 * \param result Result code, only Crash and Timeout are allowed.
493 * \return true if ok, false otherwise
494 *//*--------------------------------------------------------------------*/
qpTestLog_terminateCase(qpTestLog * log,qpTestResult result)495 deBool qpTestLog_terminateCase (qpTestLog* log, qpTestResult result)
496 {
497 const char* resultStr = QP_LOOKUP_STRING(s_qpTestResultMap, result);
498
499 DE_ASSERT(log);
500 DE_ASSERT(result == QP_TEST_RESULT_CRASH || result == QP_TEST_RESULT_TIMEOUT);
501
502 deMutex_lock(log->lock);
503
504 if (!log->isCaseOpen)
505 {
506 deMutex_unlock(log->lock);
507 return DE_FALSE; /* Soft error. This is called from error handler. */
508 }
509
510 /* Flush XML and write #terminateTestCaseResult. */
511 qpXmlWriter_flush(log->writer);
512 fprintf(log->outputFile, "\n#terminateTestCaseResult %s\n", resultStr);
513 qpTestLog_flushFile(log);
514
515 log->isCaseOpen = DE_FALSE;
516
517 #if defined(DE_DEBUG)
518 ContainerStack_reset(&log->containerStack);
519 #endif
520
521 deMutex_unlock(log->lock);
522 return DE_TRUE;
523 }
524
qpTestLog_writeKeyValuePair(qpTestLog * log,const char * elementName,const char * name,const char * description,const char * unit,qpKeyValueTag tag,const char * text)525 static deBool qpTestLog_writeKeyValuePair (qpTestLog* log, const char* elementName, const char* name, const char* description, const char* unit, qpKeyValueTag tag, const char* text)
526 {
527 const char* tagString = QP_LOOKUP_STRING(s_qpTagMap, tag);
528 qpXmlAttribute attribs[8];
529 int numAttribs = 0;
530
531 DE_ASSERT(log && elementName && text);
532 deMutex_lock(log->lock);
533
534 /* Fill in attributes. */
535 if (name) attribs[numAttribs++] = qpSetStringAttrib("Name", name);
536 if (description) attribs[numAttribs++] = qpSetStringAttrib("Description", description);
537 if (tagString) attribs[numAttribs++] = qpSetStringAttrib("Tag", tagString);
538 if (unit) attribs[numAttribs++] = qpSetStringAttrib("Unit", unit);
539
540 if (!qpXmlWriter_startElement(log->writer, elementName, numAttribs, attribs) ||
541 !qpXmlWriter_writeString(log->writer, text) ||
542 !qpXmlWriter_endElement(log->writer, elementName))
543 {
544 qpPrintf("qpTestLog_writeKeyValuePair(): Writing XML failed\n");
545 deMutex_unlock(log->lock);
546 return DE_FALSE;
547 }
548
549 deMutex_unlock(log->lock);
550 return DE_TRUE;
551 }
552
553 /*--------------------------------------------------------------------*//*!
554 * \brief Write key-value-pair into log
555 * \param log qpTestLog instance
556 * \param name Unique identifier for entry
557 * \param description Human readable description
558 * \param tag Optional tag
559 * \param value Value of the key-value-pair
560 * \return true if ok, false otherwise
561 *//*--------------------------------------------------------------------*/
qpTestLog_writeText(qpTestLog * log,const char * name,const char * description,qpKeyValueTag tag,const char * text)562 deBool qpTestLog_writeText (qpTestLog* log, const char* name, const char* description, qpKeyValueTag tag, const char* text)
563 {
564 /* <Text Name="name" Description="description" Tag="tag">text</Text> */
565 return qpTestLog_writeKeyValuePair(log, "Text", name, description, DE_NULL, tag, text);
566 }
567
568 /*--------------------------------------------------------------------*//*!
569 * \brief Write key-value-pair into log
570 * \param log qpTestLog instance
571 * \param name Unique identifier for entry
572 * \param description Human readable description
573 * \param tag Optional tag
574 * \param value Value of the key-value-pair
575 * \return true if ok, false otherwise
576 *//*--------------------------------------------------------------------*/
qpTestLog_writeInteger(qpTestLog * log,const char * name,const char * description,const char * unit,qpKeyValueTag tag,deInt64 value)577 deBool qpTestLog_writeInteger (qpTestLog* log, const char* name, const char* description, const char* unit, qpKeyValueTag tag, deInt64 value)
578 {
579 char tmpString[64];
580 int64ToString(value, tmpString);
581
582 /* <Number Name="name" Description="description" Tag="Performance">15</Number> */
583 return qpTestLog_writeKeyValuePair(log, "Number", name, description, unit, tag, tmpString);
584 }
585
586 /*--------------------------------------------------------------------*//*!
587 * \brief Write key-value-pair into log
588 * \param log qpTestLog instance
589 * \param name Unique identifier for entry
590 * \param description Human readable description
591 * \param tag Optional tag
592 * \param value Value of the key-value-pair
593 * \return true if ok, false otherwise
594 *//*--------------------------------------------------------------------*/
qpTestLog_writeFloat(qpTestLog * log,const char * name,const char * description,const char * unit,qpKeyValueTag tag,float value)595 deBool qpTestLog_writeFloat (qpTestLog* log, const char* name, const char* description, const char* unit, qpKeyValueTag tag, float value)
596 {
597 char tmpString[64];
598 floatToString(value, tmpString, sizeof(tmpString));
599
600 /* <Number Name="name" Description="description" Tag="Performance">15</Number> */
601 return qpTestLog_writeKeyValuePair(log, "Number", name, description, unit, tag, tmpString);
602 }
603
604 typedef struct Buffer_s
605 {
606 size_t capacity;
607 size_t size;
608 deUint8* data;
609 } Buffer;
610
Buffer_init(Buffer * buffer)611 void Buffer_init (Buffer* buffer)
612 {
613 buffer->capacity = 0;
614 buffer->size = 0;
615 buffer->data = DE_NULL;
616 }
617
Buffer_deinit(Buffer * buffer)618 void Buffer_deinit (Buffer* buffer)
619 {
620 deFree(buffer->data);
621 Buffer_init(buffer);
622 }
623
Buffer_resize(Buffer * buffer,size_t newSize)624 deBool Buffer_resize (Buffer* buffer, size_t newSize)
625 {
626 /* Grow buffer if necessary. */
627 if (newSize > buffer->capacity)
628 {
629 size_t newCapacity = (size_t)deAlign32(deMax32(2*(int)buffer->capacity, (int)newSize), 512);
630 deUint8* newData = (deUint8*)deMalloc(newCapacity);
631 if (!newData)
632 return DE_FALSE;
633
634 memcpy(newData, buffer->data, buffer->size);
635 deFree(buffer->data);
636 buffer->data = newData;
637 buffer->capacity = newCapacity;
638 }
639
640 buffer->size = newSize;
641 return DE_TRUE;
642 }
643
Buffer_append(Buffer * buffer,const deUint8 * data,size_t numBytes)644 deBool Buffer_append (Buffer* buffer, const deUint8* data, size_t numBytes)
645 {
646 size_t offset = buffer->size;
647
648 if (!Buffer_resize(buffer, buffer->size + numBytes))
649 return DE_FALSE;
650
651 /* Append bytes. */
652 memcpy(&buffer->data[offset], data, numBytes);
653 return DE_TRUE;
654 }
655
656 #if defined(QP_SUPPORT_PNG)
pngWriteData(png_structp png,png_bytep dataPtr,png_size_t numBytes)657 void pngWriteData (png_structp png, png_bytep dataPtr, png_size_t numBytes)
658 {
659 Buffer* buffer = (Buffer*)png_get_io_ptr(png);
660 if (!Buffer_append(buffer, (const deUint8*)dataPtr, numBytes))
661 png_error(png, "unable to resize PNG write buffer!");
662 }
663
pngFlushData(png_structp png)664 void pngFlushData (png_structp png)
665 {
666 DE_UNREF(png);
667 /* nada */
668 }
669
writeCompressedPNG(png_structp png,png_infop info,png_byte ** rowPointers,int width,int height,int colorFormat)670 static deBool writeCompressedPNG (png_structp png, png_infop info, png_byte** rowPointers, int width, int height, int colorFormat)
671 {
672 if (setjmp(png_jmpbuf(png)) == 0)
673 {
674 /* Write data. */
675 png_set_IHDR(png, info, (png_uint_32)width, (png_uint_32)height,
676 8,
677 colorFormat,
678 PNG_INTERLACE_NONE,
679 PNG_COMPRESSION_TYPE_BASE,
680 PNG_FILTER_TYPE_BASE);
681 png_write_info(png, info);
682 png_write_image(png, rowPointers);
683 png_write_end(png, NULL);
684
685 return DE_TRUE;
686 }
687 else
688 return DE_FALSE;
689 }
690
compressImagePNG(Buffer * buffer,qpImageFormat imageFormat,int width,int height,int rowStride,const void * data)691 static deBool compressImagePNG (Buffer* buffer, qpImageFormat imageFormat, int width, int height, int rowStride, const void* data)
692 {
693 deBool compressOk = DE_FALSE;
694 png_structp png = DE_NULL;
695 png_infop info = DE_NULL;
696 png_byte** rowPointers = DE_NULL;
697 deBool hasAlpha = imageFormat == QP_IMAGE_FORMAT_RGBA8888;
698 int ndx;
699
700 /* Handle format. */
701 DE_ASSERT(imageFormat == QP_IMAGE_FORMAT_RGB888 || imageFormat == QP_IMAGE_FORMAT_RGBA8888);
702
703 /* Allocate & set row pointers. */
704 rowPointers = (png_byte**)deMalloc((size_t)height * sizeof(png_byte*));
705 if (!rowPointers)
706 return DE_FALSE;
707
708 for (ndx = 0; ndx < height; ndx++)
709 rowPointers[ndx] = (png_byte*)((const deUint8*)data + ndx*rowStride);
710
711 /* Initialize PNG compressor. */
712 png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
713 info = png ? png_create_info_struct(png) : DE_NULL;
714 if (png && info)
715 {
716 /* Set our own write function. */
717 png_set_write_fn(png, buffer, pngWriteData, pngFlushData);
718
719 compressOk = writeCompressedPNG(png, info, rowPointers, width, height,
720 hasAlpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB);
721 }
722
723 /* Cleanup & return. */
724 if (png && info)
725 {
726 png_destroy_info_struct(png, &info);
727 png_destroy_write_struct(&png, DE_NULL);
728 }
729 else if (png)
730 png_destroy_write_struct(&png, &info);
731
732 deFree(rowPointers);
733 return compressOk;
734 }
735 #endif /* QP_SUPPORT_PNG */
736
737 /*--------------------------------------------------------------------*//*!
738 * \brief Start image set
739 * \param log qpTestLog instance
740 * \param name Unique identifier for the set
741 * \param description Human readable description
742 * \return true if ok, false otherwise
743 *//*--------------------------------------------------------------------*/
qpTestLog_startImageSet(qpTestLog * log,const char * name,const char * description)744 deBool qpTestLog_startImageSet (qpTestLog* log, const char* name, const char* description)
745 {
746 qpXmlAttribute attribs[4];
747 int numAttribs = 0;
748
749 DE_ASSERT(log && name);
750 deMutex_lock(log->lock);
751
752 attribs[numAttribs++] = qpSetStringAttrib("Name", name);
753 if (description)
754 attribs[numAttribs++] = qpSetStringAttrib("Description", description);
755
756 /* <ImageSet Name="<name>"> */
757 if (!qpXmlWriter_startElement(log->writer, "ImageSet", numAttribs, attribs))
758 {
759 qpPrintf("qpTestLog_startImageSet(): Writing XML failed\n");
760 deMutex_unlock(log->lock);
761 return DE_FALSE;
762 }
763
764 DE_ASSERT(ContainerStack_push(&log->containerStack, CONTAINERTYPE_IMAGESET));
765
766 deMutex_unlock(log->lock);
767 return DE_TRUE;
768 }
769
770 /*--------------------------------------------------------------------*//*!
771 * \brief End image set
772 * \param log qpTestLog instance
773 * \return true if ok, false otherwise
774 *//*--------------------------------------------------------------------*/
qpTestLog_endImageSet(qpTestLog * log)775 deBool qpTestLog_endImageSet (qpTestLog* log)
776 {
777 DE_ASSERT(log);
778 deMutex_lock(log->lock);
779
780 /* <ImageSet Name="<name>"> */
781 if (!qpXmlWriter_endElement(log->writer, "ImageSet"))
782 {
783 qpPrintf("qpTestLog_endImageSet(): Writing XML failed\n");
784 deMutex_unlock(log->lock);
785 return DE_FALSE;
786 }
787
788 DE_ASSERT(ContainerStack_pop(&log->containerStack) == CONTAINERTYPE_IMAGESET);
789
790 deMutex_unlock(log->lock);
791 return DE_TRUE;
792 }
793
794 /*--------------------------------------------------------------------*//*!
795 * \brief Write base64 encoded raw image data into log
796 * \param log qpTestLog instance
797 * \param name Unique name (matching names can be compared across BatchResults).
798 * \param description Textual description (shown in Candy).
799 * \param compressionMode Compression mode
800 * \param imageFormat Color format
801 * \param width Width in pixels
802 * \param height Height in pixels
803 * \param stride Data stride (offset between rows)
804 * \param data Pointer to pixel data
805 * \return 0 if OK, otherwise <0
806 *//*--------------------------------------------------------------------*/
qpTestLog_writeImage(qpTestLog * log,const char * name,const char * description,qpImageCompressionMode compressionMode,qpImageFormat imageFormat,int width,int height,int stride,const void * data)807 deBool qpTestLog_writeImage (
808 qpTestLog* log,
809 const char* name,
810 const char* description,
811 qpImageCompressionMode compressionMode,
812 qpImageFormat imageFormat,
813 int width,
814 int height,
815 int stride,
816 const void* data)
817 {
818 char widthStr[32];
819 char heightStr[32];
820 qpXmlAttribute attribs[8];
821 int numAttribs = 0;
822 Buffer compressedBuffer;
823 const void* writeDataPtr = DE_NULL;
824 size_t writeDataBytes = ~(size_t)0;
825
826 DE_ASSERT(log && name);
827 DE_ASSERT(deInRange32(width, 1, 16384));
828 DE_ASSERT(deInRange32(height, 1, 16384));
829 DE_ASSERT(data);
830
831 if (log->flags & QP_TEST_LOG_EXCLUDE_IMAGES)
832 return DE_TRUE; /* Image not logged. */
833
834 Buffer_init(&compressedBuffer);
835
836 /* BEST compression mode defaults to PNG. */
837 if (compressionMode == QP_IMAGE_COMPRESSION_MODE_BEST)
838 {
839 #if defined(QP_SUPPORT_PNG)
840 compressionMode = QP_IMAGE_COMPRESSION_MODE_PNG;
841 #else
842 compressionMode = QP_IMAGE_COMPRESSION_MODE_NONE;
843 #endif
844 }
845
846 #if defined(QP_SUPPORT_PNG)
847 /* Try storing with PNG compression. */
848 if (compressionMode == QP_IMAGE_COMPRESSION_MODE_PNG)
849 {
850 deBool compressOk = compressImagePNG(&compressedBuffer, imageFormat, width, height, stride, data);
851 if (compressOk)
852 {
853 writeDataPtr = compressedBuffer.data;
854 writeDataBytes = compressedBuffer.size;
855 }
856 else
857 {
858 /* Fall-back to default compression. */
859 qpPrintf("WARNING: PNG compression failed -- storing image uncompressed.\n");
860 compressionMode = QP_IMAGE_COMPRESSION_MODE_NONE;
861 }
862 }
863 #endif
864
865 /* Handle image compression. */
866 switch (compressionMode)
867 {
868 case QP_IMAGE_COMPRESSION_MODE_NONE:
869 {
870 int pixelSize = imageFormat == QP_IMAGE_FORMAT_RGB888 ? 3 : 4;
871 int packedStride = pixelSize*width;
872
873 if (packedStride == stride)
874 writeDataPtr = data;
875 else
876 {
877 /* Need to re-pack pixels. */
878 if (Buffer_resize(&compressedBuffer, (size_t)(packedStride*height)))
879 {
880 int row;
881 for (row = 0; row < height; row++)
882 memcpy(&compressedBuffer.data[packedStride*row], &((const deUint8*)data)[row*stride], (size_t)(pixelSize*width));
883 }
884 else
885 {
886 qpPrintf("ERROR: Failed to pack pixels for writing.\n");
887 Buffer_deinit(&compressedBuffer);
888 return DE_FALSE;
889 }
890 }
891
892 writeDataBytes = (size_t)(packedStride*height);
893 break;
894 }
895
896 #if defined(QP_SUPPORT_PNG)
897 case QP_IMAGE_COMPRESSION_MODE_PNG:
898 DE_ASSERT(writeDataPtr); /* Already handled. */
899 break;
900 #endif
901
902 default:
903 qpPrintf("qpTestLog_writeImage(): Unknown compression mode: %s\n", QP_LOOKUP_STRING(s_qpImageCompressionModeMap, compressionMode));
904 Buffer_deinit(&compressedBuffer);
905 return DE_FALSE;
906 }
907
908 /* Fill in attributes. */
909 int32ToString(width, widthStr);
910 int32ToString(height, heightStr);
911 attribs[numAttribs++] = qpSetStringAttrib("Name", name);
912 attribs[numAttribs++] = qpSetStringAttrib("Width", widthStr);
913 attribs[numAttribs++] = qpSetStringAttrib("Height", heightStr);
914 attribs[numAttribs++] = qpSetStringAttrib("Format", QP_LOOKUP_STRING(s_qpImageFormatMap, imageFormat));
915 attribs[numAttribs++] = qpSetStringAttrib("CompressionMode", QP_LOOKUP_STRING(s_qpImageCompressionModeMap, compressionMode));
916 if (description) attribs[numAttribs++] = qpSetStringAttrib("Description", description);
917
918 /* \note Log lock is acquired after compression! */
919 deMutex_lock(log->lock);
920
921 /* <Image ID="result" Name="Foobar" Width="640" Height="480" Format="RGB888" CompressionMode="None">base64 data</Image> */
922 if (!qpXmlWriter_startElement(log->writer, "Image", numAttribs, attribs) ||
923 !qpXmlWriter_writeBase64(log->writer, (const deUint8*)writeDataPtr, writeDataBytes) ||
924 !qpXmlWriter_endElement(log->writer, "Image"))
925 {
926 qpPrintf("qpTestLog_writeImage(): Writing XML failed\n");
927 deMutex_unlock(log->lock);
928 Buffer_deinit(&compressedBuffer);
929 return DE_FALSE;
930 }
931
932 deMutex_unlock(log->lock);
933
934 /* Free compressed data if allocated. */
935 Buffer_deinit(&compressedBuffer);
936
937 return DE_TRUE;
938 }
939
940 /*--------------------------------------------------------------------*//*!
941 * \brief Write a OpenGL ES shader program into the log.
942 * \param linkOk Shader program link result, false on failure
943 * \param linkInfoLog Implementation provided linkage log
944 *//*--------------------------------------------------------------------*/
qpTestLog_startShaderProgram(qpTestLog * log,deBool linkOk,const char * linkInfoLog)945 deBool qpTestLog_startShaderProgram (qpTestLog* log, deBool linkOk, const char* linkInfoLog)
946 {
947 qpXmlAttribute programAttribs[4];
948 int numProgramAttribs = 0;
949
950 DE_ASSERT(log);
951 deMutex_lock(log->lock);
952
953 programAttribs[numProgramAttribs++] = qpSetStringAttrib("LinkStatus", linkOk ? "OK" : "Fail");
954
955 if (!qpXmlWriter_startElement(log->writer, "ShaderProgram", numProgramAttribs, programAttribs) ||
956 !qpXmlWriter_writeStringElement(log->writer, "InfoLog", linkInfoLog))
957 {
958 qpPrintf("qpTestLog_startShaderProgram(): Writing XML failed\n");
959 deMutex_unlock(log->lock);
960 return DE_FALSE;
961 }
962
963 DE_ASSERT(ContainerStack_push(&log->containerStack, CONTAINERTYPE_SHADERPROGRAM));
964
965 deMutex_unlock(log->lock);
966 return DE_TRUE;
967 }
968
969 /*--------------------------------------------------------------------*//*!
970 * \brief End shader program
971 * \param log qpTestLog instance
972 * \return true if ok, false otherwise
973 *//*--------------------------------------------------------------------*/
qpTestLog_endShaderProgram(qpTestLog * log)974 deBool qpTestLog_endShaderProgram (qpTestLog* log)
975 {
976 DE_ASSERT(log);
977 deMutex_lock(log->lock);
978
979 /* </ShaderProgram> */
980 if (!qpXmlWriter_endElement(log->writer, "ShaderProgram"))
981 {
982 qpPrintf("qpTestLog_endShaderProgram(): Writing XML failed\n");
983 deMutex_unlock(log->lock);
984 return DE_FALSE;
985 }
986
987 DE_ASSERT(ContainerStack_pop(&log->containerStack) == CONTAINERTYPE_SHADERPROGRAM);
988
989 deMutex_unlock(log->lock);
990 return DE_TRUE;
991 }
992
993 /*--------------------------------------------------------------------*//*!
994 * \brief Write a OpenGL ES shader into the log.
995 * \param type Shader type
996 * \param source Shader source
997 * \param compileOk Shader compilation result, false on failure
998 * \param infoLog Implementation provided shader compilation log
999 *//*--------------------------------------------------------------------*/
qpTestLog_writeShader(qpTestLog * log,qpShaderType type,const char * source,deBool compileOk,const char * infoLog)1000 deBool qpTestLog_writeShader (qpTestLog* log, qpShaderType type, const char* source, deBool compileOk, const char* infoLog)
1001 {
1002 const char* tagName = QP_LOOKUP_STRING(s_qpShaderTypeMap, type);
1003 const char* sourceStr = ((log->flags & QP_TEST_LOG_EXCLUDE_SHADER_SOURCES) == 0 || !compileOk) ? source : "";
1004 int numShaderAttribs = 0;
1005 qpXmlAttribute shaderAttribs[4];
1006
1007 deMutex_lock(log->lock);
1008
1009 DE_ASSERT(source);
1010 DE_ASSERT(ContainerStack_getTop(&log->containerStack) == CONTAINERTYPE_SHADERPROGRAM);
1011
1012 shaderAttribs[numShaderAttribs++] = qpSetStringAttrib("CompileStatus", compileOk ? "OK" : "Fail");
1013
1014 if (!qpXmlWriter_startElement(log->writer, tagName, numShaderAttribs, shaderAttribs) ||
1015 !qpXmlWriter_writeStringElement(log->writer, "ShaderSource", sourceStr) ||
1016 !qpXmlWriter_writeStringElement(log->writer, "InfoLog", infoLog) ||
1017 !qpXmlWriter_endElement(log->writer, tagName))
1018 {
1019 qpPrintf("qpTestLog_writeShader(): Writing XML failed\n");
1020 deMutex_unlock(log->lock);
1021 return DE_FALSE;
1022 }
1023
1024 deMutex_unlock(log->lock);
1025 return DE_TRUE;
1026 }
1027
1028 /*--------------------------------------------------------------------*//*!
1029 * \brief Start writing a set of EGL configurations into the log.
1030 *//*--------------------------------------------------------------------*/
qpTestLog_startEglConfigSet(qpTestLog * log,const char * name,const char * description)1031 deBool qpTestLog_startEglConfigSet (qpTestLog* log, const char* name, const char* description)
1032 {
1033 qpXmlAttribute attribs[4];
1034 int numAttribs = 0;
1035
1036 DE_ASSERT(log && name);
1037 deMutex_lock(log->lock);
1038
1039 attribs[numAttribs++] = qpSetStringAttrib("Name", name);
1040 if (description)
1041 attribs[numAttribs++] = qpSetStringAttrib("Description", description);
1042
1043 /* <EglConfigSet Name="<name>"> */
1044 if (!qpXmlWriter_startElement(log->writer, "EglConfigSet", numAttribs, attribs))
1045 {
1046 qpPrintf("qpTestLog_startEglImageSet(): Writing XML failed\n");
1047 deMutex_unlock(log->lock);
1048 return DE_FALSE;
1049 }
1050
1051 DE_ASSERT(ContainerStack_push(&log->containerStack, CONTAINERTYPE_EGLCONFIGSET));
1052
1053 deMutex_unlock(log->lock);
1054 return DE_TRUE;
1055 }
1056
1057 /*--------------------------------------------------------------------*//*!
1058 * \brief End an EGL config set
1059 *//*--------------------------------------------------------------------*/
qpTestLog_endEglConfigSet(qpTestLog * log)1060 deBool qpTestLog_endEglConfigSet (qpTestLog* log)
1061 {
1062 DE_ASSERT(log);
1063 deMutex_lock(log->lock);
1064
1065 /* <EglConfigSet Name="<name>"> */
1066 if (!qpXmlWriter_endElement(log->writer, "EglConfigSet"))
1067 {
1068 qpPrintf("qpTestLog_endEglImageSet(): Writing XML failed\n");
1069 deMutex_unlock(log->lock);
1070 return DE_FALSE;
1071 }
1072
1073 DE_ASSERT(ContainerStack_pop(&log->containerStack) == CONTAINERTYPE_EGLCONFIGSET);
1074
1075 deMutex_unlock(log->lock);
1076 return DE_TRUE;
1077 }
1078
1079 /*--------------------------------------------------------------------*//*!
1080 * \brief Write an EGL config inside an EGL config set
1081 * \see qpElgConfigInfo for details
1082 *//*--------------------------------------------------------------------*/
qpTestLog_writeEglConfig(qpTestLog * log,const qpEglConfigInfo * config)1083 deBool qpTestLog_writeEglConfig (qpTestLog* log, const qpEglConfigInfo* config)
1084 {
1085 qpXmlAttribute attribs[64];
1086 int numAttribs = 0;
1087
1088 DE_ASSERT(log && config);
1089 deMutex_lock(log->lock);
1090
1091 attribs[numAttribs++] = qpSetIntAttrib ("BufferSize", config->bufferSize);
1092 attribs[numAttribs++] = qpSetIntAttrib ("RedSize", config->redSize);
1093 attribs[numAttribs++] = qpSetIntAttrib ("GreenSize", config->greenSize);
1094 attribs[numAttribs++] = qpSetIntAttrib ("BlueSize", config->blueSize);
1095 attribs[numAttribs++] = qpSetIntAttrib ("LuminanceSize", config->luminanceSize);
1096 attribs[numAttribs++] = qpSetIntAttrib ("AlphaSize", config->alphaSize);
1097 attribs[numAttribs++] = qpSetIntAttrib ("AlphaMaskSize", config->alphaMaskSize);
1098 attribs[numAttribs++] = qpSetBoolAttrib ("BindToTextureRGB", config->bindToTextureRGB);
1099 attribs[numAttribs++] = qpSetBoolAttrib ("BindToTextureRGBA", config->bindToTextureRGBA);
1100 attribs[numAttribs++] = qpSetStringAttrib ("ColorBufferType", config->colorBufferType);
1101 attribs[numAttribs++] = qpSetStringAttrib ("ConfigCaveat", config->configCaveat);
1102 attribs[numAttribs++] = qpSetIntAttrib ("ConfigID", config->configID);
1103 attribs[numAttribs++] = qpSetStringAttrib ("Conformant", config->conformant);
1104 attribs[numAttribs++] = qpSetIntAttrib ("DepthSize", config->depthSize);
1105 attribs[numAttribs++] = qpSetIntAttrib ("Level", config->level);
1106 attribs[numAttribs++] = qpSetIntAttrib ("MaxPBufferWidth", config->maxPBufferWidth);
1107 attribs[numAttribs++] = qpSetIntAttrib ("MaxPBufferHeight", config->maxPBufferHeight);
1108 attribs[numAttribs++] = qpSetIntAttrib ("MaxPBufferPixels", config->maxPBufferPixels);
1109 attribs[numAttribs++] = qpSetIntAttrib ("MaxSwapInterval", config->maxSwapInterval);
1110 attribs[numAttribs++] = qpSetIntAttrib ("MinSwapInterval", config->minSwapInterval);
1111 attribs[numAttribs++] = qpSetBoolAttrib ("NativeRenderable", config->nativeRenderable);
1112 attribs[numAttribs++] = qpSetStringAttrib ("RenderableType", config->renderableType);
1113 attribs[numAttribs++] = qpSetIntAttrib ("SampleBuffers", config->sampleBuffers);
1114 attribs[numAttribs++] = qpSetIntAttrib ("Samples", config->samples);
1115 attribs[numAttribs++] = qpSetIntAttrib ("StencilSize", config->stencilSize);
1116 attribs[numAttribs++] = qpSetStringAttrib ("SurfaceTypes", config->surfaceTypes);
1117 attribs[numAttribs++] = qpSetStringAttrib ("TransparentType", config->transparentType);
1118 attribs[numAttribs++] = qpSetIntAttrib ("TransparentRedValue", config->transparentRedValue);
1119 attribs[numAttribs++] = qpSetIntAttrib ("TransparentGreenValue", config->transparentGreenValue);
1120 attribs[numAttribs++] = qpSetIntAttrib ("TransparentBlueValue", config->transparentBlueValue);
1121 DE_ASSERT(numAttribs <= DE_LENGTH_OF_ARRAY(attribs));
1122
1123 if (!qpXmlWriter_startElement(log->writer, "EglConfig", numAttribs, attribs) ||
1124 !qpXmlWriter_endElement(log->writer, "EglConfig"))
1125 {
1126 qpPrintf("qpTestLog_writeEglConfig(): Writing XML failed\n");
1127 deMutex_unlock(log->lock);
1128 return DE_FALSE;
1129 }
1130
1131 deMutex_unlock(log->lock);
1132 return DE_TRUE;
1133 }
1134
1135 /*--------------------------------------------------------------------*//*!
1136 * \brief Start section in log.
1137 * \param log qpTestLog instance
1138 * \param name Section name
1139 * \param description Human readable description
1140 * \return true if ok, false otherwise
1141 *//*--------------------------------------------------------------------*/
qpTestLog_startSection(qpTestLog * log,const char * name,const char * description)1142 deBool qpTestLog_startSection (qpTestLog* log, const char* name, const char* description)
1143 {
1144 qpXmlAttribute attribs[2];
1145 int numAttribs = 0;
1146
1147 DE_ASSERT(log && name);
1148 deMutex_lock(log->lock);
1149
1150 attribs[numAttribs++] = qpSetStringAttrib("Name", name);
1151 if (description)
1152 attribs[numAttribs++] = qpSetStringAttrib("Description", description);
1153
1154 /* <Section Name="<name>" Description="<description>"> */
1155 if (!qpXmlWriter_startElement(log->writer, "Section", numAttribs, attribs))
1156 {
1157 qpPrintf("qpTestLog_startSection(): Writing XML failed\n");
1158 deMutex_unlock(log->lock);
1159 return DE_FALSE;
1160 }
1161
1162 DE_ASSERT(ContainerStack_push(&log->containerStack, CONTAINERTYPE_SECTION));
1163
1164 deMutex_unlock(log->lock);
1165 return DE_TRUE;
1166 }
1167
1168 /*--------------------------------------------------------------------*//*!
1169 * \brief End section in log.
1170 * \param log qpTestLog instance
1171 * \return true if ok, false otherwise
1172 *//*--------------------------------------------------------------------*/
qpTestLog_endSection(qpTestLog * log)1173 deBool qpTestLog_endSection (qpTestLog* log)
1174 {
1175 DE_ASSERT(log);
1176 deMutex_lock(log->lock);
1177
1178 /* </Section> */
1179 if (!qpXmlWriter_endElement(log->writer, "Section"))
1180 {
1181 qpPrintf("qpTestLog_endSection(): Writing XML failed\n");
1182 deMutex_unlock(log->lock);
1183 return DE_FALSE;
1184 }
1185
1186 DE_ASSERT(ContainerStack_pop(&log->containerStack) == CONTAINERTYPE_SECTION);
1187
1188 deMutex_unlock(log->lock);
1189 return DE_TRUE;
1190 }
1191
1192 /*--------------------------------------------------------------------*//*!
1193 * \brief Write OpenCL compute kernel source into the log.
1194 *//*--------------------------------------------------------------------*/
qpTestLog_writeKernelSource(qpTestLog * log,const char * source)1195 deBool qpTestLog_writeKernelSource (qpTestLog* log, const char* source)
1196 {
1197 const char* sourceStr = (log->flags & QP_TEST_LOG_EXCLUDE_SHADER_SOURCES) != 0 ? "" : source;
1198
1199 DE_ASSERT(log);
1200 deMutex_lock(log->lock);
1201
1202 if (!qpXmlWriter_writeStringElement(log->writer, "KernelSource", sourceStr))
1203 {
1204 qpPrintf("qpTestLog_writeKernelSource(): Writing XML failed\n");
1205 deMutex_unlock(log->lock);
1206 return DE_FALSE;
1207 }
1208
1209 deMutex_unlock(log->lock);
1210 return DE_TRUE;
1211 }
1212
1213 /*--------------------------------------------------------------------*//*!
1214 * \brief Write a SPIR-V module assembly source into the log.
1215 *//*--------------------------------------------------------------------*/
qpTestLog_writeSpirVAssemblySource(qpTestLog * log,const char * source)1216 deBool qpTestLog_writeSpirVAssemblySource (qpTestLog* log, const char* source)
1217 {
1218 const char* const sourceStr = (log->flags & QP_TEST_LOG_EXCLUDE_SHADER_SOURCES) != 0 ? "" : source;
1219
1220 deMutex_lock(log->lock);
1221
1222 DE_ASSERT(ContainerStack_getTop(&log->containerStack) == CONTAINERTYPE_SHADERPROGRAM);
1223
1224 if (!qpXmlWriter_writeStringElement(log->writer, "SpirVAssemblySource", sourceStr))
1225 {
1226 qpPrintf("qpTestLog_writeSpirVAssemblySource(): Writing XML failed\n");
1227 deMutex_unlock(log->lock);
1228 return DE_FALSE;
1229 }
1230
1231 deMutex_unlock(log->lock);
1232 return DE_TRUE;
1233 }
1234
1235 /*--------------------------------------------------------------------*//*!
1236 * \brief Write OpenCL kernel compilation results into the log
1237 *//*--------------------------------------------------------------------*/
qpTestLog_writeCompileInfo(qpTestLog * log,const char * name,const char * description,deBool compileOk,const char * infoLog)1238 deBool qpTestLog_writeCompileInfo (qpTestLog* log, const char* name, const char* description, deBool compileOk, const char* infoLog)
1239 {
1240 int numAttribs = 0;
1241 qpXmlAttribute attribs[3];
1242
1243 DE_ASSERT(log && name && description && infoLog);
1244 deMutex_lock(log->lock);
1245
1246 attribs[numAttribs++] = qpSetStringAttrib("Name", name);
1247 attribs[numAttribs++] = qpSetStringAttrib("Description", description);
1248 attribs[numAttribs++] = qpSetStringAttrib("CompileStatus", compileOk ? "OK" : "Fail");
1249
1250 if (!qpXmlWriter_startElement(log->writer, "CompileInfo", numAttribs, attribs) ||
1251 !qpXmlWriter_writeStringElement(log->writer, "InfoLog", infoLog) ||
1252 !qpXmlWriter_endElement(log->writer, "CompileInfo"))
1253 {
1254 qpPrintf("qpTestLog_writeCompileInfo(): Writing XML failed\n");
1255 deMutex_unlock(log->lock);
1256 return DE_FALSE;
1257 }
1258
1259 deMutex_unlock(log->lock);
1260 return DE_TRUE;
1261 }
1262
qpTestLog_startSampleList(qpTestLog * log,const char * name,const char * description)1263 deBool qpTestLog_startSampleList (qpTestLog* log, const char* name, const char* description)
1264 {
1265 int numAttribs = 0;
1266 qpXmlAttribute attribs[2];
1267
1268 DE_ASSERT(log && name && description);
1269 deMutex_lock(log->lock);
1270
1271 attribs[numAttribs++] = qpSetStringAttrib("Name", name);
1272 attribs[numAttribs++] = qpSetStringAttrib("Description", description);
1273
1274 if (!qpXmlWriter_startElement(log->writer, "SampleList", numAttribs, attribs))
1275 {
1276 qpPrintf("qpTestLog_startSampleList(): Writing XML failed\n");
1277 deMutex_unlock(log->lock);
1278 return DE_FALSE;
1279 }
1280
1281 DE_ASSERT(ContainerStack_push(&log->containerStack, CONTAINERTYPE_SAMPLELIST));
1282
1283 deMutex_unlock(log->lock);
1284 return DE_TRUE;
1285 }
1286
qpTestLog_startSampleInfo(qpTestLog * log)1287 deBool qpTestLog_startSampleInfo (qpTestLog* log)
1288 {
1289 DE_ASSERT(log);
1290 deMutex_lock(log->lock);
1291
1292 if (!qpXmlWriter_startElement(log->writer, "SampleInfo", 0, DE_NULL))
1293 {
1294 qpPrintf("qpTestLog_startSampleInfo(): Writing XML failed\n");
1295 deMutex_unlock(log->lock);
1296 return DE_FALSE;
1297 }
1298
1299 DE_ASSERT(ContainerStack_push(&log->containerStack, CONTAINERTYPE_SAMPLEINFO));
1300
1301 deMutex_unlock(log->lock);
1302 return DE_TRUE;
1303 }
1304
qpTestLog_writeValueInfo(qpTestLog * log,const char * name,const char * description,const char * unit,qpSampleValueTag tag)1305 deBool qpTestLog_writeValueInfo (qpTestLog* log, const char* name, const char* description, const char* unit, qpSampleValueTag tag)
1306 {
1307 const char* tagName = QP_LOOKUP_STRING(s_qpSampleValueTagMap, tag);
1308 int numAttribs = 0;
1309 qpXmlAttribute attribs[4];
1310
1311 DE_ASSERT(log && name && description && tagName);
1312 deMutex_lock(log->lock);
1313
1314 DE_ASSERT(ContainerStack_getTop(&log->containerStack) == CONTAINERTYPE_SAMPLEINFO);
1315
1316 attribs[numAttribs++] = qpSetStringAttrib("Name", name);
1317 attribs[numAttribs++] = qpSetStringAttrib("Description", description);
1318 attribs[numAttribs++] = qpSetStringAttrib("Tag", tagName);
1319
1320 if (unit)
1321 attribs[numAttribs++] = qpSetStringAttrib("Unit", unit);
1322
1323 if (!qpXmlWriter_startElement(log->writer, "ValueInfo", numAttribs, attribs) ||
1324 !qpXmlWriter_endElement(log->writer, "ValueInfo"))
1325 {
1326 qpPrintf("qpTestLog_writeValueInfo(): Writing XML failed\n");
1327 deMutex_unlock(log->lock);
1328 return DE_FALSE;
1329 }
1330
1331 deMutex_unlock(log->lock);
1332 return DE_TRUE;
1333 }
1334
qpTestLog_endSampleInfo(qpTestLog * log)1335 deBool qpTestLog_endSampleInfo (qpTestLog* log)
1336 {
1337 DE_ASSERT(log);
1338 deMutex_lock(log->lock);
1339
1340 if (!qpXmlWriter_endElement(log->writer, "SampleInfo"))
1341 {
1342 qpPrintf("qpTestLog_endSampleInfo(): Writing XML failed\n");
1343 deMutex_unlock(log->lock);
1344 return DE_FALSE;
1345 }
1346
1347 DE_ASSERT(ContainerStack_pop(&log->containerStack) == CONTAINERTYPE_SAMPLEINFO);
1348
1349 deMutex_unlock(log->lock);
1350 return DE_TRUE;
1351 }
1352
qpTestLog_startSample(qpTestLog * log)1353 deBool qpTestLog_startSample (qpTestLog* log)
1354 {
1355 DE_ASSERT(log);
1356 deMutex_lock(log->lock);
1357
1358 DE_ASSERT(ContainerStack_getTop(&log->containerStack) == CONTAINERTYPE_SAMPLELIST);
1359
1360 if (!qpXmlWriter_startElement(log->writer, "Sample", 0, DE_NULL))
1361 {
1362 qpPrintf("qpTestLog_startSample(): Writing XML failed\n");
1363 deMutex_unlock(log->lock);
1364 return DE_FALSE;
1365 }
1366
1367 DE_ASSERT(ContainerStack_push(&log->containerStack, CONTAINERTYPE_SAMPLE));
1368
1369 deMutex_unlock(log->lock);
1370 return DE_TRUE;
1371 }
1372
qpTestLog_writeValueFloat(qpTestLog * log,double value)1373 deBool qpTestLog_writeValueFloat (qpTestLog* log, double value)
1374 {
1375 char tmpString[512];
1376 doubleToString(value, tmpString, (int)sizeof(tmpString));
1377
1378 deMutex_lock(log->lock);
1379
1380 DE_ASSERT(ContainerStack_getTop(&log->containerStack) == CONTAINERTYPE_SAMPLE);
1381
1382 if (!qpXmlWriter_writeStringElement(log->writer, "Value", &tmpString[0]))
1383 {
1384 qpPrintf("qpTestLog_writeSampleValue(): Writing XML failed\n");
1385 deMutex_unlock(log->lock);
1386 return DE_FALSE;
1387 }
1388
1389 deMutex_unlock(log->lock);
1390 return DE_TRUE;
1391 }
1392
qpTestLog_writeValueInteger(qpTestLog * log,deInt64 value)1393 deBool qpTestLog_writeValueInteger (qpTestLog* log, deInt64 value)
1394 {
1395 char tmpString[64];
1396 int64ToString(value, tmpString);
1397
1398 deMutex_lock(log->lock);
1399
1400 DE_ASSERT(ContainerStack_getTop(&log->containerStack) == CONTAINERTYPE_SAMPLE);
1401
1402 if (!qpXmlWriter_writeStringElement(log->writer, "Value", &tmpString[0]))
1403 {
1404 qpPrintf("qpTestLog_writeSampleValue(): Writing XML failed\n");
1405 deMutex_unlock(log->lock);
1406 return DE_FALSE;
1407 }
1408
1409 deMutex_unlock(log->lock);
1410 return DE_TRUE;
1411 }
1412
qpTestLog_endSample(qpTestLog * log)1413 deBool qpTestLog_endSample (qpTestLog* log)
1414 {
1415 DE_ASSERT(log);
1416 deMutex_lock(log->lock);
1417
1418 if (!qpXmlWriter_endElement(log->writer, "Sample"))
1419 {
1420 qpPrintf("qpTestLog_endSample(): Writing XML failed\n");
1421 deMutex_unlock(log->lock);
1422 return DE_FALSE;
1423 }
1424
1425 DE_ASSERT(ContainerStack_pop(&log->containerStack) == CONTAINERTYPE_SAMPLE);
1426
1427 deMutex_unlock(log->lock);
1428 return DE_TRUE;
1429 }
1430
qpTestLog_endSampleList(qpTestLog * log)1431 deBool qpTestLog_endSampleList (qpTestLog* log)
1432 {
1433 DE_ASSERT(log);
1434 deMutex_lock(log->lock);
1435
1436 if (!qpXmlWriter_endElement(log->writer, "SampleList"))
1437 {
1438 qpPrintf("qpTestLog_endSampleList(): Writing XML failed\n");
1439 deMutex_unlock(log->lock);
1440 return DE_FALSE;
1441 }
1442
1443 DE_ASSERT(ContainerStack_pop(&log->containerStack) == CONTAINERTYPE_SAMPLELIST);
1444
1445 deMutex_unlock(log->lock);
1446 return DE_TRUE;
1447 }
1448
qpTestLog_getLogFlags(const qpTestLog * log)1449 deUint32 qpTestLog_getLogFlags (const qpTestLog* log)
1450 {
1451 DE_ASSERT(log);
1452 return log->flags;
1453 }
1454
qpGetTestResultName(qpTestResult result)1455 const char* qpGetTestResultName (qpTestResult result)
1456 {
1457 return QP_LOOKUP_STRING(s_qpTestResultMap, result);
1458 }
1459