Merge lp:~cyphermox/dbus-cpp/autopkgtests into lp:dbus-cpp

Proposed by Mathieu Trudel-Lapierre on 2014-10-28
Status: Approved
Approved by: Mathieu Trudel-Lapierre on 2014-10-29
Approved revision: 84
Proposed branch: lp:~cyphermox/dbus-cpp/autopkgtests
Merge into: lp:dbus-cpp
Prerequisite: lp:~thomas-voss/dbus-cpp/fix-1361642
Diff against target: 307 lines (+263/-0)
7 files modified
debian/changelog (+7/-0)
debian/control (+1/-0)
debian/tests/control (+3/-0)
debian/tests/dbus-cpp_get_prop.cpp (+103/-0)
debian/tests/property_test_timeout (+58/-0)
debian/tests/property_tests (+5/-0)
debian/tests/tests_dbus_prop_server.py (+86/-0)
To merge this branch: bzr merge lp:~cyphermox/dbus-cpp/autopkgtests
Reviewer Review Type Date Requested Status
Sergio Schvezov 2014-10-28 Approve on 2014-10-28
PS Jenkins bot continuous-integration Approve on 2014-10-28
Review via email: mp+239875@code.launchpad.net

Commit message

Add autopkgtests to test the fix for bug 1361642.

Description of the change

Add autopkgtests to test the fix for bug 1361642.

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

Added a couple of inline comments.

I also thing you should add an autopackage test to the app you use that depends on this using the timeout you require.

review: Needs Information
Mathieu Trudel-Lapierre (cyphermox) wrote :

Responded to the comments.

I don't understand what you mean by adding an autopkgtest to the app I use. This is a generic test that affects any user of dbus-cpp, so it makes sense for it to be in dbus-cpp -- usually apps built with dbus-cpp don't really expect any specific delay.

lp:~cyphermox/dbus-cpp/autopkgtests updated on 2014-10-28
84. By Mathieu Trudel-Lapierre on 2014-10-28

Ensure the property test server is always killed on cleanup.

Sergio Schvezov (sergiusens) wrote :

When I run
sudo adt-run dbus-cpp_4.0.0+14.10.20141006-0ubuntu2.dsc --- lxc adt-utopic

I get:
(dbus-test-runner:3174): libdbustest-WARNING **: Unable to start process './debian/tests/property_test_timeout': Failed to execute child process "./debian/tests/property_test_timeout" (Permission denied)

And when I run
adt-run dbus-cpp_4.0.0+14.10.20141006-0ubuntu2.dsc --- qemu --ram-size=4096 ~/images/adt-utopic-amd64-cloud.img

I get:
qemu: terminating on signal 15 from pid 12847

which is probably something wrong with qemu itself.

Mathieu Trudel-Lapierre (cyphermox) wrote :

It works just fine here. Why are you using lxc instead of qemu? It works quite well here even without specifying any kind of different ram size.

Sergio Schvezov (sergiusens) wrote :
review: Approve
Dimitri John Ledkov (xnox) wrote :

is this going to land?

Unmerged revisions

84. By Mathieu Trudel-Lapierre on 2014-10-28

Ensure the property test server is always killed on cleanup.

83. By Mathieu Trudel-Lapierre on 2014-10-28

Enable the tests for delays >= 1 second.

82. By Mathieu Trudel-Lapierre on 2014-10-28

