Mir

Merge lp:~alan-griffiths/mir/dlopen-graphicsplatform into lp:~mir-team/mir/trunk

Proposed by Alan Griffiths
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 767
Proposed branch: lp:~alan-griffiths/mir/dlopen-graphicsplatform
Merge into: lp:~mir-team/mir/trunk
Diff against target: 514 lines (+260/-24)
16 files modified
CMakeLists.txt (+1/-1)
debian/libmirserver0.install (+1/-0)
examples/render_to_fb.cpp (+4/-1)
include/server/mir/graphics/platform.h (+4/-4)
include/server/mir/shared_library.h (+55/-0)
src/server/CMakeLists.txt (+3/-1)
src/server/default_server_configuration.cpp (+5/-7)
src/server/graphics/CMakeLists.txt (+2/-1)
src/server/graphics/android/CMakeLists.txt (+5/-2)
src/server/graphics/android/android_platform.cpp (+3/-3)
src/server/graphics/gbm/CMakeLists.txt (+4/-3)
src/server/graphics/gbm/gbm_platform.cpp (+1/-1)
src/server/shared_library.cpp (+55/-0)
tests/integration-tests/CMakeLists.txt (+1/-0)
tests/unit-tests/CMakeLists.txt (+2/-0)
tests/unit-tests/shared_library_test.cpp (+114/-0)
To merge this branch: bzr merge lp:~alan-griffiths/mir/dlopen-graphicsplatform
Reviewer Review Type Date Requested Status
Kevin DuBois (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Review via email: mp+170797@code.launchpad.net

Commit message

graphics, config: Dynamically load the graphics platform

Description of the change

graphics, config: Dynamically load the graphics platform

Will follow up with MP to make the library configurable

To post a comment you must log in.
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good, and works just fine locally.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-06-19 09:57:32 +0000
+++ CMakeLists.txt 2013-06-21 15:26:27 +0000
@@ -42,7 +42,7 @@
42include (cmake/PrePush.cmake)42include (cmake/PrePush.cmake)
4343
44set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Werror -Wall -pedantic -Wextra -fPIC")44set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Werror -Wall -pedantic -Wextra -fPIC")
45set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++0x -Werror -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC")45set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++0x -Werror -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC -Wno-return-type-c-linkage")
46set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")46set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
4747
48#####################################################################48#####################################################################
4949
=== modified file 'debian/libmirserver0.install'
--- debian/libmirserver0.install 2013-05-22 10:24:51 +0000
+++ debian/libmirserver0.install 2013-06-21 15:26:27 +0000
@@ -1,2 +1,3 @@
1usr/lib/libmirserver.so.*1usr/lib/libmirserver.so.*
2usr/lib/libmirplatformgraphics.so*
2usr/lib/libmirserverlttng.so3usr/lib/libmirserverlttng.so
34
=== modified file 'examples/render_to_fb.cpp'
--- examples/render_to_fb.cpp 2013-06-20 02:16:09 +0000
+++ examples/render_to_fb.cpp 2013-06-21 15:26:27 +0000
@@ -16,6 +16,7 @@
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */17 */
1818
19#include "mir/shared_library.h"
19#include "mir/graphics/platform.h"20#include "mir/graphics/platform.h"
20#include "mir/graphics/display.h"21#include "mir/graphics/display.h"
21#include "mir/graphics/display_buffer.h"22#include "mir/graphics/display_buffer.h"
@@ -56,8 +57,10 @@
56 sigaction(SIGINT, &sa, NULL);57 sigaction(SIGINT, &sa, NULL);
57 sigaction(SIGTERM, &sa, NULL);58 sigaction(SIGTERM, &sa, NULL);
5859
60 mir::SharedLibrary libmirplatformgraphics("libmirplatformgraphics.so");
59 auto logger = std::make_shared<ml::DumbConsoleLogger>();61 auto logger = std::make_shared<ml::DumbConsoleLogger>();
60 auto platform = mg::create_platform(std::make_shared<mo::ProgramOption>(), std::make_shared<ml::DisplayReport>(logger));62 auto report = std::make_shared<ml::DisplayReport>(logger);
63 auto platform = libmirplatformgraphics.load_function<mg::CreatePlatform>("create_platform")(std::make_shared<mo::ProgramOption>(), report);
61 auto display = platform->create_display();64 auto display = platform->create_display();
6265
63 mir::draw::glAnimationBasic gl_animation;66 mir::draw::glAnimationBasic gl_animation;
6467
=== modified file 'include/server/mir/graphics/platform.h'
--- include/server/mir/graphics/platform.h 2013-06-20 23:34:40 +0000
+++ include/server/mir/graphics/platform.h 2013-06-21 15:26:27 +0000
@@ -101,7 +101,7 @@
101 */101 */
102 virtual void fill_ipc_package(std::shared_ptr<compositor::BufferIPCPacker> const& packer,102 virtual void fill_ipc_package(std::shared_ptr<compositor::BufferIPCPacker> const& packer,
103 std::shared_ptr<compositor::Buffer> const& buffer) const = 0;103 std::shared_ptr<compositor::Buffer> const& buffer) const = 0;
104 104
105 /**105 /**
106 * Creates the in-process client support object.106 * Creates the in-process client support object.
107 */107 */
@@ -109,7 +109,7 @@
109};109};
110110
111/**111/**
112 * Creates and returns a new graphics platform.112 * Function prototype used to return a new graphics platform.
113 *113 *
114 * \param [in] options options to use for this platform114 * \param [in] options options to use for this platform
115 * \param [in] report the object to use to report interesting events from the display subsystem115 * \param [in] report the object to use to report interesting events from the display subsystem
@@ -118,8 +118,8 @@
118 *118 *
119 * \ingroup platform_enablement119 * \ingroup platform_enablement
120 */120 */
121std::shared_ptr<Platform> create_platform(std::shared_ptr<options::Option> const& options, std::shared_ptr<DisplayReport> const& report);121extern "C" typedef std::shared_ptr<Platform>(*CreatePlatform)(std::shared_ptr<options::Option> const& options, std::shared_ptr<DisplayReport> const& report);
122122extern "C" std::shared_ptr<Platform> create_platform (std::shared_ptr<options::Option> const& options, std::shared_ptr<DisplayReport> const& report);
123}123}
124}124}
125125
126126
=== added file 'include/server/mir/shared_library.h'
--- include/server/mir/shared_library.h 1970-01-01 00:00:00 +0000
+++ include/server/mir/shared_library.h 2013-06-21 15:26:27 +0000
@@ -0,0 +1,55 @@
1/*
2 * Copyright © 2013 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 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_SHARED_LIBRARY_H_
20#define MIR_SHARED_LIBRARY_H_
21
22#include <string>
23
24namespace mir
25{
26class SharedLibrary
27{
28public:
29 explicit SharedLibrary(char const* library_name);
30 explicit SharedLibrary(std::string const& library_name);
31 ~SharedLibrary();
32
33 template<typename FunctionPtr>
34 FunctionPtr load_function(char const* function_name) const
35 {
36 FunctionPtr result{};
37 (void*&)result = load_symbol(function_name);
38 return result;
39 }
40
41 template<typename FunctionPtr>
42 FunctionPtr load_function(std::string const& function_name) const
43 {
44 return load_function<FunctionPtr>(function_name.c_str());
45 }
46private:
47 void* const so;
48 void* load_symbol(char const* function_name) const;
49 SharedLibrary(SharedLibrary const&) = delete;
50 SharedLibrary& operator=(SharedLibrary const&) = delete;
51};
52}
53
54
55#endif /* MIR_SHARED_LIBRARY_H_ */
056
=== modified file 'src/server/CMakeLists.txt'
--- src/server/CMakeLists.txt 2013-06-03 08:14:01 +0000
+++ src/server/CMakeLists.txt 2013-06-21 15:26:27 +0000
@@ -28,6 +28,7 @@
28 display_server.cpp28 display_server.cpp
29 default_server_configuration.cpp29 default_server_configuration.cpp
30 asio_main_loop.cpp30 asio_main_loop.cpp
31 shared_library.cpp
31)32)
3233
33set(MIRSERVER_LINKAGE SHARED)34set(MIRSERVER_LINKAGE SHARED)
@@ -50,9 +51,10 @@
50)51)
5152
52list(APPEND MIRSERVER_LINKS53list(APPEND MIRSERVER_LINKS
53 mirplatformgraphics
54 mirprotobuf54 mirprotobuf
55 3rd_party55 3rd_party
56 ${EGL_LDFLAGS} ${EGL_LIBRARIES}
57 ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES}
56)58)
5759
58if(${MIRSERVER_LINKAGE} STREQUAL SHARED)60if(${MIRSERVER_LINKAGE} STREQUAL SHARED)
5961
=== modified file 'src/server/default_server_configuration.cpp'
--- src/server/default_server_configuration.cpp 2013-06-20 23:34:12 +0000
+++ src/server/default_server_configuration.cpp 2013-06-21 15:26:27 +0000
@@ -19,6 +19,7 @@
19#include "mir/default_server_configuration.h"19#include "mir/default_server_configuration.h"
20#include "mir/abnormal_exit.h"20#include "mir/abnormal_exit.h"
21#include "mir/asio_main_loop.h"21#include "mir/asio_main_loop.h"
22#include "mir/shared_library.h"
2223
23#include "mir/options/program_option.h"24#include "mir/options/program_option.h"
24#include "mir/compositor/buffer_allocation_strategy.h"25#include "mir/compositor/buffer_allocation_strategy.h"
@@ -290,18 +291,15 @@
290 });291 });
291}292}
292293
294
293std::shared_ptr<mg::Platform> mir::DefaultServerConfiguration::the_graphics_platform()295std::shared_ptr<mg::Platform> mir::DefaultServerConfiguration::the_graphics_platform()
294{296{
295 return graphics_platform(297 return graphics_platform(
296 [this]()298 [this]()
297 {299 {
298 // TODO I doubt we need the extra level of indirection provided by300 static SharedLibrary libmirplatformgraphics("libmirplatformgraphics.so");
299 // mg::create_platform() - we just need to move the implementation301 static auto create_platform = libmirplatformgraphics.load_function<mg::CreatePlatform>("create_platform");
300 // of DefaultServerConfiguration::the_graphics_platform() to the302 return create_platform(the_options(), the_display_report());
301 // graphics libraries.
302 // Alternatively, if we want to dynamically load the graphics library
303 // then this would be the place to do that.
304 return mg::create_platform(the_options(), the_display_report());
305 });303 });
306}304}
307305
308306
=== modified file 'src/server/graphics/CMakeLists.txt'
--- src/server/graphics/CMakeLists.txt 2013-06-14 18:24:09 +0000
+++ src/server/graphics/CMakeLists.txt 2013-06-21 15:26:27 +0000
@@ -32,5 +32,6 @@
32 mirlogging32 mirlogging
3333
34 ${MIR_COMMON_PLATFORM_LIBRARIES}34 ${MIR_COMMON_PLATFORM_LIBRARIES}
35 ${GLESv2_LIBRARIES}35 ${EGL_LDFLAGS} ${EGL_LIBRARIES}
36 ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES}
36)37)
3738
=== modified file 'src/server/graphics/android/CMakeLists.txt'
--- src/server/graphics/android/CMakeLists.txt 2013-05-21 21:43:25 +0000
+++ src/server/graphics/android/CMakeLists.txt 2013-06-21 15:26:27 +0000
@@ -5,7 +5,7 @@
5)5)
66
7add_library(7add_library(
8 mirplatformgraphics STATIC8 mirplatformgraphics SHARED
99
10 android_platform.cpp10 android_platform.cpp
11 android_buffer_allocator.cpp11 android_buffer_allocator.cpp
@@ -33,9 +33,12 @@
3333
34target_link_libraries(34target_link_libraries(
35 mirplatformgraphics35 mirplatformgraphics
36 mircompositor36 mirserver
37 mirsharedandroid
3738
38 ${LIBHARDWARE_LIBRARIES}39 ${LIBHARDWARE_LIBRARIES}
39 ${EGL_LDFLAGS} ${EGL_LIBRARIES}40 ${EGL_LDFLAGS} ${EGL_LIBRARIES}
40 ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES}41 ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES}
41)42)
43
44install(TARGETS mirplatformgraphics LIBRARY DESTINATION lib)
4245
=== modified file 'src/server/graphics/android/android_platform.cpp'
--- src/server/graphics/android/android_platform.cpp 2013-06-20 23:34:40 +0000
+++ src/server/graphics/android/android_platform.cpp 2013-06-21 15:26:27 +0000
@@ -86,11 +86,11 @@
86 for(auto i=0; i<buffer_handle->numFds; i++)86 for(auto i=0; i<buffer_handle->numFds; i++)
87 {87 {
88 packer->pack_fd(buffer_handle->data[offset++]);88 packer->pack_fd(buffer_handle->data[offset++]);
89 } 89 }
90 for(auto i=0; i<buffer_handle->numInts; i++)90 for(auto i=0; i<buffer_handle->numInts; i++)
91 {91 {
92 packer->pack_data(buffer_handle->data[offset++]);92 packer->pack_data(buffer_handle->data[offset++]);
93 } 93 }
9494
95 packer->pack_stride(buffer->stride());95 packer->pack_stride(buffer->stride());
96}96}
@@ -100,7 +100,7 @@
100 return std::make_shared<mga::InternalClient>();100 return std::make_shared<mga::InternalClient>();
101}101}
102102
103std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& /*options*/, std::shared_ptr<DisplayReport> const& display_report)103extern "C" std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& /*options*/, std::shared_ptr<DisplayReport> const& display_report)
104{104{
105 return std::make_shared<mga::AndroidPlatform>(display_report);105 return std::make_shared<mga::AndroidPlatform>(display_report);
106}106}
107107
=== modified file 'src/server/graphics/gbm/CMakeLists.txt'
--- src/server/graphics/gbm/CMakeLists.txt 2013-06-05 20:36:34 +0000
+++ src/server/graphics/gbm/CMakeLists.txt 2013-06-21 15:26:27 +0000
@@ -11,7 +11,7 @@
1111
1212
13add_library(13add_library(
14 mirplatformgraphics STATIC14 mirplatformgraphics SHARED
1515
16 gbm_platform.cpp16 gbm_platform.cpp
17 gbm_buffer_allocator.cpp17 gbm_buffer_allocator.cpp
@@ -34,11 +34,12 @@
3434
35target_link_libraries(35target_link_libraries(
36 mirplatformgraphics36 mirplatformgraphics
37 mircompositor37 mirserver
38 mirlogging
3938
40 ${DRM_LDFLAGS} ${DRM_LIBRARIES}39 ${DRM_LDFLAGS} ${DRM_LIBRARIES}
41 ${GBM_LDFLAGS} ${GBM_LIBRARIES}40 ${GBM_LDFLAGS} ${GBM_LIBRARIES}
42 ${EGL_LDFLAGS} ${EGL_LIBRARIES}41 ${EGL_LDFLAGS} ${EGL_LIBRARIES}
43 ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES}42 ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES}
44)43)
44
45install(TARGETS mirplatformgraphics LIBRARY DESTINATION lib)
4546
=== modified file 'src/server/graphics/gbm/gbm_platform.cpp'
--- src/server/graphics/gbm/gbm_platform.cpp 2013-06-20 23:34:40 +0000
+++ src/server/graphics/gbm/gbm_platform.cpp 2013-06-21 15:26:27 +0000
@@ -144,7 +144,7 @@
144 return std::make_shared<mgg::InternalClient>(internal_native_display);144 return std::make_shared<mgg::InternalClient>(internal_native_display);
145}145}
146146
147std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& options, std::shared_ptr<DisplayReport> const& report)147extern "C" std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& options, std::shared_ptr<DisplayReport> const& report)
148{148{
149 auto real_fops = std::make_shared<RealVTFileOperations>();149 auto real_fops = std::make_shared<RealVTFileOperations>();
150 auto vt = std::make_shared<mgg::LinuxVirtualTerminal>(real_fops, options->get("vt", 0), report);150 auto vt = std::make_shared<mgg::LinuxVirtualTerminal>(real_fops, options->get("vt", 0), report);
151151
=== added file 'src/server/shared_library.cpp'
--- src/server/shared_library.cpp 1970-01-01 00:00:00 +0000
+++ src/server/shared_library.cpp 2013-06-21 15:26:27 +0000
@@ -0,0 +1,55 @@
1/*
2 * Copyright © 2013 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 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#include "mir/shared_library.h"
20
21#include <boost/throw_exception.hpp>
22#include <boost/exception/info.hpp>
23
24#include <dlfcn.h>
25
26#include <stdexcept>
27
28mir::SharedLibrary::SharedLibrary(char const* library_name) :
29 so(dlopen(library_name, RTLD_NOW))
30{
31 if (!so)
32 {
33 BOOST_THROW_EXCEPTION(std::runtime_error(dlerror()));
34 }
35}
36
37mir::SharedLibrary::SharedLibrary(std::string const& library_name) :
38 SharedLibrary(library_name.c_str()) {}
39
40mir::SharedLibrary::~SharedLibrary()
41{
42 dlclose(so);
43}
44
45void* mir::SharedLibrary::load_symbol(char const* function_name) const
46{
47 if (void* result = dlsym(so, function_name))
48 {
49 return result;
50 }
51 else
52 {
53 BOOST_THROW_EXCEPTION(std::runtime_error(dlerror()));
54 }
55}
056
=== modified file 'tests/integration-tests/CMakeLists.txt'
--- tests/integration-tests/CMakeLists.txt 2013-05-30 03:50:54 +0000
+++ tests/integration-tests/CMakeLists.txt 2013-06-21 15:26:27 +0000
@@ -47,6 +47,7 @@
47 mir-test-cucumber47 mir-test-cucumber
4848
49 mirserver49 mirserver
50 mirplatformgraphics
50 mirclient51 mirclient
51 mirdraw52 mirdraw
52 mirtestdraw53 mirtestdraw
5354
=== modified file 'tests/unit-tests/CMakeLists.txt'
--- tests/unit-tests/CMakeLists.txt 2013-05-20 15:55:48 +0000
+++ tests/unit-tests/CMakeLists.txt 2013-06-21 15:26:27 +0000
@@ -6,6 +6,7 @@
66
7 test_gmock_fixes.cpp7 test_gmock_fixes.cpp
8 test_asio_main_loop.cpp8 test_asio_main_loop.cpp
9 shared_library_test.cpp
9)10)
1011
11add_subdirectory(options/)12add_subdirectory(options/)
@@ -29,6 +30,7 @@
2930
30 mirclient31 mirclient
31 mirserver32 mirserver
33 mirplatformgraphics
32 mirdraw34 mirdraw
33 mirtestdraw35 mirtestdraw
34 mirlogging36 mirlogging
3537
=== added file 'tests/unit-tests/shared_library_test.cpp'
--- tests/unit-tests/shared_library_test.cpp 1970-01-01 00:00:00 +0000
+++ tests/unit-tests/shared_library_test.cpp 2013-06-21 15:26:27 +0000
@@ -0,0 +1,114 @@
1/*
2 * Copyright © 2013 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 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#include "mir/shared_library.h"
20
21#include <gtest/gtest.h>
22
23#include <boost/exception/diagnostic_information.hpp>
24
25#include <stdexcept>
26
27namespace
28{
29class HasSubstring
30{
31public:
32 HasSubstring(char const* substring) : substring(substring) {}
33
34 friend::testing::AssertionResult operator,(std::string const& target, HasSubstring const& match)
35 {
36 if (std::string::npos != target.find(match.substring))
37 return ::testing::AssertionSuccess();
38 else
39 return ::testing::AssertionFailure() <<
40 "The target:\n\"" << target << "\"\n"
41 "Does not contain:\n\"" << match.substring << "\"";
42 }
43
44private:
45 char const* const substring;
46
47 HasSubstring(HasSubstring const&) = delete;
48 HasSubstring& operator=(HasSubstring const&) = delete;
49};
50
51#define EXPECT_THAT(target, condition) EXPECT_TRUE((target, condition))
52
53char const* const nonexistent_library = "nonexistent_library";
54char const* const existing_library = "libmirplatformgraphics.so";
55char const* const nonexistent_function = "nonexistent_library";
56char const* const existing_function = "create_platform";
57}
58
59TEST(SharedLibrary, load_nonexistent_library_fails)
60{
61 EXPECT_THROW({ mir::SharedLibrary nonexistent(nonexistent_library); }, std::runtime_error);
62}
63
64TEST(SharedLibrary, load_nonexistent_library_fails_with_useful_info)
65{
66 try
67 {
68 mir::SharedLibrary nonexistent(nonexistent_library);
69 }
70 catch (std::exception const& error)
71 {
72 auto info = boost::diagnostic_information(error);
73
74 EXPECT_THAT(info, HasSubstring("cannot open shared object")) << "What went wrong";
75 EXPECT_THAT(info, HasSubstring(nonexistent_library)) << "Name of library";
76 }
77}
78
79TEST(SharedLibrary, load_valid_library_works)
80{
81 mir::SharedLibrary existing(existing_library);
82}
83
84TEST(SharedLibrary, load_nonexistent_function_fails)
85{
86 mir::SharedLibrary existing(existing_library);
87
88 EXPECT_THROW({ existing.load_function<void(*)()>(nonexistent_function); }, std::runtime_error);
89}
90
91TEST(SharedLibrary, load_nonexistent_function_fails_with_useful_info)
92{
93 mir::SharedLibrary existing(existing_library);
94
95 try
96 {
97 existing.load_function<void(*)()>(nonexistent_function);
98 }
99 catch (std::exception const& error)
100 {
101 auto info = boost::diagnostic_information(error);
102
103 EXPECT_THAT(info, HasSubstring("undefined symbol")) << "What went wrong";
104 EXPECT_THAT(info, HasSubstring(existing_library)) << "Name of library";
105 EXPECT_THAT(info, HasSubstring(nonexistent_function)) << "Name of function";
106 }
107}
108
109TEST(SharedLibrary, load_valid_function_works)
110{
111 mir::SharedLibrary existing(existing_library);
112 existing.load_function<void(*)()>(existing_function);
113}
114

Subscribers

People subscribed via source and target branches