X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.testing%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftesting%2Fbase%2FSCLScriptTestBase.java;h=511af6dc3d3ec05e5646d25ed872e06d57740b0c;hb=HEAD;hp=26e916fc1bcdfa53ed8f0076155b33b3d7bf603e;hpb=67fd62f9c742337ec80eef658192db198a0efaac;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java index 26e916fc1..511af6dc3 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java @@ -19,21 +19,24 @@ import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.osgi.internal.Activator; import org.simantics.scl.osgi.internal.ServiceBasedModuleSourceRepository; import org.simantics.scl.osgi.internal.ServiceBasedTestRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import gnu.trove.map.hash.THashMap; /** * Utilizies {@link TestRepository} for collecting SCL tests from bundles * - * @author Jani - * + * @author Jani Simomaa */ public class SCLScriptTestBase extends FreshDatabaseTest { + private static final Logger LOGGER = LoggerFactory.getLogger(SCLScriptTestBase.class); + private Map testRunnables = new THashMap(); - + @Rule public TestName testName = new TestName(); - + /** * Constructor that initially searches for all SCL test scripts and stores * them into a Map for later access @@ -47,14 +50,14 @@ public class SCLScriptTestBase extends FreshDatabaseTest { testRunnables.put(runnable.getName(), runnable); } } - + /** * Simplest method for running a SCL test */ protected void test() { test(-1); } - + /** * Executes a test case with given timeout as seconds. When time runs out one * can assume a deadlock has happened. The process is killed after the timeout @@ -65,7 +68,7 @@ public class SCLScriptTestBase extends FreshDatabaseTest { protected void test(int timeout) { testImpl(timeout); } - + /** * Executes a test case with given timeout as seconds * @@ -75,45 +78,57 @@ public class SCLScriptTestBase extends FreshDatabaseTest { SCLOsgi.SOURCE_REPOSITORY = new ServiceBasedModuleSourceRepository(Activator.getContext()); SCLOsgi.MODULE_REPOSITORY = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY); SCLOsgi.TEST_REPOSITORY = new ServiceBasedTestRepository(Activator.getContext()); - + String testName = resolveTestName(); TestRunnable runnable = testRunnables.get(testName); - + if (runnable == null) { + LOGGER.error("SCL Test Suite file (.sts) for test {} cannot be found from test repository.", testName); + return; + } + + long start = System.nanoTime(); if (timeout > -1) { + LOGGER.info("Running test {} with a timeout of {} seconds", testName, timeout); //$NON-NLS-1$ Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { + LOGGER.info("Watchdog will kill this test process because it has been executing for over {} seconds", timeout); //$NON-NLS-1$ String processName = ManagementFactory.getRuntimeMXBean().getName(); - System.out.println("PID: " + processName); + LOGGER.info("Test Process Name: {}", processName); //$NON-NLS-1$ String PID = processName.split("@")[0]; String command = "taskkill /F /PID " + PID; - System.out.println("Command: " + command); + LOGGER.info("Running command to kill test process: {}", command); //$NON-NLS-1$ try { Runtime.getRuntime().exec(command); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("Failed to kill process that ran over its execution time limit of {} seconds", timeout, e); } } }, timeout*1000); try { runnable.run(); + long end = System.nanoTime(); + LOGGER.info("Completed test {} execution in {} seconds", testName, String.format("%.3f", (end-start)*1e-9)); //$NON-NLS-1$ } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Failed to run test {} runnable {}", testName, runnable, e); } finally { timer.cancel(); } } else { + LOGGER.info("Running test {} without timeout", testName); //$NON-NLS-1$ try { runnable.run(); + long end = System.nanoTime(); + LOGGER.info("Completed test {} execution in {} seconds", testName, String.format("%.3f", (end-start)*1e-9)); //$NON-NLS-1$ } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Failed to run test {} runnable {}", testName, runnable, e); } } } - + /** * Resolves the full test name based on the names of classes that extends this * SCLScriptTestBase class.