diff --git a/bin/runtest.py b/bin/runtest.py new file mode 100644 index 0000000..22e8678 --- /dev/null +++ b/bin/runtest.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python + +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is Mozilla Eideticker. +# +# The Initial Developer of the Original Code is +# Mozilla foundation +# Portions created by the Initial Developer are Copyright (C) 2011 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# William Lachance +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +import atexit +import optparse +import os +import sys +import json +import signal +import subprocess + +BINDIR = os.path.dirname(__file__) +TALOS_DIR = os.path.join(BINDIR, "../src/talos/talos") +CONFIG_FILE = os.path.join(BINDIR, "../conf/talos.config") +MANIFEST_FILES = { + "tp4m": "page_load_test/tp4m.manifest", + "tsvg": "page_load_test/svg/svg.manifest" + } + +class FatalError(Exception): + def __init__(self, msg): + self.msg = msg + def __str__(self): + return repr(self.msg) + +class TalosRunner: + + def __init__(self, testname, manifest, pagename): + try: + self.config = json.loads(open(CONFIG_FILE).read()) + except: + raise FatalError("Could not read configuration file %s" % CONFIG_FILE) + + self.testname = testname + self.manifest = manifest + self.pagename = pagename + + def _kill_bcontrollers(self): + pids = subprocess.check_output("ps ax | grep bcontroller.py | grep -v grep | " + " cut -d ' ' -f 1", shell=True).split() + for pid in pids: + os.kill(int(pid), 9) + + def _write_manifest_file(self): + manifest_file = MANIFEST_FILES.get(self.manifest) + if not manifest_file: + raise FatalError("No file associated with manifest %s" % self.manifest) + + manifest_file = os.path.join(TALOS_DIR, manifest_file) + page = None + try: + for line in open(manifest_file).readlines(): + if self.pagename in line: + page = line.rstrip() + break + except: + raise FatalError("Unable to read from manifest file %s" % manifest_file) + + if not page: + raise FatalError("Page %s not found in manifest" % pagename) + + abridged_manifest_file = os.path.join(TALOS_DIR, "page_load_test/v.manifest") + try: + with open(abridged_manifest_file, "w") as f: + f.write(page+"\n") + except: + raise FatalError("Can't write abridged manifest file %s" % abridged_manifest_file) + + def run(self): + print "TESTNAME: %s" % self.testname + if self.testname == "tpageload": + print "WRITING manifest" + self._write_manifest_file() + + try: + os.chdir(TALOS_DIR) + subprocess.call("python remotePerfConfigurator.py -v -e %s " + "--activeTests %s --sampleConfig eideticker-base.config " + "--noChrome --videoCapture --develop " + "--remoteDevice=%s " + "--output eideticker-%s.config" % (self.config['appname'], + self.testname, + self.config['device_ip'], + self.testname), + shell=True) + + subprocess.call("python run_tests.py -d -n eideticker-%s.config" % self.testname, + shell=True) + finally: + self._kill_bcontrollers() + os.killpg(0, signal.SIGKILL) # kill all processes in my group + +def main(args=sys.argv[1:]): + usage = "usage: %prog [options] [subtest]" + parser = optparse.OptionParser(usage) + + options, args = parser.parse_args() + if len(args) < 1 or len(args) > 2: + parser.error("incorrect number of arguments") + + testnames = [ "tpageload", "tcolorcycle" ] # maybe eventually load this from a file + (testname, manifest, pagename) = (args[0], None, None) + if testname not in testnames: + parser.error("test '%s' not valid. valid tests are: %s" % ( + testname, " ".join(testnames))) + + if testname == "tpageload": + if len(args) < 2: + parser.error("must specify a subtest with a manifest and page " + "name (e.g. tp5m:m.news.google.com) for tpageload") + else: + (manifest, pagename) = args[1].split(":") + + os.setpgrp() # create new process group, become its leader + try: + runner = TalosRunner(testname, manifest, pagename) + runner.run() + except FatalError, err: + print >> sys.stderr, "ERROR: " + err.msg + sys.exit(1) + +main() diff --git a/bin/runtest.sh b/bin/runtest.sh deleted file mode 100755 index 017a731..0000000 --- a/bin/runtest.sh +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash - -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is Mozilla Eideticker. -# -# The Initial Developer of the Original Code is -# Mozilla foundation -# Portions created by the Initial Developer are Copyright (C) 2011 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# William Lachance -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -set -e - -kill_bcontrollers () { - BCONTROLLER_PIDS=`ps ax | grep bcontroller.py | grep -v grep | cut -d ' ' -f 1` - for PID in $BCONTROLLER_PIDS; do - echo "Killing zombie bcontroller process: $PID" - kill -9 $PID - done -} - -TEST=$1 -SITE=$2 -BINDIR=$(dirname $0) -CONF_FILE=$(dirname $0)/../conf/talos.config -TALOS_DIR=$(dirname $0)/../src/talos/talos - -if [ ! $TEST ]; then - echo "Must specify a valid test name!" - exit 1 -fi - -if [ $TEST == tpageload ]; then - fail_no_url () { - - OPTIONS="news.google.com m.news.google.com amazon.com m.amazon.com yahoo.co.jp m.yahoo.co.jp m.google.com m.accuweather.com m.mail.ru m.baidu.com m.news.baidu.com m.yandex.ru m.news.yandex.ru" - echo "Must specify a valid site with pageload test. E.g. tpageload m.amazon.com" - echo "Options: $OPTIONS" - exit 1 - } - - # FIXME FIXME: I just don't understand combining conditional expressions in bash at all - if [ ! $SITE ]; then - fail_no_url - fi - - URL=`grep "mobile_tp4/$SITE/" $TALOS_DIR/page_load_test/tp4m.manifest || true` - if [ ! $URL ]; then - fail_no_url - fi - - echo $URL > $TALOS_DIR/page_load_test/v.manifest -fi - -if [ ! -e $CONF_FILE ]; then - echo "Please generate a configuration file of defaults for talos by running setup.sh" - exit 1 -fi - -source $BINDIR/activate -source $CONF_FILE - -# Kill any current bcontroller processes and set up a trap on exit to do the -# same. Stop zombies! -kill_bcontrollers -trap kill_bcontrollers INT TERM EXIT - -# Running the configurator every time is annoying, but we need to do it as -# long as we're copying the remote manifest to the device during the -# configuration step -cd $TALOS_DIR -python remotePerfConfigurator.py -v -e $FENNEC_APP \ - --activeTests $TEST --sampleConfig eideticker-base.config --noChrome \ - --resultsServer ' ' --resultsLink ' ' \ - --videoCapture \ - --remoteDevice=$DEVICE_IP \ - --webServer $WEBSERVER_ADDRESS \ - --output eideticker-$TEST.config -python run_tests.py -d -n eideticker-$TEST.config diff --git a/bin/setup.sh b/bin/setup.py similarity index 74% rename from bin/setup.sh rename to bin/setup.py index cd06aa5..7b36f86 100755 --- a/bin/setup.sh +++ b/bin/setup.py @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env python # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -37,19 +37,22 @@ # # ***** END LICENSE BLOCK ***** -set -e +import optparse +import os +import sys +import json -CONF_FILE=$(dirname $0)/../conf/talos.config +CONFIG_FILE = os.path.join(os.path.dirname(__file__), "../conf/talos.config") -if [ $# -ne 3 ] -then - echo "Usage: `basename $0` " - echo - exit 1 -fi +usage = "usage: %prog [options] " +parser = optparse.OptionParser(usage) -cat > $CONF_FILE << EOF -DEVICE_IP=$1 -WEBSERVER_ADDRESS=$2 -FENNEC_APP=$3 -EOF +options, args = parser.parse_args() +if len(args) != 2: + parser.error("incorrect number of arguments") + +try: + open(CONFIG_FILE, "w").write(json.dumps({"device_ip": args[0], + "appname": args[1]})) +except: + fatal_error("Could not write configuration file %s" % CONFIG_FILE) diff --git a/src/pageloader b/src/pageloader index 124237d..7e5fd5b 160000 --- a/src/pageloader +++ b/src/pageloader @@ -1 +1 @@ -Subproject commit 124237d68b4cef5d8221bcc5da9655be7b3ede5f +Subproject commit 7e5fd5b3ec94e6443cc897acc4cc6f9a95fcd567 diff --git a/src/talos b/src/talos index b68d2e7..46feed8 160000 --- a/src/talos +++ b/src/talos @@ -1 +1 @@ -Subproject commit b68d2e78780e62d54a923d1dfdf20adeda59e995 +Subproject commit 46feed872dcc1b85c2b4b708c0a19376bbcf5419