Skip to content

Commit 651841f

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#238 from diffblue/owen/tests-for-lvsa
SEC-86: Tests for arrays in LVSA
2 parents ee8f934 + ffcf0b0 commit 651841f

16 files changed

+187
-36
lines changed

regression/LVSA/Test/Test.class

-367 Bytes
Binary file not shown.

regression/LVSA/Test/Test.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

regression/LVSA/Test/test_basic.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

regression/LVSA/TestArray/Test.class

972 Bytes
Binary file not shown.

regression/LVSA/TestArray/Test.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package LVSA.TestArray;
2+
3+
public class Test {
4+
static Object output;
5+
6+
public static void null_initialized_array() {
7+
Object[] array = new Object[3];
8+
output = array[1];
9+
}
10+
11+
public static void manually_filled_array_1() {
12+
Object[] array = new Object[3];
13+
Object local = new Object();
14+
for (int i = 0; i < array.length; ++i) {
15+
array[i] = local;
16+
}
17+
output = array[1];
18+
}
19+
20+
public static void manually_filled_array_2() {
21+
Object[] array = new Object[3];
22+
for (int i = 0; i < array.length; ++i) {
23+
array[i] = new Object();
24+
}
25+
output = array[1];
26+
}
27+
28+
public static void initialize_array() {
29+
Object[] array = new Object[3];
30+
array[0] = new Object();
31+
array[0] = new Object();
32+
array[2] = new Object();
33+
output = array[1];
34+
}
35+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from regression.LVSA.lvsa_driver import LvsaDriver
2+
3+
4+
folder_name = 'TestArray'
5+
6+
7+
def test_lvsa_null_initialized_array(tmpdir):
8+
"""Arrays are automatically null-initialized"""
9+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('null_initialized_array')
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_null_object()
16+
17+
18+
def test_lvsa_manually_filled_array_1(tmpdir):
19+
"""We cannot tell that the whole array has been given a non-null value"""
20+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('manually_filled_array_1')
21+
lvsa_expectation = lvsa_driver.run()
22+
23+
output_value_expectation = lvsa_expectation.check_output()
24+
25+
output_value_expectation.check_number_of_values(2)
26+
output_value_expectation.check_contains_null_object()
27+
output_value_expectation.check_contains_most_recent_allocation_dynamic_object()
28+
29+
30+
def test_lvsa_manually_filled_array_2(tmpdir):
31+
"""We cannot tell that the whole array has been given a non-null value"""
32+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('manually_filled_array_2')
33+
lvsa_expectation = lvsa_driver.run()
34+
35+
output_value_expectation = lvsa_expectation.check_output()
36+
37+
output_value_expectation.check_number_of_values(3)
38+
output_value_expectation.check_contains_null_object()
39+
output_value_expectation.check_contains_non_recent_allocation_dynamic_object()
40+
output_value_expectation.check_contains_most_recent_allocation_dynamic_object()
41+
42+
43+
def test_lvsa_initialize_array(tmpdir):
44+
"""We use one value set for all indices"""
45+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('initialize_array')
46+
lvsa_expectation = lvsa_driver.run()
47+
48+
output_value_expectation = lvsa_expectation.check_output()
49+
50+
output_value_expectation.check_number_of_values(4)
51+
output_value_expectation.check_contains_null_object()
52+
output_value_expectation.check_contains_most_recent_allocation_dynamic_object(3)

regression/LVSA/TestBasic/Test.class

551 Bytes
Binary file not shown.

regression/LVSA/TestBasic/Test.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package LVSA.TestBasic;
2+
3+
public class Test {
4+
static Object output;
5+
6+
public static void outputs_null() {
7+
output = null;
8+
}
9+
10+
public static void outputs_dynamic_object() {
11+
output = new Object();
12+
}
13+
}

regression/LVSA/TestBasic/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from regression.LVSA.lvsa_driver import LvsaDriver
2+
3+
4+
folder_name = 'TestBasic'
5+
6+
7+
def test_outputs_null(tmpdir):
8+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_null')
9+
lvsa_expectation = lvsa_driver.run()
10+
11+
output_value_expectation = lvsa_expectation.check_output()
12+
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()
467 Bytes
Binary file not shown.
584 Bytes
Binary file not shown.

regression/LVSA/TestRecency/Test.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
public class Test {
44
static Object output;
55

6-
public static void returns_most_recent() {
6+
public static void outputs_most_recent() {
77
output = null;
88
output = new Object();
99
}
1010

11-
public static void returns_most_recent_or_null() {
11+
public static void outputs_most_recent_or_null() {
1212
output = null;
1313
for (int i = 0; i < 5; i++) {
1414
output = new Object();
1515
}
1616
}
1717

18-
public static void returns_most_recent_non_recent_or_null(int unknown) {
18+
public static void outputs_most_recent_non_recent_or_null(int unknown) {
1919
output = null;
2020
for (int i = 0; i < 5; i++) {
2121
Object local = new Object();
@@ -25,12 +25,42 @@ public static void returns_most_recent_non_recent_or_null(int unknown) {
2525
}
2626
}
2727

28-
public static void returns_non_recent_or_null() {
28+
public static void outputs_non_recent_or_null() {
2929
output = null;
3030
Object local = null;
3131
for (int i = 0; i < 5; i++) {
3232
output = local;
3333
local = new Object();
3434
}
3535
}
36+
37+
public class A {
38+
Object b;
39+
}
40+
41+
public void most_recent_gets_strong_update() {
42+
A a = new A();
43+
a.b = null;
44+
a.b = new Object();
45+
output = a.b;
46+
}
47+
48+
public void non_recent_gets_weak_update() {
49+
A a1 = null;
50+
A a2 = null;
51+
52+
for (int i = 0; i < 2; ++i) {
53+
A aInLoop = new A();
54+
if (i == 0) {
55+
a1 = aInLoop;
56+
}
57+
else {
58+
a2 = aInLoop;
59+
}
60+
}
61+
62+
a1.b = null;
63+
a1.b = new Object();
64+
output = a1.b;
65+
}
3666
}

regression/LVSA/TestRecency/test_recency.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
folder_name = 'TestRecency'
55

66

7-
def test_lvsa_returns_most_recent(tmpdir):
8-
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('returns_most_recent')
7+
def test_outputs_most_recent(tmpdir):
8+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_most_recent')
99
lvsa_expectation = lvsa_driver.run()
1010

1111
output_value_expectation = lvsa_expectation.check_output()
@@ -14,8 +14,8 @@ def test_lvsa_returns_most_recent(tmpdir):
1414
output_value_expectation.check_contains_most_recent_allocation_dynamic_object()
1515

1616

17-
def test_lvsa_returns_most_recent_or_null(tmpdir):
18-
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('returns_most_recent_or_null')
17+
def test_outputs_most_recent_or_null(tmpdir):
18+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_most_recent_or_null')
1919
lvsa_expectation = lvsa_driver.run()
2020

2121
output_value_expectation = lvsa_expectation.check_output()
@@ -25,8 +25,8 @@ def test_lvsa_returns_most_recent_or_null(tmpdir):
2525
output_value_expectation.check_contains_most_recent_allocation_dynamic_object()
2626

2727

28-
def test_lvsa_returns_most_recent_non_recent_or_null(tmpdir):
29-
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('returns_most_recent_non_recent_or_null')
28+
def test_outputs_most_recent_non_recent_or_null(tmpdir):
29+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_most_recent_non_recent_or_null')
3030
lvsa_expectation = lvsa_driver.run()
3131

3232
output_value_expectation = lvsa_expectation.check_output()
@@ -37,12 +37,33 @@ def test_lvsa_returns_most_recent_non_recent_or_null(tmpdir):
3737
output_value_expectation.check_contains_non_recent_allocation_dynamic_object()
3838

3939

40-
def test_lvsa_returns_non_recent_or_null(tmpdir):
41-
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('returns_non_recent_or_null')
40+
def test_outputs_non_recent_or_null(tmpdir):
41+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_non_recent_or_null')
4242
lvsa_expectation = lvsa_driver.run()
4343

4444
output_value_expectation = lvsa_expectation.check_output()
4545

4646
output_value_expectation.check_number_of_values(2)
4747
output_value_expectation.check_contains_null_object()
4848
output_value_expectation.check_contains_non_recent_allocation_dynamic_object()
49+
50+
51+
def test_most_recent_gets_strong_update(tmpdir):
52+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('most_recent_gets_strong_update')
53+
lvsa_expectation = lvsa_driver.run()
54+
55+
output_value_expectation = lvsa_expectation.check_output()
56+
57+
output_value_expectation.check_number_of_values(1)
58+
output_value_expectation.check_contains_dynamic_object()
59+
60+
61+
def test_non_recent_gets_weak_update(tmpdir):
62+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('non_recent_gets_weak_update')
63+
lvsa_expectation = lvsa_driver.run()
64+
65+
output_value_expectation = lvsa_expectation.check_output()
66+
67+
output_value_expectation.check_number_of_values(2)
68+
output_value_expectation.check_contains_null_object()
69+
output_value_expectation.check_contains_dynamic_object()

regression/LVSA/lvsa_driver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import re
43

54
from regression.executable_runner import ExecutableRunner
65

0 commit comments

Comments
 (0)