diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-10-23 16:37:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 16:37:27 -0700 |
commit | 54efd418f3758882aaf0401d3e7f0f7a86c21cc2 (patch) | |
tree | 78f593b9f5586b18bb23b7830dba89b37ede0368 /src | |
parent | 83a05025ee883f86cabdf92a9891d6c5ef5afbd4 (diff) | |
download | binaryen-54efd418f3758882aaf0401d3e7f0f7a86c21cc2.tar.gz binaryen-54efd418f3758882aaf0401d3e7f0f7a86c21cc2.tar.bz2 binaryen-54efd418f3758882aaf0401d3e7f0f7a86c21cc2.zip |
add a timeout param to wasm-reduce (#1230)
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm-reduce.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index 90ae9bbe6..ff3408b9a 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -37,6 +37,9 @@ using namespace wasm; +// a timeout on every execution of the command +size_t timeout = 2; + struct ProgramResult { int code; std::string output; @@ -51,10 +54,10 @@ struct ProgramResult { void getFromExecution(std::string command) { // do this using just core stdio.h and stdlib.h, for portability // sadly this requires two invokes - code = system(("timeout 2s " + command + " > /dev/null 2> /dev/null").c_str()); + code = system(("timeout " + std::to_string(timeout) + "s " + command + " > /dev/null 2> /dev/null").c_str()); const int MAX_BUFFER = 1024; char buffer[MAX_BUFFER]; - FILE *stream = popen(("timeout 2s " + command + " 2> /dev/null").c_str(), "r"); + FILE *stream = popen(("timeout " + std::to_string(timeout) + "s " + command + " 2> /dev/null").c_str(), "r"); while (fgets(buffer, MAX_BUFFER, stream) != NULL) { output.append(buffer); } @@ -526,6 +529,12 @@ int main(int argc, const char* argv[]) { [&](Options* o, const std::string& argument) { force = true; }) + .add("--timeout", "-to", "A timeout to apply to each execution of the command, in seconds (default: 2)", + Options::Arguments::One, + [&](Options* o, const std::string& argument) { + timeout = atoi(argument.c_str()); + std::cout << "|applying timeout: " << timeout << "\n"; + }) .add_positional("INFILE", Options::Arguments::One, [&](Options* o, const std::string& argument) { input = argument; |