blob: f142318ee8dbbc3bd9ff58f0ab465e66dd6c80b3 [file] [log] [blame]
Brandon Kimdab96f12021-02-18 11:21:37 -08001# Copyright 2021 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
William A. Kennington III7d6fa422021-02-08 17:04:02 -080015gtest = dependency('gtest', main: true, disabler: true, required: false)
16gmock = dependency('gmock', disabler: true, required: false)
17if not gtest.found() or not gmock.found()
Patrick Williams24c61c72025-02-01 08:38:07 -050018 gtest_proj = import('cmake').subproject(
19 'googletest',
20 cmake_options: ['-DCMAKE_CXX_FLAGS=-Wno-pedantic'],
21 required: false,
22 )
23 if gtest_proj.found()
24 gtest = declare_dependency(
25 dependencies: [
26 dependency('threads'),
27 gtest_proj.dependency('gtest'),
28 gtest_proj.dependency('gtest_main'),
29 ],
30 )
31 gmock = gtest_proj.dependency('gmock')
32 else
33 assert(not build_tests.allowed(), 'Googletest is required')
34 endif
William A. Kennington III7d6fa422021-02-08 17:04:02 -080035endif
36
37tests = [
Patrick Williams24c61c72025-02-01 08:38:07 -050038 'iface_test',
39 'sock_test',
40 #'ncsi_test', # TODO: Re-enable when fixed
William A. Kennington III7d6fa422021-02-08 17:04:02 -080041]
42
43ncsid_test_headers = include_directories('.')
44
45ncsid_test_lib = static_library(
Patrick Williams24c61c72025-02-01 08:38:07 -050046 'ncsid_test',
47 ['net_iface_mock.cpp', 'nic_mock.cpp'],
48 include_directories: ncsid_test_headers,
49 implicit_include_directories: false,
50 dependencies: ncsid,
51)
William A. Kennington III7d6fa422021-02-08 17:04:02 -080052
53ncsid_test = declare_dependency(
Patrick Williams24c61c72025-02-01 08:38:07 -050054 dependencies: ncsid,
55 include_directories: ncsid_test_headers,
56 link_with: ncsid_test_lib,
57)
William A. Kennington III7d6fa422021-02-08 17:04:02 -080058
59foreach t : tests
Patrick Williams24c61c72025-02-01 08:38:07 -050060 test(
61 t,
62 executable(
63 t.underscorify(),
64 t + '.cpp',
65 implicit_include_directories: false,
66 dependencies: [gtest, gmock, ncsid_test],
67 ),
68 )
William A. Kennington III7d6fa422021-02-08 17:04:02 -080069endforeach
70
Patrick Williams24c61c72025-02-01 08:38:07 -050071script_tests = ['normalize_ip_test', 'normalize_mac_test']
William A. Kennington III7d6fa422021-02-08 17:04:02 -080072
73script_env = environment()
74script_deps = []
75script_env.set('NORMALIZE_IP', normalize_ip.full_path())
76script_deps += normalize_ip
77script_env.set('NORMALIZE_MAC', normalize_mac.full_path())
78script_deps += normalize_mac
79
80foreach st : script_tests
Patrick Williams24c61c72025-02-01 08:38:07 -050081 test(
82 st,
83 find_program('bash'),
84 args: files(st + '.sh'),
85 protocol: 'tap',
86 env: script_env,
87 depends: script_deps,
88 )
William A. Kennington III7d6fa422021-02-08 17:04:02 -080089endforeach