| // Copyright 2023 Google Inc. All Rights Reserved. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #ifndef NINJA_PERSISTENT_SERVICE_TEST_LIB_H_ |
| #define NINJA_PERSISTENT_SERVICE_TEST_LIB_H_ |
| |
| #include <string> |
| #include <vector> |
| |
| #include "ipc_handle.h" |
| #include "persistent_service.h" |
| |
| namespace persistent_service_test { |
| |
| /// Name of persistent service name for the test. |
| extern const char kServiceName[]; |
| |
| /// Default PersistentService::Config::version_info as a C string. |
| extern const char kDefaultVersion[]; |
| |
| /// Return the server arguments to pass to PersistentService::Client::Connect() |
| /// For this helper, this should only be the name of or path to the executable |
| /// itself. |
| PersistentService::Config GetServerConfig(); |
| |
| /// Set a non-default service version information. |
| /// information for the server. |
| void SetServiceConfigVersion(PersistentService::Config& config, |
| const std::string& version); |
| |
| /// Set the server connection timeout in milliseconds. |
| void SetServiceConfigTimeoutMs(PersistentService::Config& config, |
| int64_t connection_timeout_ms); |
| |
| /// Retrieve a VersionCheckHandler instance that expects client version info |
| /// to match |server_version_info|. |
| PersistentService::Server::VersionCheckHandler GetVersionCheckHandler( |
| const std::string& server_version_info); |
| |
| /// Implement the request handler for the test handler. |
| bool RequestHandler(ScopedHandle connection); |
| |
| /// Run the test. Return true in case of success. In case of failure, |
| /// set |*error| and return false. |client| is the handle returned |
| /// PersistentService::CreateClient(). |
| bool RunTest(ScopedHandle& client, std::string* error); |
| |
| /// Tell the server to stop and exit. This does not use IpcServer::StopServer(), |
| /// instead the server's RequestHandler will return false. |
| bool StopServer(ScopedHandle& client, std::string* error); |
| |
| } // namespace persistent_service_test |
| |
| #endif // NINJA_PERSISTENT_SERVICE_TEST_LIB_H_ |