1# 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 15gtest = dependency('gtest', main: true, disabler: true, required: false) 16gmock = dependency('gmock', disabler: true, required: false) 17if not gtest.found() or not gmock.found() 18 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 35endif 36 37tests = [ 38 'iface_test', 39 #'sock_test', 40 #'ncsi_test', # TODO: Re-enable when fixed 41] 42 43ncsid_test_headers = include_directories('.') 44 45ncsid_test_lib = static_library( 46 '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) 52 53ncsid_test = declare_dependency( 54 dependencies: ncsid, 55 include_directories: ncsid_test_headers, 56 link_with: ncsid_test_lib, 57) 58 59foreach t : tests 60 test( 61 t, 62 executable( 63 t.underscorify(), 64 t + '.cpp', 65 implicit_include_directories: false, 66 dependencies: [gtest, gmock, ncsid_test], 67 ), 68 ) 69endforeach 70 71script_tests = ['normalize_ip_test', 'normalize_mac_test'] 72 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 81 test( 82 st, 83 find_program('bash'), 84 args: files(st + '.sh'), 85 protocol: 'tap', 86 env: script_env, 87 depends: script_deps, 88 ) 89endforeach 90