[Merge] lp:~mathieu-tl/dbus-cpp/autopkgtests into lp:dbus-cpp
Mathieu Trudel-Lapierre
mathieu.tl at gmail.com
Tue Oct 28 15:56:26 UTC 2014
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.
Diff comments:
> === modified file 'debian/changelog'
> --- debian/changelog 2014-10-06 15:55:54 +0000
> +++ debian/changelog 2014-10-28 15:23:16 +0000
> @@ -1,3 +1,10 @@
> +dbus-cpp (4.0.0+14.10.20141006-0ubuntu2) UNRELEASED; urgency=medium
> +
> + * debian/control, debian/tests: added autopkgtests for property retrieval
> + (and by extension, for building an app using dbus-cpp). Tests bug 1361642.
> +
> + -- Mathieu Trudel-Lapierre <mathieu-tl at ubuntu.com> Tue, 28 Oct 2014 09:47:05 -0400
> +
> dbus-cpp (4.0.0+14.10.20141006-0ubuntu1) utopic; urgency=low
>
> [ thomas-voss ]
>
> === modified file 'debian/control'
> --- debian/control 2014-06-17 09:36:53 +0000
> +++ debian/control 2014-10-28 15:23:16 +0000
> @@ -25,6 +25,7 @@
> # just go ahead. ~phablet-team will notice and sync up the code again.
> Vcs-Bzr: https://code.launchpad.net/~phablet-team/dbus-cpp/trunk
> Vcs-Browser: http://bazaar.launchpad.net/~phablet-team/dbus-cpp/trunk/files
> +XS-Testsuite: autopkgtest
>
> Package: libdbus-cpp4
> Section: libdevel
>
> === added directory 'debian/tests'
> === added file 'debian/tests/control'
> --- debian/tests/control 1970-01-01 00:00:00 +0000
> +++ debian/tests/control 2014-10-28 15:23:16 +0000
> @@ -0,0 +1,3 @@
> +Tests: property_tests
> +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
> +
>
> === added file 'debian/tests/dbus-cpp_get_prop.cpp'
> --- debian/tests/dbus-cpp_get_prop.cpp 1970-01-01 00:00:00 +0000
> +++ debian/tests/dbus-cpp_get_prop.cpp 2014-10-28 15:23:16 +0000
> @@ -0,0 +1,103 @@
> +/*
> + * Copyright © 2013 Canonical Ltd.
> + *
> + * This program is free software: you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License version 3,
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + *
> + * Authored by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre at canonical.com>
> + */
> +
> +#include <iostream>
> +
> +#include <core/dbus/bus.h>
> +#include <core/dbus/object.h>
> +#include <core/dbus/property.h>
> +#include <core/dbus/service.h>
> +
> +#include <core/dbus/asio/executor.h>
> +#include <core/dbus/types/stl/tuple.h>
> +#include <core/dbus/types/stl/vector.h>
> +#include <core/dbus/types/struct.h>
> +
> +#include <sys/types.h>
> +#include <signal.h>
> +
> +namespace dbus = core::dbus;
> +
> +namespace core
> +{
> +dbus::Bus::Ptr the_session_bus()
> +{
> + static dbus::Bus::Ptr session_bus = std::make_shared<dbus::Bus>(dbus::WellKnownBus::session);
> + return session_bus;
> +}
> +
> +struct Foo
> +{
> + struct Properties
> + {
> + struct Bar
> + {
> + inline static std::string name()
> + {
> + return "Bar";
> + };
> + typedef Foo Interface;
> + typedef std::string ValueType;
> + static const bool readable = true;
> + static const bool writable = false;
> + };
> +
> + };
> +};
> +}
> +
> +namespace core
> +{
> +namespace dbus
> +{
> +namespace traits
> +{
> +template<>
> +struct Service<core::Foo>
> +{
> + inline static const std::string& interface_name()
> + {
> + static const std::string s
> + {
> + "com.canonical.Foo"
> + };
> + return s;
> + }
> +};
> +}
> +}
> +}
> +
> +
> +int main(int, char**)
> +{
> + std::shared_ptr<core::dbus::Property<core::Foo::Properties::Bar> > bar;
> + auto bus = core::the_session_bus();
> + bus->install_executor(core::dbus::asio::make_executor(bus));
> + std::thread t {std::bind(&dbus::Bus::run, bus)};
> +
> + auto foo_service = dbus::Service::use_service(bus, "com.canonical.Foo");
> + auto foo_obj = foo_service->object_for_path(dbus::types::ObjectPath("/"));
> + bar = foo_obj->get_property<core::Foo::Properties::Bar>();
> +
> + std::cout << "Bar: " << bar->get() << std::endl;
> +
> + t.detach();
> +
> + return EXIT_SUCCESS;
> +}
>
> === added file 'debian/tests/property_test_timeout'
> --- debian/tests/property_test_timeout 1970-01-01 00:00:00 +0000
> +++ debian/tests/property_test_timeout 2014-10-28 15:23:16 +0000
> @@ -0,0 +1,58 @@
> +#!/bin/sh
> +#
> +# Copyright © 2013 Canonical Ltd.
> +#
> +# This program is free software: you can redistribute it and/or modify it
> +# under the terms of the GNU Lesser General Public License version 3,
> +# as published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +# Authored by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre at canonical.com>
> +#
> +
> +set -e
> +
> +delay=$1 # seconds to delay property Get responses
It is.
> +expected="Bar: bar-response"
> +
> +echo "+++ Building the test program"
> +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`
> +
> +echo "+++ Starting the sample DBus service; response delay is $delay seconds."
> +python3 debian/tests/tests_dbus_prop_server.py $delay &
> +id=$!
> +
> +sleep 1
> +
> +# Handle the return for the dbus-cpp sample app manually.
> +set +e
> +
> +echo "+++ Running the test dbus-cpp app"
> +value=`./dbus-cpp_get_prop`
> +ret=$?
> +
> +echo "+++ Cleanup"
> +kill $id
> +rm dbus-cpp_get_prop
> +
> +if [ $ret -eq 0 ]; then
> + echo "+++ Checking the output:"
> + echo "Expected: $expected"
> + echo "Result: $value"
> + if [ "$value" = "$expected" ]; then
> + echo OK
> + else
> + echo FAIL
> + return 1
> + fi
> +else
> + echo FAIL
> + exit 1
> +fi
>
> === added file 'debian/tests/property_tests'
> --- debian/tests/property_tests 1970-01-01 00:00:00 +0000
> +++ debian/tests/property_tests 2014-10-28 15:23:16 +0000
> @@ -0,0 +1,5 @@
> +#!/bin/sh
> +
> +dbus-test-runner -t ./debian/tests/property_test_timeout -p 0
> +dbus-test-runner -t ./debian/tests/property_test_timeout -p 1
> +dbus-test-runner -t ./debian/tests/property_test_timeout -p 5
We could. Something to do once we've fixed the initial case, I think. For now, the top boundary isn't exactly a huge deal. 10-30 seconds is really really slow to respond to a property request.
>
> === added file 'debian/tests/tests_dbus_prop_server.py'
> --- debian/tests/tests_dbus_prop_server.py 1970-01-01 00:00:00 +0000
> +++ debian/tests/tests_dbus_prop_server.py 2014-10-28 15:23:16 +0000
> @@ -0,0 +1,86 @@
> +#!/usr/bin/python3
> +#
> +# Copyright © 2013 Canonical Ltd.
> +#
> +# This program is free software: you can redistribute it and/or modify it
> +# under the terms of the GNU Lesser General Public License version 3,
> +# as published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +# Authored by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre at canonical.com>
> +#
> +
> +import sys
> +import time
> +import dbus
> +import dbus.service
> +from dbus.mainloop.glib import DBusGMainLoop
> +
> +from gi.repository import GLib
> +
> +MY_INTERFACE = 'com.canonical.Foo'
> +
> +main_loop = GLib.MainLoop()
> +
> +class Foo(dbus.service.Object):
> +
> + def __init__(self, wait):
> + self.wait = wait
> + bus_name = dbus.service.BusName(MY_INTERFACE, bus=dbus.SessionBus())
> + dbus.service.Object.__init__(self, bus_name, '/')
> +
> + @dbus.service.method(dbus.PROPERTIES_IFACE,
> + in_signature='ss', out_signature='v')
> + def Get(self, interface_name, property_name):
> + return self.GetAll(interface_name)[property_name]
> +
> + @dbus.service.method(dbus.PROPERTIES_IFACE,
> + in_signature='s', out_signature='a{sv}')
> + def GetAll(self, interface_name):
> + time.sleep(self.wait)
> + if interface_name == MY_INTERFACE:
> + return {
> + 'Foo': "foo-response",
> + 'Bar': "bar-response",
> + }
> + else:
> + raise dbus.exceptions.DBusException(
> + 'com.example.UnknownInterface',
> + 'The Foo object does not implement the %s interface'
> + % interface_name)
> +
> + @dbus.service.method(dbus.PROPERTIES_IFACE,
> + in_signature='ssv')
> + def Set(self, interface_name, property_name, new_value):
> + # validate the property name and value, update internal state…
> + time.sleep(self.wait)
> + self.PropertiesChanged(interface_name,
> + { property_name: new_value }, [])
> +
> + @dbus.service.signal(dbus.PROPERTIES_IFACE,
> + signature='sa{sv}as')
> + def PropertiesChanged(self, interface_name, changed_properties,
> + invalidated_properties):
> + pass
> +
> +def end_service():
> + main_loop.quit()
> +
> +DBusGMainLoop(set_as_default=True)
> +GLib.timeout_add_seconds(30, end_service)
> +wait = 0
> +if (len(sys.argv) > 1):
> + if (float(sys.argv[1])):
> + wait = float(sys.argv[1])
> +myservice = Foo(wait)
> +try:
> + main_loop.run()
> +except:
> + pass
>
--
https://code.launchpad.net/~mathieu-tl/dbus-cpp/autopkgtests/+merge/239875
Your team Ubuntu Phablet Team is subscribed to branch lp:dbus-cpp.
More information about the Ubuntu-reviews
mailing list