1 #ifndef _XSPOSIXTESTPROCESS_HPP
2 #define _XSPOSIXTESTPROCESS_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Execution Server
5  * ---------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  *//*!
22  * \file
23  * \brief TestProcess implementation for Unix-like systems.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "xsDefs.hpp"
27 #include "xsTestProcess.hpp"
28 #include "xsPosixFileReader.hpp"
29 #include "deProcess.hpp"
30 #include "deThread.hpp"
31 
32 #include <vector>
33 #include <string>
34 
35 namespace xs
36 {
37 namespace posix
38 {
39 
40 class CaseListWriter : public de::Thread
41 {
42 public:
43 							CaseListWriter		(void);
44 							~CaseListWriter		(void);
45 
46 	void					start				(const char* caseList, deFile* dst);
47 	void					stop				(void);
48 
49 	void					run					(void);
50 
51 private:
52 	deFile*					m_file;
53 	std::vector<char>		m_caseList;
54 	bool					m_run;
55 };
56 
57 class PipeReader : public de::Thread
58 {
59 public:
60 							PipeReader			(ThreadedByteBuffer* dst);
61 							~PipeReader			(void);
62 
63 	void					start				(deFile* file);
64 	void					stop				(void);
65 
66 	void					run					(void);
67 
68 private:
69 	deFile*					m_file;
70 	ThreadedByteBuffer*		m_buf;
71 };
72 
73 } // posix
74 
75 class PosixTestProcess : public TestProcess
76 {
77 public:
78 							PosixTestProcess		(void);
79 	virtual					~PosixTestProcess		(void);
80 
81 	virtual void			start					(const char* name, const char* params, const char* workingDir, const char* caseList);
82 	virtual void			terminate				(void);
83 	virtual void			cleanup					(void);
84 
85 	virtual bool			isRunning				(void);
86 
87 	virtual int				getExitCode				(void) const;
88 
89 	virtual int				readTestLog				(deUint8* dst, int numBytes);
readInfoLog(deUint8 * dst,int numBytes)90 	virtual int				readInfoLog				(deUint8* dst, int numBytes) { return m_infoBuffer.tryRead(numBytes, dst); }
91 
92 private:
93 							PosixTestProcess		(const PosixTestProcess& other);
94 	PosixTestProcess&		operator=				(const PosixTestProcess& other);
95 
96 	de::Process*			m_process;
97 	deUint64				m_processStartTime;		//!< Used for determining log file timeout.
98 	std::string				m_logFileName;
99 	ThreadedByteBuffer		m_infoBuffer;
100 
101 	// Threads.
102 	posix::CaseListWriter	m_caseListWriter;
103 	posix::PipeReader		m_stdOutReader;
104 	posix::PipeReader		m_stdErrReader;
105 	posix::FileReader		m_logReader;
106 };
107 
108 } // xs
109 
110 #endif // _XSPOSIXTESTPROCESS_HPP
111