1# 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
23test_arg = [
24    '-DTEST_TRACE',
25]
26
27# Compile the test dts into a binary for pdbg.
28pdbg_test_dtb = custom_target('build_pdbg_test_dtb',
29    input   : files('pdbg_test.dts'),
30    output  : 'pdbg_test.dtb',
31    command : [ find_program('dtc'), '-I', 'dts', '-O', 'dtb',
32                '-o', '@OUTPUT@', '@INPUT@' ])
33
34# end2end code exerciser for experiment and testing
35subdir('end2end')
36
37tests = [
38  'bin_stream_test',
39  'ffdc_file_test',
40  'resolution_test',
41  'test-lpc-timeout',
42  'test-pll-unlock',
43]
44
45analyzer_src = files(
46  '../analyzer/plugins/p10-plugins.cpp',
47  '../analyzer/service_data.cpp',
48  '../analyzer/resolution.cpp',
49)
50
51# We cannot link to `util_lib` because that is built without `-DTEST_TRACE` and
52# any of the util functions that use `trace.hpp` will throw a linker error
53# because we don't have access to phosphor-logging in test ... yet.
54util_src = files(
55    '../util/ffdc_file.cpp',
56    '../util/pdbg.cpp',
57    '../util/temporary_file.cpp',
58)
59
60sim_src = files(
61  'pdbg-sim-only.cpp',
62)
63
64foreach t : tests
65    test(t,
66         executable(t.underscorify(),
67                    [ files(t + '.cpp'), pdbg_test_dtb,
68                      analyzer_src, util_src, sim_src ],
69                    dependencies : [ libhei_dep, libpdbg_dep, gtest_dep ],
70                    cpp_args : test_arg,
71                    include_directories : incdir),
72         env : [ 'PDBG_DTB=' + pdbg_test_dtb.full_path() ])
73endforeach
74