diff --git a/src/Engine.ml b/src/Engine.ml index 98bd1ed7e5fa7a2de810472c752df014e101b74f..080c3aad99181be6fda1d28f49b96e7928daf3ea 100644 --- a/src/Engine.ml +++ b/src/Engine.ml @@ -1365,6 +1365,25 @@ let run prologue fuel = (* -------------------------------------------------------------------------- *) +(* [init()] performs global initialization. *) + +(* It is used both in random testing mode and in AFL mode. *) + +let init () = + (* Printing the following two lines at the beginning of every scenario + allows us to use [Monolith.Support], under the name [Sup], in our + scenarios. *) + DelayedOutput.dprintf " #require \"monolith\";;\n"; + DelayedOutput.dprintf " module Sup = Monolith.Support;;\n"; + (* We are about to perform many runs, and each run begins with a call to + [prologue] that can modify our global state by calling functions such + as [declare], [override_exn_eq], [dprintf], etc. Therefore, we must + save our global state now, just once, and reset it at the beginning + of every run, before calling [prologue]. *) + GlobalState.save() + +(* -------------------------------------------------------------------------- *) + (* [main_afl source prologue fuel] performs many test runs in AFL mode. *) (* [source] is the name of the input file that AFL has created for us. *) @@ -1499,17 +1518,7 @@ let source : string option = line, perform a number of test runs. *) let main ?prologue:(prologue=ignore) fuel = - (* Printing the following two lines at the beginning of every scenario - allows us to use [Monolith.Support], under the name [Sup], in our - scenarios. *) - DelayedOutput.dprintf " #require \"monolith\";;\n"; - DelayedOutput.dprintf " module Sup = Monolith.Support;;\n"; - (* We are about to perform many runs, and each run begins with a call to - [prologue] that can modify our global state by calling functions such - as [declare], [override_exn_eq], [dprintf], etc. Therefore, we must - save our global state now, just once, and reset it at the beginning - of every run, before calling [prologue]. *) - GlobalState.save(); + init(); match source with | Some _ -> main_afl source prologue fuel