Commits

Jason McKesson committed 3b79211

Report now has a good Lua printer.

  • Participants
  • Parent commits 3eec91d

Comments (0)

Files changed (3)

File tests/manual/main.cpp

 			}
 		}
 
-		std::cout << report;
+//		std::cout << report;
+		report.WriteToLua(std::cout, "Manual Test Suite", "This is a manual suite for testing stuff.",
+			"GL Version", "GL Vendor", "GL Renderer");
 	}
 	catch(...)
 	{

File tests/util/report.cpp

 #include <boost/array.hpp>
 #include <boost/foreach.hpp>
 #include <boost/range/irange.hpp>
+#include <boost/range/iterator_range.hpp>
 #include <boost/range/adaptors.hpp>
 
 #include "report.h"
 
 	typedef boost::variant<boost::blank, double> Datum;
 
+	namespace
+	{
+		static const char *g_datumNames[] = {"cpu_time", "gpu_time", "gpu_latency"};
+
+		BOOST_STATIC_ASSERT(sizeof(g_datumNames) / sizeof(g_datumNames[0]) == NUM_TOTAL_DATUM);
+	}
+
 	struct DatumHasValue : public boost::static_visitor<bool>
 	{
 		bool operator()(const boost::blank &) const {return false;}
 				{
 					if(boost::apply_visitor(DatumHasValue(), initial.data[datumId]))
 					{
-						static const char *datumNames[] = {"cpu_time", "gpu_time", "gpu_latency"};
-
-						BOOST_STATIC_ASSERT(sizeof(datumNames) / sizeof(datumNames[0]) == NUM_TOTAL_DATUM);
-
-						stream << "\t\tTiming: " << datumNames[datumId] << "\n";
+						stream << "\t\tTiming: " << g_datumNames[datumId] << "\n";
 
 						BOOST_FOREACH(int execution, boost::irange(0, m_pData->numExecutions))
 						{
 		return stream;
 	}
 
+	namespace
+	{
+		size_t CalcNumEqualsToEscape( const char * val )
+		{
+			size_t lenVal = strlen(val);
+
+			size_t maxConsecutive = 0;
+			size_t currConsecutive = 0;
+			BOOST_FOREACH(size_t loop, boost::irange(size_t(0), lenVal))
+			{
+				if(val[loop] == '=')
+				{
+					++currConsecutive;
+					if(maxConsecutive < currConsecutive)
+						maxConsecutive = currConsecutive;
+				}
+				else
+				{
+					currConsecutive = 0;
+				}
+			}
+
+			//The number needed to escape is one greater than the maximum number of
+			//consecutive '=' signs.
+			return maxConsecutive + 1; 
+		}
+
+		std::ostream &OutputRawStringLua(std::ostream &stream, const char *val)
+		{
+			size_t numEquals = CalcNumEqualsToEscape(val);
+
+			stream << "[" << std::string(numEquals, '=') << "[";
+			stream << val;
+			stream << "]" << std::string(numEquals, '=') << "]";
+
+			return stream;
+		}
+
+		std::ostream &OutputNamedValueLua(std::ostream &stream, int numIndent,
+			const char *name, const char *val)
+		{
+			stream << std::string(numIndent, '\t');
+			stream << "[\"" << name << "\"] = ";
+
+			OutputRawStringLua(stream, val);
+
+			stream << ",\n";
+			return stream;
+		}
+
+		template<typename T>
+		std::ostream &OutputNamedValueLua(std::ostream &stream, int numIndent,
+			const char *name, const T &val)
+		{
+			stream << std::string(numIndent, '\t');
+			stream << "[\"" << name << "\"] = " << val << ",\n";
+			return stream;
+		}
+
+	
+		struct LuaTable
+		{
+			LuaTable(std::ostream &_stream, int _numIndent, bool _multiline = true)
+				: stream(_stream)
+				, numIndent(_numIndent)
+				, multiline(_multiline)
+			{
+				if(multiline)
+					stream << std::string(numIndent, '\t') << "{\n";
+				else
+					stream << "{";
+			}
+
+			~LuaTable()
+			{
+				if(multiline)
+					stream << std::string(numIndent, '\t') << "},\n";
+				else
+					stream << "},\n";
+			}
+
+			std::ostream &stream;
+			bool multiline;
+			int numIndent;
+		};
+
+		struct LuaWriteDatumVisitor : public boost::static_visitor<>
+		{
+			LuaWriteDatumVisitor(std::ostream &_stream) : stream(_stream){}
+
+			void operator()(const boost::blank&) const {stream << "WTF!!!!" << ", ";}
+			void operator()(double value) const {stream << value << ", ";}
+
+			std::ostream &stream;
+		};
+
+	}
+
+	std::ostream & Report::WriteToLua( std::ostream &stream, const char *suite_name,
+		const char *suite_desc, const char *gl_version, const char *gl_vendor,
+		const char *gl_renderer ) const
+	{
+		stream << "return\n{\n";
+
+		OutputNamedValueLua(stream, 1, "name", suite_name);
+		OutputNamedValueLua(stream, 1, "description", suite_desc);
+		OutputNamedValueLua(stream, 1, "opengl_version", gl_version);
+		OutputNamedValueLua(stream, 1, "opengl_vendor", gl_vendor);
+		OutputNamedValueLua(stream, 1, "opengl_renderer", gl_renderer);
+
+		BOOST_FOREACH(const MapReportTest::value_type &testPair, m_pData->tests)
+		{
+			stream << "\t[\"" << testPair.first << "\"] = \n";
+
+			LuaTable testTable(stream, 1);
+
+			const ReportTest &test = testPair.second;
+
+			OutputNamedValueLua(stream, 2, "name", test.GetName().c_str());
+			OutputNamedValueLua(stream, 2, "description", test.GetDescription().c_str());
+
+			BOOST_FOREACH(int instance, boost::irange(0, m_pData->numInstances))
+			{
+				LuaTable instTable(stream, 2);
+
+				//Write parameter names.
+				stream << "\t\t\t[params] = \n";
+				{
+					LuaTable paramTable(stream, 3);
+					BOOST_FOREACH(int paramIx, boost::irange((int)0, (int)m_pData->params.size()))
+					{
+						OutputNamedValueLua(stream, 4, m_pData->params[paramIx].name,
+							m_pData->instanceValues[paramIx + instance * m_pData->params.size()]);
+					}
+				}
+
+				//Write list of data values for each available datum in this test instance.
+				const TestDatumElement &initial = test.GetDatum(instance, 0);
+				BOOST_FOREACH(int datumId, boost::irange(0, (int)NUM_TOTAL_DATUM))
+				{
+					if(boost::apply_visitor(DatumHasValue(), initial.data[datumId]))
+					{
+						stream << "\t\t\t[" << g_datumNames[datumId] << "] = ";
+						LuaTable datumTable(stream, 4, false);
+
+						BOOST_FOREACH(int execution, boost::irange(0, m_pData->numExecutions))
+						{
+							boost::apply_visitor(LuaWriteDatumVisitor(stream),
+								test.GetDatum(instance, execution).data[datumId]);
+						}
+					}
+				}
+
+			}
+		}
+
+		stream << "}\n" << std::flush;
+		return stream;
+	}
+
 	TestDatum::TestDatum( Report &report, const std::string &testName, int instance, int execution )
 		: data(report.GetDatumElement(testName, instance, execution))
 	{}
 	{
 		data.data[eId] = value;
 	}
+
 }

File tests/util/report.h

 			const std::vector<ParamDecl> &params, const std::vector<TestDesc> &tests);
 		~Report();
 
+		std::ostream &WriteToLua(std::ostream &stream, const char *suite_name,
+			const char *suite_desc, const char *gl_version, const char *gl_vendor,
+			const char *gl_renderer) const;
+
 	private:
 		boost::scoped_ptr<ReportData> m_pData;
 
 	//Simple output stream writer. Not meant for later processing.
 	inline std::ostream &operator<<(std::ostream &stream, const Report &report) {return report.DisplayWriter(stream);}
 
+	void TestMethod( const char * val );
 	enum TestDatumId
 	{
 		DATUM_CPU_ELAPSED = 0,