Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Support consuming Open vSwitch from snap #425

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ test_env = [
]

if get_option('unit_testing')
subdir('tests/ctests')
test('ctests',
find_program('tests/ctests/run.sh'),
workdir: join_paths(meson.current_source_dir(), 'tests/ctests'),
args: [join_paths(meson.current_build_dir(), '_ctestsbuild'),
'-Dparent_current_source_dir=' + meson.current_source_dir(),
'-Dparent_current_build_dir=' + meson.current_build_dir()])
endif

#FIXME: exclude doc/env/
Expand Down
9 changes: 9 additions & 0 deletions tests/ctests/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

BUILDDIR="$1"; shift
meson setup ${BUILDDIR} $*
meson compile -C ${BUILDDIR} --verbose

if [ "$(basename $0)" = "run.sh" ]; then
meson test -C ${BUILDDIR}
fi
23 changes: 20 additions & 3 deletions tests/ctests/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
project('ctests', 'c')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to get @daniloegea's opinion on this new project structure. Overall, it looks fine to me and I'm happy to change it that way, as long as we can run our tests as usual and don't need to adopt the packaging.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ctests were intentionally not linked against libnetplan. The idea was to build only the necessary files with the test files. The problem is that each file has dependencies spread across almost all the others so to get it working properly we need to do a good refactoring in the C code...

I think it should be fine to separate and link them against libnetplan to make things easier for the time being as long as we still can run them as part of meson test and the coverage checks still work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: would adding link_with: libnetplan to tests/ctests/meson.build work?


add_project_arguments(
'-DSBINDIR="' + join_paths(get_option('prefix'), get_option('sbindir')) + '"',
'-D_GNU_SOURCE',
language: 'c')

tests = {
'test_netplan_parser': false,
'test_netplan_state': false,
Expand All @@ -10,15 +17,25 @@ tests = {
'test_netplan_openvswitch': false,
}

glib = dependency('glib-2.0')
gio = dependency('gio-2.0')
yaml = dependency('yaml-0.1')
uuid = dependency('uuid')
cmocka = dependency('cmocka', required: true)
netplan = meson.get_compiler('c').find_library(
'netplan',
dirs: [join_paths(get_option('parent_current_build_dir'), 'src')])

foreach name, should_fail: tests
exe = executable(name,
'@[email protected]'.format(name),
include_directories: [inc, inc_internal],
dependencies: [cmocka, glib, gio, yaml, uuid],
include_directories: [
join_paths(get_option('parent_current_source_dir'), 'include'),
join_paths(get_option('parent_current_source_dir'), 'src'),
],
dependencies: [cmocka, glib, gio, yaml, uuid, netplan],
c_args: [
'-DFIXTURESDIR="' + meson.project_source_root() + '/tests/ctests/fixtures"',
'-DFIXTURESDIR="' + meson.project_source_root() + '/fixtures"',
'-Wno-deprecated-declarations',
'-D_GNU_SOURCE',
],
Expand Down
2 changes: 2 additions & 0 deletions tests/ctests/meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
option('parent_current_source_dir', type: 'string', value: '')
option('parent_current_build_dir', type: 'string', value: '')
1 change: 1 addition & 0 deletions tests/ctests/run.sh
13 changes: 11 additions & 2 deletions tools/run_asan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ set -x

BUILDDIR="_leakcheckbuild"
CLEANBUILDDIR="_cleanbuild"
CTESTSBUILDDIR="_ctestsbuild"
CC=gcc

meson setup ${BUILDDIR} -Db_sanitize=address,undefined
meson compile -C ${BUILDDIR} --verbose

tests/ctests/build.sh \
${CTESTSBUILDDIR} \
tests/ctests \
-Dparent_current_source_dir=$(realpath .) \
-Dparent_current_build_dir=$(realpath ${BUILDDIR}) \
-Db_sanitize=address,undefined

meson setup ${CLEANBUILDDIR}
meson compile -C ${CLEANBUILDDIR} --verbose

Expand All @@ -18,10 +26,11 @@ ${CC} tools/keyfile_to_yaml.c -o tools/keyfile_to_yaml \
-Iinclude -L${BUILDDIR}/src \
-fsanitize=address,undefined -g

TESTS=$(find ${BUILDDIR}/tests/ctests/ -executable -type f)
TESTS=$(find ${CTESTSBUILDDIR} -executable -type f)
for test in ${TESTS}
do
./${test}
# https://github.com/google/sanitizers/issues/1017
ASAN_OPTIONS=detect_odr_violation=0 ./${test}
done

mkdir -p ${BUILDDIR}/fakeroot/{etc/netplan,run}
Expand Down