-
Notifications
You must be signed in to change notification settings - Fork 165
Maximize API #1036
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
Open
kyakdan
wants to merge
9
commits into
main
Choose a base branch
from
CIF-1902-maximize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Maximize API #1036
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9d4548f
feat: add CountersTracker for generic coverage counter management
kyakdan 43317b5
feat: add maximize() hill-climbing API to Jazzer
kyakdan 9ccd312
examples: add ReactorFuzzTest example demonstrating maximize API
kyakdan bf55101
sanitize minValue and maxValue for maximize
kyakdan aff5c29
fix: ensure correct parsing of JAZZER_MAXIMIZE_MAX_COUNTERS
kyakdan 1da3c75
feat: throw a JazzerApiException in case of API exceptions
kyakdan 9ba7492
feat: rename CountersTracker's max counters env var
kyakdan 63e3efd
feat: throw an exception if JAZZER_MAX_NUM_COUNTERS is negative
kyakdan d692165
feat: refactor the maximize API to remove minVale, maxValue
kyakdan 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
60 changes: 60 additions & 0 deletions
60
examples/junit/src/test/java/com/example/ReactorFuzzTest.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,60 @@ | ||
| /* | ||
| * Copyright 2026 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.example; | ||
|
|
||
| import com.code_intelligence.jazzer.api.Jazzer; | ||
| import com.code_intelligence.jazzer.junit.FuzzTest; | ||
| import com.code_intelligence.jazzer.mutation.annotation.NotNull; | ||
|
|
||
| public class ReactorFuzzTest { | ||
|
|
||
| @FuzzTest | ||
| public void fuzz(@NotNull String input) { | ||
| for (char c : input.toCharArray()) { | ||
| if (c < 32 || c > 126) return; | ||
| } | ||
| controlReactor(input); | ||
| } | ||
|
|
||
| private void controlReactor(String commands) { | ||
| long temperature = 0; // Starts cold | ||
|
|
||
| for (char cmd : commands.toCharArray()) { | ||
| // Complex, chaotic feedback loop. | ||
| // It is hard to predict which character increases temperature | ||
| // because it depends on the CURRENT temperature. | ||
| if ((temperature ^ cmd) % 3 == 0) { | ||
| temperature += (cmd % 10); // Heat up slightly | ||
| } else if ((temperature ^ cmd) % 3 == 1) { | ||
| temperature -= (cmd % 8); // Cool down slightly | ||
| } else { | ||
| temperature += 1; // Tiny increase | ||
| } | ||
|
|
||
| // Prevent dropping below absolute zero for simulation sanity | ||
| if (temperature < 0) temperature = 0; | ||
| } | ||
| // THE GOAL: MAXIMIZATION | ||
| // We need to drive 'temperature' to an extreme value. | ||
| // Standard coverage is 100% constant here (it just loops). | ||
| long mapped = temperature * 1023 / 4500; | ||
| Jazzer.maximize(mapped); | ||
| if (temperature >= 4500) { | ||
| throw new RuntimeException("Meltdown! Temperature maximized."); | ||
| } | ||
| } | ||
| } |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/code_intelligence/jazzer/api/JazzerApiException.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,38 @@ | ||
| /* | ||
| * 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.api; | ||
|
|
||
| /** | ||
| * Signals error from the Jazzer API (e.g. invalid arguments to {@link Jazzer#maximize}). | ||
| * | ||
| * <p>This exception is treated as a fatal error by the fuzzing engine rather than as a finding in | ||
| * the code under test. When thrown during fuzzing, it stops the current fuzz test with an error | ||
| * instead of reporting a bug in the fuzz target. | ||
| */ | ||
| public class JazzerApiException extends RuntimeException { | ||
| public JazzerApiException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public JazzerApiException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
|
|
||
| public JazzerApiException(Throwable cause) { | ||
| super(cause); | ||
| } | ||
| } |
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.