2024-03-08 12:00:23 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <Common.hpp>
|
|
|
|
|
|
|
|
namespace helpers
|
|
|
|
{
|
|
|
|
|
2024-03-10 10:47:24 -05:00
|
|
|
constexpr int KIT_PID_TIMEOUT_MS = 10000 * TRACE_MULTIPLIER;
|
2024-03-07 14:55:34 -06:00
|
|
|
constexpr int KIT_PID_RETRY_MS = 20;
|
2024-03-08 12:00:23 -06:00
|
|
|
|
2024-03-07 14:55:34 -06:00
|
|
|
/*
|
|
|
|
* Get the list of all kit pids
|
|
|
|
*/
|
2024-03-08 12:00:23 -06:00
|
|
|
std::set<pid_t> getKitPids();
|
2024-03-07 14:55:34 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the list of spare (unused) kit pids
|
|
|
|
*/
|
2024-03-08 12:00:23 -06:00
|
|
|
std::set<pid_t> getSpareKitPids();
|
2024-03-07 14:55:34 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the list of doc (loaded) kit pids
|
|
|
|
*/
|
2024-03-08 12:00:23 -06:00
|
|
|
std::set<pid_t> getDocKitPids();
|
|
|
|
|
2024-03-07 14:55:34 -06:00
|
|
|
/*
|
|
|
|
* Get the pid of the coolforkit process
|
|
|
|
*/
|
|
|
|
pid_t getForKitPid();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log the current doc and spare kit pids
|
|
|
|
* Useful for debugging
|
|
|
|
*/
|
|
|
|
void logKitProcesses(const std::string& testname);
|
2024-03-08 12:00:23 -06:00
|
|
|
|
2024-03-07 14:55:34 -06:00
|
|
|
/*
|
2024-03-21 11:11:37 -05:00
|
|
|
* SIGKILL relevant pid
|
2024-03-07 14:55:34 -06:00
|
|
|
*/
|
2024-03-21 11:11:37 -05:00
|
|
|
void killPid(const std::string& testname, const pid_t pid);
|
2024-03-08 12:00:23 -06:00
|
|
|
|
2024-03-07 14:55:34 -06:00
|
|
|
/*
|
|
|
|
* Wait until ready with 0 doc kits and 1 spare kit
|
|
|
|
* Used to wait for spare kit to start up before use
|
|
|
|
* or to wait for doc kits to shut down after
|
|
|
|
*/
|
|
|
|
void waitForKitPidsReady(
|
|
|
|
const std::string& testname,
|
|
|
|
const std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(KIT_PID_TIMEOUT_MS),
|
|
|
|
const std::chrono::milliseconds retryMs = std::chrono::milliseconds(KIT_PID_RETRY_MS));
|
|
|
|
|
|
|
|
/*
|
2024-03-21 11:11:37 -05:00
|
|
|
* Kill all and wait for previous processes to die
|
2024-03-07 14:55:34 -06:00
|
|
|
*/
|
2024-03-21 11:11:37 -05:00
|
|
|
void killAllKitProcesses(const std::string& testname,
|
|
|
|
const std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(KIT_PID_TIMEOUT_MS),
|
|
|
|
const std::chrono::milliseconds retryMs = std::chrono::milliseconds(KIT_PID_RETRY_MS));
|
2024-03-08 12:00:23 -06:00
|
|
|
|
2024-03-07 14:55:34 -06:00
|
|
|
} // namespace helpers
|