Skip to content

Commit

Permalink
Write test for aborting analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
karoliineh committed Jan 12, 2024
1 parent b1136f1 commit b7d55d5
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/test/java/GoblintAnalysisTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import analysis.GoblintAnalysis;
import api.GoblintService;
import api.messages.params.AnalyzeParams;
import com.ibm.wala.classLoader.Module;
import goblintserver.GoblintConfWatcher;
import goblintserver.GoblintServer;
import gobpie.GobPieConfiguration;
import magpiebridge.core.AnalysisConsumer;
import magpiebridge.core.MagpieServer;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;

import static org.mockito.Mockito.*;

class GoblintAnalysisTest {

@Test
void abortAnalysis() throws IOException {

// Mock everything needed for creating GoblintAnalysis
MagpieServer magpieServer = mock(MagpieServer.class);
GoblintServer goblintServer = mock(GoblintServer.class);
GoblintService goblintService = mock(GoblintService.class);
GobPieConfiguration gobPieConfiguration = mock(GobPieConfiguration.class);
GoblintConfWatcher goblintConfWatcher = mock(GoblintConfWatcher.class);

GoblintAnalysis goblintAnalysis = new GoblintAnalysis(magpieServer, goblintServer, goblintService, gobPieConfiguration, goblintConfWatcher);

// Mock that GoblintServer is alive and everything is fine with Goblint's configuration file
when(goblintServer.isAlive()).thenReturn(true);
when(goblintConfWatcher.refreshGoblintConfig()).thenReturn(true);

// Mock that the analyses of goblint have started but not completed (still run)
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(new CompletableFuture<>());

// Mock that the incremental analysis is turned off (TODO: not sure why this is checked in reanalyze?)
when(gobPieConfiguration.useIncrementalAnalysis()).thenReturn(true);

// Mock the arguments for calling the goblintAnalyze.analyze method
// And call the method twice
Collection<? extends Module> files = new ArrayDeque<>();
AnalysisConsumer analysisConsumer = mock(AnalysisConsumer.class);
goblintAnalysis.analyze(files, analysisConsumer, true);
goblintAnalysis.analyze(files, analysisConsumer, true);

// Verify that abortAnalysis was indeed called once
verify(goblintServer).abortAnalysis();
}

}

0 comments on commit b7d55d5

Please sign in to comment.