Add fuzz targets

Fuzzing is something that's good to do for a general purpose library and
can find bugs relatively quickly.

Enable fuzzing with libfuzzer (selected only because it was the easiest
to set up) and enable fuzz targets for 3 of our buffer-based interfaces.

Change-Id: I695a3a60ba09bea92cd462566bf2c46337eabd4b
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/tests/meson.build b/tests/meson.build
index 81060a2..6a4d16c 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -59,3 +59,39 @@
     ],
 )
 test('test-cper-tests', cper_tests)
+cxx = meson.get_compiler('cpp')
+if (cxx.get_id() == 'clang') and get_option('fuzz').allowed()
+    fuzz_args = [
+        '-fsanitize=fuzzer,address,leak',
+        '-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION',
+    ]
+
+    foreach fuzzer_test : ['fuzz_cper_buf_to_ir']
+        fuzz_exe = executable(
+            fuzzer_test,
+            [fuzzer_test + '.cpp'] + libcper_parse_sources + edk_sources,
+            implicit_include_directories: false,
+            include_directories: include_directories(test_include_dirs),
+            cpp_args: fuzz_args,
+            c_args: fuzz_args,
+            link_args: fuzz_args,
+            dependencies: [
+                json_c_dep,
+                gtest,
+                gmock,
+                nlohmann_json_dep,
+                valijson_dep,
+            ],
+        )
+        test(
+            fuzzer_test,
+            fuzz_exe,
+            args: [
+                '-max_total_time=10',
+                '-max_len=131072',
+                '-error_exitcode=1',
+                '-timeout_exitcode=2',
+            ],
+        )
+    endforeach
+endif