we can take over rand now
This commit is contained in:
parent
54c42c78c9
commit
6f1f648cd2
@ -48,6 +48,8 @@
|
|||||||
#define assume DeepState_Assume
|
#define assume DeepState_Assume
|
||||||
#define check DeepState_Check
|
#define check DeepState_Check
|
||||||
|
|
||||||
|
#define rand DeepState_Int
|
||||||
|
|
||||||
#define MAYBE(...) \
|
#define MAYBE(...) \
|
||||||
if (DeepState_Bool()) { \
|
if (DeepState_Bool()) { \
|
||||||
__VA_ARGS__ ; \
|
__VA_ARGS__ ; \
|
||||||
@ -603,36 +605,7 @@ DeepState_ForkAndRunTest(struct DeepState_TestInfo *test) {
|
|||||||
return DeepState_TestRunCrash;
|
return DeepState_TestRunCrash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run a test case with input initialized by fuzzing. */
|
enum DeepState_TestRunResult DeepState_FuzzOneTestCase(struct DeepState_TestInfo *test);
|
||||||
static enum DeepState_TestRunResult
|
|
||||||
DeepState_FuzzOneTestCase(struct DeepState_TestInfo *test) {
|
|
||||||
DeepState_InputIndex = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < DeepState_InputSize; i++) {
|
|
||||||
DeepState_Input[i] = (char)rand();
|
|
||||||
}
|
|
||||||
|
|
||||||
DeepState_Begin(test);
|
|
||||||
|
|
||||||
enum DeepState_TestRunResult result = DeepState_ForkAndRunTest(test);
|
|
||||||
|
|
||||||
if (result == DeepState_TestRunCrash) {
|
|
||||||
DeepState_LogFormat(DeepState_LogError, "Crashed: %s", test->test_name);
|
|
||||||
|
|
||||||
if (HAS_FLAG_output_test_dir) {
|
|
||||||
DeepState_SaveCrashingTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
DeepState_Crash();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FLAGS_abort_on_fail && ((result == DeepState_TestRunCrash) ||
|
|
||||||
(result == DeepState_TestRunFail))) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Run a single saved test case with input initialized from the file
|
/* Run a single saved test case with input initialized from the file
|
||||||
* `name` in directory `dir`. */
|
* `name` in directory `dir`. */
|
||||||
|
|||||||
@ -23,6 +23,8 @@
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#undef rand
|
||||||
|
|
||||||
DEEPSTATE_BEGIN_EXTERN_C
|
DEEPSTATE_BEGIN_EXTERN_C
|
||||||
|
|
||||||
DEFINE_uint(num_workers, 1,
|
DEFINE_uint(num_workers, 1,
|
||||||
@ -630,6 +632,37 @@ bool DeepState_CatchAbandoned(void) {
|
|||||||
return DeepState_CurrentTestRun->result == DeepState_TestRunAbandon;
|
return DeepState_CurrentTestRun->result == DeepState_TestRunAbandon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Run a test case with input initialized by fuzzing.
|
||||||
|
Has to be defined here since we redefine rand in the header. */
|
||||||
|
enum DeepState_TestRunResult DeepState_FuzzOneTestCase(struct DeepState_TestInfo *test) {
|
||||||
|
DeepState_InputIndex = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < DeepState_InputSize; i++) {
|
||||||
|
DeepState_Input[i] = (char)rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
DeepState_Begin(test);
|
||||||
|
|
||||||
|
enum DeepState_TestRunResult result = DeepState_ForkAndRunTest(test);
|
||||||
|
|
||||||
|
if (result == DeepState_TestRunCrash) {
|
||||||
|
DeepState_LogFormat(DeepState_LogError, "Crashed: %s", test->test_name);
|
||||||
|
|
||||||
|
if (HAS_FLAG_output_test_dir) {
|
||||||
|
DeepState_SaveCrashingTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
DeepState_Crash();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FLAGS_abort_on_fail && ((result == DeepState_TestRunCrash) ||
|
||||||
|
(result == DeepState_TestRunFail))) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||||
if (Size > sizeof(DeepState_Input)) {
|
if (Size > sizeof(DeepState_Input)) {
|
||||||
return 0; // Just ignore any too-big inputs
|
return 0; // Just ignore any too-big inputs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user