From a1644e21eb0a5c424f629b66b80052b860f245c5 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Thu, 18 Jan 2024 13:43:39 +1030 Subject: [PATCH 1/2] meson: Specify the pytest test case as depending on test-mctpd Otherwise `meson setup build && meson test -C build` fails as test-mctpd isn't present in the dependency graph. Signed-off-by: Andrew Jeffery --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index 02c714a..8c5a90f 100644 --- a/meson.build +++ b/meson.build @@ -84,6 +84,7 @@ pytest = find_program('pytest', required: false) if pytest.found() test('test-mctpd', pytest, + depends: mctpd_test, args: '--tap', protocol: 'tap', ) From 77d17147e40a4b5cdfab905105d370c83d4805f6 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Wed, 17 Jan 2024 16:45:24 +1030 Subject: [PATCH 2/2] github: Implement CI as a pull-request workflow Run the tests under their own bus session to isolate them from the rest of the test environment Signed-off-by: Andrew Jeffery --- .github/workflows/pr.yml | 27 +++++++++++++++++++++++ CHANGELOG.md | 6 +++++ meson.build | 47 +++++++++++++++++++++++++++++++++++----- meson_options.txt | 1 + tests/test-proto.h | 3 ++- 5 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..b181cfc --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,27 @@ +name: pull-request-ci +on: [push, pull_request] +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install system build dependencies + run: > + sudo apt-get update && + sudo apt-get install libsystemd-dev ninja-build + + - name: Install meson + run: pip install --user meson + + - name: Install python dependencies for mctp tests + run: pip install --user -r tests/requirements.txt + + - name: Configure mctp build + run: meson setup build + + - name: Build mctp + run: meson compile -C build + + - name: Test mctp + run: meson test -C build diff --git a/CHANGELOG.md b/CHANGELOG.md index 53de778..55ffafb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,4 +17,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). 1. dbus interface: the NetworkID field is now a `u` rather than an `i`, to match OpenBMC's MCTP endpoint specification +2. Use Github Actions for CI + + Note that this bumps the meson requirement from >=0.47.0 to >=0.59.0. The + bump allows us to exploit some features helpful for chaining the solution + together. + ## [1.1] - 2023-04-13 diff --git a/meson.build b/meson.build index 8c5a90f..95aaf97 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ # project( 'mctp', 'c', - meson_version: '>= 0.47.0', + meson_version: '>= 0.59.0', version: 'v1.1', license: 'GPLv2', default_options: [ @@ -11,6 +11,7 @@ project( ) cc = meson.get_compiler('c') + add_project_arguments('-Wno-unused-parameter', language : 'c') libsystemd = dependency('libsystemd', version: '>=247', required: false) @@ -80,12 +81,46 @@ configure_file( configuration: test_conf_data, ) -pytest = find_program('pytest', required: false) - -if pytest.found() - test('test-mctpd', pytest, +tests = get_option('tests') +if tests.allowed() + # The test suite contains integration-style tests that we wish to isolate. + # The tests drive mctpd's D-Bus interfaces and navigate relevant code paths + # by mocking kernel and MCTP device behaviour. The mock behaviours are + # implemented by encapsulating netlink and MCTP messages over Unix domain + # sockets bound to mock implementations in the test suite. + # + # Isolate the test suite under its own D-Bus session to prevent test + # behaviours impacting applications connected to the usual buses. To + # implement the isolation we need to work under some constraints: + # + # 1. mctpd's implementation connects to a bus by invoking `sd_bus_default()`, + # which uses a combination of environment variables and session + # properties to determine whether to connect to the system bus or the + # session bus + # + # 2. dbus-run-session configures an isolated session bus and controls the + # relevant environment variables for influencing the application to + # connect to this isolated bus instance. + # + # `sd_bus_default()` selects the system bus if the application is + # not running in a systemd user slice. From experience, in a Github + # Action environment the system bus is selected by `sd_bus_default()`, + # implying that they aren't exploiting systemd slices. However, + # `sd_bus_default()` can be influenced to select the user session by setting + # `DBUS_STARTER_BUS_TYPE=user` in the environment. At this point with a + # naive approach we run up against 2, where `dbus-run-session` sanitises + # that configuration away + # + # Invoke pytest via a shell script under `dbus-run-session` so we can + # override the sanitation of `DBUS_STARTER_BUS_TYPE`, ensuring `test-mctpd` + # connects to the isolated session bus prepared by `dbus-run-session`. + pytest = find_program('pytest', required: tests) + script = 'export DBUS_STARTER_BUS_TYPE=user ; @0@ --tap'.format(pytest.full_path()) + sh = find_program('sh', required: tests) + dbus_run_session = find_program('dbus-run-session', required: tests) + test('test-mctpd', dbus_run_session, depends: mctpd_test, - args: '--tap', + args: [ sh.full_path(), '-c', script ], protocol: 'tap', ) endif diff --git a/meson_options.txt b/meson_options.txt index 57c4e80..b41cb7e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -3,3 +3,4 @@ option('unsafe-writable-connectivity', type: 'boolean', value: false, description: 'Allow writes to the Connectivity member of the au.com.CodeConstruct.MCTP.Endpoint interface on endpoint objects') +option('tests', type: 'feature') diff --git a/tests/test-proto.h b/tests/test-proto.h index 879c69f..882950f 100644 --- a/tests/test-proto.h +++ b/tests/test-proto.h @@ -1,9 +1,10 @@ #include -#include #include +#include "mctp.h" + enum { CONTROL_OP_INIT, CONTROL_OP_SOCKET_MCTP,