From 5921c48fcf37179435b94db98bb6a9fe03fea8e5 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 12 Jul 2025 02:14:00 +0900 Subject: [PATCH 1/2] meson: fix coverage build This moves coverage.h to src/coverage/, and specifies path to coverage.h with files() directive, to make it can be included even when located outside of the include directories. Otherwise, libc-wrapper cannot be built when -Db_coverage=true option is enabled. Follow-up for 543a48b653ff25cc562ce4dcffec377a875f604e. --- meson.build | 7 +++---- src/{basic => coverage}/coverage.h | 0 src/coverage/meson.build | 6 ++++++ src/version/meson.build | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) rename src/{basic => coverage}/coverage.h (100%) create mode 100644 src/coverage/meson.build diff --git a/meson.build b/meson.build index f5362ece8a..e3e088d413 100644 --- a/meson.build +++ b/meson.build @@ -344,6 +344,7 @@ conf.set10('ENABLE_FIRST_BOOT_FULL_PRESET', get_option('first- cc = meson.get_compiler('c') userspace_c_args = [] userspace_c_ld_args = [] +userspace_sources = [] meson_build_sh = find_program('tools/meson-build.sh') want_tests = get_option('tests') @@ -1963,9 +1964,7 @@ endif ##################################################################### -if get_option('b_coverage') - userspace_c_args += ['-include', 'coverage.h'] -endif +subdir('src/coverage') ##################################################################### @@ -1980,7 +1979,7 @@ jinja2_cmdline = [meson_render_jinja2, config_h] userspace = declare_dependency( compile_args : userspace_c_args, link_args : userspace_c_ld_args, - sources : version_h, + sources : userspace_sources, ) man_page_depends = [] diff --git a/src/basic/coverage.h b/src/coverage/coverage.h similarity index 100% rename from src/basic/coverage.h rename to src/coverage/coverage.h diff --git a/src/coverage/meson.build b/src/coverage/meson.build new file mode 100644 index 0000000000..fd0bcf35fc --- /dev/null +++ b/src/coverage/meson.build @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +if get_option('b_coverage') + userspace_c_args += ['-include', meson.current_source_dir() / 'coverage.h'] + userspace_sources += files('coverage.h') +endif diff --git a/src/version/meson.build b/src/version/meson.build index 727ae84999..03f58697b7 100644 --- a/src/version/meson.build +++ b/src/version/meson.build @@ -13,3 +13,4 @@ version_h = custom_target('version', vcs_tag ? '1' : '0', ]) version_include = include_directories('.') +userspace_sources += [version_h] From 2cc6c651ee2df408b2cc72c000d7f7f08c8932ac Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 12 Jul 2025 17:11:11 +0900 Subject: [PATCH 2/2] test: skip one test case when running on coverage Since 90fa161b5ba29d58953e9f08ddca49121b51efe6, --bind= or Bind= settings for coverage directory does not work with managed mode: ``` [ 158.105361] systemd-nspawn[3718]: Failed to open tree and set mount attributes: Operation not permitted [ 158.105364] systemd-nspawn[3718]: Failed to clone /coverage: Operation not permitted [ 158.118655] systemd-nspawn[3707]: (sd-namespace) failed with exit status 1. ``` Let's tentatively skip the test case when running on coverage. Workaround for #38163. --- test/units/TEST-13-NSPAWN.nspawn.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/units/TEST-13-NSPAWN.nspawn.sh b/test/units/TEST-13-NSPAWN.nspawn.sh index b27bfbacf7..64bd485b42 100755 --- a/test/units/TEST-13-NSPAWN.nspawn.sh +++ b/test/units/TEST-13-NSPAWN.nspawn.sh @@ -1422,7 +1422,18 @@ testcase_unpriv_dir() { # Use an image owned by the foreign UID range first via direct mapping, and than via the managed uid logic systemd-dissect --shift "$root" foreign assert_eq "$(systemd-nspawn --pipe --register=no -D "$root" --private-users=pick --private-users-ownership=foreign bash -c 'echo foobar')" "foobar" - assert_eq "$(systemd-nspawn --pipe --register=no -D "$root" --private-users=managed --private-network bash -c 'echo foobar')" "foobar" + # FIXME: + # Since 90fa161b5ba29d58953e9f08ddca49121b51efe6, --bind= or Bind= settings for coverage directory does + # not work with managed mode: + # ======== + # [ 158.105361] systemd-nspawn[3718]: Failed to open tree and set mount attributes: Operation not permitted + # [ 158.105364] systemd-nspawn[3718]: Failed to clone /coverage: Operation not permitted + # [ 158.118655] systemd-nspawn[3707]: (sd-namespace) failed with exit status 1. + # ======== + # Let's tentatively skip the test case when running on coverage. + if [[ -z "${COVERAGE_BUILD_DIR:-}" ]]; then + assert_eq "$(systemd-nspawn --pipe --register=no -D "$root" --private-users=managed --private-network bash -c 'echo foobar')" "foobar" + fi # Test unprivileged operation chown testuser:testuser "$root/.."