]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
meson.build: add a simple sanity check of kres-gen result
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 7 Jul 2021 15:14:44 +0000 (17:14 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 15 Jul 2021 17:36:32 +0000 (19:36 +0200)
daemon/lua/meson.build
meson_options.txt

index fabf0414bd1498d0d5c334b7b8d62317a1ab7d9e..f98fd631a5444089653cbefba462dfd4b7ba8948 100644 (file)
@@ -42,6 +42,38 @@ run_target(  # run manually to re-generate kres-gen.lua
   command: find_program('./kres-gen.sh'),
 )
 
+# A simple config test: check that sizes of some structures match
+# in C and pre-generated lua bindings.
+# The point is that regeneration is quite expensive in time and dependencies,
+# but this basic sanity check could be ran always.
+if get_option('kres_gen_test')
+  types_to_check = {
+       'time_t' : '#include <sys/time.h>',
+       'struct timeval' : '#include <sys/time.h>',
+       'zs_scanner_t' : '#include <libzscanner/scanner.h>',
+       'knot_pkt_t' : '#include <libknot/packet/pkt.h>',
+  }
+  # Construct the lua tester as a meson string.
+  kres_gen_test_luastr = '''
+       dofile('@0@')
+       local ffi = require('ffi')
+  '''.format(meson.current_source_dir() / 'kres-gen.lua')
+  foreach tname, tinclude: types_to_check
+       kres_gen_test_luastr += '''
+         assert(ffi.sizeof(ffi.typeof('@0@')) == @1@,
+               'Lua binding for C type ' .. '@0@' .. ' has incorrect size: '
+               .. ffi.sizeof(ffi.typeof('@0@'))
+         )
+       '''.format(tname, meson.get_compiler('c').sizeof(tname, prefix : tinclude))
+  endforeach
+  # Now feed it directly into luajit.
+  kres_gen_test = run_command(find_program('luajit'), '-e', kres_gen_test_luastr)
+  if kres_gen_test.returncode() != 0
+       error('if you use released Knot* versions, please contact us: https://www.knot-resolver.cz/contact/\n'
+               + kres_gen_test.stderr().strip())
+  endif
+endif
+
 lua_src = [
   files('postconfig.lua'),
   files('kres.lua'),
index f7ca06aabdca3fda2aff1ed43a52859137b3c96f..572cd643d93605074af931c614f007e73136c02f 100644 (file)
@@ -175,6 +175,13 @@ option(
   description: 'html documentation dependencies and installation',
 )
 
+option(
+  'kres_gen_test',
+  type: 'boolean',
+  value: true,
+  description: 'run kres_gen_test: a simple sanity check for our lua bindings',
+)
+
 option(
   'config_tests',
   type: 'combo',