1 #ifndef _XSWIN32TESTPROCESS_HPP
2 #define _XSWIN32TESTPROCESS_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Execution Server
5 * ---------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief TestProcess implementation for Win32.
24 *//*--------------------------------------------------------------------*/
27 #include "xsTestProcess.hpp"
28 #include "deThread.hpp"
33 #if !defined(VC_EXTRALEAN)
34 # define VC_EXTRALEAN 1
36 #if !defined(WIN32_LEAN_AND_MEAN)
37 # define WIN32_LEAN_AND_MEAN 1
39 #if !defined(NOMINMAX)
49 class Error : public std::runtime_error
52 Error (DWORD error, const char* msg);
61 Event (bool manualReset, bool initialState);
64 void setSignaled (void);
67 HANDLE getHandle (void) const { return m_handle; }
70 Event (const Event& other);
71 Event& operator= (const Event& other);
76 class CaseListWriter : public de::Thread
79 CaseListWriter (void);
80 ~CaseListWriter (void);
82 void start (const char* caseList, HANDLE dst);
88 std::vector<char> m_caseList;
93 class FileReader : public de::Thread
96 FileReader (ThreadedByteBuffer* dst);
99 void start (HANDLE file);
105 ThreadedByteBuffer* m_dstBuf;
113 TestLogReader (void);
114 ~TestLogReader (void);
116 void start (const char* filename);
119 bool isRunning (void) const { return m_reader.isStarted(); }
121 int read (deUint8* dst, int numBytes) { return m_logBuffer.tryRead(numBytes, dst); }
124 ThreadedByteBuffer m_logBuffer;
130 // \note deProcess uses anonymous pipes that don't have overlapped IO available.
131 // For ExecServer purposes we need overlapped IO, and it makes the handles
132 // incompatible with deFile. Thus separate Process implementation is used for now.
139 void start (const char* commandLine, const char* workingDirectory);
141 void waitForFinish (void);
142 void terminate (void);
145 bool isRunning (void);
146 int getExitCode (void) const { return m_exitCode; }
148 HANDLE getStdIn (void) const { return m_standardIn; }
149 HANDLE getStdOut (void) const { return m_standardOut; }
150 HANDLE getStdErr (void) const { return m_standardErr; }
153 Process (const Process& other);
154 Process& operator= (const Process& other);
156 void stopProcess (bool kill);
157 void cleanupHandles (void);
161 STATE_NOT_STARTED = 0,
171 PROCESS_INFORMATION m_procInfo;
173 HANDLE m_standardOut;
174 HANDLE m_standardErr;
179 class Win32TestProcess : public TestProcess
182 Win32TestProcess (void);
183 virtual ~Win32TestProcess (void);
185 virtual void start (const char* name, const char* params, const char* workingDir, const char* caseList);
186 virtual void terminate (void);
187 virtual void cleanup (void);
189 virtual bool isRunning (void);
190 virtual int getExitCode (void) const;
192 virtual int readTestLog (deUint8* dst, int numBytes);
193 virtual int readInfoLog (deUint8* dst, int numBytes) { return m_infoBuffer.tryRead(numBytes, dst); }
196 Win32TestProcess (const Win32TestProcess& other);
197 Win32TestProcess& operator= (const Win32TestProcess& other);
199 win32::Process* m_process;
200 deUint64 m_processStartTime;
201 std::string m_logFileName;
203 ThreadedByteBuffer m_infoBuffer;
206 win32::CaseListWriter m_caseListWriter;
207 win32::FileReader m_stdOutReader;
208 win32::FileReader m_stdErrReader;
209 win32::TestLogReader m_testLogReader;
214 #endif // _XSWIN32TESTPROCESS_HPP