Commit 1232d78f authored by Niklas Haas's avatar Niklas Haas
Browse files

tests: add fuzzer test cases

Designed for use with AFLplusplus's persistent mode. Didn't manage to
find anything, unfortunately. But I suppose that's a good thing.

Closes #136
parent e0093907
......@@ -29,3 +29,6 @@ option('tests', type: 'boolean', value: false,
option('bench', type: 'boolean', value: false,
description: 'Enable building benchmarks (`meson test benchmark`)')
option('fuzz', type: 'boolean', value: false,
description: 'Enable building fuzzer binaries (`CC=afl-cc`)')
......@@ -208,6 +208,11 @@ tests = [
'utils.c',
]
fuzzers = [
'user_shaders.c',
'lut.c',
]
# Optional dependencies / components
components = [
......@@ -428,3 +433,11 @@ if get_option('bench')
bench = executable('bench', 'tests/bench.c', dependencies: tdep)
test('benchmark', bench, is_parallel: false, timeout: 600)
endif
if get_option('fuzz')
foreach f : fuzzers
executable('fuzz.' + f, 'tests/fuzz/' + f,
dependencies: tdep,
)
endforeach
endif
#include "../tests.h"
__AFL_FUZZ_INIT();
#pragma clang optimize off
int main()
{
struct pl_context *ctx = pl_context_create(PL_API_VER, NULL);
struct pl_custom_lut *lut;
#ifdef __AFL_HAVE_MANUAL_CONTROL
__AFL_INIT();
#endif
unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF;
while (__AFL_LOOP(100000)) {
size_t len = __AFL_FUZZ_TESTCASE_LEN;
lut = pl_lut_parse_cube(ctx, (char *) buf, len);
pl_lut_free(&lut);
}
pl_context_destroy(&ctx);
}
#include "../tests.h"
__AFL_FUZZ_INIT();
#pragma clang optimize off
int main()
{
struct pl_context *ctx = pl_context_create(PL_API_VER, NULL);
const struct pl_gpu *gpu = pl_gpu_dummy_create(ctx, NULL);
const struct pl_hook *hook;
#ifdef __AFL_HAVE_MANUAL_CONTROL
__AFL_INIT();
#endif
unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF;
while (__AFL_LOOP(100000)) {
size_t len = __AFL_FUZZ_TESTCASE_LEN;
hook = pl_mpv_user_shader_parse(gpu, (char *) buf, len);
pl_mpv_user_shader_destroy(&hook);
}
pl_gpu_dummy_destroy(&gpu);
pl_context_destroy(&ctx);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment