-
Notifications
You must be signed in to change notification settings - Fork 163
feat: add @ValuePool to propagate values to types #975
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/java/com/code_intelligence/jazzer/mutation/annotation/ValuePool.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Copyright 2024 Code Intelligence GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.code_intelligence.jazzer.mutation.annotation; | ||
|
|
||
| import static com.code_intelligence.jazzer.mutation.utils.PropertyConstraint.RECURSIVE; | ||
| import static java.lang.annotation.ElementType.TYPE_USE; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| import com.code_intelligence.jazzer.mutation.utils.IgnoreRecursiveConflicts; | ||
| import com.code_intelligence.jazzer.mutation.utils.PropertyConstraint; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Provides values to user-selected mutator types to start fuzzing from. | ||
| * | ||
| * <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 | ||
| * {@link #constraint()} attribute. | ||
| * | ||
| * <p>Example usage: | ||
| * | ||
| * <pre>{@code | ||
| * public class MyFuzzTargets { | ||
| * | ||
| * static Stream<?> valuesVisibleByAllArgumentMutators() { | ||
| * return Stream.of("example1", "example2", "example3", 1232187321, -182371); | ||
| * } | ||
| * | ||
| * static Stream<?> valuesVisibleOnlyByAnotherInput() { | ||
| * return Stream.of("code-intelligence.com", "secret.url.1082h3u21ibsdsazuvbsa.com"); | ||
| * } | ||
| * | ||
| * @ValuePool("valuesVisibleByAllArgumentMutators") | ||
| * @FuzzTest | ||
| * public void fuzzerTestOneInput(String input, @ValuePool("valuesVisibleOnlyByAnotherInput") String anotherInput) { | ||
| * // Fuzzing logic here | ||
| * } | ||
| * } | ||
| * }</pre> | ||
| * | ||
| * In this example, the mutator for the String parameter {@code input} of the fuzz test method | ||
| * {@code fuzzerTestOneInput} will be using the values returned by {@code | ||
| * valuesVisibleByAllArgumentMutators} method during mutation, while the mutator for String {@code | ||
| * anotherInput} will use values from both methods: from the method-level {@code ValuePool} | ||
| * annotation that uses {@code valuesVisibleByAllArgumentMutators} and the parameter-level {@code | ||
| * ValuePool} annotation that uses {@code valuesVisibleOnlyByAnotherInput}. | ||
| */ | ||
| @Target({ElementType.METHOD, TYPE_USE}) | ||
| @Retention(RUNTIME) | ||
| @IgnoreRecursiveConflicts | ||
| @PropertyConstraint | ||
| 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 | ||
| * 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(); | ||
|
|
||
| /** | ||
| * This {@code ValuePool} will be used with probability {@code p} by the mutator responsible for | ||
| * fitting types. | ||
| */ | ||
| double p() default 0.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 | ||
| * RECURSIVE}. | ||
| */ | ||
| String constraint() default RECURSIVE; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.