diff options
author | Maksymilian Osowski <maxosowski@google.com> | 2010-08-12 14:35:09 +0100 |
---|---|---|
committer | Maksymilian Osowski <maxosowski@google.com> | 2010-08-13 12:07:17 +0100 |
commit | 74b13aecbe4116ce33da8ed99f1b5941ecda6505 (patch) | |
tree | 70c5245c42e6388694f33f9d00f7c1e19f5d9efb | |
parent | 2c46b6d2b168b08cea9bc28a25e1e74bd5684778 (diff) | |
download | frameworks_base-74b13aecbe4116ce33da8ed99f1b5941ecda6505.zip frameworks_base-74b13aecbe4116ce33da8ed99f1b5941ecda6505.tar.gz frameworks_base-74b13aecbe4116ce33da8ed99f1b5941ecda6505.tar.bz2 |
Added python script that starts/stops apache2 server on host machine configured to handle http layout tests.
Change-Id: I7bf4390dfb4f9a580e6e4ca0eb25c85655df723c
-rw-r--r-- | tests/DumpRenderTree2/assets/run-apache2.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/DumpRenderTree2/assets/run-apache2.py b/tests/DumpRenderTree2/assets/run-apache2.py new file mode 100644 index 0000000..d7590ee --- /dev/null +++ b/tests/DumpRenderTree2/assets/run-apache2.py @@ -0,0 +1,93 @@ +#!/usr/bin/python + +"""Start, stop, or restart apache2 server. + + Apache2 must be installed with mod_php! + + Usage: + run-apache2.py start|stop|restart +""" + +import sys +import os +import subprocess +import logging + +def main(): + if len(sys.argv) < 2: + run_cmd = "" + else: + run_cmd = sys.argv[1] + + #Setup logging class + logging.basicConfig(level=logging.INFO, format='%(message)s') + + if not run_cmd in ("start", "stop", "restart"): + logging.info("illegal argument: " + run_cmd) + logging.info("Usage: python run-apache2.py start|stop|restart") + return + + #Create /tmp/WebKit if it doesn't exist. This is needed for various files used by apache2 + tmp_WebKit = os.path.join("/tmp", "WebKit") + if not os.path.exists(tmp_WebKit): + os.mkdir(tmp_WebKit) + + #Get the path to android tree root based on the script location. + #Basically we go 5 levels up + parent = os.pardir + script_location = os.path.abspath(os.path.dirname(sys.argv[0])) + android_tree_root = os.path.join(script_location, parent, parent, parent, parent, parent) + android_tree_root = os.path.normpath(android_tree_root) + + #Prepare the command to set ${APACHE_RUN_USER} and ${APACHE_RUN_GROUP} + envvars_path = os.path.join("/etc", "apache2", "envvars") + export_envvars_cmd = "source " + envvars_path + + error_log_path = os.path.join(tmp_WebKit, "apache2-error.log") + + #Prepare the command to (re)start/stop the server with specified settings + apache2_restart_cmd = "apache2 -k " + run_cmd + directives = " -c \"ServerRoot " + android_tree_root + "\"" + directives += " -c \"DocumentRoot " + os.path.join("external", "webkit") + "\"" + + #This directive is commented out in apache2-debian-httpd.conf for some reason + #However, it is useful to browse through tests in the browser, so it's added here. + #One thing to note is that because of problems with mod_dir and port numbers, mod_dir + #is turned off. That means that there _must_ be a trailing slash at the end of URL + #for auto indexes to work correctly. + directives += " -c \"LoadModule autoindex_module /usr/lib/apache2/modules/mod_autoindex.so\"" + + directives += " -c \"ErrorLog " + error_log_path +"\"" + directives += " -c \"SSLCertificateFile " + os.path.join ("external", "webkit", "LayoutTests", + "http", "conf", "webkit-httpd.pem") + "\"" + directives += " -c \"User ${APACHE_RUN_USER}\"" + directives += " -c \"Group ${APACHE_RUN_GROUP}\"" + directives += " -C \"TypesConfig " + os.path.join("/etc", "mime.types") + "\"" + conf_file_cmd = " -f " + os.path.join(android_tree_root, "external", "webkit", "LayoutTests", + "http", "conf", "apache2-debian-httpd.conf") + + #Try to execute the commands + logging.info("Will " + run_cmd + " apache2 server.") + cmd = export_envvars_cmd + " && " + apache2_restart_cmd + directives + conf_file_cmd + p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (out, err) = p.communicate() + + #Output the stdout from the command to console + logging.info(out) + + #Report any errors + if p.returncode != 0: + logging.info("!! ERRORS:") + + if err.find(envvars_path) != -1: + logging.info(err) + elif err.find('command not found') != -1: + logging.info("apache2 is probably not installed") + else: + logging.info(err) + logging.info("Try looking in " + error_log_path + " for details") + else: + logging.info("OK") + +if __name__ == "__main__": + main(); |