Skip to content

Commit

Permalink
Merge pull request #475 from smcv/meson
Browse files Browse the repository at this point in the history
Fix Meson build system to be able to run tests
  • Loading branch information
cgwalters committed Feb 24, 2022
2 parents 576e8e0 + d8b4221 commit 5b76c60
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
( cd DESTDIR && find -ls )
- name: dist
run: |
BWRAP_MUST_WORK=1 meson dist -C _build
BWRAP_MUST_WORK=1 CI_MESON_DIST=1 meson dist -C _build
- name: Collect dist test logs on failure
if: failure()
run: mv _build/meson-private/dist-build/meson-logs/testlog.txt test-logs/disttestlog.txt || true
Expand Down
1 change: 0 additions & 1 deletion completions/bash/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ if bash_completion_dir == ''
'completionsdir',
default: '',
define_variable: [
'prefix', get_option('prefix'),
'datadir', get_option('prefix') / get_option('datadir'),
],
)
Expand Down
10 changes: 9 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project(

cc = meson.get_compiler('c')
add_project_arguments('-D_GNU_SOURCE', language : 'c')
common_include_directories = include_directories('.')

# Keep this in sync with ostree, except remove -Wall (part of Meson
# warning_level 2) and -Werror=declaration-after-statement
Expand Down Expand Up @@ -61,9 +62,14 @@ if (
], language : 'c')
endif

sh = find_program('sh', required : true)
bash = find_program('bash', required : false)

if get_option('python') == ''
python = find_program('python3')
else
python = find_program(get_option('python'))
endif

libcap_dep = dependency('libcap', required : true)

selinux_dep = dependency(
Expand Down Expand Up @@ -145,3 +151,5 @@ endif
if not meson.is_subproject()
subdir('completions')
endif

subdir('tests')
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ option(
type : 'string',
description : 'Prepend string to bwrap executable name, for use with subprojects',
)
option(
'python',
type : 'string',
description : 'Path to Python 3, or empty to use python3',
)
option(
'require_userns',
type : 'boolean',
Expand Down
24 changes: 18 additions & 6 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ test_programs = [
'../utils.c',
'../utils.h',
dependencies : [selinux_dep],
include_directories : common_include_directories,
)],
]

executable(
'try-syscall',
'try-syscall.c',
)

test_scripts = [
'test-run.sh',
'test-seccomp.py',
Expand All @@ -17,8 +23,8 @@ test_scripts = [

test_env = environment()
test_env.set('BWRAP', bwrap.full_path())
test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
test_env.set('G_TEST_BUILDDIR', meson.current_build_dir() / '..')
test_env.set('G_TEST_SRCDIR', meson.current_source_dir() / '..')

foreach pair : test_programs
name = pair[0]
Expand All @@ -40,19 +46,25 @@ foreach pair : test_programs
endforeach

foreach test_script : test_scripts
if test_script.endswith('.py')
interpreter = python
else
interpreter = bash
endif

if meson.version().version_compare('>=0.50.0')
test(
test_script,
bash,
args : [test_script],
interpreter,
args : [files(test_script)],
env : test_env,
protocol : 'tap',
)
else
test(
test_script,
bash,
args : [test_script],
interpreter,
args : [files(test_script)],
env : test_env,
)
endif
Expand Down
2 changes: 2 additions & 0 deletions tests/test-specifying-pidns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ echo "1..1"
# This test needs user namespaces
if test -n "${bwrap_is_suid:-}"; then
echo "ok - # SKIP no setuid support for --unshare-user"
elif test -n "${CI_MESON_DIST:-}"; then
echo "not ok - # TODO this test hangs under 'meson dist' during Github Workflow CI"
else
mkfifo donepipe
$RUN --info-fd 42 --unshare-user --unshare-pid sh -c 'readlink /proc/self/ns/pid > sandbox-pidns; cat < donepipe' >/dev/null 42>info.json &
Expand Down
4 changes: 2 additions & 2 deletions tests/test-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ test_has_path_prefix (void)
}

int
main (int argc,
char **argv)
main (int argc UNUSED,
char **argv UNUSED)
{
setvbuf (stdout, NULL, _IONBF, 0);
test_n_elements ();
Expand Down

0 comments on commit 5b76c60

Please sign in to comment.