1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Execution Server
3 * ---------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief ExecServer main().
22 *//*--------------------------------------------------------------------*/
23
24 #include "xsExecutionServer.hpp"
25 #include "deString.h"
26
27 #if (DE_OS == DE_OS_WIN32)
28 # include "xsWin32TestProcess.hpp"
29 #else
30 # include "xsPosixTestProcess.hpp"
31 #endif
32
33 #include <cstdlib>
34 #include <cstdio>
35
main(int argc,const char * const * argv)36 int main (int argc, const char* const* argv)
37 {
38 xs::ExecutionServer::RunMode runMode = xs::ExecutionServer::RUNMODE_FOREVER;
39 int port = 50016;
40
41 #if (DE_OS == DE_OS_WIN32)
42 xs::Win32TestProcess testProcess;
43 #else
44 xs::PosixTestProcess testProcess;
45 #endif
46
47 DE_STATIC_ASSERT(sizeof("a") == 2);
48
49 #if (DE_OS != DE_OS_WIN32)
50 // Set line buffered mode to stdout so executor gets any log messages soon enough.
51 setvbuf(stdout, DE_NULL, _IOLBF, 4*1024);
52 #endif
53
54 // Parse command line.
55 for (int argNdx = 1; argNdx < argc; argNdx++)
56 {
57 const char* arg = argv[argNdx];
58
59 if (deStringBeginsWith(arg, "--port="))
60 port = atoi(arg+sizeof("--port=")-1);
61 else if (deStringEqual(arg, "--single"))
62 runMode = xs::ExecutionServer::RUNMODE_SINGLE_EXEC;
63 }
64
65 try
66 {
67 xs::ExecutionServer server(&testProcess, DE_SOCKETFAMILY_INET4, port, runMode);
68 printf("Listening on port %d.\n", port);
69 server.runServer();
70 }
71 catch (const std::exception& e)
72 {
73 printf("%s\n", e.what());
74 return -1;
75 }
76
77 return 0;
78 }
79