meson.build 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. if not get_option('libraries')
  2. error('-Dtests=true requires -Dlibraries=true')
  3. endif
  4. test_runner = static_library(
  5. 'test-runner',
  6. sources: [
  7. 'test-runner.c',
  8. 'test-helpers.c',
  9. 'test-compositor.c'
  10. ],
  11. include_directories: [ root_inc, src_inc ],
  12. dependencies: [
  13. cc.find_library('dl', required: false),
  14. dependency('threads'),
  15. epoll_dep,
  16. ffi_dep,
  17. wayland_util_dep,
  18. wayland_private_dep,
  19. wayland_client_dep,
  20. wayland_server_dep
  21. ]
  22. )
  23. test_runner_dep = declare_dependency(
  24. link_with: test_runner,
  25. include_directories: [ src_inc ],
  26. dependencies: [
  27. dependency('threads'),
  28. cc.find_library('dl', required: false)
  29. ]
  30. )
  31. tests_protocol_xml = files('../protocol/tests.xml')
  32. tests_server_protocol_h = custom_target(
  33. 'test server protocol header',
  34. command: [ wayland_scanner_for_build, '-s', 'server-header', '@INPUT@', '@OUTPUT@' ],
  35. input: tests_protocol_xml,
  36. output: 'tests-server-protocol.h'
  37. )
  38. tests_client_protocol_c = custom_target(
  39. 'test client protocol header',
  40. command: [ wayland_scanner_for_build, '-s', 'client-header', '@INPUT@', '@OUTPUT@' ],
  41. input: tests_protocol_xml,
  42. output: 'tests-client-protocol.h'
  43. )
  44. tests_protocol_c = custom_target(
  45. 'test protocol source',
  46. command: [ wayland_scanner_for_build, '-s', 'public-code', '@INPUT@', '@OUTPUT@' ],
  47. input: tests_protocol_xml,
  48. output: 'tests-protocol.c'
  49. )
  50. exec_fd_leak_checker = executable(
  51. 'exec-fd-leak-checker',
  52. 'exec-fd-leak-checker.c',
  53. dependencies: test_runner_dep
  54. )
  55. if add_languages('cpp', native: false)
  56. test(
  57. 'cpp-compile-test',
  58. executable(
  59. 'cpp-compile-test',
  60. 'cpp-compile-test.cpp',
  61. wayland_server_protocol_h,
  62. include_directories: src_inc
  63. )
  64. )
  65. endif
  66. sed_path = find_program('sed').full_path()
  67. if get_option('scanner')
  68. scanner_test_env = [
  69. 'TEST_DATA_DIR=@0@/data'.format(meson.current_source_dir()),
  70. 'TEST_OUTPUT_DIR=@0@/output'.format(meson.current_build_dir()),
  71. 'SED=@0@'.format(sed_path),
  72. 'WAYLAND_SCANNER=@0@'.format(wayland_scanner.full_path()),
  73. ]
  74. test(
  75. 'scanner-test',
  76. find_program('scanner-test.sh'),
  77. env: scanner_test_env,
  78. )
  79. run_target(
  80. 'gen-scanner-test',
  81. command: find_program('scanner-test-gen.sh'),
  82. env: scanner_test_env,
  83. )
  84. endif
  85. tests = {
  86. 'array-test': {},
  87. 'client-test': {
  88. 'extra_sources': [ wayland_server_protocol_h ],
  89. },
  90. 'display-test': {
  91. 'extra_sources': [
  92. wayland_client_protocol_h,
  93. wayland_server_protocol_h,
  94. tests_server_protocol_h,
  95. tests_client_protocol_c,
  96. tests_protocol_c,
  97. ],
  98. },
  99. 'connection-test': {
  100. 'extra_sources': [
  101. wayland_client_protocol_h,
  102. wayland_server_protocol_h,
  103. ],
  104. },
  105. 'event-loop-test': {
  106. 'extra_sources': [ wayland_server_protocol_h ],
  107. },
  108. 'fixed-test': {},
  109. 'interface-test': {
  110. 'extra_sources': [ wayland_client_protocol_h ],
  111. },
  112. 'list-test': {},
  113. 'map-test': {},
  114. 'sanity-test' : {
  115. 'extra_sources': [
  116. wayland_client_protocol_h,
  117. wayland_server_protocol_h,
  118. ],
  119. 'runtime_deps': [ exec_fd_leak_checker ],
  120. },
  121. 'socket-test': {
  122. 'extra_sources': [
  123. wayland_client_protocol_h,
  124. wayland_server_protocol_h,
  125. ],
  126. },
  127. 'queue-test': {
  128. 'extra_sources': [
  129. wayland_client_protocol_h,
  130. wayland_server_protocol_h,
  131. ],
  132. },
  133. 'signal-test': {
  134. 'extra_sources': [ wayland_server_protocol_h ],
  135. },
  136. 'newsignal-test': {
  137. 'extra_sources': [
  138. # wayland-server.c is needed here to access wl_priv_* functions
  139. files('../src/wayland-server.c'),
  140. wayland_server_protocol_h,
  141. ],
  142. },
  143. 'resources-test': {
  144. 'extra_sources': [ wayland_server_protocol_h ],
  145. },
  146. 'message-test': {
  147. 'extra_sources': [
  148. wayland_client_protocol_h,
  149. wayland_server_protocol_h,
  150. ],
  151. },
  152. 'compositor-introspection-test': {
  153. 'extra_sources': [
  154. wayland_client_protocol_h,
  155. wayland_server_protocol_h,
  156. ],
  157. },
  158. 'protocol-logger-test': {
  159. 'extra_sources': [
  160. wayland_client_protocol_h,
  161. wayland_server_protocol_h,
  162. ],
  163. },
  164. 'headers-test': {
  165. 'extra_sources': [
  166. wayland_client_protocol_h,
  167. wayland_server_protocol_h,
  168. 'headers-protocol-test.c',
  169. wayland_client_protocol_core_h,
  170. wayland_server_protocol_core_h,
  171. 'headers-protocol-core-test.c',
  172. ],
  173. },
  174. 'os-wrappers-test': {
  175. 'runtime_deps': [ exec_fd_leak_checker ],
  176. },
  177. 'proxy-test': {
  178. 'extra_sources': [
  179. wayland_client_protocol_h,
  180. wayland_server_protocol_h,
  181. ],
  182. },
  183. 'enum-validator-test': {},
  184. }
  185. foreach test_name, test_extras : tests
  186. test_extra_sources = test_extras.get('extra_sources', [])
  187. test_runtime_deps = test_extras.get('runtime_deps', [])
  188. test_sources = [ test_name + '.c' ] + test_extra_sources
  189. test_deps = [test_runner_dep, epoll_dep]
  190. bin = executable(test_name, test_sources, dependencies: test_deps)
  191. test(
  192. test_name,
  193. bin,
  194. depends: test_runtime_deps,
  195. env: [
  196. 'TEST_SRC_DIR=@0@'.format(meson.current_source_dir()),
  197. 'TEST_BUILD_DIR=@0@'.format(meson.current_build_dir()),
  198. ],
  199. )
  200. endforeach