Skip to content

Commit adea805

Browse files
author
Max Schaefer
committed
Refactor application-mode tests so we can reuse most of it for framework mode.
1 parent 312dd16 commit adea805

File tree

3 files changed

+94
-36
lines changed

3 files changed

+94
-36
lines changed

java/ql/automodel/src/AutomodelSharedCharacteristics.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ signature module CandidateSig {
2121
* Gets the kind of this endpoint, either "sourceModel" or "sinkModel".
2222
*/
2323
string getExtensibleType();
24+
25+
/**
26+
* Gets a string representation of this endpoint.
27+
*/
28+
string toString();
2429
}
2530

2631
/**
Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,36 @@
11
import java
2-
import AutomodelApplicationModeCharacteristics
2+
import AutomodelApplicationModeCharacteristics as Characteristics
33
import TestUtilities.InlineExpectationsTest
4+
import AutomodelExtractionTests
45

5-
module Extraction implements TestSig {
6-
string getARelevantTag() {
7-
result in ["sourceModel", "sinkModel", "positiveExample", "negativeExample"]
6+
module TestHelper implements TestHelperSig<Characteristics::ApplicationCandidatesImpl> {
7+
Location getEndpointLocation(Characteristics::Endpoint endpoint) {
8+
result = endpoint.asTop().getLocation()
89
}
910

10-
additional predicate selectEndpoint(
11-
Endpoint endpoint, string name, string signature, string input, string output,
12-
string extensibleType, string tag, string suffix
11+
predicate isCandidate(
12+
Characteristics::Endpoint endpoint, string name, string signature, string input, string output,
13+
string extensibleType
1314
) {
14-
isCandidate(endpoint, _, _, _, name, signature, input, output, _, extensibleType, _) and
15-
tag = extensibleType and
16-
suffix = ""
17-
or
18-
isNegativeExample(endpoint, _, _, _, _, _, name, signature, input, output, _, extensibleType) and
19-
tag = "negativeExample" and
20-
suffix = ""
21-
or
22-
exists(string endpointType |
23-
isPositiveExample(endpoint, endpointType, _, _, _, name, signature, input, output, _,
24-
extensibleType) and
25-
tag = "positiveExample" and
26-
suffix = "(" + endpointType + ")"
27-
)
15+
Characteristics::isCandidate(endpoint, _, _, _, name, signature, input, output, _,
16+
extensibleType, _)
2817
}
2918

30-
predicate hasActualResult(Location location, string element, string tag, string value) {
31-
exists(
32-
Endpoint endpoint, string name, string signature, string input, string output,
33-
string extensibleType, string suffix
34-
|
35-
selectEndpoint(endpoint, name, signature, input, output, extensibleType, tag, suffix)
36-
|
37-
endpoint.asTop().getLocation() = location and
38-
endpoint.toString() = element and
39-
// for source models only the output is relevant, and vice versa for sink models
40-
if extensibleType = "sourceModel"
41-
then value = name + signature + ":" + output + suffix
42-
else value = name + signature + ":" + input + suffix
43-
)
19+
predicate isPositiveExample(
20+
Characteristics::Endpoint endpoint, string endpointType, string name, string signature,
21+
string input, string output, string extensibleType
22+
) {
23+
Characteristics::isPositiveExample(endpoint, endpointType, _, _, _, name, signature, input,
24+
output, _, extensibleType)
25+
}
26+
27+
predicate isNegativeExample(
28+
Characteristics::Endpoint endpoint, string name, string signature, string input, string output,
29+
string extensibleType
30+
) {
31+
Characteristics::isNegativeExample(endpoint, _, _, _, _, _, name, signature, input, output, _,
32+
extensibleType)
4433
}
4534
}
4635

47-
import MakeTest<Extraction>
36+
import MakeTest<Extraction<Characteristics::ApplicationCandidatesImpl, TestHelper>>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import java
2+
import TestUtilities.InlineExpectationsTest
3+
import AutomodelSharedCharacteristics
4+
5+
signature module TestHelperSig<CandidateSig Candidate> {
6+
Location getEndpointLocation(Candidate::Endpoint e);
7+
8+
predicate isCandidate(
9+
Candidate::Endpoint e, string name, string signature, string input, string output,
10+
string extensibleType
11+
);
12+
13+
predicate isPositiveExample(
14+
Candidate::Endpoint e, string endpointType, string name, string signature, string input,
15+
string output, string extensibleType
16+
);
17+
18+
predicate isNegativeExample(
19+
Candidate::Endpoint e, string name, string signature, string input, string output,
20+
string extensibleType
21+
);
22+
}
23+
24+
module Extraction<CandidateSig Candidate, TestHelperSig<Candidate> TestHelper> implements TestSig {
25+
string getARelevantTag() {
26+
result in ["sourceModel", "sinkModel", "positiveExample", "negativeExample"]
27+
}
28+
29+
additional predicate selectEndpoint(
30+
Candidate::Endpoint endpoint, string name, string signature, string input, string output,
31+
string extensibleType, string tag, string suffix
32+
) {
33+
TestHelper::isCandidate(endpoint, name, signature, input, output, extensibleType) and
34+
tag = extensibleType and
35+
suffix = ""
36+
or
37+
TestHelper::isNegativeExample(endpoint, name, signature, input, output, extensibleType) and
38+
tag = "negativeExample" and
39+
suffix = ""
40+
or
41+
exists(string endpointType |
42+
TestHelper::isPositiveExample(endpoint, endpointType, name, signature, input, output,
43+
extensibleType) and
44+
tag = "positiveExample" and
45+
suffix = "(" + endpointType + ")"
46+
)
47+
}
48+
49+
predicate hasActualResult(Location location, string element, string tag, string value) {
50+
exists(
51+
Candidate::Endpoint endpoint, string name, string signature, string input, string output,
52+
string extensibleType, string suffix
53+
|
54+
selectEndpoint(endpoint, name, signature, input, output, extensibleType, tag, suffix)
55+
|
56+
TestHelper::getEndpointLocation(endpoint) = location and
57+
endpoint.toString() = element and
58+
// for source models only the output is relevant, and vice versa for sink models
59+
if extensibleType = "sourceModel"
60+
then value = name + signature + ":" + output + suffix
61+
else value = name + signature + ":" + input + suffix
62+
)
63+
}
64+
}

0 commit comments

Comments
 (0)