Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 1 | gtest = dependency('gtest', main: true, disabler: true, required: false) |
| 2 | gmock = dependency('gmock', disabler: true, required: false) |
| 3 | |
| 4 | if 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 |
| 17 | endif |
| 18 | |
| 19 | swampd_sources = include_directories('../') |
| 20 | |
| 21 | unit_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 | |
| 38 | unittest_source = { |
| 39 | 'dbus_active_unittest': ['../dbus/dbusactiveread.cpp'], |
| 40 | 'dbus_passive_unittest': ['../dbus/dbuspassive.cpp', |
| 41 | '../dbus/dbuspassiveredundancy.cpp', |
| 42 | '../dbus/dbusutil.cpp'], |
| 43 | 'dbus_util_unittest': ['../dbus/dbusutil.cpp'], |
| 44 | 'json_parse_unittest': ['../buildjson/buildjson.cpp'], |
Josh Lehan | 31058fd | 2023-01-13 11:06:16 -0800 | [diff] [blame] | 45 | 'pid_json_unittest': ['../pid/buildjson.cpp', |
| 46 | '../util.cpp'], |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 47 | 'pid_fancontroller_unittest': ['../pid/ec/pid.cpp', |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 48 | '../pid/ec/logging.cpp', |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 49 | '../pid/fancontroller.cpp', |
| 50 | '../pid/pidcontroller.cpp', |
| 51 | '../pid/tuning.cpp', |
| 52 | '../pid/util.cpp'], |
| 53 | 'pid_stepwisecontroller_unittest': ['../pid/ec/stepwise.cpp', |
| 54 | '../pid/stepwisecontroller.cpp', |
Josh Lehan | 5d678da | 2022-11-15 19:25:02 -0800 | [diff] [blame] | 55 | '../pid/tuning.cpp', |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 56 | '../pid/util.cpp'], |
| 57 | 'pid_thermalcontroller_unittest': ['../pid/ec/pid.cpp', |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 58 | '../pid/ec/logging.cpp', |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 59 | '../pid/pidcontroller.cpp', |
| 60 | '../pid/thermalcontroller.cpp', |
| 61 | '../pid/tuning.cpp', |
| 62 | '../pid/util.cpp'], |
| 63 | 'pid_zone_unittest': ['../pid/ec/pid.cpp', |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 64 | '../pid/ec/logging.cpp', |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 65 | '../pid/pidcontroller.cpp', |
| 66 | '../pid/tuning.cpp', |
| 67 | '../pid/zone.cpp', |
| 68 | '../sensors/manager.cpp'], |
| 69 | 'sensor_host_unittest': ['../sensors/host.cpp'], |
| 70 | 'sensor_manager_unittest': ['../sensors/manager.cpp'], |
| 71 | 'sensor_pluggable_unittest': ['../sensors/pluggable.cpp'], |
| 72 | 'sensors_json_unittest': ['../sensors/buildjson.cpp'], |
| 73 | 'util_unittest': ['../sensors/build_utils.cpp'] |
| 74 | } |
| 75 | |
| 76 | foreach t : unit_tests |
| 77 | test(t, executable(t.underscorify(), t + '.cpp', |
| 78 | unittest_source.get(t), |
| 79 | include_directories: [ |
| 80 | swampd_sources, |
| 81 | ], |
| 82 | link_args: dynamic_linker, |
Patrick Williams | 397e6bc | 2023-11-29 06:44:45 -0600 | [diff] [blame] | 83 | build_rpath: get_option('oe-sdk').allowed() ? rpath : '', |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 84 | dependencies: [ |
| 85 | gtest, |
| 86 | gmock, |
| 87 | deps, |
| 88 | ])) |
| 89 | endforeach |