2
* Copyright © 2013 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: Alan Griffiths <alan@octopull.co.uk>
19
#include "mir_test_framework/in_process_server.h"
21
#include "mir/default_server_configuration.h"
22
#include "mir/display_server.h"
23
#include "mir/frontend/connector.h"
24
#include "mir/run_mir.h"
26
#include <gtest/gtest.h>
28
#include <condition_variable>
31
namespace mtf = mir_test_framework;
33
void mtf::InProcessServer::SetUp()
35
display_server = start_mir_server();
36
ASSERT_TRUE(display_server);
39
std::string mtf::InProcessServer::new_connection()
41
char connect_string[64] = {0};
42
sprintf(connect_string, "fd://%d", server_config().the_connector()->client_socket_fd());
43
return connect_string;
46
void mtf::InProcessServer::TearDown()
48
ASSERT_TRUE(display_server)
49
<< "Did you override SetUp() and forget to call mtf::InProcessServer::SetUp()?";
50
display_server->stop();
53
mtf::InProcessServer::~InProcessServer()
55
if (server_thread.joinable()) server_thread.join();
58
mir::DisplayServer* mtf::InProcessServer::start_mir_server()
61
std::condition_variable cv;
62
mir::DisplayServer* result{nullptr};
64
server_thread = std::thread([&]
68
mir::run_mir(server_config(), [&](mir::DisplayServer& ds)
70
std::unique_lock<std::mutex> lock(mutex);
75
catch (std::exception const& e)
81
using namespace std::chrono;
82
auto const time_limit = system_clock::now() + seconds(2);
84
std::unique_lock<std::mutex> lock(mutex);
86
while (!result && time_limit > system_clock::now())
87
cv.wait_until(lock, time_limit);