Skip to content

Commit c22a720

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#269 from diffblue/owen-jones-diffblue/lvsa-test-escape-analysis
Owen jones diffblue/lvsa test escape analysis
2 parents a4e98bc + 1e4234f commit c22a720

File tree

14 files changed

+212
-140
lines changed

14 files changed

+212
-140
lines changed

regression/LVSA/TestArray/test_array.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,44 @@ def test_lvsa_null_initialized_array(tmpdir):
99
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('null_initialized_array')
1010
lvsa_expectation = lvsa_driver.run()
1111

12-
output_value_expectation = lvsa_expectation.check_output()
12+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
1313

14-
output_value_expectation.check_number_of_values(1)
15-
output_value_expectation.check_contains_null_object()
14+
value_set_expectation.check_number_of_values(1)
15+
value_set_expectation.check_contains_null_object()
1616

1717

1818
def test_lvsa_manually_filled_array_1(tmpdir):
1919
"""We cannot tell that the whole array has been given a non-null value"""
2020
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('manually_filled_array_1')
2121
lvsa_expectation = lvsa_driver.run()
2222

23-
output_value_expectation = lvsa_expectation.check_output()
23+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
2424

25-
output_value_expectation.check_number_of_values(2)
26-
output_value_expectation.check_contains_null_object()
27-
output_value_expectation.check_contains_dynamic_object(is_most_recent_allocation=True)
25+
value_set_expectation.check_number_of_values(2)
26+
value_set_expectation.check_contains_null_object()
27+
value_set_expectation.check_contains_dynamic_object(is_most_recent_allocation=True)
2828

2929

3030
def test_lvsa_manually_filled_array_2(tmpdir):
3131
"""We cannot tell that the whole array has been given a non-null value"""
3232
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('manually_filled_array_2')
3333
lvsa_expectation = lvsa_driver.run()
3434

35-
output_value_expectation = lvsa_expectation.check_output()
35+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
3636

37-
output_value_expectation.check_number_of_values(3)
38-
output_value_expectation.check_contains_null_object()
39-
output_value_expectation.check_contains_dynamic_object(is_most_recent_allocation=True)
40-
output_value_expectation.check_contains_dynamic_object(is_most_recent_allocation=False)
37+
value_set_expectation.check_number_of_values(3)
38+
value_set_expectation.check_contains_null_object()
39+
value_set_expectation.check_contains_dynamic_object(is_most_recent_allocation=True)
40+
value_set_expectation.check_contains_dynamic_object(is_most_recent_allocation=False)
4141

4242

4343
def test_lvsa_initialize_array(tmpdir):
4444
"""We use one value set for all indices"""
4545
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('initialize_array')
4646
lvsa_expectation = lvsa_driver.run()
4747

48-
output_value_expectation = lvsa_expectation.check_output()
48+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
4949

50-
output_value_expectation.check_number_of_values(4)
51-
output_value_expectation.check_contains_null_object()
52-
output_value_expectation.check_contains_dynamic_object(3, is_most_recent_allocation=True)
50+
value_set_expectation.check_number_of_values(4)
51+
value_set_expectation.check_contains_null_object()
52+
value_set_expectation.check_contains_dynamic_object(3, is_most_recent_allocation=True)

regression/LVSA/TestBasic/Test.class

-97 Bytes
Binary file not shown.

regression/LVSA/TestBasic/Test.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ public void outputs_null() {
1212
output = null;
1313
}
1414

