2c9dfc2f312a7c9aef843c32ddd184bfcb6c835d
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / runner / glcTestRunnerMain.cpp
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
33 // See tcuMain.cpp
34 tcu::Platform* createPlatform(void);
35
36 struct CommandLine
37 {
38         CommandLine(void) : runType(glu::ApiType::es(2, 0)), flags(0)
39         {
40         }
41
42         glu::ApiType runType;
43         std::string  dstLogDir;
44         deUint32         flags;
45 };
46
47 static bool parseCommandLine(CommandLine& cmdLine, int argc, const char* const* argv)
48 {
49         for (int argNdx = 1; argNdx < argc; argNdx++)
50         {
51                 const char* arg = argv[argNdx];
52
53                 if (deStringBeginsWith(arg, "--type="))
54                 {
55                         static const struct
56                         {
57                                 const char*  name;
58                                 glu::ApiType runType;
59                         } runTypes[] = { { "es2", glu::ApiType::es(2, 0) },     { "es3", glu::ApiType::es(3, 0) },
60                                                          { "es31", glu::ApiType::es(3, 1) },   { "es32", glu::ApiType::es(3, 2) },
61                                                          { "gl30", glu::ApiType::core(3, 0) }, { "gl31", glu::ApiType::core(3, 1) },
62                                                          { "gl32", glu::ApiType::core(3, 2) }, { "gl33", glu::ApiType::core(3, 3) },
63                                                          { "gl40", glu::ApiType::core(4, 0) }, { "gl41", glu::ApiType::core(4, 1) },
64                                                          { "gl42", glu::ApiType::core(4, 2) }, { "gl43", glu::ApiType::core(4, 3) },
65                                                          { "gl44", glu::ApiType::core(4, 4) }, { "gl45", glu::ApiType::core(4, 5) } };
66
67                         const char* value = arg + 7;
68                         int                     ndx   = 0;
69
70                         for (; ndx < DE_LENGTH_OF_ARRAY(runTypes); ndx++)
71                         {
72                                 if (deStringEqual(runTypes[ndx].name, value))
73                                 {
74                                         cmdLine.runType = runTypes[ndx].runType;
75                                         break;
76                                 }
77                         }
78
79                         if (ndx >= DE_LENGTH_OF_ARRAY(runTypes))
80                                 return false;
81                 }
82                 else if (deStringBeginsWith(arg, "--logdir="))
83                 {
84                         const char* value = arg + 9;
85                         cmdLine.dstLogDir = value;
86                 }
87                 else if (deStringBeginsWith(arg, "--summary"))
88                 {
89                         cmdLine.flags = glcts::TestRunner::PRINT_SUMMARY;
90                 }
91                 else if (deStringEqual(arg, "--verbose"))
92                         cmdLine.flags = glcts::TestRunner::VERBOSE_ALL;
93                 else
94                         return false;
95         }
96
97         return true;
98 }
99
100 static void printHelp(const char* binName)
101 {
102         printf("%s:\n", binName);
103         printf("  --type=[esN[M]|glNM] Conformance test run type. Choose from\n");
104         printf("                       ES: es2, es3, es31, es32\n");
105         printf("                       GL: gl30, gl31, gl32, gl33, gl40, gl41, gl42, gl43, gl44, gl45\n");
106         printf("  --logdir=[path]      Destination directory for log files\n");
107         printf("  --summary            Print summary without running the tests\n");
108         printf("  --verbose            Print out and log more information\n");
109 }
110
111 int main(int argc, char** argv)
112 {
113         CommandLine cmdLine;
114
115         if (!parseCommandLine(cmdLine, argc, argv))
116         {
117                 printHelp(argv[0]);
118                 return -1;
119         }
120
121         try
122         {
123                 de::UniquePtr<tcu::Platform> platform(createPlatform());
124                 tcu::DirArchive                          archive(".");
125                 glcts::TestRunner runner(static_cast<tcu::Platform&>(*platform.get()), archive, cmdLine.dstLogDir.c_str(),
126                                                                  cmdLine.runType, cmdLine.flags);
127
128                 for (;;)
129                 {
130                         if (!runner.iterate())
131                                 break;
132                 }
133         }
134         catch (const std::exception& e)
135         {
136                 printf("ERROR: %s\n", e.what());
137                 return -1;
138         }
139
140         return 0;
141 }