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: [ 21 '-DCMAKE_CXX_FLAGS=-Wno-pedantic', 22 ], 23 required: false) 24 if gtest_proj.found() 25 gtest = declare_dependency( 26 dependencies: [ 27 dependency('threads'), 28 gtest_proj.dependency('gtest'), 29 gtest_proj.dependency('gtest_main'), 30 ]) 31 gmock = gtest_proj.dependency('gmock') 32 else 33 assert(not build_tests.enabled(), '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 [ 48 'net_iface_mock.cpp', 49 'nic_mock.cpp', 50 ], 51 include_directories: ncsid_test_headers, 52 implicit_include_directories: false, 53 dependencies: ncsid) 54 55ncsid_test = declare_dependency( 56 dependencies: ncsid, 57 include_directories: ncsid_test_headers, 58 link_with: ncsid_test_lib) 59 60foreach t : tests 61 test(t, executable(t.underscorify(), t + '.cpp', 62 implicit_include_directories: false, 63 dependencies: [gtest, gmock, ncsid_test])) 64endforeach 65 66script_tests = [ 67 'normalize_ip_test', 68 'normalize_mac_test', 69] 70 71script_env = environment() 72script_deps = [] 73script_env.set('NORMALIZE_IP', normalize_ip.full_path()) 74script_deps += normalize_ip 75script_env.set('NORMALIZE_MAC', normalize_mac.full_path()) 76script_deps += normalize_mac 77 78foreach st : script_tests 79 test(st, find_program('bash'), args: files(st + '.sh'), 80 protocol: 'tap', env: script_env, depends: script_deps) 81endforeach 82