Skip to content

Commit b7d55d5

Browse files
committed
Write test for aborting analysis
1 parent b1136f1 commit b7d55d5

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import analysis.GoblintAnalysis;
2+
import api.GoblintService;
3+
import api.messages.params.AnalyzeParams;
4+
import com.ibm.wala.classLoader.Module;
5+
import goblintserver.GoblintConfWatcher;
6+
import goblintserver.GoblintServer;
7+
import gobpie.GobPieConfiguration;
8+
import magpiebridge.core.AnalysisConsumer;
9+
import magpiebridge.core.MagpieServer;
10+
import org.junit.jupiter.api.Test;
11+
12+
import java.io.IOException;
13+
import java.util.ArrayDeque;
14+
import java.util.Collection;
15+
import java.util.concurrent.CompletableFuture;
16+
17+
import static org.mockito.Mockito.*;
18+
19+
class GoblintAnalysisTest {
20+
21+
@Test
22+
void abortAnalysis() throws IOException {
23+
24+
// Mock everything needed for creating GoblintAnalysis
25+
MagpieServer magpieServer = mock(MagpieServer.class);
26+
GoblintServer goblintServer = mock(GoblintServer.class);
27+
GoblintService goblintService = mock(GoblintService.class);
28+
GobPieConfiguration gobPieConfiguration = mock(GobPieConfiguration.class);
29+
GoblintConfWatcher goblintConfWatcher = mock(GoblintConfWatcher.class);
30+
31+
GoblintAnalysis goblintAnalysis = new GoblintAnalysis(magpieServer, goblintServer, goblintService, gobPieConfiguration, goblintConfWatcher);
32+
33+
// Mock that GoblintServer is alive and everything is fine with Goblint's configuration file
34+
when(goblintServer.isAlive()).thenReturn(true);
35+
when(goblintConfWatcher.refreshGoblintConfig()).thenReturn(true);
36+
37+
// Mock that the analyses of goblint have started but not completed (still run)
38+
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(new CompletableFuture<>());
39+
40+
// Mock that the incremental analysis is turned off (TODO: not sure why this is checked in reanalyze?)
41+
when(gobPieConfiguration.useIncrementalAnalysis()).thenReturn(true);
42+
43+
// Mock the arguments for calling the goblintAnalyze.analyze method
44+
// And call the method twice
45+
Collection<? extends Module> files = new ArrayDeque<>();
46+
AnalysisConsumer analysisConsumer = mock(AnalysisConsumer.class);
47+
goblintAnalysis.analyze(files, analysisConsumer, true);
48+
goblintAnalysis.analyze(files, analysisConsumer, true);
49+
50+
// Verify that abortAnalysis was indeed called once
51+
verify(goblintServer).abortAnalysis();
52+
}
53+
54+
}

0 commit comments

Comments
 (0)