meson.build 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. test_env = environment()
  2. test_env.set('XKB_LOG_LEVEL', 'debug')
  3. test_env.set('XKB_LOG_VERBOSITY', '10')
  4. test_env.set('top_srcdir', meson.project_source_root())
  5. test_env.set('top_builddir', meson.project_build_root())
  6. test_env.set(
  7. 'HAVE_XKBCLI_INTERACTIVE_EVDEV',
  8. configh_data.get('HAVE_XKBCLI_INTERACTIVE_EVDEV', 0).to_string(),
  9. )
  10. test_env.set(
  11. 'HAVE_XKBCLI_INTERACTIVE_WAYLAND',
  12. configh_data.get('HAVE_XKBCLI_INTERACTIVE_WAYLAND', 0).to_string(),
  13. )
  14. test_env.set(
  15. 'HAVE_XKBCLI_INTERACTIVE_X11',
  16. configh_data.get('HAVE_XKBCLI_INTERACTIVE_X11', 0).to_string(),
  17. )
  18. test_env.set(
  19. 'HAVE_XKBCLI_LIST',
  20. configh_data.get('HAVE_XKBCLI_LIST', 0).to_string(),
  21. )
  22. test_configh_data = configuration_data()
  23. test_configh_data.set_quoted(
  24. 'TEST_XKB_CONFIG_ROOT',
  25. meson.current_source_dir() / 'data',
  26. )
  27. test_configh_data.set('_FORTIFY_SOURCE', '3')
  28. configure_file(output: 'test-config.h', configuration: test_configh_data)
  29. # Headers C++ compatibility test (optional)
  30. # Exclude MSVC because it does not handle mixing C and C++ well
  31. if build_machine.system() != 'windows' and add_languages(
  32. 'cpp',
  33. required: false,
  34. native: false,
  35. )
  36. cpp_compat_test_deps = []
  37. cpp_compat_test_cpp_args = []
  38. if get_option('enable-x11')
  39. cpp_compat_test_cpp_args += '-DHAS_XKB_X11'
  40. cpp_compat_test_deps += xcb_dep
  41. endif
  42. if get_option('enable-xkbregistry')
  43. cpp_compat_test_cpp_args += '-DHAS_XKB_REGISTRY'
  44. endif
  45. test(
  46. 'headers C++ compatibility',
  47. executable(
  48. 'cpp-headers',
  49. 'headers-compatibility.cpp',
  50. include_directories: include_directories(
  51. '..', # required to #include "config.h" in subdirs
  52. '../include',
  53. ),
  54. dependencies: cpp_compat_test_deps,
  55. cpp_args: cpp_compat_test_cpp_args,
  56. override_options: ['cpp_std=c++11'],
  57. ),
  58. )
  59. endif
  60. m_dep = cc.find_library('m', required: false)
  61. test_shared_lib = static_library(
  62. 'test-shared',
  63. sources: [
  64. '../bench/bench.c',
  65. '../src/utils.c',
  66. 'common.c',
  67. 'compose-iter.c',
  68. 'utils-text.c',
  69. ],
  70. include_directories: include_directories(
  71. '..', # required to #include "config.h" in subdirs
  72. '../src',
  73. '../include',
  74. '.',
  75. ),
  76. link_with: [libxkbcommon_test_internal, tools_shared_lib],
  77. )
  78. test_dep = declare_dependency(
  79. include_directories: include_directories(
  80. '..', # required to #include "config.h" in subdirs
  81. '../src',
  82. '../include',
  83. '.',
  84. ),
  85. link_with: [libxkbcommon_test_internal, test_shared_lib],
  86. dependencies: [m_dep],
  87. )
  88. test(
  89. 'features',
  90. executable(
  91. 'features',
  92. 'features.c',
  93. dependencies: test_dep,
  94. c_args: ['-DENABLE_PRIVATE_APIS'],
  95. ),
  96. env: test_env,
  97. )
  98. # TODO: version range?
  99. keysyms_test_dep = [test_dep]
  100. keysyms_test_c_args = ['-DENABLE_PRIVATE_APIS']
  101. if icu_dep.found()
  102. keysyms_test_dep += [icu_dep]
  103. configh_data.set10('HAVE_ICU', true)
  104. endif
  105. test(
  106. 'keysym',
  107. executable(
  108. 'keysym',
  109. 'keysym.c',
  110. dependencies: keysyms_test_dep,
  111. c_args: keysyms_test_c_args,
  112. ),
  113. env: test_env,
  114. )
  115. test(
  116. 'keysym-unicode',
  117. executable(
  118. 'keysym-unicode',
  119. 'keysym-unicode.c',
  120. dependencies: keysyms_test_dep,
  121. c_args: keysyms_test_c_args,
  122. ),
  123. env: test_env,
  124. )
  125. test(
  126. 'keymap',
  127. executable('keymap', 'keymap.c', dependencies: test_dep),
  128. env: test_env,
  129. )
  130. test(
  131. 'filecomp',
  132. executable('filecomp', 'filecomp.c', dependencies: test_dep),
  133. env: test_env,
  134. )
  135. test(
  136. 'context',
  137. executable('context', 'context.c', dependencies: test_dep),
  138. env: test_env,
  139. )
  140. test(
  141. 'rules-file',
  142. executable('rules-file', 'rules-file.c', dependencies: test_dep),
  143. env: test_env,
  144. )
  145. test(
  146. 'rules-file-includes',
  147. executable(
  148. 'rules-file-includes',
  149. 'rules-file-includes.c',
  150. dependencies: test_dep,
  151. ),
  152. env: test_env,
  153. )
  154. test(
  155. 'stringcomp',
  156. executable('stringcomp', 'stringcomp.c', dependencies: test_dep),
  157. env: test_env,
  158. )
  159. test(
  160. 'buffercomp',
  161. executable('buffercomp', 'buffercomp.c', dependencies: test_dep),
  162. env: test_env,
  163. )
  164. test(
  165. 'lenient-mode',
  166. executable(
  167. 'lenient-mode',
  168. 'lenient-mode.c',
  169. dependencies: test_dep,
  170. ),
  171. env: test_env,
  172. )
  173. if has_extensions_directories
  174. extensions_test_deps = [test_dep]
  175. extensions_test_c_args = []
  176. if get_option('enable-xkbregistry')
  177. extensions_test_deps += [dep_libxkbregistry, dep_libxml]
  178. extensions_test_c_args += ['-DHAS_XKBREGISTRY']
  179. endif
  180. test(
  181. 'extensions-directories',
  182. executable(
  183. 'extensions-directories',
  184. 'extensions-directories.c',
  185. dependencies: extensions_test_deps,
  186. c_args: extensions_test_c_args,
  187. ),
  188. env: test_env,
  189. )
  190. endif
  191. test(
  192. 'introspection',
  193. executable(
  194. 'introspection',
  195. 'introspection.c',
  196. dependencies: test_dep,
  197. ),
  198. env: test_env,
  199. )
  200. # The merge modes tests are optional and generated locally on-the-fly
  201. pymod = import('python')
  202. python = pymod.find_installation('python3', modules: ['jinja2'], required: false)
  203. has_merge_modes_tests = python.found() and python.language_version().version_compare(
  204. '>=3.11',
  205. )
  206. if has_merge_modes_tests
  207. script = find_program('../scripts/update-merge-modes-tests.py')
  208. merge_modes_tests = [meson.project_name()]
  209. # NOTE: The following tests deal with third-party XKB compilers and are
  210. # reserved for debugging purposes. Uncomment to enable them.
  211. # merge_modes_tests += 'xkbcomp' # Xorg XKB compiler
  212. # merge_modes_tests += 'kbvm' # Jay compositor XKB compiler
  213. foreach xkb_compiler : merge_modes_tests
  214. if xkb_compiler == meson.project_name()
  215. suffix = ''
  216. extra_args = []
  217. else
  218. suffix = '-' + xkb_compiler
  219. extra_args = [xkb_compiler]
  220. endif
  221. filename = f'merge-modes@suffix@.c'
  222. merge_modes_c = custom_target(
  223. filename,
  224. build_by_default: true,
  225. command: [
  226. script,
  227. '--root',
  228. meson.project_source_root(),
  229. '--c-out',
  230. '@OUTPUT@',
  231. '--no-xkb',
  232. ] + extra_args,
  233. depend_files: ['merge_modes.c.jinja'],
  234. output: filename,
  235. capture: false,
  236. install: false,
  237. )
  238. test(
  239. f'merge-modes@suffix@',
  240. executable(
  241. f'merge-modes@suffix@',
  242. merge_modes_c,
  243. dependencies: test_dep,
  244. ),
  245. env: test_env,
  246. )
  247. endforeach
  248. endif
  249. test(
  250. 'log',
  251. executable('log', 'log.c', dependencies: test_dep),
  252. env: test_env,
  253. )
  254. test(
  255. 'atom',
  256. executable('atom', 'atom.c', dependencies: test_dep),
  257. env: test_env,
  258. )
  259. test(
  260. 'utf8',
  261. executable('utf8', 'utf8.c', dependencies: test_dep),
  262. env: test_env,
  263. )
  264. test(
  265. 'state',
  266. executable('state', 'state.c', dependencies: test_dep),
  267. env: test_env,
  268. )
  269. test(
  270. 'server-state',
  271. executable(
  272. 'server-state',
  273. 'server-state.c',
  274. dependencies: test_dep,
  275. ),
  276. env: test_env,
  277. )
  278. test(
  279. 'keyseq',
  280. executable('keyseq', 'keyseq.c', dependencies: test_dep),
  281. env: test_env,
  282. )
  283. test(
  284. 'rulescomp',
  285. executable('rulescomp', 'rulescomp.c', dependencies: test_dep),
  286. env: test_env,
  287. )
  288. test(
  289. 'compose',
  290. executable(
  291. 'compose',
  292. 'compose.c',
  293. '../src/compose/dump.c',
  294. dependencies: test_dep,
  295. ),
  296. env: test_env,
  297. )
  298. test(
  299. 'utils',
  300. executable('utils', 'utils.c', dependencies: test_dep),
  301. env: test_env,
  302. )
  303. test(
  304. 'symbols-leak-test',
  305. find_program('symbols-leak-test.py'),
  306. env: test_env,
  307. suite: ['python-tests'],
  308. )
  309. test(
  310. 'modifiers',
  311. executable('modifiers', 'modifiers.c', dependencies: test_dep),
  312. env: test_env,
  313. )
  314. test(
  315. 'messages',
  316. executable(
  317. 'messages',
  318. 'messages.c',
  319. '../tools/messages.c',
  320. include_directories: include_directories('../tools'),
  321. dependencies: test_dep,
  322. ),
  323. env: test_env,
  324. )
  325. if get_option('enable-x11')
  326. has_xvfb = find_program('Xvfb', required: false)
  327. has_xkbcomp = find_program('xkbcomp', required: false)
  328. # We only warn because the build machine may not be the same
  329. # as the host/test machine.
  330. if not has_xvfb.found()
  331. warning('Xvfb program not found, but is required to run X11 tests.')
  332. endif
  333. if not has_xkbcomp.found()
  334. warning('xkbcomp program not found, but is required to run X11 tests.')
  335. endif
  336. x11_test_dep = declare_dependency(
  337. link_with: libxkbcommon_x11_test_internal,
  338. dependencies: [
  339. test_dep,
  340. xcb_dep,
  341. ],
  342. )
  343. x11_xvfb_test_shared_lib = static_library(
  344. 'x11-xvfb-test-shared',
  345. sources: [
  346. 'xvfb-wrapper.c',
  347. ],
  348. dependencies: x11_test_dep,
  349. )
  350. x11_xvfb_test_dep = declare_dependency(
  351. link_with: x11_xvfb_test_shared_lib,
  352. dependencies: [x11_test_dep],
  353. )
  354. test(
  355. 'x11',
  356. executable('x11', 'x11.c', dependencies: x11_xvfb_test_dep),
  357. suite: ['x11'],
  358. env: test_env,
  359. is_parallel: false,
  360. )
  361. test(
  362. 'x11comp',
  363. executable(
  364. 'x11comp',
  365. 'x11comp.c',
  366. dependencies: x11_xvfb_test_dep,
  367. ),
  368. suite: ['x11', 'flaky'],
  369. env: test_env,
  370. is_parallel: false,
  371. )
  372. endif
  373. if get_option('enable-xkbregistry')
  374. test(
  375. 'registry',
  376. executable(
  377. 'registry',
  378. 'registry.c',
  379. dependencies: [dep_libxkbregistry, dep_libxml, test_dep],
  380. ),
  381. env: test_env,
  382. )
  383. endif
  384. if build_tools
  385. test(
  386. 'tool-option-parsing',
  387. find_program('tool-option-parsing.py'),
  388. env: test_env,
  389. suite: ['python-tests'],
  390. )
  391. # A set of keysyms to test for. Add one or two symbols to this array
  392. # whenever the xorgproto gets updated to make sure we resolve them.
  393. keysyms_to_test = [
  394. 'XF86Macro23',
  395. ]
  396. env = environment()
  397. env.set('XKB_CONFIG_ROOT', meson.current_source_dir() / 'data')
  398. foreach keysym : keysyms_to_test
  399. test(
  400. 'keysym-@0@'.format(keysym),
  401. find_program('test-keysym.py'),
  402. env: env,
  403. args: [keysym, '--tool', xkbcli_compile_keymap],
  404. suite: ['python-tests'],
  405. )
  406. endforeach
  407. endif
  408. valgrind = find_program('valgrind', required: false)
  409. if valgrind.found()
  410. add_test_setup(
  411. 'valgrind',
  412. exe_wrapper: [
  413. valgrind,
  414. '--leak-check=full',
  415. '--track-origins=yes',
  416. '--gen-suppressions=all',
  417. '--error-exitcode=99',
  418. ],
  419. # This is used in some tests, to avoid excessive run time.
  420. env: {'RUNNING_VALGRIND': '1'},
  421. timeout_multiplier: 10,
  422. )
  423. else
  424. message('valgrind not found, disabling valgrind test setup')
  425. endif
  426. # xkeyboard-config "verifier"
  427. xkct_config = configuration_data()
  428. xkct_config.set('MESON_BUILD_ROOT', meson.current_build_dir())
  429. xkct_config.set('XKB_CONFIG_ROOT', XKB_CONFIG_ROOT)
  430. configure_file(
  431. input: 'xkeyboard-config-test.py.in',
  432. output: 'xkeyboard-config-test',
  433. configuration: xkct_config,
  434. )