|
48 | 48 | #define assume DeepState_Assume |
49 | 49 | #define check DeepState_Check |
50 | 50 |
|
| 51 | +#define rand DeepState_Int |
| 52 | +#define srand DeepState_Warn_srand |
| 53 | + |
51 | 54 | #define MAYBE(...) \ |
52 | 55 | if (DeepState_Bool()) { \ |
53 | 56 | __VA_ARGS__ ; \ |
@@ -445,6 +448,8 @@ static bool DeepState_IsTestCaseFile(const char *name) { |
445 | 448 | return false; |
446 | 449 | } |
447 | 450 |
|
| 451 | +extern void DeepState_Warn_srand(unsigned int seed); |
| 452 | + |
448 | 453 | /* Resets the global `DeepState_Input` buffer, then fills it with the |
449 | 454 | * data found in the file `path`. */ |
450 | 455 | static void DeepState_InitInputFromFile(const char *path) { |
@@ -603,36 +608,7 @@ DeepState_ForkAndRunTest(struct DeepState_TestInfo *test) { |
603 | 608 | return DeepState_TestRunCrash; |
604 | 609 | } |
605 | 610 |
|
606 | | -/* Run a test case with input initialized by fuzzing. */ |
607 | | -static enum DeepState_TestRunResult |
608 | | -DeepState_FuzzOneTestCase(struct DeepState_TestInfo *test) { |
609 | | - DeepState_InputIndex = 0; |
610 | | - |
611 | | - for (int i = 0; i < DeepState_InputSize; i++) { |
612 | | - DeepState_Input[i] = (char)rand(); |
613 | | - } |
614 | | - |
615 | | - DeepState_Begin(test); |
616 | | - |
617 | | - enum DeepState_TestRunResult result = DeepState_ForkAndRunTest(test); |
618 | | - |
619 | | - if (result == DeepState_TestRunCrash) { |
620 | | - DeepState_LogFormat(DeepState_LogError, "Crashed: %s", test->test_name); |
621 | | - |
622 | | - if (HAS_FLAG_output_test_dir) { |
623 | | - DeepState_SaveCrashingTest(); |
624 | | - } |
625 | | - |
626 | | - DeepState_Crash(); |
627 | | - } |
628 | | - |
629 | | - if (FLAGS_abort_on_fail && ((result == DeepState_TestRunCrash) || |
630 | | - (result == DeepState_TestRunFail))) { |
631 | | - abort(); |
632 | | - } |
633 | | - |
634 | | - return result; |
635 | | -} |
| 611 | +extern enum DeepState_TestRunResult DeepState_FuzzOneTestCase(struct DeepState_TestInfo *test); |
636 | 612 |
|
637 | 613 | /* Run a single saved test case with input initialized from the file |
638 | 614 | * `name` in directory `dir`. */ |
@@ -757,61 +733,7 @@ static int DeepState_RunSingleSavedTestCase(void) { |
757 | 733 | return num_failed_tests; |
758 | 734 | } |
759 | 735 |
|
760 | | -/* Fuzz test `FLAGS_input_which_test` or first test, if not defined. */ |
761 | | -static int DeepState_Fuzz(void) { |
762 | | - DeepState_LogFormat(DeepState_LogInfo, "Starting fuzzing"); |
763 | | - |
764 | | - if (HAS_FLAG_seed) { |
765 | | - srand(FLAGS_seed); |
766 | | - } else { |
767 | | - unsigned int seed = time(NULL); |
768 | | - DeepState_LogFormat(DeepState_LogWarning, "No seed provided; using %u", seed); |
769 | | - srand(seed); |
770 | | - } |
771 | | - |
772 | | - long start = (long)time(NULL); |
773 | | - long current = (long)time(NULL); |
774 | | - long diff = 0; |
775 | | - unsigned i = 0; |
776 | | - |
777 | | - int num_failed_tests = 0; |
778 | | - |
779 | | - struct DeepState_TestInfo *test = NULL; |
780 | | - |
781 | | - DeepState_Setup(); |
782 | | - |
783 | | - for (test = DeepState_FirstTest(); test != NULL; test = test->prev) { |
784 | | - if (HAS_FLAG_input_which_test) { |
785 | | - if (strncmp(FLAGS_input_which_test, test->test_name, strlen(FLAGS_input_which_test)) == 0) { |
786 | | - break; |
787 | | - } |
788 | | - } else { |
789 | | - DeepState_LogFormat(DeepState_LogInfo, |
790 | | - "No test specified, defaulting to last test defined"); |
791 | | - break; |
792 | | - } |
793 | | - } |
794 | | - |
795 | | - if (test == NULL) { |
796 | | - DeepState_LogFormat(DeepState_LogInfo, |
797 | | - "Could not find matching test for %s", |
798 | | - FLAGS_input_which_test); |
799 | | - return 0; |
800 | | - } |
801 | | - |
802 | | - while (diff < FLAGS_timeout) { |
803 | | - i++; |
804 | | - num_failed_tests += DeepState_FuzzOneTestCase(test); |
805 | | - |
806 | | - current = (long)time(NULL); |
807 | | - diff = current-start; |
808 | | - } |
809 | | - |
810 | | - DeepState_LogFormat(DeepState_LogInfo, "Ran %u tests. %d failed tests.", |
811 | | - i, num_failed_tests); |
812 | | - |
813 | | - return num_failed_tests; |
814 | | -} |
| 736 | +extern int DeepState_Fuzz(void); |
815 | 737 |
|
816 | 738 | /* Run tests from `FLAGS_input_test_files_dir`, under `FLAGS_input_which_test` |
817 | 739 | * or first test, if not defined. */ |
|
0 commit comments