Mir

Merge lp:~kdub/mir/device-detection into lp:mir

Proposed by Kevin DuBois
Status: Merged
Merged at revision: 1648
Proposed branch: lp:~kdub/mir/device-detection
Merge into: lp:mir
Diff against target: 456 lines (+267/-0)
13 files modified
CMakeLists.txt (+1/-0)
cmake/FindAndroidProperties.cmake (+22/-0)
debian/control (+1/-0)
include/test/mir_test/android_device_detection.h (+36/-0)
src/platform/graphics/android/CMakeLists.txt (+3/-0)
src/platform/graphics/android/device_detector.cpp (+49/-0)
src/platform/graphics/android/device_detector.h (+68/-0)
tests/integration-tests/client/test_client_render.cpp (+5/-0)
tests/integration-tests/graphics/android/test_buffer_integration.cpp (+4/-0)
tests/integration-tests/graphics/android/test_display_integration.cpp (+2/-0)
tests/integration-tests/graphics/android/test_internal_client.cpp (+2/-0)
tests/unit-tests/graphics/android/CMakeLists.txt (+1/-0)
tests/unit-tests/graphics/android/test_device_detection.cpp (+73/-0)
To merge this branch: bzr merge lp:~kdub/mir/device-detection
Reviewer Review Type Date Requested Status
Alberto Aguirre (community) Abstain
Daniel van Vugt Needs Information
Alexandros Frantzis (community) Approve
Alan Griffiths Abstain
PS Jenkins bot (community) continuous-integration Approve
Chris Halse Rogers Needs Information
Review via email: mp+210292@code.launchpad.net

Commit message

Skip tests at runtime if the tests are being ran on a device without android hardware. This adds libandroid-properites1 as an android dependency.

Description of the change

Skip tests at runtime if the tests are being ran on a device without android hardware.

This adds libandroid-properites1 as a dependency, which is available is already in the system image for the phone images. This library will give the device name, (manta, mako, etc), or give back no device name if we're not on a ubuntu-touch device.

I figured its useful in the production code so android can log/blacklist/insert quirks based on the device name. I eventually want to log all the properties set, as they can effect driver behavior.

nb.
android has global settings stored in a properties cache (check it out with getprop/setprop). Because surfaceflinger is not configurable to the degree the driver vendors would like, oftentimes the property cache is used to specify different driver behavior (like swapinterval, number of overlays, etc). I'd like to avoid wading into setting the properties cache in mir, but being able to log the settings is useful for debug.

To post a comment you must log in.
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
Chris Halse Rogers (raof) wrote :

Is there some particular reason that you're manually adding a dependency on libandroid-properties1 to the platform-android package? The dpkg shlibs handling should pick this up automatically for you (if not, it's likely a bug in libandroid-properties-dev).

There's a lot of “char const[]” which are marked as static for no reason that's obvious to me. They're also explicitly sized to PROP_NAME_MAX, even though some of them are known to fit in smaller array - I presume this is because of some bizzare Android API?

If the buffers really need to be of size PROP_NAME_MAX, maybe this is a good time to use std::array? AFAIK annotating the formal parameters with an array size is only for API reference; it's entirely ignored by the compiler.

review: Needs Information
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

94 + std::cout << "WARNING: test skipped due to lack of android drivers on system\n"; \

It seems inelegant to write directly to cout and not use the gtest output formatting but the latter appears to only be extensible when using XML output.

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

@Chris, good points, addressed.
@Alan, I didn't find a quick way to output using gtest's formatting either, will look some more though

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

~~~
155+int mga::PropertiesOps::property_get(
156+ char const key[PROP_NAME_MAX],
157+ char value[PROP_VALUE_MAX],
158+ char const default_value[PROP_VALUE_MAX]) const
159+{
160+ return ::property_get(key, value, default_value);
161+}
~~~

why not:
std::string mga::PropertiesOps::property_get(std::string const& key, std::string const &default)
{
    char value[PROP_VALUE_MAX] = {'\0'};
    ::property_get(key.c_str(), value, default_value.c_str());
    value[PROP_VALUE_MAX - 1] = '\0';
    return std::string{value};
}

or return a std::pair<int, std::string> if you really want to check the return code of ::property_get.

