xref: /aosp_15_r20/external/deqp/framework/platform/android/tcuAndroidExecService.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _TCUANDROIDEXECSERVICE_HPP
2 #define _TCUANDROIDEXECSERVICE_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
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 Android ExecService.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "deThread.hpp"
28 #include "xsExecutionServer.hpp"
29 #include "xsPosixFileReader.hpp"
30 
31 #include <jni.h>
32 
33 namespace tcu
34 {
35 namespace Android
36 {
37 
38 enum
39 {
40     DEFAULT_PORT         = 50016,
41     DEFAULT_SOCKETFAMILY = DE_SOCKETFAMILY_INET4
42 };
43 
44 class TestProcess : public xs::TestProcess
45 {
46 public:
47     TestProcess(JavaVM *vm, jobject context);
48     ~TestProcess(void);
49 
50     virtual void start(const char *name, const char *params, const char *workingDir, const char *caseList);
51     virtual void terminate(void);
52     virtual void cleanup(void);
53 
54     virtual bool isRunning(void);
55     virtual int getExitCode(void) const;
56 
57     virtual int readTestLog(uint8_t *dst, int numBytes);
58     virtual int readInfoLog(uint8_t *dst, int numBytes);
59 
60 private:
61     JNIEnv *getCurrentThreadEnv(void);
62 
63     JavaVM *m_vm;
64     jclass m_remoteCls;
65     jobject m_remote;
66     jmethodID m_start;
67     jmethodID m_kill;
68     jmethodID m_isRunning;
69 
70     uint64_t m_launchTime;
71     uint64_t m_lastQueryTime;
72     bool m_lastRunningStatus;
73     xs::posix::FileReader m_logReader;
74 };
75 
76 class ExecutionServer : public xs::ExecutionServer
77 {
78 public:
79     ExecutionServer(JavaVM *vm, xs::TestProcess *testProcess, deSocketFamily family, int port, RunMode runMode);
80     xs::ConnectionHandler *createHandler(de::Socket *socket, const de::SocketAddress &clientAddress);
81 
82 private:
83     JavaVM *m_vm;
84 };
85 
86 class ConnectionHandler : public xs::ExecutionRequestHandler
87 {
88 public:
89     ConnectionHandler(JavaVM *vm, xs::ExecutionServer *server, de::Socket *socket);
90     void run(void);
91 
92 private:
93     JavaVM *m_vm;
94 };
95 
96 class ServerThread : public de::Thread
97 {
98 public:
99     ServerThread(JavaVM *vm, xs::TestProcess *testProcess, deSocketFamily family, int port);
100 
101     void run(void);
102     void stop(void);
103 
104 private:
105     ExecutionServer m_server;
106 };
107 
108 class ExecService
109 {
110 public:
111     ExecService(JavaVM *vm, jobject context, int port, deSocketFamily family = (deSocketFamily)DEFAULT_SOCKETFAMILY);
112     ~ExecService(void);
113 
114     void start(void);
115     void stop(void);
116 
117 private:
118     ExecService(const ExecService &other);
119     ExecService &operator=(const ExecService &other);
120 
121     TestProcess m_process;
122     ServerThread m_thread;
123 };
124 
125 } // namespace Android
126 } // namespace tcu
127 
128 #endif // _TCUANDROIDEXECSERVICE_HPP
129