2
* Copyright © 2012 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voss <thomas.voss@canonical.com>
17
* Thomas Guest <thomas.guest@canonical.com>
20
#ifndef MIR_TEST_FRAMEWORK_PROCESS_H_
21
#define MIR_TEST_FRAMEWORK_PROCESS_H_
32
namespace mir_test_framework
35
enum class TerminationReason
38
child_terminated_normally,
39
child_terminated_by_signal,
40
child_terminated_with_core_dump,
41
child_stopped_by_signal,
42
child_resumed_by_signal
46
// Aggregated results of running a process to completion
51
// Did the process exit without error?
52
bool succeeded() const;
54
// Was the process terminated by a signal?
55
bool signalled() const;
57
TerminationReason reason;
62
// Posix process control class.
66
// Construct a process with the supplied pid
69
// Destroy the process cleanly, by terminating it and waiting for
73
// Wait for the process to terminate, and return the results.
74
Result wait_for_termination(const std::chrono::milliseconds& timeout = std::chrono::milliseconds(60 * 1000));
84
Process(const Process&) = delete;
85
Process& operator=(const Process&) = delete;
93
// Stream print helper
94
std::ostream& operator<<(std::ostream& out, const Result& result);
96
// Fork a child process to run the supplied main function, calling
97
// the exit function when done.
98
// Returns the parent process.
99
template<typename Callable>
100
std::shared_ptr<Process> fork_and_run_in_a_different_process(
101
Callable&& main_fn, std::function<int()> exit_fn)
107
throw std::runtime_error("Failed to fork process");
116
return std::shared_ptr<Process>(new Process(pid));
120
#endif // MIR_TEST_FRAMEWORK_PROCESS_H_