Skip to content

Commit 91c08c3

Browse files
committed
Tried convert function from json
1 parent 2f37b22 commit 91c08c3

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

src/test/java/GoblintMessagesTest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import analysis.GoblintAnalysis;
2+
import analysis.GoblintCFGAnalysisResult;
23
import analysis.GoblintMessagesAnalysisResult;
34
import api.GoblintService;
45
import api.json.GoblintMessageJsonHandler;
56
import api.messages.GoblintAnalysisResult;
7+
import api.messages.GoblintFunctionsResult;
68
import api.messages.GoblintMessagesResult;
79
import api.messages.GoblintPosition;
810
import api.messages.params.AnalyzeParams;
@@ -86,6 +88,13 @@ private List<GoblintMessagesResult> readGoblintResponseJson() throws IOException
8688
return gson.fromJson(messages, new TypeToken<List<GoblintMessagesResult>>() {}.getType());
8789
}
8890

91+
private List<GoblintFunctionsResult> readGoblintResponseJsonFunc() throws IOException {
92+
String functions = Files.readString(
93+
Path.of(GoblintMessagesTest.class.getResource("messagesResponse.json").getPath())
94+
);
95+
return gson.fromJson(functions, new TypeToken<List<GoblintFunctionsResult>>() {}.getType());
96+
}
97+
8998

9099
/**
91100
* Mock test to ensure that the Goblint warnings received from a response in JSON format
@@ -163,5 +172,61 @@ public void testConvertMessagesFromJson() throws IOException {
163172
}
164173

165174

175+
176+
177+
@Test
178+
public void testConvertFunctionsFromJson() throws IOException {
179+
List<GoblintFunctionsResult> goblintFunctionsResults = readGoblintResponseJsonFunc();
180+
181+
when(goblintService.functions()).thenReturn(CompletableFuture.completedFuture(goblintFunctionsResults));
182+
when(gobPieConfiguration.showCfg()).thenReturn(false);
183+
184+
goblintAnalysis.analyze(files, analysisConsumer, true);
185+
186+
URL emptyUrl = new File("").toURI().toURL();
187+
GoblintPosition defaultPos = new GoblintPosition(1, 1, 1, 1, emptyUrl);
188+
URL exampleUrl = new File("src/example.c").toURI().toURL();
189+
190+
List<AnalysisResult> response = new ArrayList<>();
191+
response.add(
192+
new GoblintCFGAnalysisResult(
193+
defaultPos,
194+
"2.0",
195+
"t_fun"
196+
197+
198+
)
199+
);
200+
response.add(
201+
new GoblintMessagesAnalysisResult(
202+
new GoblintPosition(4, 4, 4, 12, exampleUrl),
203+
"[Race] Memory location myglobal (race with conf. 110)",
204+
"Warning",
205+
List.of(
206+
Pair.make(
207+
new GoblintPosition(10, 10, 2, 21, exampleUrl),
208+
"write with [mhp:{tid=[main, t_fun@src/example.c:17:3-17:40#top]}, lock:{mutex1}, thread:[main, t_fun@src/example.c:17:3-17:40#top]] (conf. 110) (exp: & myglobal)"
209+
)
210+
)
211+
)
212+
);
213+
response.add(
214+
new GoblintMessagesAnalysisResult(
215+
defaultPos,
216+
"[Race] Memory locations race summary",
217+
"Info",
218+
List.of(
219+
Pair.make(defaultPos, "safe: 0"),
220+
Pair.make(defaultPos, "vulnerable: 0"),
221+
Pair.make(defaultPos, "unsafe: 1"),
222+
Pair.make(defaultPos, "total memory locations: 1")
223+
)
224+
)
225+
);
226+
verify(analysisConsumer).consume(response, "GobPie");
227+
}
228+
229+
230+
166231
}
167232

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"id": 0,
3+
"jsonrpc": "2.0",
4+
"result": [
5+
{
6+
"funName": "t_fun",
7+
"location": {
8+
"file": "src/example.c",
9+
"line": 8,
10+
"column": 1,
11+
"byte": 52058,
12+
"endLine": 13,
13+
"endColumn": 1,
14+
"endByte": 52264
15+
}
16+
},
17+
{
18+
"funName": "main",
19+
"location": {
20+
"file": "src/example.c",
21+
"line": 15,
22+
"column": 1,
23+
"byte": 52267,
24+
"endLine": 23,
25+
"endColumn": 1,
26+
"endByte": 52805
27+
}
28+
},
29+
{
30+
"funName": "pthread_once",
31+
"location": {
32+
"file": "/home/anette/goblint/analyzer/_opam/share/goblint/lib/stub/src/pthread.c",
33+
"line": 5,
34+
"column": 1,
35+
"byte": 38717,
36+
"endLine": 10,
37+
"endColumn": 1,
38+
"endByte": 38837
39+
}
40+
},
41+
{
42+
"funName": "qsort",
43+
"location": {
44+
"file": "/home/anette/goblint/analyzer/_opam/share/goblint/lib/stub/src/stdlib.c",
45+
"line": 7,
46+
"column": 1,
47+
"byte": 1254,
48+
"endLine": 33,
49+
"endColumn": 1,
50+
"endByte": 1804
51+
}
52+
},
53+
{
54+
"funName": "bsearch",
55+
"location": {
56+
"file": "/home/anette/goblint/analyzer/_opam/share/goblint/lib/stub/src/stdlib.c",
57+
"line": 38,
58+
"column": 1,
59+
"byte": 1954,
60+
"endLine": 48,
61+
"endColumn": 1,
62+
"endByte": 2408
63+
}
64+
}
65+
]
66+
}

0 commit comments

Comments
 (0)