vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

test-fuzz.c (1358B)


      1 /* See LICENSE for copyright details */
      2 #include "test-common.c"
      3 
      4 static void
      5 fuzz_entry_point(s8 data, Stream error_stream)
      6 {
      7 	MemoryBlock term_backing = {.memory = malloc(MB(4)), .size = MB(4)};
      8 	Term *term = place_term_into_memory(term_backing, 24, 80);
      9 	term->error_stream = error_stream;
     10 	s8 raw = launder_static_string(term, data);
     11 	handle_input(term, term->arena_for_frame, raw);
     12 
     13 	if (term->error_stream.widx != 0)
     14 		os_write_err_msg(stream_to_s8(&term->error_stream));
     15 
     16 	release_term_memory(term_backing);
     17 }
     18 
     19 i32
     20 LLVMFuzzerTestOneInput(const u8 *data, size_t size)
     21 {
     22 	fuzz_entry_point((s8){.data = (u8 *)data, .len = size}, (Stream){0});
     23 	return 0;
     24 }
     25 
     26 #ifdef __AFL_FUZZ_TESTCASE_LEN
     27 #include <unistd.h>
     28 
     29 __AFL_FUZZ_INIT();
     30 i32
     31 main(void)
     32 {
     33 	__AFL_INIT();
     34 	u8 *buf = __AFL_FUZZ_TESTCASE_BUF;
     35 	while (__AFL_LOOP(10000)) {
     36 		i32 len = __AFL_FUZZ_TESTCASE_LEN;
     37 		fuzz_entry_point((s8){.data = buf, .len = len}, (Stream){0});
     38 	}
     39 	return 0;
     40 }
     41 #endif
     42 
     43 #ifdef FUZZ_RESULTS
     44 i32
     45 main(i32 argc, char *argv[])
     46 {
     47 	if (argc != 2) {
     48 		os_write_err_msg(s8("usage: test-fuzz-results crash_input\n"));
     49 		return 1;
     50 	}
     51 
     52 	Arena file_backing = arena_from_memory_block(os_block_alloc(MB(1)));
     53 	s8 file_data       = os_read_file((u8 *)argv[1], &file_backing);
     54 	fuzz_entry_point(file_data, arena_stream(arena_from_memory_block(os_block_alloc(MB(4)))));
     55 
     56 	return 0;
     57 }
     58 #endif