blob: 25b3cfae16cdd96797b0ba32fe55b7ea109a3e87 [file] [log] [blame]
William A. Kennington III0a01b2a2021-05-13 18:38:57 -07001gtest = dependency('gtest', main: true, disabler: true, required: false)
2gmock = dependency('gmock', disabler: true, required: false)
3if not gtest.found() or not gmock.found()
Patrick Williams297a63b2025-03-03 11:07:57 -05004 gtest_opts = import('cmake').subproject_options()
5 gtest_opts.add_cmake_defines({'CMAKE_CXX_FLAGS': '-Wno-pedantic'})
6 gtest_proj = import('cmake').subproject(
7 'googletest',
8 options: gtest_opts,
9 required: false,
10 )
11 if gtest_proj.found()
12 gtest = declare_dependency(
13 dependencies: [
14 dependency('threads'),
15 gtest_proj.dependency('gtest'),
16 gtest_proj.dependency('gtest_main'),
17 ],
18 )
19 gmock = gtest_proj.dependency('gmock')
20 else
21 assert(not get_option('tests').enabled(), 'Googletest is required')
22 endif
William A. Kennington III0a01b2a2021-05-13 18:38:57 -070023endif
24
25test_headers = include_directories('.')
26
27test_deps = [
Patrick Williams297a63b2025-03-03 11:07:57 -050028 meson.get_compiler('cpp').find_library('dl'),
29 networkd_dep,
30 gtest,
31 gmock,
32 dependency('stdplus-gtest'),
William A. Kennington III0a01b2a2021-05-13 18:38:57 -070033]
34
35test_lib = static_library(
Patrick Williams297a63b2025-03-03 11:07:57 -050036 'networkd-test',
37 'mock_syscall.cpp',
38 implicit_include_directories: false,
39 include_directories: test_headers,
40 dependencies: test_deps,
41)
William A. Kennington III0a01b2a2021-05-13 18:38:57 -070042
43test_dep = declare_dependency(
Patrick Williams297a63b2025-03-03 11:07:57 -050044 dependencies: test_deps,
45 include_directories: test_headers,
46 link_with: test_lib,
47)
William A. Kennington III0a01b2a2021-05-13 18:38:57 -070048
49tests = [
Patrick Williams297a63b2025-03-03 11:07:57 -050050 'config_parser',
51 'ethernet_interface',
52 'netlink',
53 'network_manager',
54 'rtnetlink',
55 'types',
56 'util',
William A. Kennington III0a01b2a2021-05-13 18:38:57 -070057]
58
William A. Kennington III84bfe672022-07-13 14:15:30 -070059run_with_tmp = find_program('run_with_tmp', native: true)
60
William A. Kennington III7ba2d562022-08-02 13:20:23 -070061add_test_setup(
Patrick Williams297a63b2025-03-03 11:07:57 -050062 'networkd',
63 exe_wrapper: run_with_tmp,
64 env: {'TMPTMPL': 'phosphor-networkd-test.XXXXXXXXXX'},
65 is_default: true,
66)
William A. Kennington III7ba2d562022-08-02 13:20:23 -070067
68add_test_setup(
Patrick Williams297a63b2025-03-03 11:07:57 -050069 'valgrind',
70 exe_wrapper: [run_with_tmp, 'valgrind'],
71 env: {'TMPTMPL': 'phosphor-networkd-test.XXXXXXXXXX'},
72)
William A. Kennington III7ba2d562022-08-02 13:20:23 -070073
William A. Kennington III0a01b2a2021-05-13 18:38:57 -070074foreach t : tests
Patrick Williams297a63b2025-03-03 11:07:57 -050075 test(
76 t,
77 executable(
78 t.underscorify(),
79 'test_' + t + '.cpp',
80 implicit_include_directories: false,
81 dependencies: test_dep,
82 ),
83 )
William A. Kennington III0a01b2a2021-05-13 18:38:57 -070084endforeach
Asmitha Karunanithia6c07572022-05-05 03:19:45 -050085
86if (get_option('hyp-nw-config') == true)
Patrick Williams297a63b2025-03-03 11:07:57 -050087 subdir('ibm/hypervisor-network-mgr-test')
Asmitha Karunanithia6c07572022-05-05 03:19:45 -050088endif