Skip to content

Add dedicated timeout parameter for @FuzzTest #930

Description

@Marcono1234

Problem

JUnit version: 5.13.0
Jazzer JUnit version: 0.24.0

Currently Jazzer recognizes JUnit's @Timeout annotation, see

private static Optional<String> translateJUnitTimeoutToLibFuzzerFlag(ExtensionContext context) {

This is quite useful for detecting application hangs (e.g. due to infinite loops) detected by Jazzer during fuzzing. For example when you normally expect a single fuzz execution to take a few milliseconds, you can make it fail fast if it unexpectedly takes more than one second.

The problem is that @Timeout is additionally still respected by JUnit and can lead to spurious timeout failures if the complete fuzzing run takes longer.

Example

Consider this example:

@Timeout(value = 2, unit = TimeUnit.SECONDS)
@FuzzTest(maxExecutions = 10)
void test(int ignored) throws Exception {
    long start = System.nanoTime();
    // Busy wait 1 second
    while ((System.nanoTime() - start) / 1_000_000_000 < 1) {
    }
}

When run in fuzzing mode each fuzzing execution takes less than the 2 seconds timeout and passes (as desired). However the complete fuzzing run takes ~10 seconds, so JUnit then (erroneously) reports the fuzzing run as failure.

Suggested solution

Maybe instead of (or in addition to?) levaraging JUnit's timeout mechanism it would be better to add a dedicated @FuzzTest parameter, e.g.:

/**
 * Timeout for a single fuzzing execution. Only has an effect in fuzzing mode, not in regression mode.
 * The timeout format is the same as for {@link #maxDuration()}, for example "1s". An empty string
 * (the default) means no timeout.
 */
String executionTimeout() default "";

A nice side effect of this might be that it is easier to discover by users than the current @Timeout support.

Possibly related to #478

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions