Mir
interprocess_client_server_test.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
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 2 or 3,
6  * as published by the Free Software Foundation.
7  *
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.
12  *
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/>.
15  *
16  * Authored By: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIR_TEST_FRAMEWORK_INTERPROCESS_CLIENT_SERVER_TEST_H_
20 #define MIR_TEST_FRAMEWORK_INTERPROCESS_CLIENT_SERVER_TEST_H_
21 
24 
25 namespace mir_test_framework
26 {
27 class Process;
28 class Result;
29 
31 {
32 public:
33  char const* const mir_test_socket = test_socket_file().c_str();
34 
36 
37  void init_server(std::function<void()> const& init_code);
38 
39  void run_in_server(std::function<void()> const& exec_code);
41  std::function<void()> const& exec_code);
42 
43  void run_in_client(std::function<void()> const& client_code);
44 
45  auto new_client_process(std::function<void()> const& client_code) -> std::shared_ptr<Process>;
46 
47  bool is_test_process() const;
48 
49  pid_t client_pid() const { return client_process_id; }
50 
51  void TearDown() override;
52 
53  // Convenient [test|server|client] identifier if adding debug messages
54  auto process_type() const -> char const* { return process_tag; }
55 
56  void expect_server_signalled(int signal);
57 
58  void stop_server();
59 
61 
63 
64 private:
65 
66  pid_t test_process_id{getpid()};
67  pid_t server_process_id{0};
68  pid_t client_process_id{0};
69  std::shared_ptr<Process> server_process;
70  std::unique_ptr<mir::test::CrossProcessSync> shutdown_sync{new mir::test::CrossProcessSync()};
71  char const* process_tag = "test";
72  std::function<void()> server_setup = []{};
73  bool server_signal_expected{false};
74  int expected_server_failure_signal{0};
75 };
76 }
77 
78 #endif /* MIR_TEST_FRAMEWORK_INTERPROCESS_CLIENT_SERVER_TEST_H_ */
std::string const & test_socket_file()
auto new_client_process(std::function< void()> const &client_code) -> std::shared_ptr< Process >
void run_in_server(std::function< void()> const &exec_code)
pid_t client_pid() const
Definition: interprocess_client_server_test.h:49
char const *const mir_test_socket
Definition: interprocess_client_server_test.h:33
void init_server(std::function< void()> const &init_code)
auto process_type() const -> char const *
Definition: interprocess_client_server_test.h:54
void run_in_client(std::function< void()> const &client_code)
Definition: interprocess_client_server_test.h:30
Definition: any_surface.h:25
Definition: cross_process_sync.h:30
void run_in_server_and_disable_core_dump(std::function< void()> const &exec_code)
Definition: process.h:47
Basic fixture for tests that don&#39;t use graphics or input hardware.
Definition: headless_test.h:39

Copyright © 2012-2018 Canonical Ltd.
Generated on Thu Apr 5 15:26:05 UTC 2018