xref: /openbmc/openpower-hw-diags/test/meson.build (revision 69e3771f9e131c97a3ca7f139170988bd3e8fb48)
18018391dSZane Shelley# Get the gtest/gmock dependencies.
28018391dSZane Shelleygtest_dep = dependency('gtest', main: true, disabler: true, required: false)
38018391dSZane Shelleygmock_dep = dependency('gmock', disabler: true, required: false)
48018391dSZane Shelleyif not gtest_dep.found() or not gmock_dep.found()
58018391dSZane Shelley    cmake = import('cmake')
68018391dSZane Shelley    gtest_proj = cmake.subproject('googletest',
78018391dSZane Shelley                                  required: false)
88018391dSZane Shelley    if gtest_proj.found()
98018391dSZane Shelley        gtest_dep = declare_dependency(
108018391dSZane Shelley            dependencies: [
118018391dSZane Shelley                dependency('threads'),
128018391dSZane Shelley                gtest_proj.dependency('gtest'),
138018391dSZane Shelley                gtest_proj.dependency('gtest_main'),
148018391dSZane Shelley            ]
158018391dSZane Shelley        )
168018391dSZane Shelley        gmock_dep = gtest_proj.dependency('gmock')
178018391dSZane Shelley    else
188018391dSZane Shelley        assert(not get_option('tests').enabled(),
198018391dSZane Shelley               'Googletest is required if tests are enabled')
208018391dSZane Shelley    endif
218018391dSZane Shelleyendif
228018391dSZane Shelley
239491cdb4SZane Shelley################################################################################
249491cdb4SZane Shelley
25afc6acdaSZane Shelley# Compile the test dts into a binary for pdbg.
26afc6acdaSZane Shelleypdbg_test_dtb = custom_target('build_pdbg_test_dtb',
2708c21c25SZane Shelley    input   : files('pdbg-test.dts'),
2808c21c25SZane Shelley    output  : 'pdbg-test.dtb',
29afc6acdaSZane Shelley    command : [ find_program('dtc'), '-I', 'dts', '-O', 'dtb',
30afc6acdaSZane Shelley                '-o', '@OUTPUT@', '@INPUT@' ])
31afc6acdaSZane Shelley
32d195b716SZane Shelleypdbg_env = 'PDBG_DTB=' + pdbg_test_dtb.full_path()
33d195b716SZane Shelley
3408c21c25SZane Shelley################################################################################
3508c21c25SZane Shelley
36985388a8SZane Shelley# IMPORTANT NOTE:
37985388a8SZane Shelley# We cannot link to `util_lib` because:
38985388a8SZane Shelley#   - It is built without `-DTEST_TRACE` and any of the util functions that use
39985388a8SZane Shelley#     `trace.hpp` will throw a linker error because we don't have access to
40985388a8SZane Shelley#     phosphor-logging in test ... yet.
41985388a8SZane Shelley#   - Some functions related to pdbg and dbus simply cannot be built in the test
42985388a8SZane Shelley#     environment. Instead, there are alternate implementation of those
43985388a8SZane Shelley#     functions to simulate them for testing.
44985388a8SZane Shelley
45985388a8SZane Shelleytest_args = [
46985388a8SZane Shelley  '-DTEST_TRACE',
47985388a8SZane Shelley  package_args,
48985388a8SZane Shelley]
49985388a8SZane Shelley
50985388a8SZane Shelleytest_util_srcs = [
51985388a8SZane Shelley  files(
52985388a8SZane Shelley    '../util/data_file.cpp',
53985388a8SZane Shelley    '../util/ffdc_file.cpp',
54985388a8SZane Shelley    '../util/pdbg.cpp',
55985388a8SZane Shelley    '../util/temporary_file.cpp',
56985388a8SZane Shelley    'dbus-sim-only.cpp',
57985388a8SZane Shelley    'pdbg-sim-only.cpp',
58985388a8SZane Shelley  ),
59985388a8SZane Shelley  pdbg_test_dtb
60985388a8SZane Shelley]
61985388a8SZane Shelley
62985388a8SZane Shelleytest_deps = [
63985388a8SZane Shelley  libhei_dep,
64985388a8SZane Shelley  libpdbg_dep,
65985388a8SZane Shelley  gtest_dep,
66985388a8SZane Shelley]
67985388a8SZane Shelley
68985388a8SZane Shelleytest_vars = [
69985388a8SZane Shelley  pdbg_env,
70985388a8SZane Shelley]
71985388a8SZane Shelley
72985388a8SZane Shelleytest_util_lib = static_library('test_util_lib',
73985388a8SZane Shelley  sources             : test_util_srcs,
74985388a8SZane Shelley  include_directories : incdir,
75985388a8SZane Shelley  dependencies        : test_deps,
76985388a8SZane Shelley  cpp_args            : test_args,
77985388a8SZane Shelley  install             : false,
78985388a8SZane Shelley)
79985388a8SZane Shelley
80985388a8SZane Shelleytest_libs = [
81985388a8SZane Shelley  analyzer_lib,
82985388a8SZane Shelley  attn_lib,
83985388a8SZane Shelley  test_util_lib,
84985388a8SZane Shelley]
85985388a8SZane Shelley
86*69e3771fSZane Shelley# Additional SRCs that are not (or should not be) included in libraries.
87*69e3771fSZane Shelley# NOTE: Try to limit this, if possible, to prevent duplicate compilation.
88*69e3771fSZane Shelleytest_additional_srcs = [
892c228cdcSZane Shelley  '../analyzer/plugins/p10-plugins.cpp',
90d195b716SZane Shelley  '../analyzer/plugins/p10-tod-plugins.cpp',
91edfcbc38SZane Shelley  '../cli.cpp',
92edfcbc38SZane Shelley]
93edfcbc38SZane Shelley
94*69e3771fSZane Shelley################################################################################
95edfcbc38SZane Shelley
96*69e3771fSZane Shelleytestcases = [
97*69e3771fSZane Shelley  'test-bin-stream',
98*69e3771fSZane Shelley  'test-ffdc-file',
99*69e3771fSZane Shelley  'test-lpc-timeout',
100*69e3771fSZane Shelley  'test-pdbg-dts',
101*69e3771fSZane Shelley  'test-pll-unlock',
102*69e3771fSZane Shelley  'test-resolution',
103*69e3771fSZane Shelley  'test-tod-step-check-fault',
104*69e3771fSZane Shelley]
105edfcbc38SZane Shelley
106*69e3771fSZane Shelleyforeach tc : testcases
107*69e3771fSZane Shelley
108*69e3771fSZane Shelley  exe = executable(tc.underscorify(),
109*69e3771fSZane Shelley    sources             : [ files(tc + '.cpp'), test_additional_srcs ],
110*69e3771fSZane Shelley    include_directories : incdir,
111*69e3771fSZane Shelley    dependencies        : test_deps,
112*69e3771fSZane Shelley    cpp_args            : test_args,
113*69e3771fSZane Shelley    link_with           : test_libs,
114*69e3771fSZane Shelley  )
115*69e3771fSZane Shelley
116*69e3771fSZane Shelley  test(tc, exe, env: test_vars)
117*69e3771fSZane Shelley
118*69e3771fSZane Shelleyendforeach
119*69e3771fSZane Shelley
120*69e3771fSZane Shelley################################################################################
121*69e3771fSZane Shelley
122*69e3771fSZane Shelleytestcases = [
123*69e3771fSZane Shelley  'test-attention',
124*69e3771fSZane Shelley  'test-end2end',
125*69e3771fSZane Shelley  'test-util-data-file',
126*69e3771fSZane Shelley  'test-ti-handler',
127*69e3771fSZane Shelley]
128*69e3771fSZane Shelley
129*69e3771fSZane Shelleyforeach tc : testcases
130*69e3771fSZane Shelley
131*69e3771fSZane Shelley  exe = executable(tc.underscorify(),
132*69e3771fSZane Shelley    sources             : [ files(tc + '.cpp'), test_additional_srcs ],
133*69e3771fSZane Shelley    include_directories : incdir,
134*69e3771fSZane Shelley    dependencies        : test_deps,
135*69e3771fSZane Shelley    cpp_args            : test_args,
136985388a8SZane Shelley    link_with           : hwdiags_libs, # TODO: should use test_libs instead
137*69e3771fSZane Shelley  )
138edfcbc38SZane Shelley
139*69e3771fSZane Shelley  test(tc, exe, env: test_vars)
140*69e3771fSZane Shelley
141*69e3771fSZane Shelleyendforeach
142edfcbc38SZane Shelley
143