-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
experimental: add test-to-harness conversion logic #495
Conversation
Signed-off-by: David Korczynski <[email protected]>
Signed-off-by: David Korczynski <[email protected]>
/gcbrun skip |
Signed-off-by: David Korczynski <[email protected]>
/gcbrun skip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some nits:
name = 'TestConverterPrompt' | ||
|
||
def __init__(self, introspector_report: Dict[str, Any], | ||
all_header_files: List[str], test_dir: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dict[...]
and list[...]
in lower cases. Same below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't do, see here: #454 (comment)
# was found empirically to be valuable. | ||
macros_defined_in_test = [] | ||
for line in test_case.test_content.split('\n'): | ||
if '#define' in line and len(line.split(' ')) == 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe exclude commented lines later?
// #define a b
/*
#define a b
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave this for now -- it works well but ultimately I would want some stronger logic for macros (e.g. using IR/AST stuff). Will leave as is and monitor if it shows up as a limitation.
/gcbrun skip |
Signed-off-by: David Korczynski <[email protected]>
Adds a fuzz harness heuristic that relies on converting existing tests. At this stage, it's done without relying on FI, we simply (1) find tests files in the target project; (2) read them; (3) for each test file we use a simple prompt to convert it into a harness. At this stage, it already out-performs on some existing projects, e.g: https://github.com/jkuhlmann/cgltf/blob/master/test/main.c In this case, we have a harness generated that looks quite nice: ```c // Heuristic: TestConverterPrompt :: Target: #include <stdlib.h> #include <stdint.h> #include <stdio.h> #include <string.h> #define CGLTF_IMPLEMENTATION #include "cgltf.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (size < 1) { return 0; } cgltf_options options; memset(&options, 0, sizeof(cgltf_options)); cgltf_data* parsed_data = NULL; cgltf_result result; // Parse input data result = cgltf_parse(&options, data, size, &parsed_data); if (result == cgltf_result_success) { result = cgltf_validate(parsed_data); } if (result == cgltf_result_success) { // Use the parsed data in some way // For example, print file type and mesh count printf("Type: %u\n", parsed_data->file_type); printf("Meshes: %u\n", (unsigned)parsed_data->meshes_count); } cgltf_free(parsed_data); return 0; } ``` Ref: google#494 --------- Signed-off-by: David Korczynski <[email protected]>
Adds a fuzz harness heuristic that relies on converting existing tests. At this stage, it's done without relying on FI, we simply (1) find tests files in the target project; (2) read them; (3) for each test file we use a simple prompt to convert it into a harness.
At this stage, it already out-performs on some existing projects, e.g: https://github.com/jkuhlmann/cgltf/blob/master/test/main.c
In this case, we have a harness generated that looks quite nice:
Ref: #494