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( |
Patrick Williams | 6813d89 | 2025-02-01 08:37:30 -0500 | [diff] [blame] | 8 | dependencies: [ |
| 9 | dependency('threads'), |
| 10 | gtest_proj.dependency('gtest'), |
| 11 | gtest_proj.dependency('gtest_main'), |
| 12 | ], |
| 13 | ) |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 14 | gmock = gtest_proj.dependency('gmock') |
| 15 | else |
| 16 | assert(not get_option('tests').enabled(), 'Googletest is required') |
| 17 | endif |
| 18 | endif |
| 19 | |
| 20 | swampd_sources = include_directories('../') |
| 21 | |
| 22 | unit_tests = [ |
| 23 | 'dbus_active_unittest', |
| 24 | 'dbus_passive_unittest', |
| 25 | 'dbus_util_unittest', |
| 26 | 'json_parse_unittest', |
| 27 | 'pid_json_unittest', |
| 28 | 'pid_fancontroller_unittest', |
| 29 | 'pid_stepwisecontroller_unittest', |
| 30 | 'pid_thermalcontroller_unittest', |
| 31 | 'pid_zone_unittest', |
| 32 | 'sensor_host_unittest', |
| 33 | 'sensor_manager_unittest', |
| 34 | 'sensor_pluggable_unittest', |
| 35 | 'sensors_json_unittest', |
| 36 | 'util_unittest', |
| 37 | ] |
| 38 | |
| 39 | unittest_source = { |
| 40 | 'dbus_active_unittest': ['../dbus/dbusactiveread.cpp'], |
Patrick Williams | 6813d89 | 2025-02-01 08:37:30 -0500 | [diff] [blame] | 41 | 'dbus_passive_unittest': [ |
| 42 | '../dbus/dbuspassive.cpp', |
| 43 | '../dbus/dbuspassiveredundancy.cpp', |
| 44 | '../dbus/dbusutil.cpp', |
| 45 | '../failsafeloggers/failsafe_logger_utility.cpp', |
| 46 | ], |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 47 | 'dbus_util_unittest': ['../dbus/dbusutil.cpp'], |
| 48 | 'json_parse_unittest': ['../buildjson/buildjson.cpp'], |
Patrick Williams | 6813d89 | 2025-02-01 08:37:30 -0500 | [diff] [blame] | 49 | 'pid_json_unittest': ['../pid/buildjson.cpp', '../util.cpp'], |
| 50 | 'pid_fancontroller_unittest': [ |
| 51 | '../pid/ec/pid.cpp', |
| 52 | '../pid/ec/logging.cpp', |
| 53 | '../pid/fancontroller.cpp', |
| 54 | '../pid/pidcontroller.cpp', |
| 55 | '../pid/tuning.cpp', |
| 56 | '../pid/util.cpp', |
| 57 | ], |
| 58 | 'pid_stepwisecontroller_unittest': [ |
| 59 | '../pid/ec/stepwise.cpp', |
| 60 | '../pid/stepwisecontroller.cpp', |
| 61 | '../pid/tuning.cpp', |
| 62 | '../pid/util.cpp', |
| 63 | ], |
| 64 | 'pid_thermalcontroller_unittest': [ |
| 65 | '../pid/ec/pid.cpp', |
| 66 | '../pid/ec/logging.cpp', |
| 67 | '../pid/pidcontroller.cpp', |
| 68 | '../pid/thermalcontroller.cpp', |
| 69 | '../pid/tuning.cpp', |
| 70 | '../pid/util.cpp', |
| 71 | ], |
| 72 | 'pid_zone_unittest': [ |
| 73 | '../failsafeloggers/builder.cpp', |
| 74 | '../failsafeloggers/failsafe_logger.cpp', |
| 75 | '../failsafeloggers/failsafe_logger_utility.cpp', |
| 76 | '../pid/ec/pid.cpp', |
| 77 | '../pid/ec/logging.cpp', |
| 78 | '../pid/pidcontroller.cpp', |
| 79 | '../pid/tuning.cpp', |
| 80 | '../pid/zone.cpp', |
| 81 | '../sensors/manager.cpp', |
| 82 | ], |
| 83 | 'sensor_host_unittest': [ |
| 84 | '../failsafeloggers/failsafe_logger.cpp', |
| 85 | '../failsafeloggers/failsafe_logger_utility.cpp', |
| 86 | '../sensors/host.cpp', |
| 87 | ], |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 88 | 'sensor_manager_unittest': ['../sensors/manager.cpp'], |
| 89 | 'sensor_pluggable_unittest': ['../sensors/pluggable.cpp'], |
| 90 | 'sensors_json_unittest': ['../sensors/buildjson.cpp'], |
Patrick Williams | 6813d89 | 2025-02-01 08:37:30 -0500 | [diff] [blame] | 91 | 'util_unittest': ['../sensors/build_utils.cpp'], |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | foreach t : unit_tests |
Patrick Williams | 6813d89 | 2025-02-01 08:37:30 -0500 | [diff] [blame] | 95 | test( |
| 96 | t, |
| 97 | executable( |
| 98 | t.underscorify(), |
| 99 | t + '.cpp', |
| 100 | unittest_source.get(t), |
| 101 | include_directories: [swampd_sources], |
| 102 | link_args: dynamic_linker, |
| 103 | build_rpath: get_option('oe-sdk').allowed() ? rpath : '', |
| 104 | dependencies: [gtest, gmock, deps], |
| 105 | ), |
| 106 | ) |
Harvey.Wu | b1225b2 | 2022-10-28 17:42:07 +0800 | [diff] [blame] | 107 | endforeach |