blob: 61b8b26d55bbeabb851a0c12c2083dac16d1dbcb [file] [log] [blame]
Harvey.Wub1225b22022-10-28 17:42:07 +08001gtest = dependency('gtest', main: true, disabler: true, required: false)
2gmock = dependency('gmock', disabler: true, required: false)
3
4if not gtest.found() or not gmock.found()
5 gtest_proj = import('cmake').subproject('googletest', required: false)
6 if gtest_proj.found()
7 gtest = declare_dependency(
8 dependencies: [
9 dependency('threads'),
10 gtest_proj.dependency('gtest'),
11 gtest_proj.dependency('gtest_main'),
12 ])
13 gmock = gtest_proj.dependency('gmock')
14 else
15 assert(not get_option('tests').enabled(), 'Googletest is required')
16 endif
17endif
18
19swampd_sources = include_directories('../')
20
21unit_tests = [
22 'dbus_active_unittest',
23 'dbus_passive_unittest',
24 'dbus_util_unittest',
25 'json_parse_unittest',
26 'pid_json_unittest',
27 'pid_fancontroller_unittest',
28 'pid_stepwisecontroller_unittest',
29 'pid_thermalcontroller_unittest',
30 'pid_zone_unittest',
31 'sensor_host_unittest',
32 'sensor_manager_unittest',
33 'sensor_pluggable_unittest',
34 'sensors_json_unittest',
35 'util_unittest',
36]
37
38unittest_source = {
39 'dbus_active_unittest': ['../dbus/dbusactiveread.cpp'],
40 'dbus_passive_unittest': ['../dbus/dbuspassive.cpp',
41 '../dbus/dbuspassiveredundancy.cpp',
James Zheng6df8bb52024-11-27 23:38:47 +000042 '../dbus/dbusutil.cpp',
43 '../failsafeloggers/failsafe_logger_utility.cpp'],
Harvey.Wub1225b22022-10-28 17:42:07 +080044 'dbus_util_unittest': ['../dbus/dbusutil.cpp'],
45 'json_parse_unittest': ['../buildjson/buildjson.cpp'],
Josh Lehan31058fd2023-01-13 11:06:16 -080046 'pid_json_unittest': ['../pid/buildjson.cpp',
47 '../util.cpp'],
Harvey.Wub1225b22022-10-28 17:42:07 +080048 'pid_fancontroller_unittest': ['../pid/ec/pid.cpp',
Josh Lehande745422020-11-07 02:14:09 -080049 '../pid/ec/logging.cpp',
Harvey.Wub1225b22022-10-28 17:42:07 +080050 '../pid/fancontroller.cpp',
51 '../pid/pidcontroller.cpp',
52 '../pid/tuning.cpp',
53 '../pid/util.cpp'],
54 'pid_stepwisecontroller_unittest': ['../pid/ec/stepwise.cpp',
55 '../pid/stepwisecontroller.cpp',
Josh Lehan5d678da2022-11-15 19:25:02 -080056 '../pid/tuning.cpp',
Harvey.Wub1225b22022-10-28 17:42:07 +080057 '../pid/util.cpp'],
58 'pid_thermalcontroller_unittest': ['../pid/ec/pid.cpp',
Josh Lehande745422020-11-07 02:14:09 -080059 '../pid/ec/logging.cpp',
Harvey.Wub1225b22022-10-28 17:42:07 +080060 '../pid/pidcontroller.cpp',
61 '../pid/thermalcontroller.cpp',
62 '../pid/tuning.cpp',
63 '../pid/util.cpp'],
James Zheng6df8bb52024-11-27 23:38:47 +000064 'pid_zone_unittest': ['../failsafeloggers/builder.cpp',
65 '../failsafeloggers/failsafe_logger.cpp',
66 '../failsafeloggers/failsafe_logger_utility.cpp',
67 '../pid/ec/pid.cpp',
Josh Lehande745422020-11-07 02:14:09 -080068 '../pid/ec/logging.cpp',
Harvey.Wub1225b22022-10-28 17:42:07 +080069 '../pid/pidcontroller.cpp',
70 '../pid/tuning.cpp',
71 '../pid/zone.cpp',
72 '../sensors/manager.cpp'],
James Zheng6df8bb52024-11-27 23:38:47 +000073 'sensor_host_unittest': ['../failsafeloggers/failsafe_logger.cpp',
74 '../failsafeloggers/failsafe_logger_utility.cpp',
75 '../sensors/host.cpp'],
Harvey.Wub1225b22022-10-28 17:42:07 +080076 'sensor_manager_unittest': ['../sensors/manager.cpp'],
77 'sensor_pluggable_unittest': ['../sensors/pluggable.cpp'],
78 'sensors_json_unittest': ['../sensors/buildjson.cpp'],
79 'util_unittest': ['../sensors/build_utils.cpp']
80}
81
82foreach t : unit_tests
83 test(t, executable(t.underscorify(), t + '.cpp',
84 unittest_source.get(t),
85 include_directories: [
86 swampd_sources,
87 ],
88 link_args: dynamic_linker,
Patrick Williams397e6bc2023-11-29 06:44:45 -060089 build_rpath: get_option('oe-sdk').allowed() ? rpath : '',
Harvey.Wub1225b22022-10-28 17:42:07 +080090 dependencies: [
91 gtest,
92 gmock,
93 deps,
94 ]))
95endforeach