commit | 592128cd44aac754d4ae87950d410895a78fddd7 | [log] [tgz] |
---|---|---|
author | William A. Kennington III <wak@google.com> | Tue Jun 19 18:34:17 2018 -0700 |
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | Mon Jul 09 18:20:42 2018 +0000 |
tree | 63dc51f954fe25ebe28ccd9f2e4f5a8801458e1d | |
parent | cb582e06513764a122a0777f57fc7be1a5ae9ff1 [diff] |
tests: Add code coverage We want to be able to measure code coverage for our test cases. This patch adds initial support for measuring the coverage of all of the files in the repo when running the test cases. Simply run: `make check-code-coverage` and an lcov report will be generated NOTE: This doesn't yet add any filtering to throw out the results for system headers and tests cases, but the list of results isn't long so it is easy to see the relevant coverage results and we don't want to add any false negatives. Tested: Sdbuplus plus still builds fine without the code coverage utilities by default. sdbusplus now builds with `./configure --enable-code-coverage` and corrects the libs and cflags accordingly to enable coverage. Make then succeeds to generate a report when run with `make check-code-coverage` Change-Id: I7f640b82e771bc9043abf381d14393be54c3e672 Signed-off-by: William A. Kennington III <wak@google.com>
sdbusplus contains two parts:
The sdbusplus library requires sd-bus, which is contained in libsystemd.
The sdbus++ application requires python and the python libraries mako and py-inflection.
The sdbusplus library builds on top of the sd-bus library to create a modern C++ API for D-Bus. The library attempts to be as lightweight as possible, usually compiling to exactly the sd-bus API calls that would have been necessary, while also providing compile-time type-safety and memory leak protection afforded by modern C++ practices.
Consider the following code:
auto b = bus::new_system(); auto m = b.new_method_call("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "ListUsers"); auto reply = b.call(m); std::vector<std::tuple<uint32_t, std::string, message::object_path>> users; reply.read(users);
In a few, relatively succinct, C++ lines this snippet will create a D-Bus connection to the system bus, and call the systemd login manager to get a list of active users. The message and bus objects are automatically freed when they leave scope and the message format strings are generated at compile time based on the types being read. Compare this to the corresponding server code within logind.
In general, the library attempts to mimic the naming conventions of the sd-bus library: ex. sd_bus_call
becomes sdbusplus::bus::call
, sd_bus_get_unique_name
becomes sdbusplus::bus::get_unique_name
, sd_bus_message_get_signature
becomes sdbusplus::message::get_signature
, etc. This allows a relatively straight-forward translation back to the sd-bus functions for looking up the manpage details.
sdbusplus also contains a bindings generator tool: sdbus++
. The purpose of a bindings generator is to reduce the boilerplate associated with creating D-Bus server or client applications. When creating a server application, rather than creating sd-bus vtables and writing C-style functions to handle each vtable callback, you can create a small YAML file to define your D-Bus interface and the sdbus++
tool will create a C++ class that implements your D-Bus interface. This class has a set of virtual functions for each method and property, which you can overload to create your own customized behavior for the interface.
There are currently two types of YAML files: interface and error. Interfaces are used to create server and client D-Bus interfaces. Errors are used to define C++ exceptions which can be thrown and will automatically turn into D-Bus error responses.
[[ D-Bus client bindings are not yet implemented. See openbmc/openbmc#851. ]]
The path of your file will be the interface name. For example, for an interface org.freedesktop.Example
, you would create the files org/freedesktop/Example.interface.yaml
and org/freedesktop/Example.errors.yaml]
for interfaces and errors respectively. These can then be used to generate the server and error bindings:
sdbus++ interface server-header org.freedesktop.Example > \ org/freedesktop/Example/server.hpp sdbus++ interface server-cpp org.freedesktop.Example > \ org/freedesktop/Example/server.cpp sdbus++ error exception-header org.freedesktop.Example > \ org/freedesktop/Example/error.hpp \ sdbus++ error exception-cpp org.freedesktop.Example > \ org/freedesktop/Example/error.cpp
Markdown-based documentation can also be generated from the interface and exception files:
sdbus++ interface markdown org.freedesktop.Example > \ org/freedesktop/Example.md sdbus++ error markdown org.freedesktop.Example >> \ org/freedesktop/Example.md
See the example/Makefile.am
for more details.