~~~
165+ static char const key[PROP_NAME_MAX] = "ro.product.device";
166+ static char const default_value[PROP_VALUE_MAX] = "";
167+ static char value[PROP_VALUE_MAX] = "";
168+ properties.property_get(key, value, default_value);
169+ device_name_ = std::string{value};
170+ android_device_present_ = !(device_name_ == std::string{default_value});
~~~

Given above comment, then this can turn into:

std::string default_value{""};
device_name_ = properties.property_get("ro.product.device", default_value);
android_device_present_ = device_name_ != default_value;

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
Alan Griffiths (alan-griffiths) wrote :

I can't help feeling that this approach is mildly wrong.

A test passing should mean one thing: that the code passes the test.

What we have here is a test passing indicates either that the test "decided" to pass without because of the environment or that the code passed the test.

The decision of whether a test is appropriate to the environment doesn't belong in the test execution - it should be determined before the test ever runs. And tests that are inappropriate shouldn't be run.

But that is probably significantly more work.

review: Abstain
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

I agree this is not ideal (passing a test that we really just want to skip), but unfortunately googletest doesn't offer a straightforward way to achieve runtime skipping.

One suggestion I have found online is to detect whether we want to skip some tests when calling the test main() function, and pass the appropriate --gtest_filter pattern to the googletest init function. Unfortunately this is not ideal either, since it moves the skip logic away from the tests themselves.

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

@Alan, Alexandros

Like Alexandros mentions, the only things I could find for a more-integrated-with-gtest approach were to wade
into the gtest and the test's main function, which seemed quite a heavyweight solution.

@Alberto,
The point of the class is to be a lightweight, untested wrapper to facilitate easy testing of the class that is doing the logic. I want to keep it a 1-1 function signature match to keep it simple and keep bugs out of code that's tough to test (because of C linkage)

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Looks good other than:

(1) I'm concerned that we're making it harder to port Mir to other distros (which probably don't have Android packages):
  -- checking for module 'libandroid-properties'
  -- package 'libandroid-properties' not found
  CMake Error at /usr/share/cmake-2.8/Modules/FindPkgConfig.cmake:283 (message):
    A required package was not found

Although that problem pre-dates this proposal, I'm wondering if there's a way to soften that requirement and be more flexible than: find_package(AndroidProperties REQUIRED)

review: Needs Information
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> @Alberto,
> The point of the class is to be a lightweight, untested wrapper to facilitate
> easy testing of the class that is doing the logic. I want to keep it a 1-1
> function signature match to keep it simple and keep bugs out of code that's
> tough to test (because of C linkage)

Then why wrap the api at all then? If you are going to wrap it, you might as well make it a bit nicer to call.

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

Alan's point about 'reporting success when there it was merely skipped' is concerning to me to...

I'll table this until we see if this
https://code.launchpad.net/~afrantzis/mir/no-display-hw-tests-on-armhf-package-builds/+merge/212122
lands (as just passing the builders is the pressing issue):

Accessing this library is useful though for gathering debug information and potentially modifying driver configuration by setting different property keys so the MP would just drop the SKIP_IF_NO_ANDROID_HARDWARE_PRESENT parts

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

> concerning to me to...
to me too

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-03-06 06:05:17 +0000
3+++ CMakeLists.txt 2014-03-12 00:59:01 +0000
4@@ -122,6 +122,7 @@
5 find_package(GFlags REQUIRED)
6 find_package(XKBCOMMON REQUIRED)
7 find_package(LTTngUST REQUIRED)
8+find_package(AndroidProperties REQUIRED)
9 pkg_check_modules(UDEV REQUIRED libudev)
10
11 include_directories (${GLESv2_INCLUDE_DIRS})
12
13=== added file 'cmake/FindAndroidProperties.cmake'
14--- cmake/FindAndroidProperties.cmake 1970-01-01 00:00:00 +0000
15+++ cmake/FindAndroidProperties.cmake 2014-03-12 00:59:01 +0000
16@@ -0,0 +1,22 @@
17+# Variables defined by this module:
18+# ANDROID_PROPERTIES_FOUND
19+# ANDROID_PROPERTIES_LIBRARIES
20+# ANDROID_PROPERTIES_INCLUDE_DIRS
21+
22+INCLUDE(FindPackageHandleStandardArgs)
23+
24+find_package( PkgConfig )
25+pkg_check_modules(ANDROID_PROPERTIES REQUIRED libandroid-properties)
26+
27+find_path(ANDROID_PROPERTIES_INCLUDE_DIR hybris/properties/properties.h
28+ HINTS ${PC_ANDROID_PROPERTIES_INCLUDEDIR} ${PC_ANDROID_PROPERTIES_INCLUDE_DIRS})
29+find_library(ANDROID_PROPERTIES_LIBRARIES
30+ NAMES libandroid-properties.so
31+ HINTS ${PC_ANDROID_PROPERTIES_LIBDIR} ${PC_ANDROID_PROPERTIES_LIBRARY_DIRS})
32+
33+# handle the QUIETLY and REQUIRED arguments and set ANDROID_PROPERTIES_FOUND to TRUE
34+# if all listed variables are TRUE
35+find_package_handle_standard_args(ANDROID_PROPERTIES DEFAULT_MSG
36+ ANDROID_PROPERTIES_LIBRARIES)
37+
38+mark_as_advanced(ANDROID_PROPERTIES_INCLUDE_DIR ANDROID_PROPERTIES_LIBRARY )
39
40=== modified file 'debian/control'
41--- debian/control 2014-03-07 03:15:55 +0000
42+++ debian/control 2014-03-12 00:59:01 +0000
43@@ -28,6 +28,7 @@
44 pkg-config,
45 android-headers (>=4.2.2) [i386 amd64 armhf],
46 libhardware-dev [i386 amd64 armhf],
47+ libandroid-properties-dev,
48 libgoogle-glog-dev,
49 liblttng-ust-dev,
50 libxkbcommon-dev,
51
52=== added file 'include/test/mir_test/android_device_detection.h'
53--- include/test/mir_test/android_device_detection.h 1970-01-01 00:00:00 +0000
54+++ include/test/mir_test/android_device_detection.h 2014-03-12 00:59:01 +0000
55@@ -0,0 +1,36 @@
56+/*
57+ * Copyright © 2014 Canonical Ltd.
58+ *
59+ * This program is free software: you can redistribute it and/or modify it
60+ * under the terms of the GNU General Public License version 3,
61+ * as published by the Free Software Foundation.
62+ *
63+ * This program is distributed in the hope that it will be useful,
64+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
65+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66+ * GNU General Public License for more details.
67+ *
68+ * You should have received a copy of the GNU General Public License
69+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
70+ *
71+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
72+ */
73+
74+#ifndef MIR_TEST_ANDROID_DEVICE_DETECTION_H_
75+#define MIR_TEST_ANDROID_DEVICE_DETECTION_H_
76+
77+#include "src/platform/graphics/android/device_detector.h"
78+#include <gtest/gtest.h>
79+#include <iostream>
80+
81+#define SKIP_IF_NO_ANDROID_HARDWARE_PRESENT() \
82+ mir::graphics::android::PropertiesOps ops; \
83+ mir::graphics::android::DeviceDetector detector{ops}; \
84+ if(!detector.android_device_present()) \
85+ { \
86+ std::cout << "WARNING: test skipped due to lack of android drivers on system\n"; \
87+ SUCCEED(); \
88+ return; \
89+ }
90+
91+#endif /* MIR_TEST_ANDROID_DEVICE_DETECTION_H_ */
92
93=== modified file 'src/platform/graphics/android/CMakeLists.txt'
94--- src/platform/graphics/android/CMakeLists.txt 2014-03-11 13:44:57 +0000
95+++ src/platform/graphics/android/CMakeLists.txt 2014-03-12 00:59:01 +0000
96@@ -2,6 +2,7 @@
97 include_directories(
98 ${EGL_INCLUDE_DIRS}
99 ${GLESv2_INCLUDE_DIRS}
100+ ${ANDROID_PROPERTIES_INCLUDE_DIRS}
101 )
102
103 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
104@@ -32,6 +33,7 @@
105 interpreter_cache.cpp
106 internal_client.cpp
107 gl_context.cpp
108+ device_detector.cpp
109 real_hwc_wrapper.cpp
110 )
111
112@@ -50,6 +52,7 @@
113 ${LIBHARDWARE_LIBRARIES}
114 ${EGL_LDFLAGS} ${EGL_LIBRARIES}
115 ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES}
116+ ${ANDROID_PROPERTIES_LIBRARIES}
117 )
118
119 install(TARGETS mirplatformgraphicsandroid LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/mir/platformgraphics/android)
120
121=== added file 'src/platform/graphics/android/device_detector.cpp'
122--- src/platform/graphics/android/device_detector.cpp 1970-01-01 00:00:00 +0000
123+++ src/platform/graphics/android/device_detector.cpp 2014-03-12 00:59:01 +0000
124@@ -0,0 +1,49 @@
125+/*
126+ * Copyright © 2014 Canonical Ltd.
127+ *
128+ * This program is free software: you can redistribute it and/or modify
129+ * it under the terms of the GNU Lesser General Public License version 3 as
130+ * published by the Free Software Foundation.
131+ *
132+ * This program is distributed in the hope that it will be useful,
133+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
134+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135+ * GNU Lesser General Public License for more details.
136+ *
137+ * You should have received a copy of the GNU Lesser General Public License
138+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
139+ *
140+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
141+ */
142+
143+#include "device_detector.h"
144+
145+namespace mga=mir::graphics::android;
146+
147+int mga::PropertiesOps::property_get(
148+ char const* key,
149+ char* value,
150+ char const* default_value) const
151+{
152+ return ::property_get(key, value, default_value);
153+}
154+
155+mga::DeviceDetector::DeviceDetector(PropertiesWrapper const& properties)
156+{
157+ char const key[] = "ro.product.device";
158+ char const default_value[] = "";
159+ char value[PROP_VALUE_MAX] = "";
160+ properties.property_get(key, value, default_value);
161+ device_name_ = std::string{value};
162+ android_device_present_ = !(device_name_ == std::string{default_value});
163+}
164+
165+bool mga::DeviceDetector::android_device_present() const
166+{
167+ return android_device_present_;
168+}
169+
170+std::string mga::DeviceDetector::device_name() const
171+{
172+ return device_name_;
173+}
174
175=== added file 'src/platform/graphics/android/device_detector.h'
176--- src/platform/graphics/android/device_detector.h 1970-01-01 00:00:00 +0000
177+++ src/platform/graphics/android/device_detector.h 2014-03-12 00:59:01 +0000
178@@ -0,0 +1,68 @@
179+/*
180+ * Copyright © 2014 Canonical Ltd.
181+ *
182+ * This program is free software: you can redistribute it and/or modify
183+ * it under the terms of the GNU Lesser General Public License version 3 as
184+ * published by the Free Software Foundation.
185+ *
186+ * This program is distributed in the hope that it will be useful,
187+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
188+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
189+ * GNU Lesser General Public License for more details.
190+ *
191+ * You should have received a copy of the GNU Lesser General Public License
192+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
193+ *
194+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
195+ */
196+
197+#ifndef MIR_GRAPHICS_ANDROID_DEVICE_DETECTOR_H_
198+#define MIR_GRAPHICS_ANDROID_DEVICE_DETECTOR_H_
199+
200+#include <hybris/properties/properties.h>
201+#include <string>
202+
203+namespace mir
204+{
205+namespace graphics
206+{
207+namespace android
208+{
209+class PropertiesWrapper
210+{
211+public:
212+ PropertiesWrapper() = default;
213+ virtual ~PropertiesWrapper() = default;
214+ virtual int property_get(
215+ char const* key,
216+ char* value,
217+ char const* default_value) const = 0;
218+private:
219+ PropertiesWrapper(PropertiesWrapper const&) = delete;
220+ PropertiesWrapper& operator=(PropertiesWrapper const&) = delete;
221+};
222+
223+class PropertiesOps : public PropertiesWrapper
224+{
225+public:
226+ int property_get(
227+ char const* key,
228+ char* value,
229+ char const* default_value) const;
230+};
231+
232+class DeviceDetector
233+{
234+public:
235+ DeviceDetector(PropertiesWrapper const& properties);
236+
237+ bool android_device_present() const;
238+ std::string device_name() const;
239+private:
240+ std::string device_name_;
241+ bool android_device_present_;
242+};
243+}
244+}
245+}
246+#endif /* MIR_GRAPHICS_ANDROID_DEVICE_DETECTOR_H_ */
247
248=== modified file 'tests/integration-tests/client/test_client_render.cpp'
249--- tests/integration-tests/client/test_client_render.cpp 2014-03-06 06:05:17 +0000
250+++ tests/integration-tests/client/test_client_render.cpp 2014-03-12 00:59:01 +0000
251@@ -29,6 +29,7 @@
252 #include "testdraw/patterns.h"
253 #include "mir_test/stub_server_tool.h"
254 #include "mir_test/test_protobuf_server.h"
255+#include "mir_test/android_device_detection.h"
256
257 #include "mir/frontend/connector.h"
258
259@@ -346,6 +347,7 @@
260
261 TEST_F(TestClientIPCRender, test_render_single)
262 {
263+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
264 sync1.try_signal_ready_for();
265
266 /* wait for client to finish */
267@@ -359,6 +361,7 @@
268
269 TEST_F(TestClientIPCRender, test_render_double)
270 {
271+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
272 sync2.try_signal_ready_for();
273
274 /* wait for client to finish */
275@@ -375,6 +378,7 @@
276
277 TEST_F(TestClientIPCRender, test_accelerated_render)
278 {
279+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
280 mtd::DrawPatternSolid red_pattern(0xFF0000FF);
281
282 sync3.try_signal_ready_for();
283@@ -389,6 +393,7 @@
284
285 TEST_F(TestClientIPCRender, test_accelerated_render_double)
286 {
287+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
288 mtd::DrawPatternSolid red_pattern(0xFF0000FF);
289 mtd::DrawPatternSolid green_pattern(0xFF00FF00);
290
291
292=== modified file 'tests/integration-tests/graphics/android/test_buffer_integration.cpp'
293--- tests/integration-tests/graphics/android/test_buffer_integration.cpp 2014-03-11 13:44:57 +0000
294+++ tests/integration-tests/graphics/android/test_buffer_integration.cpp 2014-03-12 00:59:01 +0000
295@@ -23,6 +23,7 @@
296 #include "mir/graphics/android/native_buffer.h"
297 #include "mir/graphics/buffer_properties.h"
298
299+#include "mir_test/android_device_detection.h"
300 #include "testdraw/graphics_region_factory.h"
301 #include "testdraw/patterns.h"
302
303@@ -84,6 +85,7 @@
304
305 TEST_F(AndroidBufferIntegration, allocator_can_create_sw_buffer)
306 {
307+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
308 using namespace testing;
309
310 auto allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(null_buffer_initializer);
311@@ -100,6 +102,7 @@
312
313 TEST_F(AndroidBufferIntegration, allocator_can_create_hw_buffer)
314 {
315+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
316 using namespace testing;
317
318 mg::BufferProperties hw_properties{size, pf, mg::BufferUsage::hardware};
319@@ -112,6 +115,7 @@
320
321 TEST_F(AndroidBufferIntegration, swapper_creation_is_sane)
322 {
323+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
324 using namespace testing;
325
326 auto allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(null_buffer_initializer);
327
328=== modified file 'tests/integration-tests/graphics/android/test_display_integration.cpp'
329--- tests/integration-tests/graphics/android/test_display_integration.cpp 2014-03-11 13:44:57 +0000
330+++ tests/integration-tests/graphics/android/test_display_integration.cpp 2014-03-12 00:59:01 +0000
331@@ -25,6 +25,7 @@
332
333 #include "examples/graphics.h"
334 #include "mir_test_doubles/mock_display_report.h"
335+#include "mir_test/android_device_detection.h"
336
337 #include <gtest/gtest.h>
338 #include <stdexcept>
339@@ -70,6 +71,7 @@
340
341 TEST_F(AndroidDisplay, display_can_post)
342 {
343+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
344 auto mock_display_report = std::make_shared<testing::NiceMock<mtd::MockDisplayReport>>();
345 auto buffer_initializer = std::make_shared<mg::NullBufferInitializer>();
346 auto fb_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(buffer_initializer);
347
348=== modified file 'tests/integration-tests/graphics/android/test_internal_client.cpp'
349--- tests/integration-tests/graphics/android/test_internal_client.cpp 2014-03-06 06:05:17 +0000
350+++ tests/integration-tests/graphics/android/test_internal_client.cpp 2014-03-12 00:59:01 +0000
351@@ -41,6 +41,7 @@
352
353 #include "mir_test_doubles/stub_input_registrar.h"
354 #include "mir_test_doubles/null_surface_configurator.h"
355+#include "mir_test/android_device_detection.h"
356
357 #include <EGL/egl.h>
358 #include <gtest/gtest.h>
359@@ -81,6 +82,7 @@
360
361 TEST_F(AndroidInternalClient, internal_client_creation_and_use)
362 {
363+ SKIP_IF_NO_ANDROID_HARDWARE_PRESENT();
364 auto size = geom::Size{334, 122};
365 auto pf = mir_pixel_format_abgr_8888;
366 msh::SurfaceCreationParameters params;
367
368=== modified file 'tests/unit-tests/graphics/android/CMakeLists.txt'
369--- tests/unit-tests/graphics/android/CMakeLists.txt 2014-03-11 13:44:57 +0000
370+++ tests/unit-tests/graphics/android/CMakeLists.txt 2014-03-12 00:59:01 +0000
371@@ -24,6 +24,7 @@
372 ${CMAKE_CURRENT_SOURCE_DIR}/test_interpreter_buffer_cache.cpp
373 ${CMAKE_CURRENT_SOURCE_DIR}/test_external_refcount.cpp
374 ${CMAKE_CURRENT_SOURCE_DIR}/test_output_builder.cpp
375+ ${CMAKE_CURRENT_SOURCE_DIR}/test_device_detection.cpp
376 ${CMAKE_CURRENT_SOURCE_DIR}/test_hwc_wrapper.cpp
377 )
378
379
380=== added file 'tests/unit-tests/graphics/android/test_device_detection.cpp'
381--- tests/unit-tests/graphics/android/test_device_detection.cpp 1970-01-01 00:00:00 +0000
382+++ tests/unit-tests/graphics/android/test_device_detection.cpp 2014-03-12 00:59:01 +0000
383@@ -0,0 +1,73 @@
384+/*
385+ * Copyright © 2014 Canonical Ltd.
386+ *
387+ * This program is free software: you can redistribute it and/or modify
388+ * it under the terms of the GNU General Public License version 3 as
389+ * published by the Free Software Foundation.
390+ *
391+ * This program is distributed in the hope that it will be useful,
392+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
393+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
394+ * GNU General Public License for more details.
395+ *
396+ * You should have received a copy of the GNU General Public License
397+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
398+ *
399+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
400+ */
401+
402+#include "src/platform/graphics/android/device_detector.h"
403+#include <gmock/gmock.h>
404+#include <gtest/gtest.h>
405+
406+namespace mga = mir::graphics::android;
407+
408+namespace
409+{
410+struct MockOps : mga::PropertiesWrapper
411+{
412+ MOCK_CONST_METHOD3(property_get, int(
413+ char const[PROP_NAME_MAX], char[PROP_VALUE_MAX], char const[PROP_VALUE_MAX]));
414+};
415+}
416+
417+TEST(DeviceDetection, detects_device)
418+{
419+ using namespace testing;
420+ char const default_str[] = "";
421+ char const name_str[] = "tunafish";
422+
423+ MockOps mock_ops;
424+ EXPECT_CALL(mock_ops, property_get(StrEq("ro.product.device"), _, StrEq(default_str)))
425+ .Times(1)
426+ .WillOnce(Invoke([&]
427+ (char const*, char* value, char const*)
428+ {
429+ strncpy(value, name_str, PROP_VALUE_MAX);
430+ return 0;
431+ }));
432+
433+ mga::DeviceDetector detector(mock_ops);
434+ EXPECT_TRUE(detector.android_device_present());
435+ EXPECT_EQ(std::string{name_str}, detector.device_name());
436+}
437+
438+TEST(DeviceDetection, does_not_detect_device)
439+{
440+ using namespace testing;
441+ char const default_str[] = "";
442+
443+ MockOps mock_ops;
444+ EXPECT_CALL(mock_ops, property_get(StrEq("ro.product.device"), _, StrEq(default_str)))
445+ .Times(1)
446+ .WillOnce(Invoke([&]
447+ (char const*, char* value, char const* default_value)
448+ {
449+ strncpy(value, default_value, PROP_VALUE_MAX);
450+ return 0;
451+ }));
452+
453+ mga::DeviceDetector detector(mock_ops);
454+ EXPECT_FALSE(detector.android_device_present());
455+ EXPECT_EQ(std::string{}, detector.device_name());
456+}

Subscribers

People subscribed via source and target branches