|
1 | 1 | import analysis.GoblintAnalysis; |
| 2 | +import analysis.GoblintCFGAnalysisResult; |
2 | 3 | import analysis.GoblintMessagesAnalysisResult; |
3 | 4 | import api.GoblintService; |
4 | 5 | import api.json.GoblintMessageJsonHandler; |
5 | 6 | import api.messages.GoblintAnalysisResult; |
| 7 | +import api.messages.GoblintFunctionsResult; |
6 | 8 | import api.messages.GoblintMessagesResult; |
7 | 9 | import api.messages.GoblintPosition; |
8 | 10 | import api.messages.params.AnalyzeParams; |
@@ -86,6 +88,13 @@ private List<GoblintMessagesResult> readGoblintResponseJson() throws IOException |
86 | 88 | return gson.fromJson(messages, new TypeToken<List<GoblintMessagesResult>>() {}.getType()); |
87 | 89 | } |
88 | 90 |
|
| 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 | + |
89 | 98 |
|
90 | 99 | /** |
91 | 100 | * Mock test to ensure that the Goblint warnings received from a response in JSON format |
@@ -163,5 +172,61 @@ public void testConvertMessagesFromJson() throws IOException { |
163 | 172 | } |
164 | 173 |
|
165 | 174 |
|
| 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 | + |
166 | 231 | } |
167 | 232 |
|
0 commit comments