1/*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2016 Google Inc.
6 * Copyright (c) 2016 The Khronos Group Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */ /*!
21 * \file
22 * \brief CTS runner main().
23 */ /*-------------------------------------------------------------------*/
24
25#include "deString.h"
26#include "deUniquePtr.hpp"
27#include "glcTestRunner.hpp"
28#include "tcuPlatform.hpp"
29#include "tcuResource.hpp"
30
31#include <cstdio>
32#include <cstdlib>
33
34// See tcuMain.cpp
35tcu::Platform* createPlatform(void);
36
37struct CommandLine
38{
39	CommandLine(void) : runType(glu::ApiType::es(2, 0)), flags(0)
40	{
41	}
42
43	glu::ApiType runType;
44	std::string  waiverPath;
45	std::string  dstLogDir;
46	deUint32	 flags;
47};
48
49static bool parseCommandLine(CommandLine& cmdLine, int argc, const char* const* argv)
50{
51	for (int argNdx = 1; argNdx < argc; argNdx++)
52	{
53		const char* arg = argv[argNdx];
54
55		if (deStringBeginsWith(arg, "--type="))
56		{
57			static const struct
58			{
59				const char*  name;
60				glu::ApiType runType;
61			} runTypes[] = { { "es2", glu::ApiType::es(2, 0) },	{ "es3", glu::ApiType::es(3, 0) },
62							 { "es31", glu::ApiType::es(3, 1) },   { "es32", glu::ApiType::es(3, 2) },
63							 { "gl30", glu::ApiType::core(3, 0) }, { "gl31", glu::ApiType::core(3, 1) },
64							 { "gl32", glu::ApiType::core(3, 2) }, { "gl33", glu::ApiType::core(3, 3) },
65							 { "gl40", glu::ApiType::core(4, 0) }, { "gl41", glu::ApiType::core(4, 1) },
66							 { "gl42", glu::ApiType::core(4, 2) }, { "gl43", glu::ApiType::core(4, 3) },
67							 { "gl44", glu::ApiType::core(4, 4) }, { "gl45", glu::ApiType::core(4, 5) },
68							 { "gl46", glu::ApiType::core(4, 6) } };
69
70			const char* value = arg + 7;
71			int			ndx   = 0;
72
73			for (; ndx < DE_LENGTH_OF_ARRAY(runTypes); ndx++)
74			{
75				if (deStringEqual(runTypes[ndx].name, value))
76				{
77					cmdLine.runType = runTypes[ndx].runType;
78					break;
79				}
80			}
81
82			if (ndx >= DE_LENGTH_OF_ARRAY(runTypes))
83				return false;
84		}
85		else if (deStringBeginsWith(arg, "--waivers="))
86		{
87			const char* value = arg + 10;
88			cmdLine.waiverPath = value;
89		}
90		else if (deStringBeginsWith(arg, "--logdir="))
91		{
92			const char* value = arg + 9;
93			cmdLine.dstLogDir = value;
94		}
95		else if (deStringBeginsWith(arg, "--summary"))
96		{
97			cmdLine.flags = glcts::TestRunner::PRINT_SUMMARY;
98		}
99		else if (deStringEqual(arg, "--verbose"))
100			cmdLine.flags = glcts::TestRunner::VERBOSE_ALL;
101		else
102			return false;
103	}
104
105	return true;
106}
107
108static void printHelp(const char* binName)
109{
110	printf("%s:\n", binName);
111	printf("  --type=[esN[M]|glNM] Conformance test run type. Choose from\n");
112	printf("                       ES: es2, es3, es31, es32\n");
113	printf("                       GL: gl30, gl31, gl32, gl33, gl40, gl41, gl42, gl43, gl44, gl45, gl46\n");
114	printf("  --waivers=[path]     Path to xml file containing waived tests\n");
115	printf("  --logdir=[path]      Destination directory for log files\n");
116	printf("  --summary            Print summary without running the tests\n");
117	printf("  --verbose            Print out and log more information\n");
118}
119
120int main(int argc, char** argv)
121{
122	CommandLine cmdLine;
123	int exitStatus = EXIT_SUCCESS;
124
125	if (!parseCommandLine(cmdLine, argc, argv))
126	{
127		printHelp(argv[0]);
128		return -1;
129	}
130
131	try
132	{
133		de::UniquePtr<tcu::Platform> platform(createPlatform());
134		tcu::DirArchive				 archive(".");
135		glcts::TestRunner runner(static_cast<tcu::Platform&>(*platform.get()), archive, cmdLine.waiverPath.c_str(),
136								 cmdLine.dstLogDir.c_str(), cmdLine.runType, cmdLine.flags);
137
138		for (;;)
139		{
140			if (!runner.iterate())
141			{
142				if (!runner.isConformant())
143				{
144					exitStatus = EXIT_FAILURE;
145				}
146
147				break;
148			}
149		}
150	}
151	catch (const std::exception& e)
152	{
153		printf("ERROR: %s\n", e.what());
154		return -1;
155	}
156
157	return exitStatus;
158}
159