Skip to content

Commit 54efd41

Browse files
authored
add a timeout param to wasm-reduce (#1230)
1 parent 83a0502 commit 54efd41

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/tools/wasm-reduce.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
using namespace wasm;
3939

40+
// a timeout on every execution of the command
41+
size_t timeout = 2;
42+
4043
struct ProgramResult {
4144
int code;
4245
std::string output;
@@ -51,10 +54,10 @@ struct ProgramResult {
5154
void getFromExecution(std::string command) {
5255
// do this using just core stdio.h and stdlib.h, for portability
5356
// sadly this requires two invokes
54-
code = system(("timeout 2s " + command + " > /dev/null 2> /dev/null").c_str());
57+
code = system(("timeout " + std::to_string(timeout) + "s " + command + " > /dev/null 2> /dev/null").c_str());
5558
const int MAX_BUFFER = 1024;
5659
char buffer[MAX_BUFFER];
57-
FILE *stream = popen(("timeout 2s " + command + " 2> /dev/null").c_str(), "r");
60+
FILE *stream = popen(("timeout " + std::to_string(timeout) + "s " + command + " 2> /dev/null").c_str(), "r");
5861
while (fgets(buffer, MAX_BUFFER, stream) != NULL) {
5962
output.append(buffer);
6063
}
@@ -526,6 +529,12 @@ int main(int argc, const char* argv[]) {
526529
[&](Options* o, const std::string& argument) {
527530
force = true;
528531
})
532+
.add("--timeout", "-to", "A timeout to apply to each execution of the command, in seconds (default: 2)",
533+
Options::Arguments::One,
534+
[&](Options* o, const std::string& argument) {
535+
timeout = atoi(argument.c_str());
536+
std::cout << "|applying timeout: " << timeout << "\n";
537+
})
529538
.add_positional("INFILE", Options::Arguments::One,
530539
[&](Options* o, const std::string& argument) {
531540
input = argument;

0 commit comments

Comments
 (0)