Commit: 49cccdd6886449dcc59bc24a7d77627750879d93 Author: Matt Ficken <v-maf...@microsoft.com> Fri, 2 Nov 2012 15:53:57 -0700 Parents: 3aca4906da0f27644e1e17039316358ff03b6404 Branches: master
Link: http://git.php.net/?p=pftt2.git;a=commitdiff;h=49cccdd6886449dcc59bc24a7d77627750879d93 Log: new console option for better cooperation with Visual Studio Former-commit-id: 18f65178e23b232d797b39b8e6656ad37b38ac07 Changed paths: M src/com/mostc/pftt/host/Host.java M src/com/mostc/pftt/main/PfttMain.java M src/com/mostc/pftt/model/phpt/PhpBuild.java M src/com/mostc/pftt/model/phpt/PhptTestPack.java M src/com/mostc/pftt/model/sapi/WebServerInstance.java M src/com/mostc/pftt/model/sapi/WebServerManager.java M src/com/mostc/pftt/runner/HttpTestCaseRunner.java M src/com/mostc/pftt/runner/PhptTestPackRunner.java M src/com/mostc/pftt/telemetry/ConsoleManager.java M src/com/mostc/pftt/telemetry/PhptTelemetryWriter.java M src/com/mostc/pftt/ui/PhptDebuggerFrame.java M src/com/mostc/pftt/util/HostEnvUtil.java M src/com/mostc/pftt/util/StringUtil.java
diff --git a/src/com/mostc/pftt/host/Host.java b/src/com/mostc/pftt/host/Host.java index 8c3cae9..c76635c 100644 --- a/src/com/mostc/pftt/host/Host.java +++ b/src/com/mostc/pftt/host/Host.java @@ -151,6 +151,13 @@ public abstract class Host { public abstract void saveText(String filename, String text) throws IllegalStateException, IOException; public abstract void saveText(String filename, String text, Charset charset) throws IllegalStateException, IOException; public abstract void delete(String path) throws IllegalStateException, IOException; + public void deleteIfExists(String path) { + try { + delete(path); + } catch ( Exception ex ) { + + } + } public abstract boolean exists(String string); public abstract void mkdirs(String path) throws IllegalStateException, IOException; /** copies file/directory from source to destination on host @@ -524,7 +531,7 @@ public abstract class Host { * @return */ public String fixPath(String path) { - return isWindows() ? StringUtil.replaceAll(PAT_fs, "\\", path) : toUnixPath(path); + return isWindows() ? StringUtil.replaceAll(PAT_fs, "\\\\", path) : toUnixPath(path); } public String join(String... path_parts) { diff --git a/src/com/mostc/pftt/main/PfttMain.java b/src/com/mostc/pftt/main/PfttMain.java index 2958c68..556d766 100644 --- a/src/com/mostc/pftt/main/PfttMain.java +++ b/src/com/mostc/pftt/main/PfttMain.java @@ -4,7 +4,6 @@ import groovy.lang.Binding; import groovy.lang.GroovyObject; import groovy.ui.Console; -import java.awt.Container; import java.awt.Desktop; import java.io.BufferedReader; import java.io.File; @@ -20,8 +19,6 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; -import javax.swing.JFrame; - import org.apache.commons.io.IOUtils; import org.apache.http.ConnectionReuseStrategy; import org.apache.http.HttpHost; @@ -66,9 +63,10 @@ import com.mostc.pftt.report.FBCReportGen; import com.mostc.pftt.runner.PhpUnitTestPackRunner; import com.mostc.pftt.runner.PhptTestPackRunner; import com.mostc.pftt.scenario.ScenarioSet; +import com.mostc.pftt.telemetry.ConsoleManager; import com.mostc.pftt.telemetry.PhptTelemetryReader; import com.mostc.pftt.telemetry.PhptTelemetryWriter; -import com.mostc.pftt.ui.PhptDebuggerFrame; +import com.mostc.pftt.util.HostEnvUtil; import com.mostc.pftt.util.StringUtil; import com.mostc.pftt.util.WindowsSnapshotDownloadUtil; import com.mostc.pftt.util.WindowsSnapshotDownloadUtil.FindBuildTestPackPair; @@ -115,20 +113,16 @@ public class PfttMain { return last_file == null ? null : PhptTelemetryReader.open(host, last_file); } - public void run_all(boolean show_gui, PhpBuild build, PhptTestPack test_pack, ScenarioSet scenario_set) throws Exception { + public void run_all(ConsoleManager cm, PhpBuild build, PhptTestPack test_pack, ScenarioSet scenario_set) throws Exception { LinkedList<PhptTestCase> test_cases = new LinkedList<PhptTestCase>(); - - PhptTelemetryWriter tmgr = new PhptTelemetryWriter(host, null, telem_dir(), build, test_pack, scenario_set); + + PhptTelemetryWriter tmgr = new PhptTelemetryWriter(host, cm, telem_dir(), build, test_pack, scenario_set); + test_pack.cleanup(); test_pack.add_test_files(test_cases, tmgr, build); PhptTestPackRunner test_pack_runner = new PhptTestPackRunner(tmgr, test_pack, scenario_set, build, host); + cm.showGUI(test_pack_runner); - if (show_gui) { - PhptDebuggerFrame gui = new PhptDebuggerFrame(test_pack_runner); - tmgr.gui = gui; - show_gui("phpt_all", gui); - } - test_pack_runner.runTestList(test_cases); tmgr.close(); @@ -161,20 +155,16 @@ public class PfttMain { } } - public void run_named_tests(boolean show_gui, PhpBuild build, PhptTestPack test_pack, ScenarioSet scenario_set, List<String> names) throws Exception { + public void run_named_tests(ConsoleManager cm, PhpBuild build, PhptTestPack test_pack, ScenarioSet scenario_set, List<String> names) throws Exception { LinkedList<PhptTestCase> test_cases = new LinkedList<PhptTestCase>(); - PhptTelemetryWriter tmgr = new PhptTelemetryWriter(host, null, telem_dir(), build, test_pack, scenario_set); + PhptTelemetryWriter tmgr = new PhptTelemetryWriter(host, cm, telem_dir(), build, test_pack, scenario_set); + test_pack.cleanup(); test_pack.add_named_tests(test_cases, names, tmgr, build); PhptTestPackRunner test_pack_runner = new PhptTestPackRunner(tmgr, test_pack, scenario_set, build, host); + cm.showGUI(test_pack_runner); - if (show_gui) { - PhptDebuggerFrame gui = new PhptDebuggerFrame(test_pack_runner); - tmgr.gui = gui; - show_gui("phpt_named", gui); - } - test_pack_runner.runTestList(test_cases); tmgr.close(); @@ -215,6 +205,8 @@ public class PfttMain { System.out.println("-force - disables confirmation dialogs and forces proceeding anyway"); System.out.println("-stress_each <0+> - runs each test-case N times consecutively"); System.out.println("-stress_all <0+> - runs all tests N times in loop"); + System.out.println("-results_only - displays only test results and no other information (for automation)."); + System.out.println("-disable_debug_prompt - disables asking you if you want to debug PHP crashes (for automation. default=enabled)"); System.out.println("(note: stress options not useful against CLI without code caching)"); System.out.println(); } // end protected static void cmd_help @@ -267,11 +259,11 @@ public class PfttMain { console.run(); } - protected static void cmd_phpt_all(PfttMain rt, boolean show_gui, GroovyObject config_obj, PhpBuild build, PhptTestPack test_pack) throws Exception { - rt.run_all(show_gui, build, test_pack, ScenarioSet.getScenarioSets().iterator().next()); + protected static void cmd_phpt_all(PfttMain rt, ConsoleManager cm, GroovyObject config_obj, PhpBuild build, PhptTestPack test_pack) throws Exception { + rt.run_all(cm, build, test_pack, ScenarioSet.getScenarioSets().iterator().next()); } - protected static void cmd_phpt_list(PfttMain rt, boolean show_gui, GroovyObject config_obj, PhpBuild build, PhptTestPack test_pack, File list_file) throws Exception { + protected static void cmd_phpt_list(PfttMain rt, ConsoleManager cm, GroovyObject config_obj, PhpBuild build, PhptTestPack test_pack, File list_file) throws Exception { BufferedReader fr = new BufferedReader(new FileReader(list_file)); LinkedList<String> tests = new LinkedList<String>(); String line; @@ -283,11 +275,11 @@ public class PfttMain { tests.add(line); } - rt.run_named_tests(show_gui, build, test_pack, ScenarioSet.getScenarioSets().iterator().next(), tests); + rt.run_named_tests(cm, build, test_pack, ScenarioSet.getScenarioSets().iterator().next(), tests); } - protected static void cmd_phpt_named(PfttMain rt, boolean show_gui, GroovyObject config_obj, PhpBuild build, PhptTestPack test_pack, List<String> names) throws Exception { - rt.run_named_tests(show_gui, build, test_pack, ScenarioSet.getScenarioSets().iterator().next(), names); + protected static void cmd_phpt_named(PfttMain rt, ConsoleManager cm, GroovyObject config_obj, PhpBuild build, PhptTestPack test_pack, List<String> names) throws Exception { + rt.run_named_tests(cm, build, test_pack, ScenarioSet.getScenarioSets().iterator().next(), names); } protected static void cmd_ui() { @@ -437,6 +429,7 @@ public class PfttMain { System.out.println("PFTT: release_get: decompressing "+local_file_zip+"..."); + // TODO c:\program files host.exec("\"C:\\Program Files\\7-Zip\\7z\" x "+local_file_zip, Host.NO_TIMEOUT, local_folder.toString()).printOutputIfCrash(); if (is_build) @@ -559,15 +552,6 @@ public class PfttMain { return null; // test-pack not found/readable error } - protected static void show_gui(String title, Container c) { - JFrame jf = new JFrame("PFTT - "+title); - jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - jf.setContentPane(c); - jf.pack(); - jf.setExtendedState(JFrame.MAXIMIZED_BOTH); - jf.setVisible(true); - } - protected static void no_show_gui(boolean show_gui, String command) { if (show_gui) { System.out.println("PFTT: Note: -gui not supported for "+command+" (ignored)"); @@ -581,7 +565,7 @@ public class PfttMain { int args_i = 0; GroovyObject config_obj = null; - boolean show_gui = false, force = false; + boolean show_gui = false, force = false, disable_debug_prompt = false, results_only = false; int stress_all = 0, stress_each = 0; // @@ -604,6 +588,10 @@ public class PfttMain { stress_each = Integer.parseInt(args[args_i++]); } else if (args[args_i].equals("-stress_all")) { stress_all = Integer.parseInt(args[args_i++]); + } else if (args[args_i].equals("-disable_debug_prompt")) { + disable_debug_prompt = true; + } else if (args[args_i].equals("-results_only")) { + results_only = true; } else if (args[args_i].startsWith("-")) { System.err.println("User Error: unknown option "+args[args_i]); System.exit(-255); @@ -627,6 +615,10 @@ public class PfttMain { System.err.println("PFTT: not implemented: stress_each="+stress_each+" stress_all="+stress_all+" ignored"); } + ConsoleManager cm = new ConsoleManager(results_only, show_gui, disable_debug_prompt); + + HostEnvUtil.prepareHostEnv(rt.host, cm, !disable_debug_prompt); + if (command!=null) { if (command.equals("phpt_named")||command.equals("phptnamed")||command.equals("phptn")||command.equals("pn")) { if (!(args.length > args_i+3)) { @@ -656,9 +648,12 @@ public class PfttMain { for ( ; args_i < args.length ; args_i++) names.add(args[args_i]); - System.out.println("PFTT: build: "+build); - System.out.println("PFTT: test-pack: "+test_pack); - cmd_phpt_named(rt, show_gui, config_obj, build, test_pack, names); + if (!results_only) { + System.out.println("PFTT: build: "+build); + System.out.println("PFTT: test-pack: "+test_pack); + } + + cmd_phpt_named(rt, cm, config_obj, build, test_pack, names); System.out.println("PFTT: finished"); } else if (command.equals("phpt_list")||command.equals("phptlist")||command.equals("phptl")||command.equals("pl")) { @@ -691,9 +686,11 @@ public class PfttMain { return; } - System.out.println("PFTT: build: "+build); - System.out.println("PFTT: test-pack: "+test_pack); - cmd_phpt_list(rt, show_gui, config_obj, build, test_pack, list_file); + if (!results_only) { + System.out.println("PFTT: build: "+build); + System.out.println("PFTT: test-pack: "+test_pack); + } + cmd_phpt_list(rt, cm, config_obj, build, test_pack, list_file); System.out.println("PFTT: finished"); } else if (command.equals("phpt_all")||command.equals("phptall")||command.equals("phpta")||command.equals("pa")) { @@ -718,12 +715,14 @@ public class PfttMain { return; } - System.out.println("PFTT: build: "+build); - System.out.println("PFTT: test-pack: "+test_pack); - System.out.println("PFTT: Testing all PHPTs in test pack..."); + if (!results_only) { + System.out.println("PFTT: build: "+build); + System.out.println("PFTT: test-pack: "+test_pack); + System.out.println("PFTT: Testing all PHPTs in test pack..."); + } // run all tests - cmd_phpt_all(rt, show_gui, config_obj, build, test_pack); + cmd_phpt_all(rt, cm, config_obj, build, test_pack); System.out.println("PFTT: finished"); } else if (command.equals("aut")) { diff --git a/src/com/mostc/pftt/model/phpt/PhpBuild.java b/src/com/mostc/pftt/model/phpt/PhpBuild.java index d5a2b93..076ebac 100644 --- a/src/com/mostc/pftt/model/phpt/PhpBuild.java +++ b/src/com/mostc/pftt/model/phpt/PhpBuild.java @@ -297,7 +297,8 @@ public class PhpBuild extends Build { host.saveText(php_filename, code); PHPOutput output = new PHPOutput(php_filename, host.exec(php_exe+" "+php_filename, timeout_seconds, new HashMap<String,String>(), null, Host.dirname(php_filename))); - if (auto_cleanup) + if (auto_cleanup && !output.hasFatalError()) + // if fatal error, don't clean up so user can check it output.cleanup(host); return output; } diff --git a/src/com/mostc/pftt/model/phpt/PhptTestPack.java b/src/com/mostc/pftt/model/phpt/PhptTestPack.java index 994522f..09b234e 100644 --- a/src/com/mostc/pftt/model/phpt/PhptTestPack.java +++ b/src/com/mostc/pftt/model/phpt/PhptTestPack.java @@ -46,6 +46,18 @@ public class PhptTestPack extends TestPack { return test_pack; } + /** cleans up this test-pack from previous runs of PFTT or run-test.php that were interrupted + * + */ + public void cleanup() { + // these are symlinks(junctions) which may cause an infinite loop + // + // normally, they are deleted, but if certain tests were interrupted, they may still be there + host.deleteIfExists("ext/standard/tests/file/windows_links/mklink_junction"); + host.deleteIfExists("ext/standard/tests/file/windows_links/directory"); + host.deleteIfExists("ext/standard/tests/file/windows_links/mounted_volume"); + } + public void add_named_tests(List<PhptTestCase> test_files, List<String> names, PhptTelemetryWriter twriter, PhpBuild build) throws FileNotFoundException, IOException, Exception { add_named_tests(test_files, names, twriter, build, false); } @@ -114,10 +126,6 @@ public class PhptTestPack extends TestPack { main_loop: for ( File f : files ) { if (f.getName().toLowerCase().endsWith(PhptTestCase.PHPT_FILE_EXTENSION)) { - // TODO test tests cause a blocking winpopup msg (syntax error line 31 in unknown) - skip them for now -// if (f.getPath().contains("session")&&f.getName().contains("0")) -// continue; - if (names!=null) { for(String name: names) { if (f.getName().toLowerCase().contains(name)) @@ -134,7 +142,7 @@ public class PhptTestPack extends TestPack { if (test_name.contains("a_dir")) continue; // TODO - PhptTestCase test_case = PhptTestCase.load(host, this, test_name, twriter); + PhptTestCase test_case = PhptTestCase.load(host, this, false, test_name, twriter, redirect_parent); add_test_case(test_case, test_files, names, twriter, build, redirect_parent, redirect_targets); } @@ -157,8 +165,12 @@ public class PhptTestPack extends TestPack { add_test_files(dir.listFiles(), test_files, names, twriter, build, redirect_parent, redirect_targets); } else { - // test refers to a specific test, try to load it - test_case = PhptTestCase.load(host, this, false, target_test_name, twriter, redirect_parent); + // test refers to a specific test, try to load it + try { + test_case = PhptTestCase.load(host, this, false, target_test_name, twriter, redirect_parent); + } catch ( Exception ex ) { + ex.printStackTrace(); // TODO temp + } if (redirect_targets.contains(test_case)) // can only have 1 level of redirection diff --git a/src/com/mostc/pftt/model/sapi/WebServerInstance.java b/src/com/mostc/pftt/model/sapi/WebServerInstance.java index 0d821a7..bdc6b10 100644 --- a/src/com/mostc/pftt/model/sapi/WebServerInstance.java +++ b/src/com/mostc/pftt/model/sapi/WebServerInstance.java @@ -66,7 +66,6 @@ public abstract class WebServerInstance extends SAPIInstance { */ public void notifyCrash(String output, int exit_code) { // make sure it gets closed!! - // TODO temp vs close(); synchronized(sync_lock) { // if (crashed) { @@ -77,6 +76,7 @@ public abstract class WebServerInstance extends SAPIInstance { sb.append(sapi_output); sb.append("\nPFTT: later web server returned exit code("+exit_code+") and output:\n"); sb.append(output); + sb.append("\nPFTT: end output.\n"); sapi_output = sb.toString(); } return; @@ -96,6 +96,7 @@ public abstract class WebServerInstance extends SAPIInstance { } else { sb.append("PFTT: before crashing/exiting web server returned("+output.length()+"):\n"); sb.append(output); + sb.append("\nPFTT: end output.\n"); } sapi_output = sb.toString(); diff --git a/src/com/mostc/pftt/model/sapi/WebServerManager.java b/src/com/mostc/pftt/model/sapi/WebServerManager.java index 1b060a9..4b93cd8 100644 --- a/src/com/mostc/pftt/model/sapi/WebServerManager.java +++ b/src/com/mostc/pftt/model/sapi/WebServerManager.java @@ -67,6 +67,7 @@ public abstract class WebServerManager extends SAPIManager { } } } + assigned.replacement = sapi = createWebServerInstance(host, build, ini, docroot); synchronized(assigned.active_test_cases) { sapi.active_test_cases.addAll(assigned.active_test_cases); diff --git a/src/com/mostc/pftt/runner/HttpTestCaseRunner.java b/src/com/mostc/pftt/runner/HttpTestCaseRunner.java index 311f071..a3c68b5 100644 --- a/src/com/mostc/pftt/runner/HttpTestCaseRunner.java +++ b/src/com/mostc/pftt/runner/HttpTestCaseRunner.java @@ -82,9 +82,11 @@ public class HttpTestCaseRunner extends AbstractPhptTestCaseRunner2 { } catch ( IOException ex1 ) { // SocketTimeoutException or ConnectException // notify of crash so it gets reported everywhere web.notifyCrash("PFTT: timeout during test("+section+" SECTION): "+test_case.getName()+"\n"+ErrorUtil.toString(ex1), 0); - // TODO temp VS + // ok to close this here, since its not an Access Violation(AV) and so won't prompt + // the user to enter Visual Studio, WinDbg or GDB web.close(); + // TODO System.out.println("RESTART_AND_RETRY "+test_case.getName()); // get #do_http_execute to make a new server @@ -132,6 +134,13 @@ public class HttpTestCaseRunner extends AbstractPhptTestCaseRunner2 { _web.notifyTestPreRequest(test_case); } } + + path = Host.toUnixPath(path); + if (path.startsWith(Host.toUnixPath(test_pack.getTestPack()))) + path = path.substring(test_pack.getTestPack().length()); + if (!path.startsWith("/")) + path = "/" + path; + try { if (web.isCrashed()) // test will fail (because this(`PFTT: server...`) is the actual output which won't match the expected output) @@ -146,53 +155,31 @@ public class HttpTestCaseRunner extends AbstractPhptTestCaseRunner2 { // only do POST for TEST sections where stdin_post!=null return do_http_post(path); } finally { - if (is_replacement) + if (is_replacement && (twriter.getConsoleManager().isDisableDebugPrompt()||!web.isCrashed()||!host.isWindows())) { // CRITICAL: if this WebServerInstance is a replacement, then it exists only within this specific HttpTestCaseRunner // instance. if it is not terminated here, it will keep running forever! + // + // don't close crashed servers on windows unless WER popup is disabled because user may want to + // debug them. if user doesn't, they'll click close in WER popup web.close(); + } } } protected String do_http_get(String path) throws Exception { - /*HttpParams params = new SyncBasicHttpParams(); - HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(params, "UTF-8"); - HttpProtocolParams.setUserAgent(params, "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/ 20120405 Firefox/14.0.1"); - HttpProtocolParams.setUseExpectContinue(params, true); - - HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {// XXX reuse - // Required protocol interceptors - new RequestContent(), - new RequestTargetHost(), - // Recommended protocol interceptors - new RequestConnControl(), - new RequestUserAgent(), - new RequestExpectContinue()}); - - HttpRequestExecutor httpexecutor = new HttpRequestExecutor();*/ - HttpContext context = new BasicHttpContext(null); HttpHost http_host = new HttpHost(web.hostname(), web.port()); DefaultHttpClientConnection conn = new DefaultHttpClientConnection(); - //ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); + // TODO ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, http_host); Socket socket = new Socket(http_host.getHostName(), http_host.getPort()); - //socket.setSoTimeout(6*1000); conn.bind(socket, params); conn.setSocketTimeout(60*1000); - // - path = Host.toUnixPath(path); - if (path.startsWith(Host.toUnixPath(test_pack.getTestPack()))) - path = path.substring(test_pack.getTestPack().length()); - if (!path.startsWith("/")) - path = "/" + path; - // - BasicHttpRequest request = new BasicHttpRequest("GET", path); request.setParams(params); @@ -207,47 +194,22 @@ public class HttpTestCaseRunner extends AbstractPhptTestCaseRunner2 { } // end protected String do_http_get protected String do_http_post(String path) throws Exception { - /*HttpParams params = new SyncBasicHttpParams(); - HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(params, "UTF-8"); - HttpProtocolParams.setUserAgent(params, "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/ 20120405 Firefox/14.0.1"); - HttpProtocolParams.setUseExpectContinue(params, true); // TODO if (content_type!=null) // params.setParameter("Content-Type", content_type); - - HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {// XXX reuse - // Required protocol interceptors - new RequestContent(), - new RequestTargetHost(), - // Recommended protocol interceptors - new RequestConnControl(), - new RequestUserAgent(), - new RequestExpectContinue()}); - - HttpRequestExecutor httpexecutor = new HttpRequestExecutor();*/ HttpContext context = new BasicHttpContext(null); HttpHost http_host = new HttpHost(web.hostname(), web.port()); DefaultHttpClientConnection conn = new DefaultHttpClientConnection(); - //ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); + // TODO ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, http_host); Socket socket = new Socket(http_host.getHostName(), http_host.getPort()); - //socket.setSoTimeout(6*1000); conn.bind(socket, params); conn.setSocketTimeout(60*1000); - // - path = Host.toUnixPath(path); - if (path.startsWith(Host.toUnixPath(test_pack.getTestPack()))) - path = path.substring(test_pack.getTestPack().length()); - if (!path.startsWith("/")) - path = "/" + path; - // - BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", path); request.setParams(params); httpexecutor.preProcess(request, httpproc, context); diff --git a/src/com/mostc/pftt/runner/PhptTestPackRunner.java b/src/com/mostc/pftt/runner/PhptTestPackRunner.java index 44db4be..a8c6f20 100644 --- a/src/com/mostc/pftt/runner/PhptTestPackRunner.java +++ b/src/com/mostc/pftt/runner/PhptTestPackRunner.java @@ -12,14 +12,12 @@ import com.mostc.pftt.model.phpt.PhpBuild; import com.mostc.pftt.model.phpt.PhpIni; import com.mostc.pftt.model.phpt.PhptTestCase; import com.mostc.pftt.model.phpt.PhptTestPack; -import com.mostc.pftt.model.sapi.SAPIInstance; import com.mostc.pftt.model.sapi.TestCaseGroupKey; import com.mostc.pftt.model.sapi.WebServerInstance; import com.mostc.pftt.scenario.AbstractSAPIScenario; import com.mostc.pftt.scenario.AbstractWebServerScenario; import com.mostc.pftt.scenario.ScenarioSet; import com.mostc.pftt.telemetry.PhptTelemetryWriter; -import com.mostc.pftt.util.HostEnvUtil; /** Runs PHPTs from a given PhptTestPack. * @@ -51,8 +49,6 @@ public class PhptTestPackRunner extends AbstractTestPackRunner { runner_state = ETestPackRunnerState.RUNNING; sapi_scenario = ScenarioSet.getSAPIScenario(scenario_set); - HostEnvUtil.prepareHostEnv(host); - System.out.println("PFTT: loaded tests: "+test_cases.size()); try { @@ -239,7 +235,13 @@ public class PhptTestPackRunner extends AbstractTestPackRunner { exec_jobs(group_key, jobs, test_count); // TODO temp - ((WebServerInstance)group_key).close(); + if ( twriter.getConsoleManager().isDisableDebugPrompt() || !((WebServerInstance)group_key).isCrashed() || !host.isWindows() ) { + // don't close this server if it crashed because user will get prompted + // to debug it on Windows and may still be debugging it (Visual Studio or WinDbg) + // + // it will get closed when user clicks close in WER popup dialog so its not like it would be running forever + ((WebServerInstance)group_key).close(); + } } } } // end protected void runThreadSafe diff --git a/src/com/mostc/pftt/telemetry/ConsoleManager.java b/src/com/mostc/pftt/telemetry/ConsoleManager.java index 75ce99d..c8d7512 100644 --- a/src/com/mostc/pftt/telemetry/ConsoleManager.java +++ b/src/com/mostc/pftt/telemetry/ConsoleManager.java @@ -1,23 +1,66 @@ package com.mostc.pftt.telemetry; +import java.awt.Container; + +import javax.swing.JFrame; + +import com.mostc.pftt.host.Host; import com.mostc.pftt.model.phpt.PhptTestCase; import com.mostc.pftt.model.phpt.EPhptTestStatus; +import com.mostc.pftt.runner.PhptTestPackRunner; +import com.mostc.pftt.ui.PhptDebuggerFrame; public class ConsoleManager { - - public ConsoleManager(boolean result_only) { + protected final boolean results_only, show_gui, disable_debug_prompt; + protected PhptDebuggerFrame gui; + + public ConsoleManager(boolean results_only, boolean show_gui, boolean disable_debug_prompt) { + this.results_only = results_only; + this.show_gui = show_gui; + this.disable_debug_prompt = disable_debug_prompt; } + + public void showGUI(PhptTestPackRunner test_pack_runner) { + if (show_gui) { + gui = new PhptDebuggerFrame(test_pack_runner); + show_gui("", gui); + } + } + + protected static void show_gui(String title, Container c) { + JFrame jf = new JFrame("PFTT - "+title); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jf.setContentPane(c); + jf.pack(); + jf.setExtendedState(JFrame.MAXIMIZED_BOTH); + jf.setVisible(true); + } + + public boolean isDisableDebugPrompt() { + return disable_debug_prompt; + } public void finishedTest(PhptTestCase test_case, EPhptTestStatus status) { - + System.out.println(status+" "+test_case.getName()); } - public void retryingTest(PhptTestCase test_case) { + public void restartingAndRetryingTest(PhptTestCase test_case) { + if (results_only) + return; + System.out.println("RESTARTING_AND_RETRYING "+test_case.getName()); } - public void restartingSAPI() { + public void showResult(Host host, int totalCount, int completed, PhptTestResult result) { + if (gui!=null) + gui.showResult(host, totalCount, completed, result); + } + + public void println(String ctx_str, String string) { + if (results_only) + return; + System.out.println("PFTT: "+ctx_str+": "+string); } } diff --git a/src/com/mostc/pftt/telemetry/PhptTelemetryWriter.java b/src/com/mostc/pftt/telemetry/PhptTelemetryWriter.java index 517fb5a..b5f40a3 100644 --- a/src/com/mostc/pftt/telemetry/PhptTelemetryWriter.java +++ b/src/com/mostc/pftt/telemetry/PhptTelemetryWriter.java @@ -15,7 +15,6 @@ import com.mostc.pftt.model.phpt.PhpBuild; import com.mostc.pftt.model.phpt.PhptTestCase; import com.mostc.pftt.model.phpt.PhptTestPack; import com.mostc.pftt.scenario.ScenarioSet; -import com.mostc.pftt.ui.PhptDebuggerFrame; import com.mostc.pftt.util.ErrorUtil; /** Writes the telemetry during a test run. @@ -31,16 +30,16 @@ public class PhptTelemetryWriter extends PhptTelemetry { protected Host host; protected PrintWriter exception_writer; protected int total_count = 0; - public PhptDebuggerFrame gui; // XXX + protected ConsoleManager cm; protected HashMap<EPhptTestStatus,AtomicInteger> counts; protected PhpBuild build; protected PhptTestPack test_pack; protected ScenarioSet scenario_set; - public PhptTelemetryWriter(Host host, PhptDebuggerFrame gui, File telem_base_dir, PhpBuild build, PhptTestPack test_pack, ScenarioSet scenario_set) throws IOException { + public PhptTelemetryWriter(Host host, ConsoleManager cm, File telem_base_dir, PhpBuild build, PhptTestPack test_pack, ScenarioSet scenario_set) throws IOException { super(host); this.host = host; - this.gui = gui; + this.cm = cm; this.scenario_set = scenario_set; this.build = build; this.test_pack = test_pack; @@ -68,6 +67,10 @@ public class PhptTelemetryWriter extends PhptTelemetry { } } + public ConsoleManager getConsoleManager() { + return cm; + } + @Override public void close() { for(EPhptTestStatus status:EPhptTestStatus.values()) { @@ -163,7 +166,7 @@ public class PhptTelemetryWriter extends PhptTelemetry { addResult(new PhptTestResult(host, EPhptTestStatus.EXCEPTION, test_case, ex_str, null, null, null, null, null, null, null, null, null, null)); // TODO show count of exceptions in gui } - int completed = 0; // XXX + int completed = 0; // XXX public void addResult(PhptTestResult result) { // FUTURE enqueue in writer thread to avoid slowing down PhptThreads // also, on Windows, enqueue printing to console here @@ -172,9 +175,9 @@ public class PhptTelemetryWriter extends PhptTelemetry { counts.get(result.status).incrementAndGet(); - if (gui!=null) { + if (cm!=null) { // show in gui (if open) - gui.showResult(host, getTotalCount(), completed, result); + cm.showResult(host, getTotalCount(), completed, result); } // record in list files diff --git a/src/com/mostc/pftt/ui/PhptDebuggerFrame.java b/src/com/mostc/pftt/ui/PhptDebuggerFrame.java index f706858..a1d7e9b 100644 --- a/src/com/mostc/pftt/ui/PhptDebuggerFrame.java +++ b/src/com/mostc/pftt/ui/PhptDebuggerFrame.java @@ -5,8 +5,6 @@ import groovy.ui.ConsoleTextEditor; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.nio.charset.Charset; -import java.util.Map; import javax.swing.ButtonGroup; import javax.swing.JButton; @@ -25,12 +23,11 @@ import javax.swing.border.LineBorder; import se.datadosen.component.RiverLayout; import com.mostc.pftt.host.Host; import com.mostc.pftt.host.LocalHost; -import com.mostc.pftt.model.phpt.EPhptTestStatus; -import com.mostc.pftt.model.phpt.PhptTestCase; import com.mostc.pftt.runner.PhptTestPackRunner; import com.mostc.pftt.scenario.ScenarioSet; import com.mostc.pftt.telemetry.PhptTestResult; +@SuppressWarnings("serial") public class PhptDebuggerFrame extends JPanel { protected JTabbedPane tabs; protected PhptHostTab localhost_tab; diff --git a/src/com/mostc/pftt/util/HostEnvUtil.java b/src/com/mostc/pftt/util/HostEnvUtil.java index a4876fa..9dcf9f2 100644 --- a/src/com/mostc/pftt/util/HostEnvUtil.java +++ b/src/com/mostc/pftt/util/HostEnvUtil.java @@ -2,6 +2,7 @@ package com.mostc.pftt.util; import com.mostc.pftt.host.ExecOutput; import com.mostc.pftt.host.Host; +import com.mostc.pftt.telemetry.ConsoleManager; /** Utilities for setting up the test environment and convenience settings on Hosts * @@ -11,9 +12,9 @@ import com.mostc.pftt.host.Host; public final class HostEnvUtil { - public static void prepareHostEnv(Host host) throws Exception { + public static void prepareHostEnv(Host host, ConsoleManager cm, boolean enable_debug_prompt) throws Exception { if (host.isWindows()) { - prepareWindows(host); + prepareWindows(host, cm, enable_debug_prompt); } else { // emerge dev-vcs/subversion } @@ -26,37 +27,44 @@ public final class HostEnvUtil { * -installs VC9 runtime if its not Windows 7/2008r2 or Windows 8/2012 (which don't need it to run PHP) * * @param host + * @param cm + * @param enable_debug_prompt * @throws Exception */ - public static void prepareWindows(Host host) throws Exception { + public static void prepareWindows(Host host, ConsoleManager cm, boolean enable_debug_prompt) throws Exception { System.out.println("PFTT: preparing Windows host to run PHP..."); // have to fix Windows Error Reporting from popping up and blocking execution: - // silence reporting - System.out.println("PFTT: HostEnvUtil: disabling Windows Error Reporting..."); - // TODO temp boolean a = regQueryAdd(host, "HKCU\\Software\\Microsoft\\Windows\\Windows Error Reporting", "DontShowUI", "0x1", REG_DWORD); - boolean a = regQueryAdd(host, "HKCU\\Software\\Microsoft\\Windows\\Windows Error Reporting", "DontShowUI", "0x0", REG_DWORD); - // TODO temp boolean b = regQueryAdd(host, "HKCU\\Software\\Microsoft\\Windows\\Windows Error Reporting", "Disable", "0x1", REG_DWORD); - boolean b = regQueryAdd(host, "HKCU\\Software\\Microsoft\\Windows\\Windows Error Reporting", "Disable", "0x0", REG_DWORD); - // then, disable reporting + + String value; + if (enable_debug_prompt) { + cm.println("HostEnvUtil", "enabling Windows Error Reporting..."); + value = "0x0"; + } else { + cm.println("HostEnvUtil", "disabling Windows Error Reporting..."); + value = "0x1"; + } + + boolean a = regQueryAdd(host, "HKCU\\Software\\Microsoft\\Windows\\Windows Error Reporting", "DontShowUI", value, REG_DWORD); + boolean b = regQueryAdd(host, "HKCU\\Software\\Microsoft\\Windows\\Windows Error Reporting", "Disable", value, REG_DWORD); if ( a || b ) { // assume if registry had to be edited, that firewall has to be disabled (avoid doing this if possible because it requires user to approve elevation) - System.out.println("PFTT: HostEnvUtil: disabling Windows Firewall..."); + cm.println("HostEnvUtil", "disabling Windows Firewall..."); // LATER edit firewall rules instead (what if on public network, ex: Azure) host.execElevated("netsh firewall set opmode disable", Host.ONE_MINUTE); - System.out.println("PFTT: HostEnvUtil: creating File Share for "+host.getPhpSdkDir()+"..."); + cm.println("HostEnvUtil", "creating File Share for "+host.getPhpSdkDir()+"..."); // share PHP-SDK over network. this also will share C$, G$, etc... host.execElevated("NET SHARE PHP_SDK="+host.getPhpSdkDir()+" /Grant:"+host.getUsername()+",Full", Host.ONE_MINUTE); } if (host.isLonghornExact()) { - // install VC9 runtime + // install VC9 runtime (win7+ don't need this) // TODO } - System.out.println("PFTT: Windows host prepared to run PHP."); + cm.println("HostEnvUtil", "Windows host prepared to run PHP."); } // end public static void prepareWindows public static final String REG_DWORD = "REG_DWORD"; diff --git a/src/com/mostc/pftt/util/StringUtil.java b/src/com/mostc/pftt/util/StringUtil.java index 4b0c6e6..90fc13f 100644 --- a/src/com/mostc/pftt/util/StringUtil.java +++ b/src/com/mostc/pftt/util/StringUtil.java @@ -228,4 +228,4 @@ public final class StringUtil { private StringUtil() {} -} +} // end public class StringUtil