!747 m { static new Flag done; static new Flag success; static int myPort, vmPort; static long lastRun; static boolean lastResult; static boolean keepVMAlive = false; // keep VM alive after test (set to false for production!) static S vmProgram = "#1001317"; !include #1000915 // Flag p { myPort = makeAndroid3("Test Case Master Bot.").port; // Start Dependent VM nohupJavax(vmProgram.substring(1) + " " + myPort); sleep(); } static void startTest() { thread { try { DialogIO io = talkTo("localhost", vmPort); print(io.readLine()); io.sendLine("What is your process id?"); S s = io.readLine(); print("VM said: " + s); int pid = parseInt(s); print("PID: " + pid); if (!(pid != 0 && processIDExists("" + pid))) fail(s); io.sendLine("What is the main program id?"); s = io.readLine(); if (parseSnippetID(s) != parseSnippetID(vmProgram)) fail(s); success.raise(); } catch (Throwable e) { e.printStackTrace(); } done.raise(); // so dependent VM exits lastRun = now(); saveLocally("lastRun"); lastResult = success.isUp(); saveLocally("lastResult"); print(success.isUp() ? "TEST SUCCESS" : "TEST FAILURE"); sendTestResult(success.isUp()); } } static synchronized S answer(S s, L history) { new Matches m; if (match3("Master: My VM port is *", s, m)) { if (vmPort == 0) { vmPort = parseInt(unquote(m.m[0])); startTest(); } return "OK"; } if (match3("Master: Should I stay alive?", s)) return !keepVMAlive && done.isUp() ? "No." : "Yes."; return null; } }