debian/control, debian/tests: added autopkgtests for property retrieval
(and by extension, for building an app using dbus-cpp). Tests bug 1361642.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2014-10-06 15:55:54 +0000
3+++ debian/changelog 2014-10-28 15:57:52 +0000
4@@ -1,3 +1,10 @@
5+dbus-cpp (4.0.0+14.10.20141006-0ubuntu2) UNRELEASED; urgency=medium
6+
7+ * debian/control, debian/tests: added autopkgtests for property retrieval
8+ (and by extension, for building an app using dbus-cpp). Tests bug 1361642.
9+
10+ -- Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Tue, 28 Oct 2014 09:47:05 -0400
11+
12 dbus-cpp (4.0.0+14.10.20141006-0ubuntu1) utopic; urgency=low
13
14 [ thomas-voss ]
15
16=== modified file 'debian/control'
17--- debian/control 2014-06-17 09:36:53 +0000
18+++ debian/control 2014-10-28 15:57:52 +0000
19@@ -25,6 +25,7 @@
20 # just go ahead. ~phablet-team will notice and sync up the code again.
21 Vcs-Bzr: https://code.launchpad.net/~phablet-team/dbus-cpp/trunk
22 Vcs-Browser: http://bazaar.launchpad.net/~phablet-team/dbus-cpp/trunk/files
23+XS-Testsuite: autopkgtest
24
25 Package: libdbus-cpp4
26 Section: libdevel
27
28=== added directory 'debian/tests'
29=== added file 'debian/tests/control'
30--- debian/tests/control 1970-01-01 00:00:00 +0000
31+++ debian/tests/control 2014-10-28 15:57:52 +0000
32@@ -0,0 +1,3 @@
33+Tests: property_tests
34+Depends: libdbus-cpp-dev, libproperties-cpp-dev, libdbus-1-dev, python3, python3-dbus, python3-gi, gir1.2-glib-2.0, dbus-test-runner, build-essential, pkg-config
35+
36
37=== added file 'debian/tests/dbus-cpp_get_prop.cpp'
38--- debian/tests/dbus-cpp_get_prop.cpp 1970-01-01 00:00:00 +0000
39+++ debian/tests/dbus-cpp_get_prop.cpp 2014-10-28 15:57:52 +0000
40@@ -0,0 +1,103 @@
41+/*
42+ * Copyright © 2013 Canonical Ltd.
43+ *
44+ * This program is free software: you can redistribute it and/or modify it
45+ * under the terms of the GNU Lesser General Public License version 3,
46+ * as published by the Free Software Foundation.
47+ *
48+ * This program is distributed in the hope that it will be useful,
49+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
50+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51+ * GNU Lesser General Public License for more details.
52+ *
53+ * You should have received a copy of the GNU Lesser General Public License
54+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
55+ *
56+ * Authored by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
57+ */
58+
59+#include <iostream>
60+
61+#include <core/dbus/bus.h>
62+#include <core/dbus/object.h>
63+#include <core/dbus/property.h>
64+#include <core/dbus/service.h>
65+
66+#include <core/dbus/asio/executor.h>
67+#include <core/dbus/types/stl/tuple.h>
68+#include <core/dbus/types/stl/vector.h>
69+#include <core/dbus/types/struct.h>
70+
71+#include <sys/types.h>
72+#include <signal.h>
73+
74+namespace dbus = core::dbus;
75+
76+namespace core
77+{
78+dbus::Bus::Ptr the_session_bus()
79+{
80+ static dbus::Bus::Ptr session_bus = std::make_shared<dbus::Bus>(dbus::WellKnownBus::session);
81+ return session_bus;
82+}
83+
84+struct Foo
85+{
86+ struct Properties
87+ {
88+ struct Bar
89+ {
90+ inline static std::string name()
91+ {
92+ return "Bar";
93+ };
94+ typedef Foo Interface;
95+ typedef std::string ValueType;
96+ static const bool readable = true;
97+ static const bool writable = false;
98+ };
99+
100+ };
101+};
102+}
103+
104+namespace core
105+{
106+namespace dbus
107+{
108+namespace traits
109+{
110+template<>
111+struct Service<core::Foo>
112+{
113+ inline static const std::string& interface_name()
114+ {
115+ static const std::string s
116+ {
117+ "com.canonical.Foo"
118+ };
119+ return s;
120+ }
121+};
122+}
123+}
124+}
125+
126+
127+int main(int, char**)
128+{
129+ std::shared_ptr<core::dbus::Property<core::Foo::Properties::Bar> > bar;
130+ auto bus = core::the_session_bus();
131+ bus->install_executor(core::dbus::asio::make_executor(bus));
132+ std::thread t {std::bind(&dbus::Bus::run, bus)};
133+
134+ auto foo_service = dbus::Service::use_service(bus, "com.canonical.Foo");
135+ auto foo_obj = foo_service->object_for_path(dbus::types::ObjectPath("/"));
136+ bar = foo_obj->get_property<core::Foo::Properties::Bar>();
137+
138+ std::cout << "Bar: " << bar->get() << std::endl;
139+
140+ t.detach();
141+
142+ return EXIT_SUCCESS;
143+}
144
145=== added file 'debian/tests/property_test_timeout'
146--- debian/tests/property_test_timeout 1970-01-01 00:00:00 +0000
147+++ debian/tests/property_test_timeout 2014-10-28 15:57:52 +0000
148@@ -0,0 +1,58 @@
149+#!/bin/sh
150+#
151+# Copyright © 2013 Canonical Ltd.
152+#
153+# This program is free software: you can redistribute it and/or modify it
154+# under the terms of the GNU Lesser General Public License version 3,
155+# as published by the Free Software Foundation.
156+#
157+# This program is distributed in the hope that it will be useful,
158+# but WITHOUT ANY WARRANTY; without even the implied warranty of
159+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160+# GNU Lesser General Public License for more details.
161+#
162+# You should have received a copy of the GNU Lesser General Public License
163+# along with this program. If not, see <http://www.gnu.org/licenses/>.
164+#
165+# Authored by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
166+#
167+
168+set -e
169+
170+delay=$1 # seconds to delay property Get responses
171+expected="Bar: bar-response"
172+
173+echo "+++ Building the test program"
174+g++ --std=c++11 `pkg-config --cflags dbus-cpp` -o dbus-cpp_get_prop debian/tests/dbus-cpp_get_prop.cpp -lpthread `pkg-config --libs dbus-cpp`
175+
176+echo "+++ Starting the sample DBus service; response delay is $delay seconds."
177+python3 debian/tests/tests_dbus_prop_server.py $delay &
178+id=$!
179+
180+sleep 1
181+
182+# Handle the return for the dbus-cpp sample app manually.
183+set +e
184+
185+echo "+++ Running the test dbus-cpp app"
186+value=`./dbus-cpp_get_prop`
187+ret=$?
188+
189+echo "+++ Cleanup"
190+kill -9 $id
191+rm dbus-cpp_get_prop
192+
193+if [ $ret -eq 0 ]; then
194+ echo "+++ Checking the output:"
195+ echo "Expected: $expected"
196+ echo "Result: $value"
197+ if [ "$value" = "$expected" ]; then
198+ echo OK
199+ else
200+ echo FAIL
201+ return 1
202+ fi
203+else
204+ echo FAIL
205+ exit 1
206+fi
207
208=== added file 'debian/tests/property_tests'
209--- debian/tests/property_tests 1970-01-01 00:00:00 +0000
210+++ debian/tests/property_tests 2014-10-28 15:57:52 +0000
211@@ -0,0 +1,5 @@
212+#!/bin/sh
213+
214+dbus-test-runner -t ./debian/tests/property_test_timeout -p 0
215+dbus-test-runner -t ./debian/tests/property_test_timeout -p 1
216+dbus-test-runner -t ./debian/tests/property_test_timeout -p 5
217
218=== added file 'debian/tests/tests_dbus_prop_server.py'
219--- debian/tests/tests_dbus_prop_server.py 1970-01-01 00:00:00 +0000
220+++ debian/tests/tests_dbus_prop_server.py 2014-10-28 15:57:52 +0000
221@@ -0,0 +1,86 @@
222+#!/usr/bin/python3
223+#
224+# Copyright © 2013 Canonical Ltd.
225+#
226+# This program is free software: you can redistribute it and/or modify it
227+# under the terms of the GNU Lesser General Public License version 3,
228+# as published by the Free Software Foundation.
229+#
230+# This program is distributed in the hope that it will be useful,
231+# but WITHOUT ANY WARRANTY; without even the implied warranty of
232+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
233+# GNU Lesser General Public License for more details.
234+#
235+# You should have received a copy of the GNU Lesser General Public License
236+# along with this program. If not, see <http://www.gnu.org/licenses/>.
237+#
238+# Authored by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
239+#
240+
241+import sys
242+import time
243+import dbus
244+import dbus.service
245+from dbus.mainloop.glib import DBusGMainLoop
246+
247+from gi.repository import GLib
248+
249+MY_INTERFACE = 'com.canonical.Foo'
250+
251+main_loop = GLib.MainLoop()
252+
253+class Foo(dbus.service.Object):
254+
255+ def __init__(self, wait):
256+ self.wait = wait
257+ bus_name = dbus.service.BusName(MY_INTERFACE, bus=dbus.SessionBus())
258+ dbus.service.Object.__init__(self, bus_name, '/')
259+
260+ @dbus.service.method(dbus.PROPERTIES_IFACE,
261+ in_signature='ss', out_signature='v')
262+ def Get(self, interface_name, property_name):
263+ return self.GetAll(interface_name)[property_name]
264+
265+ @dbus.service.method(dbus.PROPERTIES_IFACE,
266+ in_signature='s', out_signature='a{sv}')
267+ def GetAll(self, interface_name):
268+ time.sleep(self.wait)
269+ if interface_name == MY_INTERFACE:
270+ return {
271+ 'Foo': "foo-response",
272+ 'Bar': "bar-response",
273+ }
274+ else:
275+ raise dbus.exceptions.DBusException(
276+ 'com.example.UnknownInterface',
277+ 'The Foo object does not implement the %s interface'
278+ % interface_name)
279+
280+ @dbus.service.method(dbus.PROPERTIES_IFACE,
281+ in_signature='ssv')
282+ def Set(self, interface_name, property_name, new_value):
283+ # validate the property name and value, update internal state…
284+ time.sleep(self.wait)
285+ self.PropertiesChanged(interface_name,
286+ { property_name: new_value }, [])
287+
288+ @dbus.service.signal(dbus.PROPERTIES_IFACE,
289+ signature='sa{sv}as')
290+ def PropertiesChanged(self, interface_name, changed_properties,
291+ invalidated_properties):
292+ pass
293+
294+def end_service():
295+ main_loop.quit()
296+
297+DBusGMainLoop(set_as_default=True)
298+GLib.timeout_add_seconds(30, end_service)
299+wait = 0
300+if (len(sys.argv) > 1):
301+ if (float(sys.argv[1])):
302+ wait = float(sys.argv[1])
303+myservice = Foo(wait)
304+try:
305+ main_loop.run()
306+except:
307+ pass

Subscribers

People subscribed via source and target branches