Brandon Kim | dab96f1 | 2021-02-18 11:21:37 -0800 | [diff] [blame] | 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 | |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 15 | gtest = dependency('gtest', main: true, disabler: true, required: false) |
| 16 | gmock = dependency('gmock', disabler: true, required: false) |
| 17 | if not gtest.found() or not gmock.found() |
Patrick Williams | 24c61c7 | 2025-02-01 08:38:07 -0500 | [diff] [blame] | 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 |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 35 | endif |
| 36 | |
| 37 | tests = [ |
Patrick Williams | 24c61c7 | 2025-02-01 08:38:07 -0500 | [diff] [blame] | 38 | 'iface_test', |
William A. Kennington III | 7c15db6 | 2025-02-19 15:35:44 -0800 | [diff] [blame] | 39 | #'sock_test', |
Patrick Williams | 24c61c7 | 2025-02-01 08:38:07 -0500 | [diff] [blame] | 40 | #'ncsi_test', # TODO: Re-enable when fixed |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 41 | ] |
| 42 | |
| 43 | ncsid_test_headers = include_directories('.') |
| 44 | |
| 45 | ncsid_test_lib = static_library( |
Patrick Williams | 24c61c7 | 2025-02-01 08:38:07 -0500 | [diff] [blame] | 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 | ) |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 52 | |
| 53 | ncsid_test = declare_dependency( |
Patrick Williams | 24c61c7 | 2025-02-01 08:38:07 -0500 | [diff] [blame] | 54 | dependencies: ncsid, |
| 55 | include_directories: ncsid_test_headers, |
| 56 | link_with: ncsid_test_lib, |
| 57 | ) |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 58 | |
| 59 | foreach t : tests |
Patrick Williams | 24c61c7 | 2025-02-01 08:38:07 -0500 | [diff] [blame] | 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 | ) |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 69 | endforeach |
| 70 | |
Patrick Williams | 24c61c7 | 2025-02-01 08:38:07 -0500 | [diff] [blame] | 71 | script_tests = ['normalize_ip_test', 'normalize_mac_test'] |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 72 | |
| 73 | script_env = environment() |
| 74 | script_deps = [] |
| 75 | script_env.set('NORMALIZE_IP', normalize_ip.full_path()) |
| 76 | script_deps += normalize_ip |
| 77 | script_env.set('NORMALIZE_MAC', normalize_mac.full_path()) |
| 78 | script_deps += normalize_mac |
| 79 | |
| 80 | foreach st : script_tests |
Patrick Williams | 24c61c7 | 2025-02-01 08:38:07 -0500 | [diff] [blame] | 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 | ) |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 89 | endforeach |