Jason McKesson avatar Jason McKesson committed df613ff

Added command line parameters for number of execution and file output.

Comments (0)

Files changed (7)

tests/codegen.lua

 		hFile:write(iface.min, ", ", iface.max, ", ", iface.count, ", ")
 		hFile:write(gen.GetParamArrayVarname(name), "};\n\n")
 	end
+	
+	hFile:write(gen.GetCmdOptionDef(), "\n\n");
+
 end
 
 --------------------------------------
 	hFile:write("\n")
 	
 	--TODO: Get the number of executions from the command line.
-	hFile:write("\t\tutil::Report report(",
-		suite.executions, ", instValues, paramDecl, tests);\n")
+	hFile:write("\t\tutil::Report report(g_test_options.numExecutions.get(), instValues, paramDecl, tests);\n")
 	hFile:write("\n")
 
 	--Perform the timings.
+	--TODO: Cull tests that require specialized features that aren't available.
 	hFile:write([[
 		int instIx = 0;
 		boost::container::vector<ParamValue> paramValues;
 		end
 		
 		local tabs = string.rep("\t", #suite._param_array + 2)
-		hFile:write(tabs,
-			string.format([[BOOST_FOREACH(int execCounter, boost::irange(0, %s))]],
-				suite.executions), "\n")
+		hFile:write(tabs, [[
+BOOST_FOREACH(int execCounter, boost::irange(0, g_test_options.numExecutions.get()))
+]])
 		hFile:write(tabs, "{\n")
 		if(test.render_flags["discard"]) then
 			hFile:write(tabs, "\tglEnable(GL_RASTERIZER_DISCARD);\n");
 	hFile:write("\n")
 	
 	--Deliver the report
-	--TODO: Make this write to a file if one is provided.
-	hFile:write("\t\treport.WriteToLua(std::cout, \"",
-		suite.name, "\", ", GetLongStringForC(suite.desc), ", \n")
-	--TODO: Get the various strings from OpenGL.
-	hFile:write("\t\t\t", [["GL Version", "GL Vendor", "GL Renderer"]])
-	hFile:write(");\n")
+	hFile:write [[
+		const char *version_string_gl = reinterpret_cast<const char*>(glGetString(GL_VERSION));
+		const char *vendor_string_gl = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
+		const char *renderer_string_gl = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
+]]
+	
+	hFile:write(string.format([[
+		if(g_test_options.outputFilename)
+		{
+			std::ofstream filestream(g_test_options.outputFilename.get().c_str(), std::ios::binary);
+			report.WriteToLua(filestream, "%s", %s,
+				version_string_gl, vendor_string_gl, renderer_string_gl);
+		}
+		else
+		{
+			report.WriteToLua(std::cout, "%s", %s,
+				version_string_gl, vendor_string_gl, renderer_string_gl);
+		}
+]],
+		suite.name, GetLongStringForC(suite.desc),
+		suite.name, GetLongStringForC(suite.desc)))
 	
 	hFile:write("\t}\n");
 	--TODO: Don't do this if not FreeGLUT
 	
 	hFile:write "\n"
 	
-	--TODO: Determine version and core profile manually.
+	--TODO: Determine version and core profile from the suite.
 	hFile:write [[
 	glutInitDisplayMode(displayMode);
 	glutInitContextVersion (3, 3);
 
 local function WriteMainFunction(hFile, suite)
 	hFile:write [[
-	int main(int argc, char** argv)
+int main(int argc, char** argv)
 {
+	g_test_options = util::GetCmdOptions(argc, argv);
 ]]
+
+	hFile:write [[
+	if(!g_test_options.numExecutions)
+]]
+
+	if(suite.executions) then
+		--Has default, so use it.
+		hFile:write("\t\tg_test_options.numExecutions = ",
+			suite.executions, ";\n")
+	else
+		--No default, so error.
+		hFile:write("\t{\n\t\t std::cout << \"You MUST specify the -exec parameter for this test suite.\" << std::endl;\n\t\t return 1;\n\t}\n")
+	end
+	
+	hFile:write "\n"
+
+
 	--TODO: alternate main form for GLFW.
 	WriteMainGlut(hFile, suite)
 	hFile:write("}\n")

tests/generate.lua

 	return "test_display"
 end
 
+function gen.GetCmdOptionDef()
+	return "util::CommandLineOptions g_test_options;"
+end
+
 function gen.WritePreamble(hFile, suite_name)
 	hFile:write([=[
 	/* Here's some preamble text. */

tests/interleave_arrays/suite.lua

 	}
 	
 	timings {"gpu_time", "gpu_latency",}
-	executions(3)
+	executions "3"
 	
 	variables {
 		separateArrayBuffers = "gl list buffer object",

tests/premake4.lua

-
 
 dofile "../glsdk/links.lua"
 local codegen = require "codegen"
 
---[[
+newaction {
+   trigger     = "gen",
+   description = "Run codegeneration only",
+   execute = function () end --Codegen always run. This just prevents project creation.
+}
+
 solution "perftests"
 	configurations { "Debug", "Release" }
 
 
 	configuration "linux"
 		links {"GL", "GLU"}
-]]
 
 local matches = os.matchfiles("**suite.lua")
 
 end
 
 codegen.gencode()
---codegen.genproj()
+codegen.genproj()
 
 

tests/util/cmd_line.cpp

+
+
+#include <boost/container/vector.hpp>
+#include <boost/lexical_cast.hpp>
+#include "cmd_line.h"
+
+namespace util
+{
+	util::CommandLineOptions GetCmdOptions( int argc, char** argv )
+	{
+		boost::container::vector<std::string> args(argv, argv + argc);
+
+		CommandLineOptions options;
+
+		for(size_t arg = 0; arg < args.size(); ++arg)
+		{
+			if(args[arg] == "-out")
+			{
+				options.outputFilename = args.at(arg + 1);
+				++arg;
+			}
+			else if(args[arg] == "-exec")
+			{
+				options.numExecutions = boost::lexical_cast<int>(args.at(arg + 1));
+				++arg;
+			}
+		}
+
+		return options;
+	}
+}

tests/util/cmd_line.h

+
+#ifndef PERFORMANCE_COMMAND_LINE_H
+#define PERFORMANCE_COMMAND_LINE_H
+
+#include <string>
+#include <boost/optional.hpp>
+
+namespace util
+{
+	struct CommandLineOptions
+	{
+		boost::optional<int> numExecutions;
+		boost::optional<std::string> outputFilename;
+	};
+
+	CommandLineOptions GetCmdOptions(int argc, char** argv);
+}
+
+
+
+#endif //PERFORMANCE_COMMAND_LINE_H

tests/util/util.h

 #include "globj.h"
 #include "CPUTiming.h"
 #include "report.h"
+#include "cmd_line.h"
 
 
 #endif // PERFORMANCE_UTILS_H
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.