-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.js
145 lines (117 loc) · 4.43 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const { exec } = require('child_process');
const fs = require('fs');
const data = require("./configurations.json");
let waiting_processes = [];
let running_processes = new Set();
function runContract() {
if (waiting_processes.length === 0)
return
const data = waiting_processes.shift();
const configuration = data.configuration;
const contract = data.contract;
const command = data.command;
// Delete old files
console.log("Deleting old files")
const runFiles = fs.readdirSync("contracts");
for (let file of runFiles) {
fs.unlinkSync(`contracts/${file}`);
}
// if (fs.existsSync("migrations/2_deploy_contracts.js")) {
// fs.unlinkSync("migrations/2_deploy_contracts.js");
// }
fs.rmSync("syntest", { recursive: true, force: true });
fs.rmSync(".syntest", { recursive: true, force: true });
// Copy in new files
console.log("Copying in new files");
// fs.copyFileSync("Migrations.sol", "contracts/Migrations.sol");
const files = fs.readdirSync(`benchmark/${contract}`);
for (let file of files) {
const extParts = file.split(".");
switch (extParts[extParts.length - 1]) {
case "sol":
fs.copyFileSync(`benchmark/${contract}/${file}`, `contracts/${file}`)
break;
// case "js":
// if (file === "2_deploy_contracts.js")
// fs.copyFileSync(`benchmark/${contract}/${file}`, `migrations/${file}`)
// break;
}
}
// Run contract
const child = exec(command, {cwd: "./"}, (error, stdout, stderr) => {
const pid = child.pid;
console.log(`stopping ${pid}`);
running_processes.delete(pid);
if (error) {
console.error(`${pid} error: ${error}`);
}
//console.log(`${pid} stdout: ${stdout}`);
//console.error(`${pid} stderr: ${stderr}`);
// Create results dir
fs.mkdirSync(`results/${contract}`);
fs.mkdirSync(`results/${contract}/tests`);
fs.writeFileSync(`results/${contract}/stdout.txt`, stdout)
fs.writeFileSync(`results/${contract}/stderr.txt`, stderr)
// Copy results
if (fs.existsSync("syntest")) {
if (fs.existsSync("syntest/statistics/statistics.csv")) {
fs.copyFileSync("syntest/statistics/statistics.csv", `results/${contract}/statistics.csv`);
} else {
console.log("No statistics.csv");
}
if (fs.existsSync("syntest/statistics/coverage.csv")) {
fs.copyFileSync("syntest/statistics/coverage.csv", `results/${contract}/coverage.csv`);
} else {
console.log("No coverage.csv");
}
if (fs.existsSync("syntest/tests")) {
const testFiles = fs.readdirSync("syntest/tests");
for (let file of testFiles) {
fs.copyFileSync(`syntest/tests/${file}`, `results/${contract}/tests/${file}`);
}
} else {
console.log("No tests");
}
} else {
console.log("No results directory");
}
const tmpFiles = fs.readdirSync("/tmp");
for (let file of tmpFiles) {
if (file.startsWith("tmp-")) {
fs.rmSync(`/tmp/${file}`, { recursive: true, force: true });
console.log("Deleting tmp directory");
}
}
// Repeat
setTimeout(runContract, 10 * 1000);
});
const pid = child.pid;
console.log(`starting ${pid} with command: ${command}`);
running_processes.add(pid);
}
if (!fs.existsSync("contracts")) {
fs.mkdirSync("contracts");
}
fs.mkdirSync("results");
const contracts = fs.readdirSync("benchmark");
for (let configuration of data.configurations) {
for (let contract of contracts) {
let data = {};
data['configuration'] = configuration;
data['contract'] = contract;
const seed = Math.floor(Math.random() * 1000);
const arguments = ` --algorithm ${configuration.algorithm} --seed ${seed} --probe_objective ${configuration.probe_objective} --modifier_extraction ${configuration.modifier_extraction} --constant_pool ${configuration.constant_pool} --constant_pool_probability ${configuration.constant_pool_probability} --search_time ${configuration.search_time} --total_time ${configuration.total_time}`;
data['command'] = "truffle run syntest-solidity".concat(arguments);
waiting_processes.push(data);
}
}
runContract();
function trackProgress() {
if (waiting_processes.length > 0) {
console.log(`Waiting on ${running_processes.size} processes to finish:`);
console.log(running_processes);
console.log(`${waiting_processes.length} configurations still to go`);
setTimeout(trackProgress, 10 * 1000);
}
}
trackProgress();