From 988055d1ea77038dd2d2495b0d936a151fc268db Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Fri, 1 Aug 2025 16:32:31 +0800 Subject: [PATCH 1/4] meson: mctpd_test is only required for mctpd-enabled builds If we're building without mctpd (ie, no libsystemd), then we won't have a mctpd_test variable defined, so meson will fail: meson.build:156:18: ERROR: Unknown variable "mctpd_test". This builds the test dependencies according to what is enabled instead. Fixes: https://github.com/CodeConstruct/mctp/issues/102 Signed-off-by: Jeremy Kerr --- meson.build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 1a88f37..4885712 100644 --- a/meson.build +++ b/meson.build @@ -63,6 +63,8 @@ mctp_test = executable('test-mctp', include_directories: include_directories('src'), ) +test_deps = [mctp_test] + executable('mctp-req', sources: ['src/mctp-req.c'] + util_sources, ) @@ -97,6 +99,7 @@ if libsystemd.found() include_directories: include_directories('src'), dependencies: [libsystemd, toml_dep], ) + test_deps += mctpd_test endif tests = get_option('tests') @@ -153,7 +156,7 @@ if tests ) test('test-mctpd', dbus_run_session, - depends: [mctpd_test, mctp_test], + depends: [test_deps], args: [ sh.full_path(), '-c', script, '--' ], protocol: 'tap', ) From 04e13ba8f17f0d3a992e1ab8a5ceaab3f433e092 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Sat, 2 Aug 2025 10:54:14 +0800 Subject: [PATCH 2/4] meson: simplify test script Shorten the PYTEST_FLAGS var name to keep the one-line script a little more manageable, no need for an export, and re-wrap. Signed-off-by: Jeremy Kerr --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 4885712..963ff0d 100644 --- a/meson.build +++ b/meson.build @@ -141,7 +141,9 @@ if tests # redirecting to a file. We can detect this if stdout is an terminal, and # disable TAP protocol. pytest = find_program('pytest') - script = '''export DBUS_STARTER_BUS_TYPE=user; if [ ! -t 1 ]; then PYTEST_FLAGS="--tap"; fi; @0@ $PYTEST_FLAGS $@'''.format(pytest.full_path()) + script = 'if [ ! -t 1 ]; then PFL="--tap"; fi; DBUS_STARTER_BUS_TYPE=user "@0@" $PFL $@'.format( + pytest.full_path() + ) sh = find_program('sh') dbus_run_session = find_program('dbus-run-session') From a8f8f5e07c3042f201c3ec04d8265fa32c3c7472 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Mon, 4 Aug 2025 11:55:53 +0800 Subject: [PATCH 3/4] tests: split meson test() definitions into individual test scripts We currently have one pytest invocation (through one meson test()) which runs all of the tests/test_*.py scripts. However, not all of those will be testable in any particular configuration. We may be building without libsystemd, in which case the test_mctpd.py and test_mctpd_endpoint.py tests will not work. So, define individual test() calls for each of the scripts. This also lets us modify the runtime environment (the mctp-only tests don't require dbus-run-session), and meson can parallelise too. Signed-off-by: Jeremy Kerr --- meson.build | 47 +++++++++++++++++------------ tests/{pytest.ini.in => pytest.ini} | 1 - 2 files changed, 27 insertions(+), 21 deletions(-) rename tests/{pytest.ini.in => pytest.ini} (86%) diff --git a/meson.build b/meson.build index 963ff0d..f93d28c 100644 --- a/meson.build +++ b/meson.build @@ -63,8 +63,6 @@ mctp_test = executable('test-mctp', include_directories: include_directories('src'), ) -test_deps = [mctp_test] - executable('mctp-req', sources: ['src/mctp-req.c'] + util_sources, ) @@ -99,7 +97,6 @@ if libsystemd.found() include_directories: include_directories('src'), dependencies: [libsystemd, toml_dep], ) - test_deps += mctpd_test endif tests = get_option('tests') @@ -140,26 +137,36 @@ if tests # to allow pytest to print output directly onto the terminal without # redirecting to a file. We can detect this if stdout is an terminal, and # disable TAP protocol. + test_dir = join_paths(meson.current_source_dir(), 'tests') + pytest_conf = join_paths(test_dir, 'pytest.ini') + pytest = find_program('pytest') - script = 'if [ ! -t 1 ]; then PFL="--tap"; fi; DBUS_STARTER_BUS_TYPE=user "@0@" $PFL $@'.format( - pytest.full_path() + script = 'if [ ! -t 1 ]; then PFL="--tap"; fi; DBUS_STARTER_BUS_TYPE=user "@0@" $PFL --config-file "@1@" $@'.format( + pytest.full_path(), + pytest_conf, ) sh = find_program('sh') - dbus_run_session = find_program('dbus-run-session') - - test_conf_data = configuration_data() - test_conf_data.set('testpaths', - join_paths(meson.current_source_dir(), 'tests') - ) - configure_file( - input: 'tests/pytest.ini.in', - output: 'pytest.ini', - configuration: test_conf_data, - ) - - test('test-mctpd', dbus_run_session, - depends: [test_deps], - args: [ sh.full_path(), '-c', script, '--' ], + test_args = [ '-c', script, '--' ] + + if libsystemd.found() + dbus_run_session = find_program('dbus-run-session') + + test('test-mctpd', dbus_run_session, + depends: [mctpd_test], + args: [sh.full_path()] + test_args + [test_dir / 'test_mctpd.py'], + protocol: 'tap', + ) + + test('test-mctpd-endpoint', dbus_run_session, + depends: [mctpd_test], + args: [sh.full_path()] + test_args + [test_dir / 'test_mctpd_endpoint.py'], + protocol: 'tap', + ) + endif + + test('test-mctp', sh, + depends: [mctp_test], + args: test_args + [test_dir / 'test_mctp.py'], protocol: 'tap', ) diff --git a/tests/pytest.ini.in b/tests/pytest.ini similarity index 86% rename from tests/pytest.ini.in rename to tests/pytest.ini index 3185622..30a9412 100644 --- a/tests/pytest.ini.in +++ b/tests/pytest.ini @@ -1,6 +1,5 @@ [pytest] trio_mode = true -testpaths = @testpaths@ filterwarnings = ignore:.*wait_readable:DeprecationWarning:asyncdbus ignore:.*wait_writable:DeprecationWarning:asyncdbus From cc4b41608437dcf128ee8cb17e83db5ee0b2bbcc Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Mon, 4 Aug 2025 14:02:37 +0800 Subject: [PATCH 4/4] .github: Add no-libsystemd CI configuration Add a build without libsystemd present, so we can catch any issues that arise from the non-mctpd build. Enable verbose test output while we're at it. Signed-off-by: Jeremy Kerr --- .github/workflows/pr.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 42b47fc..b1a966b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,7 +1,7 @@ name: pull-request-ci on: [push, pull_request] jobs: - run-tests: + default: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -27,4 +27,29 @@ jobs: run: ninja -C build clang-format-check - name: Test mctp - run: meson test -C build + run: meson test -C build --verbose + + no-libsystemd: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install system build dependencies + run: > + sudo apt-get update && + sudo apt-get install 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 -Db_sanitize=address + + - name: Build mctp + run: meson compile -C build + + - name: Test mctp + run: meson test -C build --verbose