Class GuidedFuzzing

java.lang.Object
edu.berkeley.cs.jqf.fuzz.junit.GuidedFuzzing

public class GuidedFuzzing extends Object
  • Field Details

    • DEFAULT_MAX_TRIALS

      public static long DEFAULT_MAX_TRIALS
  • Constructor Details

    • GuidedFuzzing

      public GuidedFuzzing()
  • Method Details

    • setGuidance

      public static void setGuidance(Guidance g)
      Sets the current global fuzzing guidance. Note: There can only be one guidance in any given JVM, because the instrumented test classes make static method calls to generate callback events. The fuzzing entry point (i.e., the target method being fuzzed) should be invoked in the same thread as the thread that sets the global guidance. This property is ensured by all variants of run(Class, String, Guidance, PrintStream).
      Parameters:
      g - the guidance instance
      Throws:
      IllegalStateException - if a guidance has already been set
    • getCurrentGuidance

      public static Guidance getCurrentGuidance()
      Returns the currently registered Guidance instance.
      Returns:
      the currently registered Guidance instance
    • unsetGuidance

      public static void unsetGuidance()
      Unsets the current global fuzzing guidance. This allows running multiple fuzzing sessions in the same JVM instance sequentially. This method should be invoked from the same thread that last invoked setGuidance(Guidance). This method removes any tracers associated with the current thread, so that the entry point can be detected again. This property is ensured by run(Class, String, Guidance, PrintStream).
    • run

      public static Result run(String testClassName, String testMethod, Guidance guidance, PrintStream out) throws ClassNotFoundException, IllegalStateException
      Runs the guided fuzzing loop, using the system class loader to load test-application classes.

      The test class must be annotated with @RunWith(JQF.class) and the test method must be annotated with @Fuzz.

      Once this method is invoked, the guided fuzzing loop runs continuously until the guidance instance decides to stop by returning false for Guidance.hasInput(). Until the fuzzing stops, this method cannot be invoked again (i.e. at most one guided fuzzing can be running at any time in a single JVM instance).

      Parameters:
      testClassName - the test class containing the test method
      testMethod - the test method to execute in the fuzzing loop
      guidance - the fuzzing guidance
      out - an output stream to log Junit messages
      Returns:
      the Junit-style test result
      Throws:
      ClassNotFoundException - if testClassName cannot be loaded
      IllegalStateException - if a guided fuzzing run is currently executing
    • run

      public static Result run(String testClassName, String testMethod, ClassLoader loader, Guidance guidance, PrintStream out) throws ClassNotFoundException, IllegalStateException
      Runs the guided fuzzing loop, using a provided classloader to load test-application classes.

      The test class must be annotated with @RunWith(JQF.class) and the test method must be annotated with @Fuzz.

      Once this method is invoked, the guided fuzzing loop runs continuously until the guidance instance decides to stop by returning false for Guidance.hasInput(). Until the fuzzing stops, this method cannot be invoked again (i.e. at most one guided fuzzing can be running at any time in a single JVM instance).

      Parameters:
      testClassName - the test class containing the test method
      testMethod - the test method to execute in the fuzzing loop
      loader - the classloader to load the test class with
      guidance - the fuzzing guidance
      out - an output stream to log Junit messages
      Returns:
      the Junit-style test result
      Throws:
      ClassNotFoundException - if testClassName cannot be loaded
      IllegalStateException - if a guided fuzzing run is currently executing
    • run

      public static Result run(Class<?> testClass, String testMethod, Guidance guidance, PrintStream out) throws IllegalStateException
      Runs the guided fuzzing loop for a resolved class.

      The test class must be annotated with @RunWith(JQF.class) and the test method must be annotated with @Fuzz.

      Once this method is invoked, the guided fuzzing loop runs continuously until the guidance instance decides to stop by returning false for Guidance.hasInput(). Until the fuzzing stops, this method cannot be invoked again (i.e. at most one guided fuzzing can be running at any time in a single JVM instance).

      Parameters:
      testClass - the test class containing the test method
      testMethod - the test method to execute in the fuzzing loop
      guidance - the fuzzing guidance
      out - an output stream to log Junit messages
      Returns:
      the Junit-style test result
      Throws:
      IllegalStateException - if a guided fuzzing run is currently executing
    • runAll

      public static Result runAll(Class<?> testClass, GuidedFuzzing.GuidanceSupplier guidanceSupplier, PrintStream out) throws IllegalStateException, IOException
      Runs the guided fuzzing loop for all @Fuzz methods in a test class.

      The test class must be annotated with @RunWith(JQF.class).

      This method executes each @Fuzz method in the test class sequentially, creating a new guidance instance for each method.

      Parameters:
      testClass - the test class containing the test methods
      guidanceSupplier - a function that creates a new guidance instance for each method
      out - an output stream to log JUnit messages
      Returns:
      the JUnit-style test result
      Throws:
      IllegalStateException - if a guided fuzzing run is currently executing
      IOException - if an I/O error occurs when setting up the guidance