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 9459795..f8b4948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ 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. + ### Fixed 1. mctpd: EID assignments now work in the case where a new endpoint has a diff --git a/meson.build b/meson.build index 02c714a..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,11 +81,46 @@ configure_file( configuration: test_conf_data, ) -pytest = find_program('pytest', required: false) - -if pytest.found() - test('test-mctpd', pytest, - args: '--tap', +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: [ 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,