Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 1 | cmake = import('cmake') |
| 2 | |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 3 | gtest = dependency('gtest', main: true, disabler: true, required: false) |
| 4 | gmock = dependency('gmock', disabler: true, required: false) |
| 5 | if not gtest.found() or not gmock.found() |
| 6 | gtest_proj = import('cmake').subproject('googletest', required: false) |
| 7 | if gtest_proj.found() |
| 8 | gtest = declare_dependency( |
| 9 | dependencies: [ |
| 10 | dependency('threads'), |
| 11 | gtest_proj.dependency('gtest'), |
| 12 | gtest_proj.dependency('gtest_main'), |
Ed Tanous | c833a3a | 2024-07-15 11:53:53 -0700 | [diff] [blame] | 13 | ], |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 14 | ) |
| 15 | gmock = gtest_proj.dependency('gmock') |
| 16 | else |
| 17 | assert( |
| 18 | not get_option('tests').allowed(), |
Ed Tanous | c833a3a | 2024-07-15 11:53:53 -0700 | [diff] [blame] | 19 | 'Googletest is required if tests are enabled', |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 20 | ) |
| 21 | endif |
| 22 | endif |
| 23 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 24 | nlohmann_json_dep = dependency( |
| 25 | 'nlohmann_json', |
| 26 | required: false, |
| 27 | version: '>=3.11.2', |
| 28 | include_type: 'system', |
| 29 | ) |
| 30 | if not nlohmann_json_dep.found() |
| 31 | nlohmann_proj = subproject('nlohmann_json', required: true) |
| 32 | nlohmann_json_dep = nlohmann_proj.get_variable('nlohmann_json_dep') |
| 33 | endif |
| 34 | |
| 35 | valijson_dep = dependency('valijson', required: false) |
| 36 | if not valijson_dep.found() |
| 37 | valijson_proj = cmake.subproject('valijson') |
| 38 | valijson_dep = valijson_proj.get_variable('valijson_dep') |
| 39 | endif |
| 40 | |
Ed Tanous | 10eb6de | 2024-10-03 17:23:12 -0700 | [diff] [blame] | 41 | sources = ['ir-tests.cpp', 'test-utils.cpp', 'base64_test.cpp'] |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 42 | |
Thu Nguyen | e42fb48 | 2024-10-15 14:43:11 +0000 | [diff] [blame] | 43 | test_include_dirs = ['.', '../include'] |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 44 | |
Ed Tanous | a84fc93 | 2024-07-15 13:48:35 -0700 | [diff] [blame] | 45 | cper_tests = executable( |
| 46 | 'cper-tests', |
| 47 | sources, |
| 48 | implicit_include_directories: false, |
| 49 | include_directories: include_directories(test_include_dirs), |
| 50 | cpp_args: '-fpermissive', |
Ed Tanous | 10eb6de | 2024-10-03 17:23:12 -0700 | [diff] [blame] | 51 | dependencies: [ |
| 52 | libcper_parse_dep, |
| 53 | libcper_generate_dep, |
| 54 | json_c_dep, |
| 55 | gtest, |
| 56 | gmock, |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 57 | nlohmann_json_dep, |
Aushim Nagarkatti | 517282f | 2025-03-03 17:08:31 -0800 | [diff] [blame] | 58 | valijson_dep, |
Ed Tanous | 10eb6de | 2024-10-03 17:23:12 -0700 | [diff] [blame] | 59 | ], |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 60 | ) |
Karthik Rajagopalan | 9fe2cb5 | 2024-08-08 15:12:29 -0700 | [diff] [blame] | 61 | test('test-cper-tests', cper_tests) |
Ed Tanous | 6070e1b | 2025-03-14 11:20:35 -0700 | [diff] [blame^] | 62 | |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 63 | cxx = meson.get_compiler('cpp') |
Ed Tanous | 6070e1b | 2025-03-14 11:20:35 -0700 | [diff] [blame^] | 64 | |
| 65 | # Fuzzing only works on linux at this moment. osx clang doesn't have leak detector |
| 66 | is_darwin = host_machine.system().startswith('darwin') |
| 67 | if (cxx.get_id() == 'clang') and get_option('fuzz').allowed() and not is_darwin |
| 68 | sanitize = ['fuzzer', 'address', 'leak'] |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 69 | fuzz_args = [ |
Ed Tanous | 6070e1b | 2025-03-14 11:20:35 -0700 | [diff] [blame^] | 70 | '-fsanitize=' + ','.join(sanitize), |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 71 | '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', |
| 72 | ] |
| 73 | |
| 74 | foreach fuzzer_test : ['fuzz_cper_buf_to_ir'] |
| 75 | fuzz_exe = executable( |
| 76 | fuzzer_test, |
| 77 | [fuzzer_test + '.cpp'] + libcper_parse_sources + edk_sources, |
| 78 | implicit_include_directories: false, |
| 79 | include_directories: include_directories(test_include_dirs), |
| 80 | cpp_args: fuzz_args, |
| 81 | c_args: fuzz_args, |
| 82 | link_args: fuzz_args, |
| 83 | dependencies: [ |
| 84 | json_c_dep, |
| 85 | gtest, |
| 86 | gmock, |
| 87 | nlohmann_json_dep, |
| 88 | valijson_dep, |
| 89 | ], |
| 90 | ) |
| 91 | test( |
| 92 | fuzzer_test, |
| 93 | fuzz_exe, |
| 94 | args: [ |
| 95 | '-max_total_time=10', |
| 96 | '-max_len=131072', |
| 97 | '-error_exitcode=1', |
| 98 | '-timeout_exitcode=2', |
| 99 | ], |
| 100 | ) |
| 101 | endforeach |
| 102 | endif |