Zane Shelley | 8018391 | 2021-12-21 11:52:25 -0600 | [diff] [blame] | 1 | # Get the gtest/gmock dependencies. |
| 2 | gtest_dep = dependency('gtest', main: true, disabler: true, required: false) |
| 3 | gmock_dep = dependency('gmock', disabler: true, required: false) |
| 4 | if not gtest_dep.found() or not gmock_dep.found() |
| 5 | cmake = import('cmake') |
| 6 | gtest_proj = cmake.subproject('googletest', |
| 7 | required: false) |
| 8 | if gtest_proj.found() |
| 9 | gtest_dep = declare_dependency( |
| 10 | dependencies: [ |
| 11 | dependency('threads'), |
| 12 | gtest_proj.dependency('gtest'), |
| 13 | gtest_proj.dependency('gtest_main'), |
| 14 | ] |
| 15 | ) |
| 16 | gmock_dep = gtest_proj.dependency('gmock') |
| 17 | else |
| 18 | assert(not get_option('tests').enabled(), |
| 19 | 'Googletest is required if tests are enabled') |
| 20 | endif |
| 21 | endif |
| 22 | |
Zane Shelley | 9491cdb | 2022-02-01 10:40:45 -0600 | [diff] [blame] | 23 | ################################################################################ |
| 24 | |
Zane Shelley | afc6acd | 2022-01-12 14:32:56 -0600 | [diff] [blame] | 25 | # Compile the test dts into a binary for pdbg. |
| 26 | pdbg_test_dtb = custom_target('build_pdbg_test_dtb', |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 27 | input : files('pdbg-test.dts'), |
| 28 | output : 'pdbg-test.dtb', |
Zane Shelley | afc6acd | 2022-01-12 14:32:56 -0600 | [diff] [blame] | 29 | command : [ find_program('dtc'), '-I', 'dts', '-O', 'dtb', |
| 30 | '-o', '@OUTPUT@', '@INPUT@' ]) |
| 31 | |
Zane Shelley | d195b71 | 2022-01-26 13:26:34 -0600 | [diff] [blame] | 32 | pdbg_env = 'PDBG_DTB=' + pdbg_test_dtb.full_path() |
| 33 | |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 34 | ################################################################################ |
| 35 | |
Zane Shelley | 985388a | 2022-03-24 16:35:46 -0500 | [diff] [blame] | 36 | # IMPORTANT NOTE: |
| 37 | # We cannot link to `util_lib` because: |
| 38 | # - It is built without `-DTEST_TRACE` and any of the util functions that use |
| 39 | # `trace.hpp` will throw a linker error because we don't have access to |
| 40 | # phosphor-logging in test ... yet. |
| 41 | # - Some functions related to pdbg and dbus simply cannot be built in the test |
| 42 | # environment. Instead, there are alternate implementation of those |
| 43 | # functions to simulate them for testing. |
| 44 | |
| 45 | test_args = [ |
| 46 | '-DTEST_TRACE', |
| 47 | package_args, |
| 48 | ] |
| 49 | |
| 50 | test_util_srcs = [ |
| 51 | files( |
| 52 | '../util/data_file.cpp', |
| 53 | '../util/ffdc_file.cpp', |
| 54 | '../util/pdbg.cpp', |
| 55 | '../util/temporary_file.cpp', |
| 56 | 'dbus-sim-only.cpp', |
| 57 | 'pdbg-sim-only.cpp', |
| 58 | ), |
| 59 | pdbg_test_dtb |
| 60 | ] |
| 61 | |
| 62 | test_deps = [ |
| 63 | libhei_dep, |
| 64 | libpdbg_dep, |
| 65 | gtest_dep, |
| 66 | ] |
| 67 | |
| 68 | test_vars = [ |
| 69 | pdbg_env, |
| 70 | ] |
| 71 | |
| 72 | test_util_lib = static_library('test_util_lib', |
| 73 | sources : test_util_srcs, |
| 74 | include_directories : incdir, |
| 75 | dependencies : test_deps, |
| 76 | cpp_args : test_args, |
| 77 | install : false, |
| 78 | ) |
| 79 | |
| 80 | test_libs = [ |
| 81 | analyzer_lib, |
| 82 | attn_lib, |
| 83 | test_util_lib, |
| 84 | ] |
| 85 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 86 | # Additional SRCs that are not (or should not be) included in libraries. |
| 87 | # NOTE: Try to limit this, if possible, to prevent duplicate compilation. |
| 88 | test_additional_srcs = [ |
| 89 | '../analyzer/plugins/p10-plugins.cpp', |
| 90 | '../analyzer/plugins/p10-tod-plugins.cpp', |
| 91 | '../cli.cpp', |
Zane Shelley | 248cbf8 | 2019-05-03 17:07:18 -0500 | [diff] [blame] | 92 | ] |
| 93 | |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 94 | ################################################################################ |
| 95 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 96 | testcases = [ |
| 97 | 'test-bin-stream', |
| 98 | 'test-ffdc-file', |
| 99 | 'test-lpc-timeout', |
| 100 | 'test-pdbg-dts', |
| 101 | 'test-pll-unlock', |
| 102 | 'test-resolution', |
| 103 | 'test-tod-step-check-fault', |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 104 | ] |
Zane Shelley | 979e287 | 2021-09-20 22:46:06 -0500 | [diff] [blame] | 105 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 106 | foreach tc : testcases |
Zane Shelley | e90b85d | 2021-12-17 17:24:49 -0600 | [diff] [blame] | 107 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 108 | exe = executable(tc.underscorify(), |
| 109 | sources : [ files(tc + '.cpp'), test_additional_srcs ], |
| 110 | include_directories : incdir, |
| 111 | dependencies : test_deps, |
| 112 | cpp_args : test_args, |
| 113 | link_with : test_libs, |
| 114 | ) |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 115 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 116 | test(tc, exe, env: test_vars) |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 117 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 118 | endforeach |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 119 | |
| 120 | ################################################################################ |
| 121 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 122 | testcases = [ |
| 123 | 'test-attention', |
| 124 | 'test-end2end', |
| 125 | 'test-util-data-file', |
| 126 | 'test-ti-handler', |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 127 | ] |
| 128 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 129 | foreach tc : testcases |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 130 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 131 | exe = executable(tc.underscorify(), |
| 132 | sources : [ files(tc + '.cpp'), test_additional_srcs ], |
| 133 | include_directories : incdir, |
| 134 | dependencies : test_deps, |
| 135 | cpp_args : test_args, |
| 136 | link_with : hwdiags_libs, # TODO: should use test_libs instead |
| 137 | ) |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 138 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 139 | test(tc, exe, env: test_vars) |
Zane Shelley | 08c21c2 | 2022-01-26 16:58:18 -0600 | [diff] [blame] | 140 | |
Zane Shelley | 69e3771 | 2022-03-24 16:43:03 -0500 | [diff] [blame] | 141 | endforeach |
Zane Shelley | edfcbc3 | 2022-03-24 15:56:52 -0500 | [diff] [blame] | 142 | |