blob: 87431e1673ee68d9fe43e4b11163dd5ae33631f8 [file] [log] [blame]
// 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"
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(IpcHandle 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(). If |kill_server| is true, this also
/// sends a command to kill the server and wait for its proper shutdown.
bool RunTest(IpcHandle& client, bool kill_server, std::string* error);
} // namespace persistent_service_test
#endif // NINJA_PERSISTENT_SERVICE_TEST_LIB_H_