blob: e1ab8bbd1f7fe7120a71257461ef18457bed4415 [file] [log] [blame]
Zane Shelley80183912021-12-21 11:52:25 -06001# Get the gtest/gmock dependencies.
2gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
3gmock_dep = dependency('gmock', disabler: true, required: false)
4if 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
21endif
22
Zane Shelley9491cdb2022-02-01 10:40:45 -060023################################################################################
24
Zane Shelleyafc6acd2022-01-12 14:32:56 -060025# Compile the test dts into a binary for pdbg.
26pdbg_test_dtb = custom_target('build_pdbg_test_dtb',
Zane Shelley08c21c22022-01-26 16:58:18 -060027 input : files('pdbg-test.dts'),
28 output : 'pdbg-test.dtb',
Zane Shelleyafc6acd2022-01-12 14:32:56 -060029 command : [ find_program('dtc'), '-I', 'dts', '-O', 'dtb',
30 '-o', '@OUTPUT@', '@INPUT@' ])
31
Zane Shelleyd195b712022-01-26 13:26:34 -060032pdbg_env = 'PDBG_DTB=' + pdbg_test_dtb.full_path()
33
Zane Shelley08c21c22022-01-26 16:58:18 -060034################################################################################
35
Zane Shelley985388a2022-03-24 16:35:46 -050036# 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
45test_args = [
46 '-DTEST_TRACE',
47 package_args,
48]
49
50test_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
62test_deps = [
63 libhei_dep,
64 libpdbg_dep,
Zane Shelley20ed74d2022-03-26 13:50:57 -050065 phosphor_logging_dep,
Zane Shelley985388a2022-03-24 16:35:46 -050066 gtest_dep,
67]
68
69test_vars = [
70 pdbg_env,
Zane Shelley20ed74d2022-03-26 13:50:57 -050071 'LG2_FORCE_STDERR=true',
Zane Shelley985388a2022-03-24 16:35:46 -050072]
73
74test_util_lib = static_library('test_util_lib',
75 sources : test_util_srcs,
76 include_directories : incdir,
77 dependencies : test_deps,
78 cpp_args : test_args,
79 install : false,
80)
81
82test_libs = [
83 analyzer_lib,
84 attn_lib,
85 test_util_lib,
86]
87
Zane Shelley69e37712022-03-24 16:43:03 -050088# Additional SRCs that are not (or should not be) included in libraries.
89# NOTE: Try to limit this, if possible, to prevent duplicate compilation.
90test_additional_srcs = [
91 '../analyzer/plugins/p10-plugins.cpp',
92 '../analyzer/plugins/p10-tod-plugins.cpp',
93 '../cli.cpp',
Zane Shelley248cbf82019-05-03 17:07:18 -050094]
95
Zane Shelley08c21c22022-01-26 16:58:18 -060096################################################################################
97
Zane Shelley69e37712022-03-24 16:43:03 -050098testcases = [
99 'test-bin-stream',
100 'test-ffdc-file',
101 'test-lpc-timeout',
102 'test-pdbg-dts',
103 'test-pll-unlock',
104 'test-resolution',
105 'test-tod-step-check-fault',
Zane Shelley08c21c22022-01-26 16:58:18 -0600106]
Zane Shelley979e2872021-09-20 22:46:06 -0500107
Zane Shelley69e37712022-03-24 16:43:03 -0500108foreach tc : testcases
Zane Shelleye90b85d2021-12-17 17:24:49 -0600109
Zane Shelley69e37712022-03-24 16:43:03 -0500110 exe = executable(tc.underscorify(),
111 sources : [ files(tc + '.cpp'), test_additional_srcs ],
112 include_directories : incdir,
113 dependencies : test_deps,
114 cpp_args : test_args,
115 link_with : test_libs,
116 )
Zane Shelley08c21c22022-01-26 16:58:18 -0600117
Zane Shelley69e37712022-03-24 16:43:03 -0500118 test(tc, exe, env: test_vars)
Zane Shelley08c21c22022-01-26 16:58:18 -0600119
Zane Shelley69e37712022-03-24 16:43:03 -0500120endforeach
Zane Shelley08c21c22022-01-26 16:58:18 -0600121
122################################################################################
123
Zane Shelley69e37712022-03-24 16:43:03 -0500124testcases = [
125 'test-attention',
126 'test-end2end',
127 'test-util-data-file',
128 'test-ti-handler',
Zane Shelley08c21c22022-01-26 16:58:18 -0600129]
130
Zane Shelley69e37712022-03-24 16:43:03 -0500131foreach tc : testcases
Zane Shelley08c21c22022-01-26 16:58:18 -0600132
Zane Shelley69e37712022-03-24 16:43:03 -0500133 exe = executable(tc.underscorify(),
134 sources : [ files(tc + '.cpp'), test_additional_srcs ],
135 include_directories : incdir,
136 dependencies : test_deps,
137 cpp_args : test_args,
138 link_with : hwdiags_libs, # TODO: should use test_libs instead
139 )
Zane Shelley08c21c22022-01-26 16:58:18 -0600140
Zane Shelley69e37712022-03-24 16:43:03 -0500141 test(tc, exe, env: test_vars)
Zane Shelley08c21c22022-01-26 16:58:18 -0600142
Zane Shelley69e37712022-03-24 16:43:03 -0500143endforeach
Zane Shelleyedfcbc32022-03-24 15:56:52 -0500144