blob: cdfced738c43f972caaa16c6539ef3c9076222fb [file] [log] [blame]
George Liu687fe072021-05-04 16:16:43 +08001gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
2gmock_dep = dependency('gmock', disabler: true, required: false)
3if not gtest_dep.found() or not gmock_dep.found()
4 gtest_proj = import('cmake').subproject('googletest', required: false)
5 if gtest_proj.found()
6 gtest_dep = declare_dependency(
7 dependencies: [
8 dependency('threads'),
9 gtest_proj.dependency('gtest'),
10 gtest_proj.dependency('gtest_main'),
Patrick Williams42a4acb2025-02-01 08:36:31 -050011 ],
George Liu687fe072021-05-04 16:16:43 +080012 )
13 gmock_dep = gtest_proj.dependency('gmock')
Patrick Williams42a4acb2025-02-01 08:36:31 -050014 else
George Liu687fe072021-05-04 16:16:43 +080015 assert(
Patrick Williams95b0db92023-11-29 06:43:59 -060016 not get_option('tests').allowed(),
Patrick Williams42a4acb2025-02-01 08:36:31 -050017 'Googletest is required if tests are enabled',
George Liu687fe072021-05-04 16:16:43 +080018 )
Patrick Williams42a4acb2025-02-01 08:36:31 -050019 endif
George Liu687fe072021-05-04 16:16:43 +080020endif
21
Patrick Williams42a4acb2025-02-01 08:36:31 -050022test_yamls = ['test-empty-group', 'test-group-priority', 'test-led-priority']
Alexander Hanseneb1f46a2024-07-30 16:09:07 +020023
George Liu4b062012020-10-13 15:26:58 +080024test_sources = [
Patrick Williams42a4acb2025-02-01 08:36:31 -050025 '../manager/manager.cpp',
26 '../manager/config-validator.cpp',
27 '../utils.cpp',
George Liu4b062012020-10-13 15:26:58 +080028]
29
Alexander Hanseneb1f46a2024-07-30 16:09:07 +020030foreach yaml : test_yamls
Patrick Williams42a4acb2025-02-01 08:36:31 -050031 gen_hpp = custom_target(
32 yaml + '.hpp',
33 command: [
34 prog_python,
35 meson.project_source_root() + '/scripts/parse_led.py',
36 '--filename',
37 meson.project_source_root() + '/test/config/' + yaml + '.yaml',
38 '-o',
39 meson.current_build_dir(),
40 '--output-filename',
41 yaml + '.hpp',
42 ],
43 output: yaml + '.hpp',
44 )
Alexander Hanseneb1f46a2024-07-30 16:09:07 +020045
Patrick Williams42a4acb2025-02-01 08:36:31 -050046 test_sources += [gen_hpp]
Alexander Hanseneb1f46a2024-07-30 16:09:07 +020047endforeach
48
George Liu4b062012020-10-13 15:26:58 +080049tests = [
Patrick Williams42a4acb2025-02-01 08:36:31 -050050 'utest.cpp',
51 'utest-led-json.cpp',
52 'utest-group-priority.cpp',
53 'utest-led-yaml-group-priority.cpp',
54 'utest-led-yaml-led-priority.cpp',
55 'utest-led-yaml-empty-group.cpp',
56 'utest-config-validator.cpp',
George Liu4b062012020-10-13 15:26:58 +080057]
Patrick Williams95b0db92023-11-29 06:43:59 -060058if get_option('persistent-led-asserted').allowed()
Patrick Williams42a4acb2025-02-01 08:36:31 -050059 test_sources += ['../manager/serialize.cpp']
60 tests += ['utest-serialize.cpp']
George Liu54671852023-10-30 09:09:39 +080061endif
George Liu4b062012020-10-13 15:26:58 +080062
George Liu4b062012020-10-13 15:26:58 +080063foreach t : tests
Patrick Williams42a4acb2025-02-01 08:36:31 -050064 test(
65 t,
66 executable(
67 t.underscorify(),
68 t,
69 test_sources,
70 include_directories: ['..', '../manager'],
71 dependencies: [gtest_dep, gmock_dep, deps],
72 ),
73 workdir: meson.current_source_dir(),
74 )
Patrick Williams953315d2022-03-16 14:30:39 -050075endforeach