Skip to content

Commit e374495

Browse files
committed
Allowing multiple test execution before shutting down executors
1 parent 2725144 commit e374495

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/main/java/it/unipr/EVMLiSA.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ public static boolean isInPaperMode() {
164164
public static void setPaperMode() {
165165
PAPER_MODE = true;
166166
}
167+
168+
/**
169+
* Disables the paper mode (i.e., statistics contains jump classifications as in the reference paper).
170+
*/
171+
public static void disablePaperMode() {
172+
PAPER_MODE = false;
173+
}
167174

168175
/**
169176
* Executes the analysis workflow.
@@ -235,9 +242,19 @@ else if (cmd.hasOption("bytecode")) {
235242
* @param filePath the path to the file containing contract addresses
236243
*/
237244
public static void analyzeSetOfContracts(Path filePath) {
245+
analyzeSetOfContracts(filePath, true);
246+
}
247+
248+
/**
249+
* Analyzes a set of smart contracts from a given file.
250+
*
251+
* @param filePath the path to the file containing contract addresses
252+
* @param shutdown whether to shut down the executor after the analysis
253+
*/
254+
public static void analyzeSetOfContracts(Path filePath, boolean shutdown) {
238255
log.info("Building contracts.");
239256
List<SmartContract> contracts = buildContractsFromFile(filePath);
240-
analyzeSetOfContracts(contracts);
257+
analyzeSetOfContracts(contracts, shutdown);
241258
}
242259

243260
/**
@@ -246,6 +263,16 @@ public static void analyzeSetOfContracts(Path filePath) {
246263
* @param contracts the list of {@link SmartContract} to be analyzed
247264
*/
248265
public static void analyzeSetOfContracts(List<SmartContract> contracts) {
266+
analyzeSetOfContracts(contracts, true);
267+
}
268+
269+
/**
270+
* Analyzes a set of smart contracts from a list of {@link SmartContract}.
271+
*
272+
* @param contracts the list of {@link SmartContract} to be analyzed
273+
* @param shutdown whether to shut down the executor after the analysis
274+
*/
275+
public static void analyzeSetOfContracts(List<SmartContract> contracts, boolean shutdown) {
249276
log.info("Analyzing {} contracts.", contracts.size());
250277

251278
List<Future<?>> futures = new ArrayList<>();
@@ -272,7 +299,9 @@ public static void analyzeSetOfContracts(List<SmartContract> contracts) {
272299
System.err.println(JSONManager.throwNewError("Failed to save results in " + outputDir));
273300
System.exit(1);
274301
}
275-
EVMLiSAExecutor.shutdown();
302+
303+
if (shutdown)
304+
EVMLiSAExecutor.shutdown();
276305
}
277306

278307
/**

src/test/java/it/unipr/analysis/cron/EVMBytecodeGroundTruth.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package it.unipr.analysis.cron;
22

33
import it.unipr.EVMLiSA;
4+
import it.unipr.utils.EVMLiSAExecutor;
45
import it.unipr.utils.JSONManager;
56
import it.unipr.utils.PaperStatisticsObject;
67
import it.unipr.utils.StandardStatisticsObject;
@@ -15,6 +16,7 @@
1516
import java.util.Set;
1617
import org.apache.logging.log4j.LogManager;
1718
import org.apache.logging.log4j.Logger;
19+
import org.junit.AfterClass;
1820
import org.junit.Ignore;
1921
import org.junit.Test;
2022

@@ -30,6 +32,11 @@ public class EVMBytecodeGroundTruth {
3032
private final Path RUN_RESULTS = WORKING_DIRECTORY_PATH.resolve("set-of-contracts").resolve("results.json");
3133
private Path GROUND_TRUTH_FILE_PATH;
3234

35+
@AfterClass
36+
public static void cleanUp() {
37+
EVMLiSAExecutor.shutdown();
38+
}
39+
3340
private void setupAndRun() {
3441
if (EVMLiSA.isInPaperMode())
3542
GROUND_TRUTH_FILE_PATH = WORKING_DIRECTORY_PATH.resolve("ground-truth-data-paper-mode.json");
@@ -38,19 +45,21 @@ private void setupAndRun() {
3845
EVMLiSA.setWorkingDirectory(WORKING_DIRECTORY_PATH);
3946
EVMLiSA.setCores(Runtime.getRuntime().availableProcessors() / 4 * 3);
4047
EVMLiSA.setTestMode();
41-
EVMLiSA.analyzeSetOfContracts(SMARTCONTRACTS_FULLPATH);
48+
EVMLiSA.analyzeSetOfContracts(SMARTCONTRACTS_FULLPATH, false);
4249
}
4350

4451
@Test
4552
@Ignore
4653
public void regenerateGroundTruth() throws Exception {
54+
EVMLiSA.disablePaperMode();
4755
setupAndRun();
4856

4957
Files.copy(RUN_RESULTS, GROUND_TRUTH_FILE_PATH, StandardCopyOption.REPLACE_EXISTING);
5058
}
5159

5260
@Test
5361
public void testGroundTruth() throws Exception {
62+
EVMLiSA.disablePaperMode();
5463
setupAndRun();
5564

5665
boolean changed = false;

0 commit comments

Comments
 (0)