-
Notifications
You must be signed in to change notification settings - Fork 273
Nondet-initialize enums to be equal to a constant of the same type #2701
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
antlechner
merged 9 commits into
diffblue:develop
from
antlechner:antonia/enum-constants
Aug 14, 2018
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3be826f
Add some documentation to java_object_factory
antlechner 07d1e44
Always run clinit_wrapper before nondet object init
antlechner 6c84caa
Refactor logic for generating a nondet int
antlechner 6ecf4f9
Nondet-init enums by assigning them to a constant
antlechner 5542c54
Move nondet enum initialization to new function
antlechner 3e32140
CI lazy methods: load clinit for all param types
antlechner 03e3877
Add tests for nondet initialization of enums
antlechner c9e46ae
Temporarily remove new UNREACHABLE statements
antlechner 5ca6cd2
Restrict new clinit_wrapper calls to enum types
antlechner 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
Binary file not shown.
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,5 @@ | ||
public enum Color { | ||
RED, | ||
GREEN, | ||
BLUE | ||
} |
Binary file not shown.
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,46 @@ | ||
public class NondetEnumArg { | ||
|
||
public static void canChooseSomeConstant(Color c) { | ||
if (c == null) | ||
return; | ||
assert c != null; | ||
boolean isRed = c.name().startsWith("RED") && c.name().length() == 3 | ||
&& c.ordinal() == 0; | ||
boolean isGreen = c.name().startsWith("GREEN") && c.name().length() == 5 | ||
&& c.ordinal() == 1; | ||
boolean isBlue = c.name().startsWith("BLUE") && c.name().length() == 4 | ||
&& c.ordinal() == 2; | ||
assert (isRed || isGreen || isBlue); | ||
} | ||
|
||
public static void canChooseRed(Color c) { | ||
if (c == null) | ||
return; | ||
boolean isGreen = c.name().startsWith("GREEN") && c.name().length() == 5 | ||
&& c.ordinal() == 1; | ||
boolean isBlue = c.name().startsWith("BLUE") && c.name().length() == 4 | ||
&& c.ordinal() == 2; | ||
assert (isGreen || isBlue); | ||
} | ||
|
||
public static void canChooseGreen(Color c) { | ||
if (c == null) | ||
return; | ||
boolean isRed = c.name().startsWith("RED") && c.name().length() == 3 | ||
&& c.ordinal() == 0; | ||
boolean isBlue = c.name().startsWith("BLUE") && c.name().length() == 4 | ||
&& c.ordinal() == 2; | ||
assert (isRed || isBlue); | ||
} | ||
|
||
public static void canChooseBlue(Color c) { | ||
if (c == null) | ||
return; | ||
boolean isRed = c.name().startsWith("RED") && c.name().length() == 3 | ||
&& c.ordinal() == 0; | ||
boolean isGreen = c.name().startsWith("GREEN") && c.name().length() == 5 | ||
&& c.ordinal() == 1; | ||
assert (isRed || isGreen); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
jbmc/regression/jbmc/NondetEnumArg/test_some_constant.desc
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,10 @@ | ||
CORE | ||
NondetEnumArg.class | ||
--function NondetEnumArg.canChooseSomeConstant --cp `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar` | ||
^VERIFICATION SUCCESSFUL$ | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
The test checks that the name and ordinal fields of nondet-initialized enums | ||
correspond to those of an enum constant of the same type. |
7 changes: 7 additions & 0 deletions
7
jbmc/regression/jbmc/NondetEnumArg/test_specific_constant1.desc
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,7 @@ | ||
CORE | ||
NondetEnumArg.class | ||
--function NondetEnumArg.canChooseRed --cp `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar` | ||
^VERIFICATION FAILED$ | ||
-- | ||
-- | ||
Test 1 of 3 to check that any of the enum constants can be chosen. |
7 changes: 7 additions & 0 deletions
7
jbmc/regression/jbmc/NondetEnumArg/test_specific_constant2.desc
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,7 @@ | ||
CORE | ||
NondetEnumArg.class | ||
--function NondetEnumArg.canChooseGreen --cp `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar` | ||
^VERIFICATION FAILED$ | ||
-- | ||
-- | ||
Test 2 of 3 to check that any of the enum constants can be chosen. |
7 changes: 7 additions & 0 deletions
7
jbmc/regression/jbmc/NondetEnumArg/test_specific_constant3.desc
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,7 @@ | ||
CORE | ||
NondetEnumArg.class | ||
--function NondetEnumArg.canChooseBlue --cp `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar` | ||
^VERIFICATION FAILED$ | ||
-- | ||
-- | ||
Test 3 of 3 to check that any of the enum constants can be chosen. |
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.
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.
May we have tests with
switch
already?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.
We have one tests for
switch
on an enum type. It uses--cover location
and pretty much just checks that all possible ordinals (except the last one) can be generated for a switch statement.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.
@peterschrammel Do you think the
switch
test and the newNondetEnumArg
test should be combined?