Mir

Merge lp:~kdub/mir/fix-1342029 into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 1802
Proposed branch: lp:~kdub/mir/fix-1342029
Merge into: lp:mir
Diff against target: 417 lines (+106/-42)
20 files modified
include/test/mir_test_framework/executable_path.h (+28/-0)
include/test/mir_test_framework/udev_environment.h (+0/-3)
src/server/input/xcursor_loader.cpp (+2/-1)
tests/mir_test_framework/CMakeLists.txt (+6/-0)
tests/mir_test_framework/executable_path.cpp (+40/-0)
tests/mir_test_framework/udev_environment.cpp (+3/-19)
tests/unit-tests/CMakeLists.txt (+0/-1)
tests/unit-tests/android_input/test_eventhub.cpp (+3/-3)
tests/unit-tests/graphics/mesa/test_buffer_allocator.cpp (+1/-1)
tests/unit-tests/graphics/mesa/test_display.cpp (+1/-1)
tests/unit-tests/graphics/mesa/test_display_buffer.cpp (+1/-1)
tests/unit-tests/graphics/mesa/test_display_configuration.cpp (+1/-1)
tests/unit-tests/graphics/mesa/test_display_multi_monitor.cpp (+1/-1)
tests/unit-tests/graphics/mesa/test_drm_helper.cpp (+1/-1)
tests/unit-tests/graphics/mesa/test_gbm_buffer.cpp (+1/-1)
tests/unit-tests/graphics/mesa/test_platform.cpp (+1/-1)
tests/unit-tests/graphics/test_display.cpp (+1/-1)
tests/unit-tests/graphics/test_graphics_platform.cpp (+1/-1)
tests/unit-tests/input/test_xcursor_loader.cpp (+13/-4)
tests/unit-tests/test_udev_wrapper.cpp (+1/-1)
To merge this branch: bzr merge lp:~kdub/mir/fix-1342029
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Approve
Alexandros Frantzis (community) Approve
Review via email: mp+228470@code.launchpad.net

Commit message

correct the xcursor loader test to fail instead of segfault if it cannot find the cursor images it is looking for. Modify the test to find the cursor images from the directory the test is ran from (much like umockdev recordings) Change the scripts to install the cursor images to the proper directories when cross compiling.

fixes: lp: #1342029

Description of the change

correct the xcursor loader test to fail instead of segfault if it cannot find the cursor images it is looking for. Modify the test to find the cursor images from the directory the test is ran from (much like umockdev recordings) Change the scripts to install the cursor images to the proper directories when cross compiling.

previously, the cursor images where expected to be in a hardcoded directory based on where the code was compiled (eg, /home/kdub/source/mir/tests/mir_test_framework/testing-cursor-theme). If the images where not found in this location, the test would segfault.
Now if the image cannot be found, the test will fail instead of segfault.

fixes: lp: #1342029

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

Nit:

132 +++ tests/mir_test_framework/udev_environment.cpp

libgen.h include is not needed in this file any more.

377 + auto test_cursor_path =mir_test_framework::binary_path() + std::string("/testing-cursor-theme");

Space needed after '='

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

1 === added file 'include/test/mir_test_framework/binary_path.h'

I know we don't need it (there are only declarations) but it is traditional to use include guards.

~~~~

6 + * Copyright © 2013 Canonical Ltd.
...
21 + * Christopher James Halse Rogers <email address hidden>

90 + * Copyright © 2013 Canonical Ltd.
...
105 + * Christopher James Halse Rogers <email address hidden>

Really?

~~~~

27 +std::string binary_path();

I don't have a good suggestion, but even slightly out of context this function name is uninformative.

review: Needs Fixing
Revision history for this message
Kevin DuBois (kdub) wrote :

@Alan
Added include guards.

Corrected? copyright by adding my name to it. It feels just as funny to put my name on code I didn't write, but I guess the copyright name just applies to the file creator.

