Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/tools/wasm-reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down