Commit 2caac21b authored by Skylot's avatar Skylot

test: limit auto check execution time

parent c5d977ba
...@@ -12,6 +12,13 @@ import java.util.ArrayList; ...@@ -12,6 +12,13 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import jadx.api.JadxArgs; import jadx.api.JadxArgs;
...@@ -229,16 +236,16 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -229,16 +236,16 @@ public abstract class IntegrationTest extends TestUtils {
return; return;
} }
try { try {
checkMth.invoke(origCls.getConstructor().newInstance()); limitExecTime(() -> checkMth.invoke(origCls.getConstructor().newInstance()));
} catch (InvocationTargetException ie) { } catch (Exception e) {
rethrow("Original check failed", ie); rethrow("Original check failed", e);
} }
// run 'check' method from decompiled class // run 'check' method from decompiled class
if (compile) { if (compile) {
try { try {
invoke("check"); limitExecTime(() -> invoke("check"));
} catch (InvocationTargetException ie) { } catch (Exception e) {
rethrow("Decompiled check failed", ie); rethrow("Decompiled check failed", e);
} }
System.out.println("Auto check: PASSED"); System.out.println("Auto check: PASSED");
} }
...@@ -248,14 +255,34 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -248,14 +255,34 @@ public abstract class IntegrationTest extends TestUtils {
} }
} }
private void rethrow(String msg, InvocationTargetException ie) { private <T> T limitExecTime(Callable<T> call) {
Throwable cause = ie.getCause(); ExecutorService executor = Executors.newSingleThreadExecutor();
if (cause instanceof AssertionError) { Future<T> future = executor.submit(call);
System.err.println(msg); try {
throw (AssertionError) cause; return future.get(5, TimeUnit.SECONDS);
} catch (TimeoutException ex) {
future.cancel(true);
rethrow("Execution timeout", ex);
} catch (Exception ex) {
rethrow(ex.getMessage(), ex);
} finally {
executor.shutdownNow();
}
return null;
}
private void rethrow(String msg, Throwable e) {
if (e instanceof InvocationTargetException) {
Throwable cause = e.getCause();
if (cause instanceof AssertionError) {
throw (AssertionError) cause;
} else {
fail(cause);
}
} else if (e instanceof ExecutionException) {
rethrow(e.getMessage(), e.getCause());
} else { } else {
cause.printStackTrace(); fail(msg, e);
fail(msg + cause.getMessage());
} }
} }
...@@ -279,8 +306,7 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -279,8 +306,7 @@ public abstract class IntegrationTest extends TestUtils {
assertTrue(result, "Compilation failed"); assertTrue(result, "Compilation failed");
System.out.println("Compilation: PASSED"); System.out.println("Compilation: PASSED");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); fail(e);
fail(e.getMessage());
} }
} }
...@@ -437,13 +463,14 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -437,13 +463,14 @@ public abstract class IntegrationTest extends TestUtils {
// Use only for debug purpose // Use only for debug purpose
@Deprecated @Deprecated
protected void setOutputCFG() { protected void outputCFG() {
this.args.setCfgOutput(true); this.args.setCfgOutput(true);
this.args.setRawCFGOutput(true); this.args.setRawCFGOutput(true);
} // Use only for debug purpose }
// Use only for debug purpose
@Deprecated @Deprecated
protected void setOutputRawCFG() { protected void outputRawCFG() {
this.args.setRawCFGOutput(true); this.args.setRawCFGOutput(true);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment