Skip to content
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

Java nondet test gen support #607

Closed

Conversation

reuk
Copy link
Contributor

@reuk reuk commented Mar 6, 2017

Adds support for modelling nondet values explicitly in Java code.

Tests demonstrating the new Java interface are located in regression/cbmc-java/nondet*. For objects, the interface has been simplified: Foo f = CProver.nondetWithNull();

Currently, all nondet objects may be initialised to null, because of the opaque method stubbing behaviour. An extra method CProver.nondetWithoutNull() could be added in the future, if the method stubbing were modified to allow non-null initialisation.

The build succeeds but some of the added nondet tests fail.
The proper functioning of the code in this pull request depends on the opaque-stubbing behaviour (from java_opaque_method_stubs.h), which hasn't made its way into cbmc/test-gen-support yet. The feature will work properly once this feature is also merged in.

reuk added 30 commits March 6, 2017 09:19
Update test.desc files with correct outcomes

Fix formatting issues
Update generic testcase
Remove test case with multiple test methods
Remove mistakenly-added txt files

Fix formatting issues
Add nondet recursive expansion to typecheck_expr
Update nondet generic test cases
The new block type is replaced by a nondet initializer during bytecode
conversion and typechecking.

Add missing test case

Make small fixes to test cases

Fix formatting issues
@@ -177,3 +177,4 @@ const codet &codet::last_statement() const

return *this;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

static inline const side_effect_expr_nondett &
to_side_effect_expr_nondet(const exprt &expr)
{
const auto &x = to_side_effect_expr(expr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpplint

static inline const side_effect_expr_nondett &
to_side_effect_expr_nondet(const exprt &expr)
{
const auto &x = to_side_effect_expr(expr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better rename x to side_effect_expr

@@ -47,11 +50,16 @@ void java_bytecode_typecheckt::typecheck_expr(exprt &expr)
typecheck_expr_symbol(to_symbol_expr(expr));
else if(expr.id()==ID_side_effect)
{
const irep_idt &statement=to_side_effect_expr(expr).get_statement();
auto &side_effect_expr = to_side_effect_expr(expr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpplint

@@ -43,7 +43,7 @@ class java_bytecode_typecheckt:public typecheckt
{
}

virtual ~java_bytecode_typecheckt() { }
virtual ~java_bytecode_typecheckt() = default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the old version in this PR. We can change this consistently in the whole code base in separate PR.

{
if(&(*it)==before_1)
{
assert(it+1!=end);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes an assumption about the implementation of exprt::operandst. Use a second iterator and increment to point at the next element.

id_regex))
{
assert(2<=parents.size());
const auto before_1=*(parents.end()-1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nicer to user decrements instead of pointer arithmetic here.

template <typename Func>
static void traverse_expr_tree(
exprt &expr,
std::vector<exprt*> &parents,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exprt *

std::vector<exprt*> &parents,
Func func)
{
const auto& parents_ref=parents;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&parents


\*******************************************************************/

template <typename Func>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should go into util/expr_util.h

@reuk reuk force-pushed the java-nondet-test-gen-support branch from 4671957 to 7fc5583 Compare March 8, 2017 14:06
@reuk reuk force-pushed the java-nondet-test-gen-support branch from 7fc5583 to 67697aa Compare March 8, 2017 14:15
@peterschrammel
Copy link
Member

There are failing tests: https://travis-ci.org/diffblue/cbmc/jobs/208984797#L1874
If they are expected to fail in this version then set them to KNOWNBUG.

@reuk reuk force-pushed the java-nondet-test-gen-support branch 2 times, most recently from 491ba2e to 08cb9f5 Compare March 10, 2017 10:08
@reuk reuk force-pushed the java-nondet-test-gen-support branch from 08cb9f5 to 101a65d Compare March 10, 2017 10:09
In the case where we really want to create a nondet java.lang.Object,
the java compiler does not emit a checkcast instruction, which means
that our attempt to divine the nondet type using checkcast fails.

This commit changes the behaviour of nondetWithNull so that it will
create an Object if the following instruction is not a checkcast.
The test nondetCastToObject tests this behaviour.
@reuk reuk force-pushed the java-nondet-test-gen-support branch from ba4628e to 8321fa8 Compare March 10, 2017 16:06
@reuk reuk closed this Mar 24, 2017
NathanJPhillips pushed a commit to NathanJPhillips/cbmc that referenced this pull request Sep 6, 2018
Only allow "returnValue" value for location field in JSON rules file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants