Skip to content

Commit e02b1ac

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#359 from diffblue/update-models-library
Update models library
2 parents a9446c5 + 13113b1 commit e02b1ac

File tree

214 files changed

+8950
-788
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+8950
-788
lines changed

benchmarks/LIBRARIES/models/.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ install:
4646
- sudo apt-get update
4747
- sudo apt-get install gauge
4848
- gauge install java
49-
- gauge install html-report
49+
# Temporarily disable html-report (installing this plugin might not be required anyway)
50+
# gauge install html-report
5051
- gauge config plugin_kill_timeout 20000
52+
- gauge telemetry off
5153
- export MAVEN_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
5254
- export DIFFBLUE_MODEL_TESTS_PROCESS_TIMEOUT="500"
5355

benchmarks/LIBRARIES/models/README.md

Lines changed: 75 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -196,76 +196,128 @@ the file on Google Cloud.
196196

197197
### Adding New Tests
198198

199+
#### Quick overview of testing
200+
201+
In models-library, there are three levels of tests:
202+
- Level 0 - verify model matching behaviour of JDK
203+
- Level 1 - small "unit" tests that verify tests can be generated, compile, run and pass for one configuration of one method or constructor
204+
- Level 2 - like Level 1 tests, but more typical use cases mimicking client code combining methods or classes.
205+
206+
When writing new models, we tend to focus on writing Level 1 tests. We aim
207+
to ensure that all possible branches are covered. For example, in `ArrayList`,
208+
to check test generation of the `get(int i)` method, which gets an element
209+
at a particular index, you might a make class file `L1Get.java` that
210+
contains three methods for the following tests:
211+
- `i >= 0` and there is an element at `i`
212+
- `i >= al.size()` where `al` is an ArrayList (throws exception)
213+
- `i < 0` (throws exception)
214+
215+
The Gauge spec file will take the class file, generate tests for it
216+
using models-library, verify that the tests give full coverage,
217+
compile the tests, run the tests using the JDK and
218+
verify that they pass, or throw an error.
219+
220+
#### Gauge spec files
221+
199222
You will probably want to supply test specifications alongside any new models.
200223
First, you should probably familiarise yourself with how Gauge works, using the
201224
official documentation [here](https://docs.getgauge.io/using.html).
202225
Generally, test specifications will look like this:
203226

204227
```
205-
# java.package.ClassName
228+
# java.<package>.<Class>
206229
207-
Tags: my-unique-tag
230+
* Setup Maven project "test_data/maven/java/<package>/<Class>"
208231
209-
Plain text here is interpreted as a comment. Tags here apply to the entire
210-
file, so if you add known-bug as a tag, *none of the tests in the file will run
211-
in CI*.
232+
## Level 1 <Class>
212233
213-
* Bullet points correspond to methods in the TestRunner.java
214-
* Bullets at the top of the file are run for each subsequent subheading
234+
Level 1 - <constructor or method>
235+
<Optional comments>
236+
* Set class file "target/classes/<ClassFileName1>.class"
237+
* Generate tests for "<ClassFileName1>.<TestName1>"
238+
* Generate tests for "<ClassFileName1>.<TestName2>"
215239
240+
Level 1 - <another constructor or method>
241+
<Optional comments>
242+
* Set class file "target/classes/<ClassFileName2>.class"
243+
* Generate tests for "<ClassFileName2>.<TestName1>"
244+
* Generate tests for "<ClassFileName2>.<TestName2>"
216245
217-
## method name or signature
246+
* Verify tests in Maven project
247+
* Unset class file
218248
219-
Tags: known-bug
220249
221-
This test is known to fail. Normally we'll put a link to a relevant
222-
github issue here.
250+
## Level 1 <Class> <tagname>
223251
224-
* This step runs the test
252+
Tags: <tagname>
225253
226-
## another method name or signature
254+
<Jira ticket if a known-bug or future>
255+
<Optional comments>
256+
* Set class file "target/classes/<ClassFileName1>.class"
257+
* Generate tests for "<ClassFileName1>.<TestName1>"
258+
* Generate tests for "<ClassFileName1>.<TestName2>"
227259
228-
Tags: support-v1
260+
* Verify tests in Maven project
261+
* Unset class file
262+
```
229263

230-
This test is known to pass, and is required for the support-v1 goal.
264+
where tags are:
265+
- `future`
266+
- `long`
267+
- `known-bug`
231268

232-
* This step runs the test
233-
```
269+
The `long` tag is used to prevent tests that take too long from running
270+
on CI. We rarely use the `future` tag, but occasionally we develop models
271+
before deeptest is ready for them. Anything tagged with `known-bug` should
272+
include the Jira ticket number.
234273

235-
Check in the `specs` directory to see what "real" specs look like. Some of the
236-
most important steps/bullet-points used specifically in the models tests
237-
follow.
274+
Some of the most important steps/bullet-points used specifically
275+
in the models tests follow.
238276

239277
#### Verification
240278

241279
```
242280
* Run "classname.class", expecting exit code "0" and output "VERIFICATION SUCCESSFUL"
243281
```
244282

283+
These are Level 0 tests.
284+
245285
This step will do a CBMC-style verification (using the test-generator
246286
executable) of the `main` method in the provided class. The second argument
247287
denotes the expected return code, and the final argument is a snippet that
248288
should be matched in the program's stdout.
249289

250290
#### Grouped Test Generation (recommended)
251291

252-
The process for generating tests and verfying them (compile, run, pass) in a
292+
These are Level 1 and 2 tests.
293+
294+
The process for generating tests and verifying them (compile, run, pass) in a
253295
specified maven directory is as follows:
254296

255297
Set the maven directory and clean all test files:
256298
```
257299
* Setup Maven project "path/to/directory"
258300
```
259-
Run test-generator to populate the Maven project with generated test:
301+
Run test-generator to populate the Maven project with generated test from
302+
methods in a class file:
303+
```
304+
* Set class file "target/classes/<ClassFileName1>.class"
305+
* Generate tests for "<ClassFileName1>.<TestName1>"
306+
* Generate tests for "<ClassFileName1>.<TestName2>"
307+
```
308+
for as many class files as required.
309+
310+
In older spec files you may also see this more cumbersome notation:
260311
```
261312
* Generate tests for "java.function.signature1" in "target/classes/test1.class"
262313
* Generate tests for "java.function.signature2" in "target/classes/test2.class"
263314
* Generate tests for "java.function.signature3" in "target/classes/test3.class"
264315
...
265316
```
266-
Run mvn test on the Maven project:
317+
Run mvn test on the Maven project and unset the class file:
267318
```
268319
* Verify tests in Maven project
320+
* Unset class file
269321
```
270322

271323
#### Standalone Test Generation (not recommended)
@@ -347,4 +399,3 @@ variables set by the test-gen superbuild.
347399

348400
[build_img]: https://travis-ci.com/diffblue/models-library.svg?token=i8KzPhcTpXyyoppmAEw1
349401
[travis]: https://travis-ci.com/diffblue/models-library
350-

benchmarks/LIBRARIES/models/model/modelTests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<dependency>
1212
<groupId>com.thoughtworks.gauge</groupId>
1313
<artifactId>gauge-java</artifactId>
14-
<version>0.6.4</version>
14+
<version>0.6.6</version>
1515
<scope>test</scope>
1616
</dependency>
1717
<dependency>

benchmarks/LIBRARIES/models/model/modelTests/specs/bugs.spec

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
Tests that were previously disabled due to a bug that has now been fixed
88

9-
TG-1877 Types of elements of input arrays ignored by lazy methods
10-
causes TG-1712 Incorrect tests for comparison of primitive wrapper classes in array
119
* Generate tests for "tg1877.ArrayListElementsCustom.callMethodOnElement" in "target/classes/tg1877/ArrayListElementsCustom.class"
1210
* Generate tests for "tg1877.ArrayListElementsInteger.callLessOnElement" in "target/classes/tg1877/ArrayListElementsInteger.class"
1311
* Generate tests for "tg1877.ArrayListElementsInteger.callLessOnElementAndConst" in "target/classes/tg1877/ArrayListElementsInteger.class"
1412
* Generate tests for "tg1877.ArrayListElementsInteger.callPrimitiveLessOnElement" in "target/classes/tg1877/ArrayListElementsInteger.class"
1513
* Generate tests for "tg1877.ArrayListElementsBitSet.callMethodOnElement" in "target/classes/tg1877/ArrayListElementsBitSet.class"
1614

17-
TG-1245 Object.getClass not working for Objects that may be null
1815
* Generate tests for "tg1245.ObjectGetClassMaybeNull.test" in "target/classes/tg1245/ObjectGetClassMaybeNull.class"
1916

17+
* Generate tests for "tg1931.L1ToStringOnObject.toStringObject" in "target/classes/tg1931/L1ToStringOnObject.class"
18+
2019
* Verify tests in Maven project
2120

2221
## LONG
@@ -26,8 +25,19 @@ too long to be enabled on CI.
2625

2726
Tags: long
2827

29-
TG-1877 Types of elements of input arrays ignored by lazy methods
30-
causes TG-1712 Incorrect tests for comparison of primitive wrapper classes in array
3128
* Generate tests for "tg1877.CustomType.moreComplicatedCalls" in "target/classes/tg1877/CustomType.class"
3229

3330
* Verify tests in Maven project
31+
32+
33+
## KNOWN BUGS
34+
35+
Tests for which there is a known issue that has not yet been fixed
36+
37+
Tags: known-bug
38+
39+
TG-2717
40+
Specializing fields of a generic abstract class implementation does not work
41+
* Generate tests for "tg2717.GenericInterface.hashmapNdMap" in "target/classes/tg2717/GenericInterface.class"
42+
43+
* Verify tests in Maven project
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
# java.io.File
22

3-
## Level 1+ tests - java.io.File
4-
53
* Setup Maven project "test_data/maven/java/io/File"
64

7-
TODO Review these tests and sort into level 1 and level 2
8-
* Generate tests for "FileConstructorPath.test" in "target/classes/FileConstructorPath.class"
9-
* Generate tests for "FileConstructorPC.test" in "target/classes/FileConstructorPC.class"
10-
* Generate tests for "FileConstructorFC.test" in "target/classes/FileConstructorFC.class"
11-
* Generate tests for "FileConstructor.test" in "target/classes/FileConstructor.class"
12-
13-
* Verify tests in Maven project
14-
15-
## Level 1 Known Bugs - java.io.File
16-
17-
Tags: known-bug
18-
19-
* Setup Maven project "test_data/maven/java/io/File"
5+
## Level 1+ tests - java.io.File
206

21-
TG-1081/ TG-1976 Static fields not initialised in test
7+
Level 1 public fields
228
* Set class file "target/classes/L1Fields.class"
239
* Generate tests for "L1Fields.fieldSeparatorChar"
2410
* Generate tests for "L1Fields.fieldSeparator"
2511
* Generate tests for "L1Fields.fieldPathSeparatorChar"
2612
* Generate tests for "L1Fields.fieldPathSeparator"
2713
* Unset class file
2814

15+
TODO Review these tests and sort into level 1 and level 2
16+
* Generate tests for "FileConstructorPath.test" in "target/classes/FileConstructorPath.class"
17+
* Generate tests for "FileConstructorPC.test" in "target/classes/FileConstructorPC.class"
18+
* Generate tests for "FileConstructorFC.test" in "target/classes/FileConstructorFC.class"
19+
* Generate tests for "FileConstructor.test" in "target/classes/FileConstructor.class"
20+
2921
* Verify tests in Maven project
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,42 @@
11
# java.lang.Class
22

3-
## toString
3+
* Setup Maven project "test_data/maven/java/lang/Class"
44

5-
Tags: support-v1
5+
## toString
66

7-
* Setup Maven project "test_data/maven/java/lang/Class"
87
* Generate tests for "GetClassToString.test" in "target/classes/GetClassToString.class"
98
* Generate tests for "IntegerGetClassToString.test" in "target/classes/IntegerGetClassToString.class"
10-
* Verify tests in Maven project
11-
12-
## toString_KNOWNBUG
13-
14-
Tags: support-v1, known-bug
15-
* Setup Maven project "test_data/maven/java/lang/Class"
16-
17-
TG-1081: Integer.TYPE is always (erroneously) initialized to null
189
* Generate tests for "IntegerTypeToString.test" in "target/classes/IntegerTypeToString.class"
1910
* Verify tests in Maven project
2011

2112
## getName
2213

23-
Tags: support-v1
24-
2514
diffblue/models-library#111
2615
* Working directory is "test_data/functional/java/lang/Class"
2716
* Run "getName_Pass.class", expecting exit code "0" and output "VERIFICATION SUCCESSFUL"
2817

2918
## isAssignableFrom
3019

31-
Tags: support-v1, known-bug
20+
Tags: known-bug
3221
* Working directory is "test_data/functional/java/lang/Class"
3322
* Run "isAssignableFrom_Pass.class", expecting exit code "0" and output "VERIFICATION SUCCESSFUL"
3423

3524
## getMethod
3625

37-
Tags: support-v1, known-bug
26+
Tags: known-bug
3827

3928
diffblue/models-library#112
4029
* Working directory is "test_data/functional/java/lang/Class"
4130
* Run "getMethod_Pass.class", expecting exit code "0" and output "VERIFICATION SUCCESSFUL"
4231

4332
## getClassLoader
4433

45-
Tags: support-v1, known-bug
34+
Tags: known-bug
4635
* Working directory is "test_data/functional/java/lang/Class"
4736
* Run "getClassLoader_Pass.class", expecting exit code "0" and output "VERIFICATION SUCCESSFUL"
4837

4938
## getSimpleName
5039

51-
Tags: support-v1, known-bug
40+
Tags: known-bug
5241
* Working directory is "test_data/functional/java/lang/Class"
5342
* Run "getSimpleName_Pass.class", expecting exit code "0" and output "VERIFICATION SUCCESSFUL"

0 commit comments

Comments
 (0)