renamed to executable_path(), seemed more appropriate.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> Corrected? copyright by adding my name to it. It feels just as funny to put my
> name on code I didn't write, but I guess the copyright name just applies to
> the file creator.

I would accept an assurance that the information is correct.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'include/test/mir_test_framework/executable_path.h'
2--- include/test/mir_test_framework/executable_path.h 1970-01-01 00:00:00 +0000
3+++ include/test/mir_test_framework/executable_path.h 2014-07-29 12:29:39 +0000
4@@ -0,0 +1,28 @@
5+/*
6+ * Copyright © 2014 Canonical Ltd.
7+ *
8+ * This program is free software: you can redistribute it and/or modify
9+ * it under the terms of the GNU General Public License version 3 as
10+ * published by the Free Software Foundation.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ *
20+ * Authored by:
21+ * Kevin DuBois <kevin.dubois@canonical.com>
22+ */
23+
24+#ifndef MIR_TEST_FRAMEWORK_EXECUTABLE_PATH_H_
25+#define MIR_TEST_FRAMEWORK_EXECUTABLE_PATH_H_
26+
27+#include <string>
28+namespace mir_test_framework
29+{
30+std::string executable_path();
31+}
32+#endif /* MIR_TEST_FRAMEWORK_EXECUTABLE_PATH_H_ */
33
34=== modified file 'include/test/mir_test_framework/udev_environment.h'
35--- include/test/mir_test_framework/udev_environment.h 2014-03-26 05:48:59 +0000
36+++ include/test/mir_test_framework/udev_environment.h 2014-07-29 12:29:39 +0000
37@@ -25,8 +25,6 @@
38 #include <umockdev.h>
39 #include <libudev.h>
40
41-namespace mir
42-{
43 namespace mir_test_framework
44 {
45 class UdevEnvironment
46@@ -60,6 +58,5 @@
47 };
48
49 }
50-}
51
52 #endif //MIR_TESTING_UDEV_ENVIRONMENT
53
54=== modified file 'src/server/input/xcursor_loader.cpp'
55--- src/server/input/xcursor_loader.cpp 2014-07-22 03:26:35 +0000
56+++ src/server/input/xcursor_loader.cpp 2014-07-29 12:29:39 +0000
57@@ -193,7 +193,8 @@
58 }, this);
59 }
60
61-std::shared_ptr<mg::CursorImage> mi::XCursorLoader::image(std::string const& cursor_name,
62+std::shared_ptr<mg::CursorImage> mi::XCursorLoader::image(
63+ std::string const& cursor_name,
64 geom::Size const& size)
65 {
66 auto xcursor_name = xcursor_name_for_mir_cursor(cursor_name);
67
68=== modified file 'tests/mir_test_framework/CMakeLists.txt'
69--- tests/mir_test_framework/CMakeLists.txt 2014-06-10 12:28:03 +0000
70+++ tests/mir_test_framework/CMakeLists.txt 2014-07-29 12:29:39 +0000
71@@ -8,6 +8,7 @@
72 set(
73 TEST_FRAMEWORK_SRCS
74
75+ executable_path.cpp
76 command_line_server_configuration.cpp
77 cross_process_sync.cpp
78 server_runner.cpp
79@@ -58,3 +59,8 @@
80 ${CMAKE_CURRENT_SOURCE_DIR}/udev_recordings ${CMAKE_BINARY_DIR}/bin/udev_recordings
81 COMMENT "Copying umockdev recordings to build dir..."
82 )
83+add_custom_command(TARGET mir-test-framework POST_BUILD
84+ COMMAND ${CMAKE_COMMAND} -E copy_directory
85+ ${CMAKE_CURRENT_SOURCE_DIR}/testing-cursor-theme ${CMAKE_BINARY_DIR}/bin/testing-cursor-theme
86+ COMMENT "Copying testing cursor themes to build dir..."
87+)
88
89=== added file 'tests/mir_test_framework/executable_path.cpp'
90--- tests/mir_test_framework/executable_path.cpp 1970-01-01 00:00:00 +0000
91+++ tests/mir_test_framework/executable_path.cpp 2014-07-29 12:29:39 +0000
92@@ -0,0 +1,40 @@
93+/*
94+ * Copyright © 2013,2014 Canonical Ltd.
95+ *
96+ * This program is free software: you can redistribute it and/or modify
97+ * it under the terms of the GNU General Public License version 3 as
98+ * published by the Free Software Foundation.
99+ *
100+ * This program is distributed in the hope that it will be useful,
101+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
102+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103+ * GNU General Public License for more details.
104+ *
105+ * You should have received a copy of the GNU General Public License
106+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
107+ *
108+ * Authored by:
109+ * Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
110+ * Kevin DuBois <kevin.dubois@canonical.com>
111+ */
112+
113+#include "mir_test_framework/executable_path.h"
114+
115+#include <libgen.h>
116+#include <stdexcept>
117+#include <boost/throw_exception.hpp>
118+#include <boost/exception/errinfo_errno.hpp>
119+
120+std::string mir_test_framework::executable_path()
121+{
122+ char buf[1024];
123+ auto tmp = readlink("/proc/self/exe", buf, sizeof buf);
124+ if (tmp < 0)
125+ BOOST_THROW_EXCEPTION(boost::enable_error_info(
126+ std::runtime_error("Failed to find our executable path"))
127+ << boost::errinfo_errno(errno));
128+ if (tmp > static_cast<ssize_t>(sizeof(buf) - 1))
129+ BOOST_THROW_EXCEPTION(std::runtime_error("Path to executable is too long!"));
130+ buf[tmp] = '\0';
131+ return dirname(buf);
132+}
133
134=== renamed directory 'tests/unit-tests/input/testing-cursor-theme' => 'tests/mir_test_framework/testing-cursor-theme'
135=== modified file 'tests/mir_test_framework/udev_environment.cpp'
136--- tests/mir_test_framework/udev_environment.cpp 2014-03-26 05:48:59 +0000
137+++ tests/mir_test_framework/udev_environment.cpp 2014-07-29 12:29:39 +0000
138@@ -18,6 +18,7 @@
139 */
140
141 #include "mir_test_framework/udev_environment.h"
142+#include "mir_test_framework/executable_path.h"
143
144 #include <umockdev.h>
145
146@@ -34,27 +35,10 @@
147 #include <boost/exception/errinfo_errno.hpp>
148
149
150-namespace mtf = mir::mir_test_framework;
151-
152-namespace
153-{
154-std::string binary_path()
155-{
156- char buf[1024];
157- auto tmp = readlink("/proc/self/exe", buf, sizeof buf);
158- if (tmp < 0)
159- BOOST_THROW_EXCEPTION(boost::enable_error_info(
160- std::runtime_error("Failed to find our executable path"))
161- << boost::errinfo_errno(errno));
162- if (tmp > static_cast<ssize_t>(sizeof(buf) - 1))
163- BOOST_THROW_EXCEPTION(std::runtime_error("Path to executable is too long!"));
164- buf[tmp] = '\0';
165- return dirname(buf);
166-}
167-}
168+namespace mtf = mir_test_framework;
169
170 mtf::UdevEnvironment::UdevEnvironment()
171- : recordings_path(binary_path() + "/udev_recordings")
172+ : recordings_path(mtf::executable_path() + "/udev_recordings")
173 {
174 testbed = umockdev_testbed_new();
175 }
176
177=== modified file 'tests/unit-tests/CMakeLists.txt'
178--- tests/unit-tests/CMakeLists.txt 2014-07-28 16:26:39 +0000
179+++ tests/unit-tests/CMakeLists.txt 2014-07-29 12:29:39 +0000
180@@ -5,7 +5,6 @@
181 include_directories(${DRM_INCLUDE_DIRS} ${GBM_INCLUDE_DIRS} ${UMOCKDEV_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})
182 # TODO: Aim to remove
183 include_directories(${MIR_XCURSOR_INCLUDE_DIRECTORIES})
184-add_definitions("-DMIR_TESTING_XCURSOR_THEME=\"${CMAKE_CURRENT_SOURCE_DIR}/input/testing-cursor-theme\"")
185
186 set(
187 UNIT_TEST_SOURCES
188
189=== modified file 'tests/unit-tests/android_input/test_eventhub.cpp'
190--- tests/unit-tests/android_input/test_eventhub.cpp 2014-03-05 07:06:07 +0000
191+++ tests/unit-tests/android_input/test_eventhub.cpp 2014-07-29 12:29:39 +0000
192@@ -35,7 +35,7 @@
193
194 TEST_P(EventHubDeviceEnumerationTest, ScansOnConstruction)
195 {
196- mir::mir_test_framework::UdevEnvironment env;
197+ mir_test_framework::UdevEnvironment env;
198 env.add_standard_device(GetParam());
199
200 auto hub = android::sp<android::EventHub>{new android::EventHub{mir::report::null_input_report()}};
201@@ -54,7 +54,7 @@
202
203 TEST_P(EventHubDeviceEnumerationTest, GeneratesDeviceAddedOnHotplug)
204 {
205- mir::mir_test_framework::UdevEnvironment env;
206+ mir_test_framework::UdevEnvironment env;
207
208 auto hub = android::sp<android::EventHub>{new android::EventHub{mir::report::null_input_report()}};
209
210@@ -80,7 +80,7 @@
211
212 TEST_P(EventHubDeviceEnumerationTest, GeneratesDeviceRemovedOnHotunplug)
213 {
214- mir::mir_test_framework::UdevEnvironment env;
215+ mir_test_framework::UdevEnvironment env;
216 env.add_standard_device(GetParam());
217
218 auto hub = android::sp<android::EventHub>{new android::EventHub{mir::report::null_input_report()}};
219
220=== modified file 'tests/unit-tests/graphics/mesa/test_buffer_allocator.cpp'
221--- tests/unit-tests/graphics/mesa/test_buffer_allocator.cpp 2014-06-06 07:56:34 +0000
222+++ tests/unit-tests/graphics/mesa/test_buffer_allocator.cpp 2014-07-29 12:29:39 +0000
223@@ -42,7 +42,7 @@
224 namespace mgm = mir::graphics::mesa;
225 namespace geom = mir::geometry;
226 namespace mtd = mir::test::doubles;
227-namespace mtf = mir::mir_test_framework;
228+namespace mtf = mir_test_framework;
229
230 class MesaBufferAllocatorTest : public ::testing::Test
231 {
232
233=== modified file 'tests/unit-tests/graphics/mesa/test_display.cpp'
234--- tests/unit-tests/graphics/mesa/test_display.cpp 2014-06-23 16:29:17 +0000
235+++ tests/unit-tests/graphics/mesa/test_display.cpp 2014-07-29 12:29:39 +0000
236@@ -56,7 +56,7 @@
237 namespace ml=mir::logging;
238 namespace mrl=mir::report::logging;
239 namespace mtd=mir::test::doubles;
240-namespace mtf=mir::mir_test_framework;
241+namespace mtf=mir_test_framework;
242 namespace mr=mir::report;
243
244 namespace
245
246=== modified file 'tests/unit-tests/graphics/mesa/test_display_buffer.cpp'
247--- tests/unit-tests/graphics/mesa/test_display_buffer.cpp 2014-06-06 18:54:00 +0000
248+++ tests/unit-tests/graphics/mesa/test_display_buffer.cpp 2014-07-29 12:29:39 +0000
249@@ -38,7 +38,7 @@
250 using namespace std;
251 using namespace mir::test;
252 using namespace mir::test::doubles;
253-using namespace mir::mir_test_framework;
254+using namespace mir_test_framework;
255 using namespace mir::graphics;
256 using mir::report::null_display_report;
257
258
259=== modified file 'tests/unit-tests/graphics/mesa/test_display_configuration.cpp'
260--- tests/unit-tests/graphics/mesa/test_display_configuration.cpp 2014-06-06 07:56:34 +0000
261+++ tests/unit-tests/graphics/mesa/test_display_configuration.cpp 2014-07-29 12:29:39 +0000
262@@ -43,7 +43,7 @@
263 namespace mgm = mir::graphics::mesa;
264 namespace geom = mir::geometry;
265 namespace mtd = mir::test::doubles;
266-namespace mtf = mir::mir_test_framework;
267+namespace mtf = mir_test_framework;
268
269 namespace
270 {
271
272=== modified file 'tests/unit-tests/graphics/mesa/test_display_multi_monitor.cpp'
273--- tests/unit-tests/graphics/mesa/test_display_multi_monitor.cpp 2014-06-06 07:56:34 +0000
274+++ tests/unit-tests/graphics/mesa/test_display_multi_monitor.cpp 2014-07-29 12:29:39 +0000
275@@ -41,7 +41,7 @@
276 namespace mg = mir::graphics;
277 namespace geom = mir::geometry;
278 namespace mtd = mir::test::doubles;
279-namespace mtf = mir::mir_test_framework;
280+namespace mtf = mir_test_framework;
281
282 namespace
283 {
284
285=== modified file 'tests/unit-tests/graphics/mesa/test_drm_helper.cpp'
286--- tests/unit-tests/graphics/mesa/test_drm_helper.cpp 2014-02-26 12:25:09 +0000
287+++ tests/unit-tests/graphics/mesa/test_drm_helper.cpp 2014-07-29 12:29:39 +0000
288@@ -28,7 +28,7 @@
289 #include <gmock/gmock.h>
290
291 namespace mgm = mir::graphics::mesa;
292-namespace mtf = mir::mir_test_framework;
293+namespace mtf = mir_test_framework;
294 namespace mtd = mir::test::doubles;
295
296 namespace
297
298=== modified file 'tests/unit-tests/graphics/mesa/test_gbm_buffer.cpp'
299--- tests/unit-tests/graphics/mesa/test_gbm_buffer.cpp 2014-06-06 07:56:34 +0000
300+++ tests/unit-tests/graphics/mesa/test_gbm_buffer.cpp 2014-07-29 12:29:39 +0000
301@@ -41,7 +41,7 @@
302 namespace mgm=mir::graphics::mesa;
303 namespace geom=mir::geometry;
304 namespace mtd=mir::test::doubles;
305-namespace mtf=mir::mir_test_framework;
306+namespace mtf=mir_test_framework;
307
308 class GBMBufferTest : public ::testing::Test
309 {
310
311=== modified file 'tests/unit-tests/graphics/mesa/test_platform.cpp'
312--- tests/unit-tests/graphics/mesa/test_platform.cpp 2014-07-23 11:08:59 +0000
313+++ tests/unit-tests/graphics/mesa/test_platform.cpp 2014-07-29 12:29:39 +0000
314@@ -49,7 +49,7 @@
315 namespace mg = mir::graphics;
316 namespace mgm = mir::graphics::mesa;
317 namespace mtd = mir::test::doubles;
318-namespace mtf = mir::mir_test_framework;
319+namespace mtf = mir_test_framework;
320
321 namespace
322 {
323
324=== modified file 'tests/unit-tests/graphics/test_display.cpp'
325--- tests/unit-tests/graphics/test_display.cpp 2014-06-06 18:54:00 +0000
326+++ tests/unit-tests/graphics/test_display.cpp 2014-07-29 12:29:39 +0000
327@@ -44,7 +44,7 @@
328 namespace mg = mir::graphics;
329 namespace mtd = mir::test::doubles;
330 #ifndef ANDROID
331-namespace mtf = mir::mir_test_framework;
332+namespace mtf = mir_test_framework;
333 #endif
334
335 class DisplayTest : public ::testing::Test
336
337=== modified file 'tests/unit-tests/graphics/test_graphics_platform.cpp'
338--- tests/unit-tests/graphics/test_graphics_platform.cpp 2014-06-06 07:56:34 +0000
339+++ tests/unit-tests/graphics/test_graphics_platform.cpp 2014-07-29 12:29:39 +0000
340@@ -42,7 +42,7 @@
341 namespace mtd = mir::test::doubles;
342 namespace mo = mir::options;
343 #ifndef ANDROID
344-namespace mtf = mir::mir_test_framework;
345+namespace mtf = mir_test_framework;
346 #endif
347
348 class GraphicsPlatform : public ::testing::Test
349
350=== modified file 'tests/unit-tests/input/test_xcursor_loader.cpp'
351--- tests/unit-tests/input/test_xcursor_loader.cpp 2014-06-19 23:40:22 +0000
352+++ tests/unit-tests/input/test_xcursor_loader.cpp 2014-07-29 12:29:39 +0000
353@@ -19,6 +19,7 @@
354 #include "src/server/input/xcursor_loader.h"
355
356 #include "mir/graphics/cursor_image.h"
357+#include "mir_test_framework/executable_path.h"
358
359 #include <mir_toolkit/common.h>
360
361@@ -55,6 +56,12 @@
362 return raw_argb_is_only_pixel(raw_argb, size, pixel);
363 }
364
365+MATCHER(HasLoaded, "cursor image has loaded and is not nullptr."\
366+ " Test expects cursor images to be installed to the directory the test is ran from")
367+{
368+ return arg != nullptr;
369+}
370+
371 MATCHER(IsSolidRed, "")
372 {
373 return cursor_image_is_solid_color(arg, 0xffff0000);
374@@ -81,10 +88,8 @@
375 char const* old = getenv("XCURSOR_PATH");
376 if (old)
377 old_xcursor_path = strdup(old);
378- setenv("XCURSOR_PATH",
379- // Defined by CMake
380- MIR_TESTING_XCURSOR_THEME,
381- 1);
382+ auto test_cursor_path =mir_test_framework::executable_path() + std::string("/testing-cursor-theme");
383+ setenv("XCURSOR_PATH", test_cursor_path.c_str(), 1);
384 }
385
386 void restore_xcursor_path()
387@@ -109,6 +114,9 @@
388 auto blue_image = loader.image("blue", size);
389 auto green_image = loader.image("green", size);
390
391+ ASSERT_THAT(red_image, HasLoaded());
392+ ASSERT_THAT(green_image, HasLoaded());
393+ ASSERT_THAT(blue_image, HasLoaded());
394 EXPECT_THAT(red_image, IsSolidRed());
395 EXPECT_THAT(green_image, IsSolidGreen());
396 EXPECT_THAT(blue_image, IsSolidBlue());
397@@ -136,6 +144,7 @@
398
399 // The testing theme uses a solid black image for the "arrow" symbolic
400 // name.
401+ ASSERT_THAT(arrow_image, HasLoaded());
402 EXPECT_THAT(arrow_image, IsSolidBlack());
403
404 restore_xcursor_path();
405
406=== modified file 'tests/unit-tests/test_udev_wrapper.cpp'
407--- tests/unit-tests/test_udev_wrapper.cpp 2014-03-13 07:47:55 +0000
408+++ tests/unit-tests/test_udev_wrapper.cpp 2014-07-29 12:29:39 +0000
409@@ -31,7 +31,7 @@
410 #include <libudev.h>
411 #include <poll.h>
412
413-namespace mtf=mir::mir_test_framework;
414+namespace mtf=mir_test_framework;
415
416 namespace
417 {

Subscribers

People subscribed via source and target branches