-
Notifications
You must be signed in to change notification settings - Fork 165
feats: extend ValuePool by new fields : files, and maxMutations #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6beff90
f81f15c
10e638e
c88cfcc
928c9a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,13 +43,17 @@ | |
| import java.lang.reflect.AnnotatedType; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.lang.reflect.Method; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| public final class ArgumentsMutator { | ||
| private final ExtendedMutatorFactory mutatorFactory; | ||
| private final Method method; | ||
| private final InPlaceProductMutator productMutator; | ||
|
|
||
| private static final Map<Method, ArgumentsMutator> mutatorsCache = new ConcurrentHashMap<>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might be able to fix the JUnit integration to not create multiple mutators for the same method since it already has a store. I believe the problem is the seems to fix multiple mutators being created for each crash file. |
||
|
|
||
| private Object[] arguments; | ||
|
|
||
| /** | ||
|
|
@@ -78,15 +82,14 @@ private static String prettyPrintMethod(Method method) { | |
| } | ||
|
|
||
| public static ArgumentsMutator forMethodOrThrow(Method method) { | ||
| return forMethod(Mutators.newFactory(new ValuePoolRegistry(method)), method) | ||
| .orElseThrow( | ||
| () -> | ||
| new IllegalArgumentException( | ||
| "Failed to construct mutator for " + prettyPrintMethod(method))); | ||
| } | ||
|
|
||
| public static Optional<ArgumentsMutator> forMethod(Method method) { | ||
| return forMethod(Mutators.newFactory(new ValuePoolRegistry(method)), method); | ||
| return mutatorsCache.computeIfAbsent( | ||
| method, | ||
| m -> | ||
| forMethod(Mutators.newFactory(new ValuePoolRegistry(m)), m) | ||
| .orElseThrow( | ||
| () -> | ||
| new IllegalArgumentException( | ||
| "Failed to construct mutator for " + prettyPrintMethod(m)))); | ||
| } | ||
|
|
||
| public static Optional<ArgumentsMutator> forMethod( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Provides values to user-selected mutator types to start fuzzing from. | ||
| * Provides values to user-selected types that will be used during mutation. | ||
| * | ||
| * <p>This annotation can be applied to fuzz test methods and any parameter type or subtype. By | ||
| * default, this annotation is propagated to all nested subtypes unless specified otherwise via the | ||
|
|
@@ -68,21 +68,51 @@ | |
| public @interface ValuePool { | ||
| /** | ||
| * Specifies supplier methods that generate values for fuzzing the annotated method or type. The | ||
| * specified supplier methods must be static and return a {@code Stream <?>} of values. The values | ||
| * specified supplier methods must be static and return a {@code Stream<?>} of values. The values | ||
| * don't need to match the type of the annotated method or parameter. The mutation framework will | ||
| * extract only the values that are compatible with the target type. | ||
| */ | ||
| String[] value(); | ||
| String[] value() default {}; | ||
|
|
||
| /** | ||
| * Specifies glob patterns matching files that should be provided as {@code byte[]} to the | ||
| * annotated type. The syntax follows closely to Java's {@link | ||
| * java.nio.file.FileSystem#getPathMatcher(String) PathMatcher} "glob:" syntax. | ||
| * | ||
| * <p>Relative glob patterns are resolved against the working directory. | ||
| * | ||
| * <p>Patterns that start with <code>{</code> or <code>[</code>@code are treated as relative to | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible typo: |
||
| * the working directory. | ||
| * | ||
| * <p>Examples: | ||
| * | ||
| * <ul> | ||
| * <li>{@code *.jpeg} - matches all jpegs in the working directory | ||
| * <li>{@code **.xml} - matches all xml files recursively | ||
| * <li>{@code src/test/resources/dict/*.txt} - matches txt files in a specific directory | ||
| * <li>{@code /absolute/path/to/some/directory/**} - matches all files in an absolute path | ||
| * recursively | ||
| * <li><code>{"*.jpg", "**.png"}</code> - matches all jpg in the working directory, and png | ||
| * files recursively | ||
| * </ul> | ||
| */ | ||
| String[] files() default {}; | ||
|
|
||
| /** | ||
| * This {@code ValuePool} will be used with probability {@code p} by the mutator responsible for | ||
| * fitting types. | ||
| */ | ||
| double p() default 0.1; | ||
|
|
||
| /** | ||
| * If the mutator selects a value from this {@code ValuePool}, it will perform up to {@code | ||
| * maxMutations} additional mutations on the selected value. | ||
| */ | ||
| int maxMutations() default 1; | ||
|
|
||
| /** | ||
| * Defines the scope of the annotation. Possible values are defined in {@link | ||
| * com.code_intelligence.jazzer.mutation.utils.PropertyConstraint}. By default it's {@code | ||
| * com.code_intelligence.jazzer.mutation.utils.PropertyConstraint}. By default, it's {@code | ||
| * RECURSIVE}. | ||
| */ | ||
| String constraint() default RECURSIVE; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.