blob: 2f1e2b23453ba3c25f01d31436b52946e275b30f [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
Ed Tanousa3663052025-03-16 12:54:36 -070024jsonc_daccord = dependency('jsoncdac')
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080025
Ed Tanousd6b62632025-03-14 15:30:07 -070026test_sources = ['test-utils.cpp', 'base64_test.cpp']
John Chung197ea122024-05-03 19:57:55 +080027
Thu Nguyene42fb482024-10-15 14:43:11 +000028test_include_dirs = ['.', '../include']
John Chung197ea122024-05-03 19:57:55 +080029
Ed Tanousa84fc932024-07-15 13:48:35 -070030cper_tests = executable(
31 'cper-tests',
Ed Tanousd6b62632025-03-14 15:30:07 -070032 'ir-tests.cpp',
33 test_sources,
Ed Tanousa84fc932024-07-15 13:48:35 -070034 implicit_include_directories: false,
35 include_directories: include_directories(test_include_dirs),
36 cpp_args: '-fpermissive',
Ed Tanous10eb6de2024-10-03 17:23:12 -070037 dependencies: [
Ed Tanousa3663052025-03-16 12:54:36 -070038 json_c_dep,
39 jsonc_daccord,
Ed Tanous10eb6de2024-10-03 17:23:12 -070040 libcper_parse_dep,
41 libcper_generate_dep,
Ed Tanous10eb6de2024-10-03 17:23:12 -070042 gtest,
43 gmock,
44 ],
John Chung197ea122024-05-03 19:57:55 +080045)
Karthik Rajagopalan9fe2cb52024-08-08 15:12:29 -070046test('test-cper-tests', cper_tests)
Ed Tanous6070e1b2025-03-14 11:20:35 -070047
Ed Tanous8121f7e2025-03-06 14:39:07 -080048cxx = meson.get_compiler('cpp')
Ed Tanous6070e1b2025-03-14 11:20:35 -070049
50# Fuzzing only works on linux at this moment. osx clang doesn't have leak detector
51is_darwin = host_machine.system().startswith('darwin')
52if (cxx.get_id() == 'clang') and get_option('fuzz').allowed() and not is_darwin
Ed Tanous7a531ff2025-03-14 17:06:49 -070053 sanitize = ['fuzzer']
Ed Tanous8121f7e2025-03-06 14:39:07 -080054 fuzz_args = [
Ed Tanous6070e1b2025-03-14 11:20:35 -070055 '-fsanitize=' + ','.join(sanitize),
Ed Tanous8121f7e2025-03-06 14:39:07 -080056 '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION',
57 ]
58
59 foreach fuzzer_test : ['fuzz_cper_buf_to_ir']
60 fuzz_exe = executable(
61 fuzzer_test,
Ed Tanousd6b62632025-03-14 15:30:07 -070062 [fuzzer_test + '.cpp'] + libcper_parse_sources + edk_sources + test_sources + libcper_generate_sources,
Ed Tanous8121f7e2025-03-06 14:39:07 -080063 implicit_include_directories: false,
64 include_directories: include_directories(test_include_dirs),
65 cpp_args: fuzz_args,
66 c_args: fuzz_args,
67 link_args: fuzz_args,
Ed Tanousa3663052025-03-16 12:54:36 -070068 dependencies: [json_c_dep, jsonc_daccord, gtest, gmock],
Ed Tanous8121f7e2025-03-06 14:39:07 -080069 )
70 test(
71 fuzzer_test,
72 fuzz_exe,
73 args: [
74 '-max_total_time=10',
75 '-max_len=131072',
76 '-error_exitcode=1',
77 '-timeout_exitcode=2',
78 ],
79 )
80 endforeach
81endif