xref: /aosp_15_r20/external/deqp/execserver/xsProtocol.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _XSPROTOCOL_HPP
2 #define _XSPROTOCOL_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 Execution Server Protocol.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "xsDefs.hpp"
27 #include "deMemory.h"
28 
29 #include <string>
30 #include <vector>
31 
32 namespace xs
33 {
34 
35 enum
36 {
37     PROTOCOL_VERSION    = 18,
38     MESSAGE_HEADER_SIZE = 8,
39 
40     // Times are in milliseconds.
41     KEEPALIVE_SEND_INTERVAL = 5000,
42     KEEPALIVE_TIMEOUT       = 30000,
43 };
44 
45 enum MessageType
46 {
47     MESSAGETYPE_NONE = 0, //!< Not valid.
48 
49     // Commands (from Client to ExecServer).
50     MESSAGETYPE_HELLO          = 100, //!< First message from client, specifies the protocol version
51     MESSAGETYPE_TEST           = 101, //!< Debug only
52     MESSAGETYPE_EXECUTE_BINARY = 111, //!< Request execution of a test package binary.
53     MESSAGETYPE_STOP_EXECUTION = 112, //!< Request cancellation of the currently executing binary.
54 
55     // Responses (from ExecServer to Client)
56     MESSAGETYPE_PROCESS_STARTED       = 200, //!< Requested process has started.
57     MESSAGETYPE_PROCESS_LAUNCH_FAILED = 201, //!< Requested process failed to launch.
58     MESSAGETYPE_PROCESS_FINISHED      = 202, //!< Requested process has finished (for any reason).
59     MESSAGETYPE_PROCESS_LOG_DATA      = 203, //!< Unprocessed log data from TestResults.qpa.
60     MESSAGETYPE_INFO                  = 204, //!< Generic info message from ExecServer (for debugging purposes).
61 
62     MESSAGETYPE_KEEPALIVE = 102 //!< Keep-alive packet
63 };
64 
65 class MessageWriter;
66 
67 class Message
68 {
69 public:
70     MessageType type;
71 
Message(MessageType type_)72     Message(MessageType type_) : type(type_)
73     {
74     }
~Message(void)75     virtual ~Message(void)
76     {
77     }
78 
79     virtual void write(std::vector<uint8_t> &buf) const = DE_NULL;
80 
81     static void parseHeader(const uint8_t *data, size_t dataSize, MessageType &type, size_t &messageSize);
82     static void writeHeader(MessageType type, size_t messageSize, uint8_t *dst, size_t bufSize);
83 
84 protected:
85     void writeNoData(std::vector<uint8_t> &buf) const;
86 
87     Message(const Message &other);
88     Message &operator=(const Message &other);
89 };
90 
91 // Simple messages without any data.
92 template <int MsgType>
93 class SimpleMessage : public Message
94 {
95 public:
SimpleMessage(const uint8_t * data,size_t dataSize)96     SimpleMessage(const uint8_t *data, size_t dataSize) : Message((MessageType)MsgType)
97     {
98         DE_UNREF(data);
99         XS_CHECK_MSG(dataSize == 0, "No payload expected");
100     }
SimpleMessage(void)101     SimpleMessage(void) : Message((MessageType)MsgType)
102     {
103     }
~SimpleMessage(void)104     ~SimpleMessage(void)
105     {
106     }
107 
write(std::vector<uint8_t> & buf) const108     void write(std::vector<uint8_t> &buf) const
109     {
110         writeNoData(buf);
111     }
112 };
113 
114 typedef SimpleMessage<MESSAGETYPE_STOP_EXECUTION> StopExecutionMessage;
115 typedef SimpleMessage<MESSAGETYPE_PROCESS_STARTED> ProcessStartedMessage;
116 typedef SimpleMessage<MESSAGETYPE_KEEPALIVE> KeepAliveMessage;
117 
118 class HelloMessage : public Message
119 {
120 public:
121     int version;
122 
123     HelloMessage(const uint8_t *data, size_t dataSize);
HelloMessage(void)124     HelloMessage(void) : Message(MESSAGETYPE_HELLO), version(PROTOCOL_VERSION)
125     {
126     }
~HelloMessage(void)127     ~HelloMessage(void)
128     {
129     }
130 
131     void write(std::vector<uint8_t> &buf) const;
132 };
133 
134 class ExecuteBinaryMessage : public Message
135 {
136 public:
137     std::string name;
138     std::string params;
139     std::string workDir;
140     std::string caseList;
141 
142     ExecuteBinaryMessage(const uint8_t *data, size_t dataSize);
ExecuteBinaryMessage(void)143     ExecuteBinaryMessage(void) : Message(MESSAGETYPE_EXECUTE_BINARY)
144     {
145     }
~ExecuteBinaryMessage(void)146     ~ExecuteBinaryMessage(void)
147     {
148     }
149 
150     void write(std::vector<uint8_t> &buf) const;
151 };
152 
153 class ProcessLogDataMessage : public Message
154 {
155 public:
156     std::string logData;
157 
158     ProcessLogDataMessage(const uint8_t *data, size_t dataSize);
~ProcessLogDataMessage(void)159     ~ProcessLogDataMessage(void)
160     {
161     }
162 
163     void write(std::vector<uint8_t> &buf) const;
164 };
165 
166 class ProcessLaunchFailedMessage : public Message
167 {
168 public:
169     std::string reason;
170 
171     ProcessLaunchFailedMessage(const uint8_t *data, size_t dataSize);
ProcessLaunchFailedMessage(const char * reason_)172     ProcessLaunchFailedMessage(const char *reason_) : Message(MESSAGETYPE_PROCESS_LAUNCH_FAILED), reason(reason_)
173     {
174     }
~ProcessLaunchFailedMessage(void)175     ~ProcessLaunchFailedMessage(void)
176     {
177     }
178 
179     void write(std::vector<uint8_t> &buf) const;
180 };
181 
182 class ProcessFinishedMessage : public Message
183 {
184 public:
185     int exitCode;
186 
187     ProcessFinishedMessage(const uint8_t *data, size_t dataSize);
ProcessFinishedMessage(int exitCode_)188     ProcessFinishedMessage(int exitCode_) : Message(MESSAGETYPE_PROCESS_FINISHED), exitCode(exitCode_)
189     {
190     }
~ProcessFinishedMessage(void)191     ~ProcessFinishedMessage(void)
192     {
193     }
194 
195     void write(std::vector<uint8_t> &buf) const;
196 };
197 
198 class InfoMessage : public Message
199 {
200 public:
201     std::string info;
202 
203     InfoMessage(const uint8_t *data, size_t dataSize);
~InfoMessage(void)204     ~InfoMessage(void)
205     {
206     }
207 
208     void write(std::vector<uint8_t> &buf) const;
209 };
210 
211 // For debug purposes only.
212 class TestMessage : public Message
213 {
214 public:
215     std::string test;
216 
217     TestMessage(const uint8_t *data, size_t dataSize);
~TestMessage(void)218     ~TestMessage(void)
219     {
220     }
221 
222     void write(std::vector<uint8_t> &buf) const;
223 };
224 
225 } // namespace xs
226 
227 #endif // _XSPROTOCOL_HPP
228