Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 1 | cmake = import('cmake') |
| 2 | |
Erwin Tsaur | 8870c07 | 2025-02-28 12:57:12 -0800 | [diff] [blame] | 3 | gtest = dependency('gtest', disabler: true, required: false) |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 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'), |
Ed Tanous | c833a3a | 2024-07-15 11:53:53 -0700 | [diff] [blame] | 12 | ], |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 13 | ) |
| 14 | gmock = gtest_proj.dependency('gmock') |
| 15 | else |
| 16 | assert( |
| 17 | not get_option('tests').allowed(), |
Ed Tanous | c833a3a | 2024-07-15 11:53:53 -0700 | [diff] [blame] | 18 | 'Googletest is required if tests are enabled', |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 19 | ) |
| 20 | endif |
| 21 | endif |
| 22 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame^] | 23 | jsonc_daccord = dependency( |
| 24 | 'jsoncdac', |
| 25 | default_options: ['default_library=static'], |
| 26 | ) |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 27 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame^] | 28 | test_sources = ['test-utils.c', 'base64_test.cpp'] |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 29 | |
Thu Nguyen | e42fb48 | 2024-10-15 14:43:11 +0000 | [diff] [blame] | 30 | test_include_dirs = ['.', '../include'] |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 31 | |
Ed Tanous | a84fc93 | 2024-07-15 13:48:35 -0700 | [diff] [blame] | 32 | cper_tests = executable( |
| 33 | 'cper-tests', |
Ed Tanous | d6b6263 | 2025-03-14 15:30:07 -0700 | [diff] [blame] | 34 | 'ir-tests.cpp', |
| 35 | test_sources, |
Ed Tanous | a84fc93 | 2024-07-15 13:48:35 -0700 | [diff] [blame] | 36 | implicit_include_directories: false, |
| 37 | include_directories: include_directories(test_include_dirs), |
Ed Tanous | 10eb6de | 2024-10-03 17:23:12 -0700 | [diff] [blame] | 38 | dependencies: [ |
Ed Tanous | a366305 | 2025-03-16 12:54:36 -0700 | [diff] [blame] | 39 | json_c_dep, |
| 40 | jsonc_daccord, |
Ed Tanous | 10eb6de | 2024-10-03 17:23:12 -0700 | [diff] [blame] | 41 | libcper_parse_dep, |
| 42 | libcper_generate_dep, |
Ed Tanous | 10eb6de | 2024-10-03 17:23:12 -0700 | [diff] [blame] | 43 | gtest, |
| 44 | gmock, |
| 45 | ], |
John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 46 | ) |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame^] | 47 | test('test-cper-tests', cper_tests, protocol: 'gtest') |
Ed Tanous | 6070e1b | 2025-03-14 11:20:35 -0700 | [diff] [blame] | 48 | |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 49 | cxx = meson.get_compiler('cpp') |
Ed Tanous | 6070e1b | 2025-03-14 11:20:35 -0700 | [diff] [blame] | 50 | |
| 51 | # Fuzzing only works on linux at this moment. osx clang doesn't have leak detector |
| 52 | is_darwin = host_machine.system().startswith('darwin') |
| 53 | if (cxx.get_id() == 'clang') and get_option('fuzz').allowed() and not is_darwin |
Ed Tanous | 7a531ff | 2025-03-14 17:06:49 -0700 | [diff] [blame] | 54 | sanitize = ['fuzzer'] |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 55 | fuzz_args = [ |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 56 | '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame^] | 57 | '-fsanitize=fuzzer,address,leak', |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 58 | ] |
| 59 | |
| 60 | foreach fuzzer_test : ['fuzz_cper_buf_to_ir'] |
| 61 | fuzz_exe = executable( |
| 62 | fuzzer_test, |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame^] | 63 | [fuzzer_test + '.c'] + libcper_parse_sources + edk_sources + 'test-utils.c' + libcper_generate_sources, |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 64 | implicit_include_directories: false, |
| 65 | include_directories: include_directories(test_include_dirs), |
| 66 | cpp_args: fuzz_args, |
| 67 | c_args: fuzz_args, |
| 68 | link_args: fuzz_args, |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame^] | 69 | dependencies: [json_c_dep, jsonc_daccord], |
Ed Tanous | 8121f7e | 2025-03-06 14:39:07 -0800 | [diff] [blame] | 70 | ) |
| 71 | test( |
| 72 | fuzzer_test, |
| 73 | fuzz_exe, |
| 74 | args: [ |
| 75 | '-max_total_time=10', |
| 76 | '-max_len=131072', |
| 77 | '-error_exitcode=1', |
| 78 | '-timeout_exitcode=2', |
| 79 | ], |
| 80 | ) |
| 81 | endforeach |
| 82 | endif |