15-
public void outputs_dynamic_object() {
16-
output = new A();
17-
}
18-
1915
public void outputs_null_or_dynamic_object(Boolean someBoolean) {
2016
if (someBoolean) {
2117
output = new A();

regression/LVSA/TestBasic/test_basic.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,34 @@ def test_outputs_null(tmpdir):
88
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_null')
99
lvsa_expectation = lvsa_driver.run()
1010

11-
output_value_expectation = lvsa_expectation.check_output()
11+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
1212

13-
output_value_expectation.check_number_of_values(1)
14-
output_value_expectation.check_contains_null_object()
15-
16-
17-
def test_outputs_dynamic_object(tmpdir):
18-
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_dynamic_object')
19-
lvsa_expectation = lvsa_driver.run()
20-
21-
output_value_expectation = lvsa_expectation.check_output()
22-
23-
output_value_expectation.check_number_of_values(1)
24-
output_value_expectation.check_contains_dynamic_object()
13+
value_set_expectation.check_number_of_values(1)
14+
value_set_expectation.check_contains_null_object()
2515

2616

2717
def test_outputs_null_or_dynamic_object(tmpdir):
2818
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_null_or_dynamic_object')
2919
lvsa_expectation = lvsa_driver.run()
3020

31-
output_value_expectation = lvsa_expectation.check_output()
21+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
3222

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()
23+
value_set_expectation.check_number_of_values(2)
24+
value_set_expectation.check_contains_null_object()
25+
value_set_expectation.check_contains_dynamic_object()
3626

3727

3828
def test_outputs_dynamic_object_with_allocated_field(tmpdir):
3929
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_dynamic_object_with_allocated_field')
4030
lvsa_expectation = lvsa_driver.run()
4131

42-
output_value_expectation = lvsa_expectation.check_output()
32+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
4333

44-
output_value_expectation.check_number_of_values(1)
45-
output_value_expectation.check_contains_dynamic_object()
46-
dynamic_object_id = output_value_expectation.get_dynamic_object_ids()[0]
34+
value_set_expectation.check_number_of_values(1)
35+
value_set_expectation.check_contains_dynamic_object()
36+
dynamic_object_id = value_set_expectation.get_dynamic_object_ids()[0]
4737

48-
output_value_expectation = lvsa_expectation.check_value_set(dynamic_object_id, '.instanceObj', most_recent=True)
38+
value_set_expectation = lvsa_expectation.get_value_set_for_dynamic_object_value_set(dynamic_object_id, '.instanceObj', most_recent=True)
4939

50-
output_value_expectation.check_number_of_values(1)
51-
output_value_expectation.check_contains_dynamic_object()
40+
value_set_expectation.check_number_of_values(1)
41+
value_set_expectation.check_contains_dynamic_object()

regression/LVSA/TestEVS/test_evs.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,52 @@ def test_write_static_field_to_parameter_field(tmpdir):
77
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('write_static_field_to_parameter_field')
88
lvsa_expectation = lvsa_driver.run()
99

10-
output_value_expectation = lvsa_expectation.check_external_value_set('Node', '.left')
10+
value_set_expectation = lvsa_expectation.get_value_set_for_external_value_set('Node', '.left')
1111

12-
output_value_expectation.check_number_of_values(2)
13-
output_value_expectation.check_contains_external_value_set(expected_number=2)
12+
value_set_expectation.check_number_of_values(2)
13+
value_set_expectation.check_contains_external_value_set(expected_number=2)
1414

1515

1616
def test_write_parameter_field_to_static_field(tmpdir):
1717
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('write_parameter_field_to_static_field')
1818
lvsa_expectation = lvsa_driver.run()
1919

20-
output_value_expectation = lvsa_expectation.check_external_value_set('Node', '.left')
20+
value_set_expectation = lvsa_expectation.get_value_set_for_external_value_set('Node', '.left')
2121

22-
output_value_expectation.check_number_of_values(2)
23-
output_value_expectation.check_contains_external_value_set(expected_number=2)
22+
value_set_expectation.check_number_of_values(2)
23+
value_set_expectation.check_contains_external_value_set(expected_number=2)
2424

2525

2626
def test_write_new_class_to_parameter_field(tmpdir):
2727
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('write_new_class_to_parameter_field')
2828
lvsa_expectation = lvsa_driver.run()
2929

30-
output_value_expectation = lvsa_expectation.check_external_value_set('Node', '.left')
30+
value_set_expectation = lvsa_expectation.get_value_set_for_external_value_set('Node', '.left')
3131

32-
output_value_expectation.check_contains_dynamic_object()
32+
value_set_expectation.check_contains_dynamic_object()
3333

3434

3535
def test_write_new_class_to_static_field(tmpdir):
3636
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('write_new_class_to_static_field')
3737
lvsa_expectation = lvsa_driver.run()
3838

39-
output_value_expectation = lvsa_expectation.check_external_value_set('Node', '.left')
39+
value_set_expectation = lvsa_expectation.get_value_set_for_external_value_set('Node', '.left')
4040

41-
output_value_expectation.check_contains_dynamic_object()
41+
value_set_expectation.check_contains_dynamic_object()
4242

4343

4444
def test_is_initializer_flag(tmpdir):
4545
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('is_initializer_flag')
4646
lvsa_expectation = lvsa_driver.run()
4747

48-
output_value_expectation_1 = lvsa_expectation.check_external_value_set('Node', '.left')
48+
value_set_expectation_1 = lvsa_expectation.get_value_set_for_external_value_set('Node', '.left')
4949

50-
output_value_expectation_1.check_number_of_values(2)
51-
output_value_expectation_1.check_contains_dynamic_object(is_most_recent_allocation=True)
52-
output_value_expectation_1.check_contains_external_value_set(is_initializer=True)
50+
value_set_expectation_1.check_number_of_values(2)
51+
value_set_expectation_1.check_contains_dynamic_object(is_most_recent_allocation=True)
52+
value_set_expectation_1.check_contains_external_value_set(is_initializer=True)
5353

54-
output_value_expectation_2 = lvsa_expectation.check_public_static('static_object')
54+
value_set_expectation_2 = lvsa_expectation.get_value_set_for_public_static('static_object')
5555

56-
output_value_expectation_2.check_number_of_values(2)
57-
output_value_expectation_2.check_contains_dynamic_object(is_most_recent_allocation=True)
58-
output_value_expectation_2.check_contains_external_value_set(is_initializer=False)
56+
value_set_expectation_2.check_number_of_values(2)
57+
value_set_expectation_2.check_contains_dynamic_object(is_most_recent_allocation=True)
58+
value_set_expectation_2.check_contains_external_value_set(is_initializer=False)
507 Bytes
Binary file not shown.
564 Bytes
Binary file not shown.
1.71 KB
Binary file not shown.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package LVSA.TestEscapeAnalysis;
2+
3+
public class Test {
4+
static Object output;
5+
6+
public class A {
7+
Object object;
8+
}
9+
10+
public class B {
11+
A a;
12+
}
13+
14+
public void dynamic_object_assigned_to_local() {
15+
Object local = new Object();
16+
}
17+
18+
public void apply_dynamic_object_assigned_to_local() {
19+
dynamic_object_assigned_to_local();
20+
}
21+
22+
public Object dynamic_object_returned() {
23+
Object local = new Object();
24+
return local;
25+
}
26+
27+
public void apply_dynamic_object_returned() {
28+
output = dynamic_object_returned();
29+
}
30+
31+
public void dynamic_object_assigned_to_static() {
32+
output = new Object();
33+
}
34+
35+
public void apply_dynamic_object_assigned_to_static() {
36+
dynamic_object_assigned_to_static();
37+
}
38+
39+
public void dynamic_object_assigned_to_field_of_parameter(A param) {
40+
param.object = new Object();
41+
}
42+
43+
public void apply_dynamic_object_assigned_to_field_of_parameter(A param) {
44+
dynamic_object_assigned_to_field_of_parameter(param);
45+
}
46+
47+
public void dynamic_object_assigned_to_field_of_field_of_parameter(B param) {
48+
param.a.object = new Object();
49+
}
50+
}

regression/LVSA/TestEscapeAnalysis/__init__.py

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from regression.LVSA.lvsa_driver import LvsaDriver
2+
3+
4+
folder_name = 'TestEscapeAnalysis'
5+
6+
7+
def test_dynamic_object_assigned_to_local(tmpdir):
8+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('apply_dynamic_object_assigned_to_local')
9+
lvsa_expectation = lvsa_driver.run()
10+
11+
for value_set_expectation in lvsa_expectation.get_all_value_sets():
12+
value_set_expectation.check_contains_dynamic_object(0)
13+
14+
15+
def test_dynamic_object_returned(tmpdir):
16+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('apply_dynamic_object_returned')
17+
lvsa_expectation = lvsa_driver.run()
18+
19+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
20+
21+
value_set_expectation.check_number_of_values(1)
22+
value_set_expectation.check_contains_dynamic_object()
23+
24+
25+
def test_outputs_dynamic_object(tmpdir):
26+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('apply_dynamic_object_assigned_to_static')
27+
lvsa_expectation = lvsa_driver.run()
28+
29+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
30+
31+
value_set_expectation.check_number_of_values(1)
32+
value_set_expectation.check_contains_dynamic_object()
33+
34+
35+
def test_dynamic_object_assigned_to_parameter(tmpdir):
36+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('apply_dynamic_object_assigned_to_field_of_parameter')
37+
lvsa_expectation = lvsa_driver.run()
38+
39+
value_set_expectation = lvsa_expectation.get_value_set_for_external_value_set(inner_class='A', suffix='.object')
40+
41+
value_set_expectation.check_contains_dynamic_object()

regression/LVSA/TestPreciseAccessPaths/test_precise_access_paths.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,76 +9,76 @@ def test_field_setter(tmpdir):
99
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('field_setter')
1010
lvsa_expectation = lvsa_driver.run()
1111

12-
output_value_expectation = lvsa_expectation.check_output()
12+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
1313

14-
output_value_expectation.check_number_of_values(1)
15-
output_value_expectation.check_contains_external_value_set()
14+
value_set_expectation.check_number_of_values(1)
15+
value_set_expectation.check_contains_external_value_set()
1616

1717

1818
def test_field_getter(tmpdir):
1919
# This test should change when precise access paths have been implemented
2020
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('field_getter')
2121
lvsa_expectation = lvsa_driver.run()
2222

23-
output_value_expectation = lvsa_expectation.check_return_value()
23+
value_set_expectation = lvsa_expectation.get_value_set_for_return_value()
2424

25-
output_value_expectation.check_number_of_values(1)
26-
output_value_expectation.check_contains_external_value_set()
25+
value_set_expectation.check_number_of_values(1)
26+
value_set_expectation.check_contains_external_value_set()
2727

2828

2929
def test_read_field_before_writing_to_aliasable_field(tmpdir):
3030
# This test should change when precise access paths have been implemented
3131
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('read_field_before_writing_to_aliasable_field')
3232
lvsa_expectation = lvsa_driver.run()
3333

34-
output_value_expectation_1 = lvsa_expectation.check_external_value_set('A', '.left_object')
34+
value_set_expectation_1 = lvsa_expectation.get_value_set_for_external_value_set('A', '.left_object')
3535

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()
36+
value_set_expectation_1.check_number_of_values(2)
37+
value_set_expectation_1.check_contains_external_value_set()
38+
value_set_expectation_1.check_contains_dynamic_object()
3939

40-
output_value_expectation_2 = lvsa_expectation.check_output()
40+
value_set_expectation_2 = lvsa_expectation.get_value_set_for_output()
4141

42-
output_value_expectation_2.check_number_of_values(1)
43-
output_value_expectation_2.check_contains_external_value_set()
42+
value_set_expectation_2.check_number_of_values(1)
43+
value_set_expectation_2.check_contains_external_value_set()
4444

4545

4646
def test_read_field_after_writing_to_aliasable_field(tmpdir):
4747
# This test should not change significantly when precise access paths have been implemented
4848
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('read_field_after_writing_to_aliasable_field')
4949
lvsa_expectation = lvsa_driver.run()
5050

51-
output_value_expectation_1 = lvsa_expectation.check_external_value_set('A', '.left_object')
51+
value_set_expectation_1 = lvsa_expectation.get_value_set_for_external_value_set('A', '.left_object')
5252

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()
53+
value_set_expectation_1.check_number_of_values(2)
54+
value_set_expectation_1.check_contains_external_value_set()
55+
value_set_expectation_1.check_contains_dynamic_object()
5656

57-
output_value_expectation_2 = lvsa_expectation.check_output()
57+
value_set_expectation_2 = lvsa_expectation.get_value_set_for_output()
5858

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()
59+
value_set_expectation_2.check_number_of_values(2)
60+
value_set_expectation_2.check_contains_external_value_set()
61+
value_set_expectation_2.check_contains_dynamic_object()
6262

6363

6464
def test_call_function_to_allocate_new_object(tmpdir):
6565
# This test should change when precise access paths have been implemented
6666
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('call_function_to_allocate_new_object')
6767
lvsa_expectation = lvsa_driver.run()
6868

69-
output_value_expectation = lvsa_expectation.check_output()
69+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
7070

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()
71+
value_set_expectation.check_number_of_values(2)
72+
value_set_expectation.check_contains_external_value_set()
73+
value_set_expectation.check_contains_dynamic_object()
7474

7575

7676
def test_get_list_node(tmpdir):
7777
# This test should not change when precise access paths have been implemented
7878
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('get_list_node')
7979
lvsa_expectation = lvsa_driver.run()
8080

81-
output_value_expectation = lvsa_expectation.check_output()
81+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
8282

83-
output_value_expectation.check_number_of_values(1)
84-
output_value_expectation.check_contains_external_value_set()
83+
value_set_expectation.check_number_of_values(1)
84+
value_set_expectation.check_contains_external_value_set()

0 commit comments

Comments
 (0)