Bug 1344813 - prepare awsy for mach command, r=jmaher,pyang.

* parse_about_memory.py
  - remove extraneous data variable.
* test_memory_usage.py
  - get webRootDir, resultsDir from testvars to support mach command.
  - standardize directories.
  - catch exceptions thrown by marionette when closing tabs.
* awsy_script.py
  - change to use webRootDir, resultsDir and to pass to test_memory_usage.py
    in additional testvars.json file.
  - standardize directories.
  - set strict=False in StructuredOutputParser in order to prevent ascii
    encoding errors due to marionette loading csdn.net and outputing non-ascii
    to stdout.
This commit is contained in:
Bob Clary 2017-03-29 01:47:45 -07:00
Родитель 1feb18fd09
Коммит 286293c16e
3 изменённых файлов: 52 добавлений и 27 удалений

Просмотреть файл

@ -52,8 +52,6 @@ def calculate_memory_report_values(memory_report_path, data_point_path,
report, ie: 'explicit/heap-unclassified'.
:param process_name: Name of process to limit reports to. ie 'Main'
"""
data = None
try:
with open(memory_report_path) as f:
data = json.load(f)

Просмотреть файл

@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import glob
import json
import os
import sys
@ -14,6 +15,10 @@ from marionette_driver.errors import JavascriptException, ScriptTimeoutException
import mozlog.structured
from marionette_driver.keys import Keys
AWSY_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if AWSY_PATH not in sys.path:
sys.path.append(AWSY_PATH)
from awsy import TEST_SITES_TEMPLATES, ITERATIONS, PER_TAB_PAUSE, SETTLE_WAIT_TIME, MAX_TABS
from awsy import process_perf_data, webservers
@ -37,36 +42,38 @@ class TestMemoryUsage(MarionetteTestCase):
self.marionette.set_context('chrome')
self._webroot_dir = os.path.join(os.getcwd(), 'page_load_test')
if not os.path.exists(self._webroot_dir):
os.mkdir(self._webroot_dir)
self._webroot_dir = self.testvars["webRootDir"]
self._resultsDir = self.testvars["resultsDir"]
for f in glob.glob(os.path.join(self._resultsDir, '*')):
os.unlink(f)
self._webservers = webservers.WebServers("localhost",
8001,
os.getcwd(),
self._webroot_dir,
100)
self._webservers.start()
test_sites = []
self._urls = []
with open(os.path.join(self._webroot_dir, 'tp5n', 'tp5n.manifest')) as fp:
urls = None
tp5n_manifest = os.path.join(self._webroot_dir, 'page_load_test', 'tp5n',
'tp5n.manifest')
with open(tp5n_manifest) as fp:
urls = fp.readlines()
if urls:
urls = map(lambda x:x.replace('localhost', 'localhost:{}'), urls)
self._urls = urls
else:
urls = TEST_SITES_TEMPLATES
for url, server in zip(urls, self._webservers.servers):
test_sites.append(url.format(server.port))
self._urls.append(url.strip().format(server.port))
self._urls = self.testvars.get("urls", test_sites)
# Optional testvars.
self._pages_to_load = self.testvars.get("entities", len(self._urls))
self._iterations = self.testvars.get("iterations", ITERATIONS)
self._perTabPause = self.testvars.get("perTabPause", PER_TAB_PAUSE)
self._settleWaitTime = self.testvars.get("settleWaitTime", SETTLE_WAIT_TIME)
self._maxTabs = self.testvars.get("maxTabs", MAX_TABS)
self._resultsDir = os.path.join(os.getcwd(), "tests", "results")
self.logger.info("areweslimyet run by %d pages, %d iterations, %d perTabPause,%d settleWaitTime"
self.logger.info("areweslimyet run by %d pages, %d iterations, %d perTabPause, %d settleWaitTime"
% (self._pages_to_load, self._iterations, self._perTabPause, self._settleWaitTime))
self.reset_state()
self.logger.info("done setting up!")
@ -100,7 +107,17 @@ class TestMemoryUsage(MarionetteTestCase):
# Close all tabs except one
for x in range(len(self.marionette.window_handles) - 1):
self.logger.info("closing window")
self.marionette.execute_script("gBrowser.removeCurrentTab();")
try:
result = self.marionette.execute_script("gBrowser.removeCurrentTab();",
script_timeout=180000)
except JavascriptException, e:
self.logger.error("gBrowser.removeCurrentTab() JavaScript error: %s" % e)
except ScriptTimeoutException:
self.logger.error("gBrowser.removeCurrentTab() timed out")
except:
self.logger.error("gBrowser.removeCurrentTab() Unexpected error: %s" % sys.exc_info()[0])
else:
self.logger.info(result)
time.sleep(0.25)
self._tabs = self.marionette.window_handles

Просмотреть файл

@ -8,6 +8,7 @@
run awsy tests in a virtualenv
"""
import json
import os
import sys
import copy
@ -56,13 +57,12 @@ class AWSY(TestingMixin, MercurialScript, BlobUploadMixin,TooltoolMixin):
self.installer_url = self.config.get("installer_url")
self.tests = None
self.workdir = self.query_abs_dirs()['abs_work_dir']
self.testdir = os.path.join(self.workdir, 'tests')
self.awsy_path = os.path.join(
self.testdir, 'awsy'
)
abs_work_dir = self.query_abs_dirs()['abs_work_dir']
self.testdir = os.path.join(abs_work_dir, 'tests')
self.awsy_path = os.path.join(self.testdir, 'awsy')
self.awsy_libdir = os.path.join(self.awsy_path, 'awsy')
self.awsy_testdir = os.path.join(self.awsy_path, 'page_load_test')
self.webroot_dir = os.path.join(self.awsy_path, 'html')
self.results_dir = os.path.join(self.awsy_path, 'results')
self.binary_path = self.config.get('binary_path')
def query_abs_dirs(self):
@ -99,18 +99,19 @@ class AWSY(TestingMixin, MercurialScript, BlobUploadMixin,TooltoolMixin):
"""Populate the production test slaves' webroots"""
self.info("Downloading pageset with tooltool...")
manifest_file = os.path.join(self.awsy_path, 'tp5n-pageset.manifest')
if not os.path.isdir(self.awsy_testdir):
self.mkdir_p(self.awsy_testdir)
page_load_test_dir = os.path.join(self.webroot_dir, 'page_load_test')
if not os.path.isdir(page_load_test_dir):
self.mkdir_p(page_load_test_dir)
self.tooltool_fetch(
manifest_file,
output_dir=self.awsy_testdir,
output_dir=page_load_test_dir,
cache=self.config.get('tooltool_cache')
)
archive = os.path.join(self.awsy_testdir, 'tp5n.zip')
archive = os.path.join(page_load_test_dir, 'tp5n.zip')
unzip = self.query_exe('unzip')
unzip_cmd = [unzip, '-q', '-o', archive, '-d', self.awsy_testdir]
unzip_cmd = [unzip, '-q', '-o', archive, '-d', page_load_test_dir]
self.run_command(unzip_cmd, halt_on_failure=True)
self.run_command("ls %s" % self.awsy_testdir)
self.run_command("ls %s" % page_load_test_dir)
def run_tests(self, args=None, **kw):
@ -122,9 +123,17 @@ class AWSY(TestingMixin, MercurialScript, BlobUploadMixin,TooltoolMixin):
error_summary_file = os.path.join(dirs['abs_blob_upload_dir'],
'marionette_errorsummary.log')
runtime_testvars = {'webRootDir': self.webroot_dir,
'resultsDir': self.results_dir}
runtime_testvars_path = os.path.join(self.awsy_path, 'runtime-testvars.json')
runtime_testvars_file = open(runtime_testvars_path, 'wb')
runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
runtime_testvars_file.close()
cmd = ['marionette']
cmd.append("--preferences=%s" % os.path.join(self.awsy_path, "conf", "prefs.json"))
cmd.append("--testvars=%s" % os.path.join(self.awsy_path, "conf", "testvars.json"))
cmd.append("--testvars=%s" % runtime_testvars_path)
cmd.append("--log-raw=-")
cmd.append("--log-errorsummary=%s" % error_summary_file)
cmd.append("--binary=%s" % self.binary_path)
@ -142,7 +151,8 @@ class AWSY(TestingMixin, MercurialScript, BlobUploadMixin,TooltoolMixin):
self.mkdir_p(env['MOZ_UPLOAD_DIR'])
env = self.query_env(partial_env=env)
parser = StructuredOutputParser(config=self.config,
log_obj=self.log_obj)
log_obj=self.log_obj,
strict=False)
return_code = self.run_command(command=cmd,
cwd=self.awsy_path,
output_timeout=self.config.get("cmd_timeout"),