]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
meson: add support for the testsuite
authorEmil Velikov <emil.l.velikov@gmail.com>
Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 3 Sep 2024 01:13:54 +0000 (20:13 -0500)
Currently the stale tracking of modules/rootfs is non-existent and I
cannot quite find a way to fix that.

In addition, there is a long standing meson bug where the tests and by
extension their dependencies are always build even when annotated as
`build_by_default : false`. To workaround that, a new option is
introduced `build-tests`, defaulting to false.

Apart from that, all tests run and pass \o/

v2:
 - split from top-level meson.build to subdir one
 - add to EXTRA_DIST
 - scripts are in scripts/
 - add option to enable building tests
 - error out if building without tools

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Makefile.am
meson.build
meson_options.txt
testsuite/meson.build [new file with mode: 0644]

index 969a9ff6e7dd17aea3b097c7023380eff3857bb8..74b1130391719aa5e191e55a31aa6e746b3590ed 100644 (file)
@@ -19,6 +19,7 @@ export GCC_COLORS
 EXTRA_DIST += \
        meson.build \
        meson_options.txt \
+       testsuite/meson.build \
        scripts/kmod-symlink.sh
 
 AM_CPPFLAGS = \
index 2e39e6c446245c99a8d63fc4e8127c3150afb368..63002dc752c932544feb82caf83a044b6b50162d 100644 (file)
@@ -396,6 +396,17 @@ foreach tool : _tools
   endif
 endforeach
 
+# ------------------------------------------------------------------------------
+# TESTSUITE
+# ------------------------------------------------------------------------------
+
+if get_option('build-tests')
+  setup_modules = find_program('scripts/setup-modules.sh')
+  setup_rootfs = find_program('scripts/setup-rootfs.sh')
+  top_include = include_directories('.')
+  subdir('testsuite')
+endif
+
 summary({
   'moduledir'   : moduledir,
   'prefix'      : get_option('prefix'),
@@ -410,6 +421,7 @@ summary({
   'tools'       : get_option('tools'),
   'logging'     : get_option('logging'),
   'debug'       : get_option('debug-messages'),
+  'build-tests' : get_option('build-tests'),
 }, section : 'Options')
 
 summary({
index 086fbb39f3069d023f7726b5bd2acab7ad136eeb..f8607ece2a807318db6480ce73838476da3b50f6 100644 (file)
@@ -68,3 +68,13 @@ option(
   value : false,
   description : 'Enable debug messages. Default: false',
 )
+
+# XXX: workaround a meson bug, where the tests are always build even
+# when explicitly annotated as "build_by_default: false"
+# See: https://github.com/mesonbuild/meson/issues/2518
+option(
+  'build-tests',
+  type : 'boolean',
+  value : false,
+  description : 'Always build the test suite. Default: false',
+)
diff --git a/testsuite/meson.build b/testsuite/meson.build
new file mode 100644 (file)
index 0000000..585646e
--- /dev/null
@@ -0,0 +1,123 @@
+if not get_option('tools')
+  error('The test suite requires also building the tools')
+endif
+
+test_kmod_symlinks = []
+
+foreach tool : _tools
+  test_kmod_symlinks += custom_target(
+    tool,
+    command : ['ln', '-sf', kmod, '@OUTPUT@'],
+    output : tool,
+    depends : kmod,
+    build_by_default : false,
+  )
+endforeach
+
+build_module_playground = custom_target(
+  'build-module-playground',
+  command : [
+    setup_modules,
+    meson.project_source_root(),
+    meson.project_build_root(),
+    'testsuite/module-playground', # do not prepend source/build root
+    moduledir,
+  ],
+  output : 'bb-rootfs',
+  console : true,
+  build_always_stale : true, # TODO: only when the playground has changed
+  build_by_default : false,
+)
+
+create_rootfs = custom_target(
+  'create-rootfs',
+  command : [
+    setup_rootfs,
+    join_paths(meson.project_source_root(), 'testsuite/rootfs-pristine'),
+    join_paths(meson.project_build_root(), 'testsuite/rootfs'),
+    join_paths(meson.project_build_root(), 'testsuite/module-playground'),
+    join_paths(meson.project_build_root(), 'config.h'),
+    sysconfdir,
+    moduledir,
+  ],
+  output : 'stamp-rootfs',
+  console : true,
+  depends : build_module_playground,
+  build_always_stale : true, # TODO: only when the rootfs has changed
+  build_by_default : false,
+)
+
+_test_override_mods = [
+  'delete_module',
+  'init_module',
+  'path',
+  'uname',
+]
+
+libdl = cc.find_library('dl')
+test_override_mods = []
+
+foreach mod : _test_override_mods
+  test_override_mods += shared_module(
+    mod,
+    files('@0@.c'.format(mod)),
+    include_directories : top_include,
+    dependencies : libdl,
+    link_with : [libshared, libkmod_internal],
+    gnu_symbol_visibility : 'hidden',
+    name_prefix : '',
+    build_rpath : '',
+    build_by_default : false,
+  )
+endforeach
+
+testsuite_c_args = [
+  '-DTESTSUITE_ROOTFS="@0@/testsuite/rootfs/"'.format(meson.project_build_root()),
+  '-DTOOLS_DIR="@0@/testsuite/"'.format(meson.project_build_root()),
+  '-DOVERRIDE_LIBDIR="@0@/testsuite/"'.format(meson.project_build_root()),
+]
+
+libtestsuite = static_library(
+  'testsuite',
+  files('testsuite.c'),
+  include_directories : top_include,
+  c_args : testsuite_c_args,
+  dependencies : cc.find_library('rt'),
+  build_by_default : false,
+  install : false,
+)
+
+_testsuite = [
+  'test-array',
+  'test-blacklist',
+  'test-dependencies',
+  'test-depmod',
+  'test-hash',
+  'test-init',
+  'test-initstate',
+  'test-list',
+  'test-loaded',
+  'test-modinfo',
+  'test-modprobe',
+  'test-new-module',
+  'test-scratchbuf',
+  'test-strbuf',
+  'test-testsuite',
+  'test-util',
+  'test-weakdep',
+]
+
+foreach input : _testsuite
+  test(
+    input,
+    executable(
+      input,
+      files('@0@.c'.format(input)),
+      include_directories : top_include,
+      c_args : testsuite_c_args,
+      link_with : [libshared, libkmod_internal, libtestsuite],
+      build_by_default : false,
+    ),
+    depends : [test_kmod_symlinks, create_rootfs, test_override_mods],
+  )
+endforeach