1 #ifndef _TCUTESTLOG_HPP
2 #define _TCUTESTLOG_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Test Log C++ Wrapper.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "qpTestLog.h"
28 #include "tcuTexture.hpp"
40 class LogShaderProgram;
42 class LogSpirVAssemblySource;
43 class LogKernelSource;
47 template<typename T> class LogNumber;
49 /*--------------------------------------------------------------------*//*!
52 * TestLog provides convinient C++ API for logging. The API has been designed
53 * around stream operators much like STL iostream library. The following
54 * examples demonstrate how to use TestLog.
57 * TestLog& log = m_testCtx.getLog();
59 * // Write message to log.
60 * log << TestLog::Message << "Hello, World!" << TestLog::EndMessage;
62 * log << TestLog::Message << "Diff is " << myNumber << TestLog::EndMessage;
65 * Surface myImage(256, 256);
66 * log << TestLog::Image("TestImage", "My test image", myImage);
68 * // Multiple commands can be combined:
69 * log << TestLog::Section("Details", "Test case details")
70 * << TestLog::Message << "Here be dragons" << TestLog::EndMessage
71 * << TestLog::ImageSet("Result", "Result images")
72 * << TestLog::Image("ImageA", "Image A", imageA)
73 * << TestLog::Image("ImageB", "Image B", imageB)
74 * << TestLog::EndImageSet << TestLog::EndSection;
76 *//*--------------------------------------------------------------------*/
81 static const class BeginMessageToken {} Message;
82 static const class EndMessageToken {} EndMessage;
83 static const class EndImageSetToken {} EndImageSet;
84 static const class EndSectionToken {} EndSection;
85 static const class EndShaderProgramToken {} EndShaderProgram;
86 static const class SampleInfoToken {} SampleInfo;
87 static const class EndSampleInfoToken {} EndSampleInfo;
88 static const class BeginSampleToken {} Sample;
89 static const class EndSampleToken {} EndSample;
90 static const class EndSampleListToken {} EndSampleList;
93 typedef LogImageSet ImageSet;
94 typedef LogImage Image;
95 typedef LogSection Section;
96 typedef LogShaderProgram ShaderProgram;
97 typedef LogShader Shader;
98 typedef LogSpirVAssemblySource SpirVAssemblySource;
99 typedef LogKernelSource KernelSource;
100 typedef LogSampleList SampleList;
101 typedef LogValueInfo ValueInfo;
102 typedef LogNumber<float> Float;
103 typedef LogNumber<deInt64> Integer;
105 explicit TestLog (const char* fileName, deUint32 flags = 0);
108 MessageBuilder operator<< (const BeginMessageToken&);
109 MessageBuilder message (void);
111 TestLog& operator<< (const ImageSet& imageSet);
112 TestLog& operator<< (const Image& image);
113 TestLog& operator<< (const EndImageSetToken&);
115 TestLog& operator<< (const Section& section);
116 TestLog& operator<< (const EndSectionToken&);
118 TestLog& operator<< (const ShaderProgram& shaderProgram);
119 TestLog& operator<< (const EndShaderProgramToken&);
120 TestLog& operator<< (const Shader& shader);
121 TestLog& operator<< (const SpirVAssemblySource& module);
123 TestLog& operator<< (const KernelSource& kernelSrc);
126 TestLog& operator<< (const LogNumber<T>& number);
128 TestLog& operator<< (const SampleList& sampleList);
129 TestLog& operator<< (const SampleInfoToken&);
130 TestLog& operator<< (const ValueInfo& valueInfo);
131 TestLog& operator<< (const EndSampleInfoToken&);
132 SampleBuilder operator<< (const BeginSampleToken&);
133 TestLog& operator<< (const EndSampleListToken&);
136 void writeMessage (const char* message);
138 void startImageSet (const char* name, const char* description);
139 void endImageSet (void);
140 void writeImage (const char* name, const char* description, const ConstPixelBufferAccess& surface, const Vec4& scale, const Vec4& bias, qpImageCompressionMode compressionMode = QP_IMAGE_COMPRESSION_MODE_BEST);
141 void writeImage (const char* name, const char* description, qpImageCompressionMode compressionMode, qpImageFormat format, int width, int height, int stride, const void* data);
143 void startSection (const char* name, const char* description);
144 void endSection (void);
146 void startShaderProgram (bool linkOk, const char* linkInfoLog);
147 void endShaderProgram (void);
148 void writeShader (qpShaderType type, const char* source, bool compileOk, const char* infoLog);
149 void writeSpirVAssemblySource(const char* source);
150 void writeKernelSource (const char* source);
151 void writeCompileInfo (const char* name, const char* description, bool compileOk, const char* infoLog);
153 void writeFloat (const char* name, const char* description, const char* unit, qpKeyValueTag tag, float value);
154 void writeInteger (const char* name, const char* description, const char* unit, qpKeyValueTag tag, deInt64 value);
156 void startEglConfigSet (const char* name, const char* description);
157 void writeEglConfig (const qpEglConfigInfo* config);
158 void endEglConfigSet (void);
160 void startCase (const char* testCasePath, qpTestCaseType testCaseType);
161 void endCase (qpTestResult result, const char* description);
162 void terminateCase (qpTestResult result);
164 void startSampleList (const std::string& name, const std::string& description);
165 void startSampleInfo (void);
166 void writeValueInfo (const std::string& name, const std::string& description, const std::string& unit, qpSampleValueTag tag);
167 void endSampleInfo (void);
168 void startSample (void);
169 void writeSampleValue (double value);
170 void writeSampleValue (deInt64 value);
171 void endSample (void);
172 void endSampleList (void);
175 TestLog (const TestLog& other); // Not allowed!
176 TestLog& operator= (const TestLog& other); // Not allowed!
184 explicit MessageBuilder (TestLog* log) : m_log(log) {}
185 ~MessageBuilder (void) {}
187 std::string toString (void) const { return m_str.str(); }
189 TestLog& operator<< (const TestLog::EndMessageToken&);
191 template <typename T>
192 MessageBuilder& operator<< (const T& value);
194 MessageBuilder (const MessageBuilder& other);
195 MessageBuilder& operator= (const MessageBuilder& other);
199 std::ostringstream m_str;
205 SampleBuilder (TestLog* log) : m_log(log) {}
207 SampleBuilder& operator<< (int v) { m_values.push_back(Value((deInt64)v)); return *this; }
208 SampleBuilder& operator<< (deInt64 v) { m_values.push_back(Value(v)); return *this; }
209 SampleBuilder& operator<< (float v) { m_values.push_back(Value((double)v)); return *this; }
210 SampleBuilder& operator<< (double v) { m_values.push_back(Value(v)); return *this; }
212 TestLog& operator<< (const TestLog::EndSampleToken&);
217 enum Type { TYPE_INT64 = 0, TYPE_FLOAT64, TYPE_LAST };
226 Value (void) : type(TYPE_LAST) { value.int64 = 0; }
227 Value (double v) : type(TYPE_FLOAT64) { value.float64 = v; }
228 Value (deInt64 v) : type(TYPE_INT64) { value.int64 = v; }
232 std::vector<Value> m_values;
238 LogImageSet (const std::string& name, const std::string& description)
240 , m_description (description)
244 void write (TestLog& log) const;
248 std::string m_description;
251 // \note Doesn't take copy of surface contents
255 LogImage (const std::string& name, const std::string& description, const Surface& surface, qpImageCompressionMode compression = QP_IMAGE_COMPRESSION_MODE_BEST);
257 LogImage (const std::string& name, const std::string& description, const ConstPixelBufferAccess& access, qpImageCompressionMode compression = QP_IMAGE_COMPRESSION_MODE_BEST);
259 LogImage (const std::string& name, const std::string& description, const ConstPixelBufferAccess& access, const Vec4& scale, const Vec4& bias, qpImageCompressionMode compression = QP_IMAGE_COMPRESSION_MODE_BEST);
261 void write (TestLog& log) const;
265 std::string m_description;
266 ConstPixelBufferAccess m_access;
269 qpImageCompressionMode m_compression;
275 LogSection (const std::string& name, const std::string& description)
277 , m_description (description)
281 void write (TestLog& log) const;
285 std::string m_description;
288 class LogShaderProgram
291 LogShaderProgram (bool linkOk, const std::string& linkInfoLog)
293 , m_linkInfoLog (linkInfoLog)
297 void write (TestLog& log) const;
301 std::string m_linkInfoLog;
307 LogShader (qpShaderType type, const std::string& source, bool compileOk, const std::string& infoLog)
310 , m_compileOk (compileOk)
311 , m_infoLog (infoLog)
315 void write (TestLog& log) const;
319 std::string m_source;
321 std::string m_infoLog;
324 class LogSpirVAssemblySource
327 LogSpirVAssemblySource (const std::string& source)
332 void write (TestLog& log) const;
335 std::string m_source;
338 class LogKernelSource
341 explicit LogKernelSource (const std::string& source)
346 void write (TestLog& log) const;
349 std::string m_source;
355 LogSampleList (const std::string& name, const std::string& description)
357 , m_description (description)
361 void write (TestLog& log) const;
365 std::string m_description;
371 LogValueInfo (const std::string& name, const std::string& description, const std::string& unit, qpSampleValueTag tag)
373 , m_description (description)
379 void write (TestLog& log) const;
383 std::string m_description;
385 qpSampleValueTag m_tag;
392 LogNumber (const std::string& name, const std::string& desc, const std::string& unit, qpKeyValueTag tag, T value)
401 void write (TestLog& log) const;
411 // Section helper that closes section when leaving scope.
412 class ScopedLogSection
415 ScopedLogSection (TestLog& log, const std::string& name, const std::string& description)
418 m_log << TestLog::Section(name, description);
421 ~ScopedLogSection (void)
423 m_log << TestLog::EndSection;
430 // TestLog stream operators.
432 inline TestLog& TestLog::operator<< (const ImageSet& imageSet) { imageSet.write(*this); return *this; }
433 inline TestLog& TestLog::operator<< (const Image& image) { image.write(*this); return *this; }
434 inline TestLog& TestLog::operator<< (const EndImageSetToken&) { endImageSet(); return *this; }
435 inline TestLog& TestLog::operator<< (const Section& section) { section.write(*this); return *this; }
436 inline TestLog& TestLog::operator<< (const EndSectionToken&) { endSection(); return *this; }
437 inline TestLog& TestLog::operator<< (const ShaderProgram& shaderProg) { shaderProg.write(*this); return *this; }
438 inline TestLog& TestLog::operator<< (const EndShaderProgramToken&) { endShaderProgram(); return *this; }
439 inline TestLog& TestLog::operator<< (const Shader& shader) { shader.write(*this); return *this; }
440 inline TestLog& TestLog::operator<< (const SpirVAssemblySource& module) { module.write(*this); return *this; }
441 inline TestLog& TestLog::operator<< (const KernelSource& kernelSrc) { kernelSrc.write(*this); return *this; }
442 inline TestLog& TestLog::operator<< (const SampleList& sampleList) { sampleList.write(*this); return *this; }
443 inline TestLog& TestLog::operator<< (const SampleInfoToken&) { startSampleInfo(); return *this; }
444 inline TestLog& TestLog::operator<< (const ValueInfo& valueInfo) { valueInfo.write(*this); return *this; }
445 inline TestLog& TestLog::operator<< (const EndSampleInfoToken&) { endSampleInfo(); return *this; }
446 inline TestLog& TestLog::operator<< (const EndSampleListToken&) { endSampleList(); return *this; }
449 inline TestLog& TestLog::operator<< (const LogNumber<T>& number)
455 inline TestLog& operator<< (TestLog& log, const std::exception& e)
457 // \todo [2012-10-18 pyry] Print type info?
458 return log << TestLog::Message << e.what() << TestLog::EndMessage;
461 // Utility class inline implementations.
463 template <typename T>
464 inline MessageBuilder& MessageBuilder::operator<< (const T& value)
466 // Overload stream operator to implement custom format
471 inline MessageBuilder TestLog::operator<< (const BeginMessageToken&)
473 return MessageBuilder(this);
476 inline MessageBuilder TestLog::message (void)
478 return MessageBuilder(this);
481 inline SampleBuilder TestLog::operator<< (const BeginSampleToken&)
483 return SampleBuilder(this);
486 inline void LogImageSet::write (TestLog& log) const
488 log.startImageSet(m_name.c_str(), m_description.c_str());
491 inline void LogSection::write (TestLog& log) const
493 log.startSection(m_name.c_str(), m_description.c_str());
496 inline void LogShaderProgram::write (TestLog& log) const
498 log.startShaderProgram(m_linkOk, m_linkInfoLog.c_str());
501 inline void LogShader::write (TestLog& log) const
503 log.writeShader(m_type, m_source.c_str(), m_compileOk, m_infoLog.c_str());
506 inline void LogSpirVAssemblySource::write (TestLog& log) const
508 log.writeSpirVAssemblySource(m_source.c_str());
511 inline void LogKernelSource::write (TestLog& log) const
513 log.writeKernelSource(m_source.c_str());
516 inline void LogSampleList::write (TestLog& log) const
518 log.startSampleList(m_name, m_description);
521 inline void LogValueInfo::write (TestLog& log) const
523 log.writeValueInfo(m_name, m_description, m_unit, m_tag);
527 inline void LogNumber<float>::write (TestLog& log) const
529 log.writeFloat(m_name.c_str(), m_desc.c_str(), m_unit.c_str(), m_tag, m_value);
533 inline void LogNumber<deInt64>::write (TestLog& log) const
535 log.writeInteger(m_name.c_str(), m_desc.c_str(), m_unit.c_str(), m_tag, m_value);
540 #endif // _TCUTESTLOG_HPP