Skip to content

Commit 1001704

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#252 from diffblue/owen/tests-for-lvsa
SEC-96 Tests for LVSA precise access paths
2 parents 684464a + 2887a9d commit 1001704

File tree

8 files changed

+140
-0
lines changed

8 files changed

+140
-0
lines changed

regression/LVSA/TestBasic/Test.class

278 Bytes
Binary file not shown.

regression/LVSA/TestBasic/Test.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ public void outputs_dynamic_object() {
1616
output = new A();
1717
}
1818

19+
public void outputs_null_or_dynamic_object(Boolean someBoolean) {
20+
if (someBoolean) {
21+
output = new A();
22+
}
23+
else {
24+
output = null;
25+
}
26+
}
27+
1928
public void outputs_dynamic_object_with_allocated_field() {
2029
output = new A();
2130
output.instanceObj = new Object();

regression/LVSA/TestBasic/test_basic.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ def test_outputs_dynamic_object(tmpdir):
2424
output_value_expectation.check_contains_dynamic_object()
2525

2626

27+
def test_outputs_null_or_dynamic_object(tmpdir):
28+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_null_or_dynamic_object')
29+
lvsa_expectation = lvsa_driver.run()
30+
31+
output_value_expectation = lvsa_expectation.check_output()
32+
33+
output_value_expectation.check_number_of_values(2)
34+
output_value_expectation.check_contains_null_object()
35+
output_value_expectation.check_contains_dynamic_object()
36+
37+
2738
def test_outputs_dynamic_object_with_allocated_field(tmpdir):
2839
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_dynamic_object_with_allocated_field')
2940
lvsa_expectation = lvsa_driver.run()
555 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package LVSA.TestPreciseAccessPaths;
2+
3+
public class Test {
4+
static Object output;
5+
A left_a;
6+
A right_a;
7+
8+
public class A {
9+
Object left_object;
10+
Object right_object;
11+
}
12+
13+
// Precise access paths should work fine
14+
public void field_setter(A parameter_a) {
15+
output = parameter_a.left_object;
16+
}
17+
18+
// Precise access paths should work fine
19+
public Object field_getter() {
20+
return left_a.left_object;
21+
}
22+
23+
// Precise access paths should work fine
24+
public void read_field_before_writing_to_aliasable_field() {
25+
output = right_a.left_object;
26+
left_a.left_object = new Object();
27+
}
28+
29+
// Precise access paths must be careful that right_a.left_object could be
30+
// aliased by left_a.left_object, so it might be changed by the first line,
31+
// and thus we cannot just return "right_a.left_object"
32+
public void read_field_after_writing_to_aliasable_field() {
33+
left_a.left_object = new Object();
34+
output = right_a.left_object;
35+
}
36+
37+
// Helper function for call_function_to_allocate_new_object()
38+
public void allocate_new_object(A input_A) {
39+
input_A.left_object = new Object();
40+
}
41+
42+
// Precise access paths should work fine
43+
public void call_function_to_allocate_new_object(A param_A) {
44+
allocate_new_object(param_A);
45+
output = param_A.left_object;
46+
}
47+
}

regression/LVSA/TestPreciseAccessPaths/__init__.py

Whitespace-only changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from regression.LVSA.lvsa_driver import LvsaDriver
2+
3+
4+
folder_name = 'TestPreciseAccessPaths'
5+
6+
7+
def test_field_setter(tmpdir):
8+
# This test should change when precise access paths have been implemented
9+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('field_setter')
10+
lvsa_expectation = lvsa_driver.run()
11+
12+
output_value_expectation = lvsa_expectation.check_output()
13+
14+
output_value_expectation.check_number_of_values(1)
15+
output_value_expectation.check_contains_external_value_set()
16+
17+
18+
def test_field_getter(tmpdir):
19+
# This test should change when precise access paths have been implemented
20+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('field_getter')
21+
lvsa_expectation = lvsa_driver.run()
22+
23+
output_value_expectation = lvsa_expectation.check_return_value()
24+
25+
output_value_expectation.check_number_of_values(1)
26+
output_value_expectation.check_contains_external_value_set()
27+
28+
29+
def test_read_field_before_writing_to_aliasable_field(tmpdir):
30+
# This test should change when precise access paths have been implemented
31+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('read_field_before_writing_to_aliasable_field')
32+
lvsa_expectation = lvsa_driver.run()
33+
34+
output_value_expectation_1 = lvsa_expectation.check_external_value_set('A', '.left_object')
35+
36+
output_value_expectation_1.check_number_of_values(2)
37+
output_value_expectation_1.check_contains_external_value_set()
38+
output_value_expectation_1.check_contains_dynamic_object()
39+
40+
output_value_expectation_2 = lvsa_expectation.check_output()
41+
42+
output_value_expectation_2.check_number_of_values(1)
43+
output_value_expectation_2.check_contains_external_value_set()
44+
45+
46+
def test_read_field_after_writing_to_aliasable_field(tmpdir):
47+
# This test should not change significantly when precise access paths have been implemented
48+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('read_field_after_writing_to_aliasable_field')
49+
lvsa_expectation = lvsa_driver.run()
50+
51+
output_value_expectation_1 = lvsa_expectation.check_external_value_set('A', '.left_object')
52+
53+
output_value_expectation_1.check_number_of_values(2)
54+
output_value_expectation_1.check_contains_external_value_set()
55+
output_value_expectation_1.check_contains_dynamic_object()
56+
57+
output_value_expectation_2 = lvsa_expectation.check_output()
58+
59+
output_value_expectation_2.check_number_of_values(2)
60+
output_value_expectation_2.check_contains_external_value_set()
61+
output_value_expectation_2.check_contains_dynamic_object()
62+
63+
64+
def test_call_function_to_allocate_new_object(tmpdir):
65+
# This test should change when precise access paths have been implemented
66+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('call_function_to_allocate_new_object')
67+
lvsa_expectation = lvsa_driver.run()
68+
69+
output_value_expectation = lvsa_expectation.check_output()
70+
71+
output_value_expectation.check_number_of_values(2)
72+
output_value_expectation.check_contains_external_value_set()
73+
output_value_expectation.check_contains_dynamic_object()

0 commit comments

Comments
 (0)