xref: /openbmc/openpower-hw-diags/test/meson.build (revision 20ed74db38b328f78e72c5fe3121a6a90d6efe01)
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,
65*20ed74dbSZane Shelley  phosphor_logging_dep,
66985388a8SZane Shelley  gtest_dep,
67985388a8SZane Shelley]
68985388a8SZane Shelley
69985388a8SZane Shelleytest_vars = [
70985388a8SZane Shelley  pdbg_env,
71*20ed74dbSZane Shelley  'LG2_FORCE_STDERR=true',
72985388a8SZane Shelley]
73985388a8SZane Shelley
74985388a8SZane Shelleytest_util_lib = static_library('test_util_lib',
75985388a8SZane Shelley  sources             : test_util_srcs,
76985388a8SZane Shelley  include_directories : incdir,
77985388a8SZane Shelley  dependencies        : test_deps,
78985388a8SZane Shelley  cpp_args            : test_args,
79985388a8SZane Shelley  install             : false,
80985388a8SZane Shelley)
81985388a8SZane Shelley
82985388a8SZane Shelleytest_libs = [
83985388a8SZane Shelley  analyzer_lib,
84985388a8SZane Shelley  attn_lib,
85985388a8SZane Shelley  test_util_lib,
86985388a8SZane Shelley]
87985388a8SZane Shelley
8869e3771fSZane Shelley# Additional SRCs that are not (or should not be) included in libraries.
8969e3771fSZane Shelley# NOTE: Try to limit this, if possible, to prevent duplicate compilation.
9069e3771fSZane Shelleytest_additional_srcs = [
912c228cdcSZane Shelley  '../analyzer/plugins/p10-plugins.cpp',
92d195b716SZane Shelley  '../analyzer/plugins/p10-tod-plugins.cpp',
93edfcbc38SZane Shelley  '../cli.cpp',
94edfcbc38SZane Shelley]
95edfcbc38SZane Shelley
9669e3771fSZane Shelley################################################################################
97edfcbc38SZane Shelley
9869e3771fSZane Shelleytestcases = [
9969e3771fSZane Shelley  'test-bin-stream',
10069e3771fSZane Shelley  'test-ffdc-file',
10169e3771fSZane Shelley  'test-lpc-timeout',
10269e3771fSZane Shelley  'test-pdbg-dts',
10369e3771fSZane Shelley  'test-pll-unlock',
10469e3771fSZane Shelley  'test-resolution',
10569e3771fSZane Shelley  'test-tod-step-check-fault',
10669e3771fSZane Shelley]
107edfcbc38SZane Shelley
10869e3771fSZane Shelleyforeach tc : testcases
10969e3771fSZane Shelley
11069e3771fSZane Shelley  exe = executable(tc.underscorify(),
11169e3771fSZane Shelley    sources             : [ files(tc + '.cpp'), test_additional_srcs ],
11269e3771fSZane Shelley    include_directories : incdir,
11369e3771fSZane Shelley    dependencies        : test_deps,
11469e3771fSZane Shelley    cpp_args            : test_args,
11569e3771fSZane Shelley    link_with           : test_libs,
11669e3771fSZane Shelley  )
11769e3771fSZane Shelley
11869e3771fSZane Shelley  test(tc, exe, env: test_vars)
11969e3771fSZane Shelley
12069e3771fSZane Shelleyendforeach
12169e3771fSZane Shelley
12269e3771fSZane Shelley################################################################################
12369e3771fSZane Shelley
12469e3771fSZane Shelleytestcases = [
12569e3771fSZane Shelley  'test-attention',
12669e3771fSZane Shelley  'test-end2end',
12769e3771fSZane Shelley  'test-util-data-file',
12869e3771fSZane Shelley  'test-ti-handler',
12969e3771fSZane Shelley]
13069e3771fSZane Shelley
13169e3771fSZane Shelleyforeach tc : testcases
13269e3771fSZane Shelley
13369e3771fSZane Shelley  exe = executable(tc.underscorify(),
13469e3771fSZane Shelley    sources             : [ files(tc + '.cpp'), test_additional_srcs ],
13569e3771fSZane Shelley    include_directories : incdir,
13669e3771fSZane Shelley    dependencies        : test_deps,
13769e3771fSZane Shelley    cpp_args            : test_args,
138985388a8SZane Shelley    link_with           : hwdiags_libs, # TODO: should use test_libs instead
13969e3771fSZane Shelley  )
140edfcbc38SZane Shelley
14169e3771fSZane Shelley  test(tc, exe, env: test_vars)
14269e3771fSZane Shelley
14369e3771fSZane Shelleyendforeach
144edfcbc38SZane Shelley
145