blob: ca21b42bac4eb020705fd25863dce75f88b4a5f6 [file] [log] [blame]
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -08001cmake = import('cmake')
2
Erwin Tsaur8870c072025-02-28 12:57:12 -08003gtest = dependency('gtest', disabler: true, required: false)
John Chung197ea122024-05-03 19:57:55 +08004gmock = dependency('gmock', disabler: true, required: false)
5if 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 Tanousc833a3a2024-07-15 11:53:53 -070013 ],
John Chung197ea122024-05-03 19:57:55 +080014 )
15 gmock = gtest_proj.dependency('gmock')
16 else
17 assert(
18 not get_option('tests').allowed(),
Ed Tanousc833a3a2024-07-15 11:53:53 -070019 'Googletest is required if tests are enabled',
John Chung197ea122024-05-03 19:57:55 +080020 )
21 endif
22endif
23
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080024nlohmann_json_dep = dependency(
25 'nlohmann_json',
26 required: false,
27 version: '>=3.11.2',
28 include_type: 'system',
29)
30if not nlohmann_json_dep.found()
31 nlohmann_proj = subproject('nlohmann_json', required: true)
32 nlohmann_json_dep = nlohmann_proj.get_variable('nlohmann_json_dep')
33endif
34
35valijson_dep = dependency('valijson', required: false)
36if not valijson_dep.found()
37 valijson_proj = cmake.subproject('valijson')
38 valijson_dep = valijson_proj.get_variable('valijson_dep')
39endif
40
Ed Tanousd6b62632025-03-14 15:30:07 -070041test_sources = ['test-utils.cpp', 'base64_test.cpp']
John Chung197ea122024-05-03 19:57:55 +080042
Thu Nguyene42fb482024-10-15 14:43:11 +000043test_include_dirs = ['.', '../include']
John Chung197ea122024-05-03 19:57:55 +080044
Ed Tanousa84fc932024-07-15 13:48:35 -070045cper_tests = executable(
46 'cper-tests',
Ed Tanousd6b62632025-03-14 15:30:07 -070047 'ir-tests.cpp',
48 test_sources,
Ed Tanousa84fc932024-07-15 13:48:35 -070049 implicit_include_directories: false,
50 include_directories: include_directories(test_include_dirs),
51 cpp_args: '-fpermissive',
Ed Tanous10eb6de2024-10-03 17:23:12 -070052 dependencies: [
53 libcper_parse_dep,
54 libcper_generate_dep,
55 json_c_dep,
56 gtest,
57 gmock,
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080058 nlohmann_json_dep,
Aushim Nagarkatti517282f2025-03-03 17:08:31 -080059 valijson_dep,
Ed Tanous10eb6de2024-10-03 17:23:12 -070060 ],
John Chung197ea122024-05-03 19:57:55 +080061)
Karthik Rajagopalan9fe2cb52024-08-08 15:12:29 -070062test('test-cper-tests', cper_tests)
Ed Tanous6070e1b2025-03-14 11:20:35 -070063
Ed Tanous8121f7e2025-03-06 14:39:07 -080064cxx = meson.get_compiler('cpp')
Ed Tanous6070e1b2025-03-14 11:20:35 -070065
66# Fuzzing only works on linux at this moment. osx clang doesn't have leak detector
67is_darwin = host_machine.system().startswith('darwin')
68if (cxx.get_id() == 'clang') and get_option('fuzz').allowed() and not is_darwin
Ed Tanous7a531ff2025-03-14 17:06:49 -070069 sanitize = ['fuzzer']
Ed Tanous8121f7e2025-03-06 14:39:07 -080070 fuzz_args = [
Ed Tanous6070e1b2025-03-14 11:20:35 -070071 '-fsanitize=' + ','.join(sanitize),
Ed Tanous8121f7e2025-03-06 14:39:07 -080072 '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION',
73 ]
74
75 foreach fuzzer_test : ['fuzz_cper_buf_to_ir']
76 fuzz_exe = executable(
77 fuzzer_test,
Ed Tanousd6b62632025-03-14 15:30:07 -070078 [fuzzer_test + '.cpp'] + libcper_parse_sources + edk_sources + test_sources + libcper_generate_sources,
Ed Tanous8121f7e2025-03-06 14:39:07 -080079 implicit_include_directories: false,
80 include_directories: include_directories(test_include_dirs),
81 cpp_args: fuzz_args,
82 c_args: fuzz_args,
83 link_args: fuzz_args,
84 dependencies: [
85 json_c_dep,
86 gtest,
87 gmock,
88 nlohmann_json_dep,
89 valijson_dep,
90 ],
91 )
92 test(
93 fuzzer_test,
94 fuzz_exe,
95 args: [
96 '-max_total_time=10',
97 '-max_len=131072',
98 '-error_exitcode=1',
99 '-timeout_exitcode=2',
100 ],
101 )
102 endforeach
103endif