def test_add_second_datazilla_result(self): """Adding a second DatazillaResult joins their results.""" req = DatazillaRequest('http', 'host', 'project', 'key', 'secret', branch='mozilla-try') res1 = DatazillaResult({'suite1': {'test': [1]}}) res2 = DatazillaResult({'suite2': {'test': [2]}}) req.add_datazilla_result(res1) req.add_datazilla_result(res2) self.assertEqual( req.results.results, { 'suite1': { 'test': [1] }, 'suite2': { 'test': [2] } }, )
def test_join_results(self): """Can merge a full results dictionary into this result.""" res = DatazillaResult({"suite1": {"test1a": [1]}}) res.join_results( DatazillaResult({ "suite1": { "test1a": [2], "test1b": [3] }, "suite2": { "test2a": [4] }, })) self.assertEqual( res.results, { "suite1": { "test1a": [1, 2], "test1b": [3] }, "suite2": { "test2a": [4] }, })
def test_add_xperf_results(self): """Can add xperf results to a suite""" res = DatazillaResult() res.add_xperf_results("suite", "name", [[1, 'hello'], [2, 'world'], 3]) self.assertEqual(res.results_xperf, {"suite": { "name": [[1, 'hello'], [2, 'world'], 3] }})
def __call__(self): # platform machine = self.test_machine() # build information browser_config = self.results.browser_config # a place to put results res = DatazillaResult() for test in self.results.results: suite = "%s" % test.name() res.add_testsuite(suite, options=self.run_options(test)) # serialize test results results = {} if not test.using_xperf: for result in test.results: # XXX this will not work for manifests which list # the same page name twice. It also ignores cycles for page, val in result.raw_values(): if page == 'NULL': results.setdefault(test.name(), []).extend(val) else: results.setdefault(page, []).extend(val) for result, values in results.items(): res.add_test_results(suite, result, values) # counters results_aux data for cd in test.all_counter_results: for name, vals in cd.items(): res.add_talos_auxiliary(suite, name, vals) else: # specific xperf_aux data for cd in test.all_counter_results: for name, vals in cd.items(): res.add_xperf_results(suite, name, vals) # make a datazilla test result collection collection = DatazillaResultsCollection( machine_name=machine['name'], os=machine['os'], os_version=machine['osversion'], platform=machine['platform'], build_name=browser_config['browser_name'], version=browser_config['browser_version'], revision=browser_config['sourcestamp'], branch=browser_config['branch_name'], id=browser_config['buildid'], test_date=self.results.date) collection.add_datazilla_result(res) return collection
def __call__(self): # platform machine = self.test_machine() # build information browser_config = self.results.browser_config # a place to put results res = DatazillaResult() for test in self.results.results: suite = "%s" % test.name() res.add_testsuite(suite, options=self.run_options(test)) # serialize test results results = {} if not test.using_xperf: for result in test.results: # XXX this will not work for manifests which list # the same page name twice. It also ignores cycles for page, val in result.raw_values(): if page == 'NULL': results.setdefault(test.name(), []).extend(val) else: results.setdefault(page, []).extend(val) for result, values in results.items(): res.add_test_results(suite, result, values) # counters results_aux data for cd in test.all_counter_results: for name, vals in cd.items(): res.add_talos_auxiliary(suite, name, vals) else: # specific xperf_aux data for cd in test.all_counter_results: for name, vals in cd.items(): res.add_xperf_results(suite, name, vals) # make a datazilla test result collection collection = DatazillaResultsCollection(machine_name=machine['name'], os=machine['os'], os_version=machine['osversion'], platform=machine['platform'], build_name=browser_config['browser_name'], version=browser_config['browser_version'], revision=browser_config['sourcestamp'], branch=browser_config['branch_name'], id=browser_config['buildid'], test_date=self.results.date) collection.add_datazilla_result(res) return collection
def test_join_results(self): """Can merge a full results dictionary into this result.""" res = DatazillaResult({"suite1": {"test1a": [1]}}) res.join_results(DatazillaResult( { "suite1": {"test1a": [2], "test1b": [3]}, "suite2": {"test2a": [4]}, } )) self.assertEqual( res.results, { "suite1": {"test1a": [1, 2], "test1b": [3]}, "suite2": {"test2a": [4]}, } )
def test_add_datazilla_result(self): """Can add a DatazillaResult to a DatazillaRequest.""" req = DatazillaRequest('http', 'host', 'project', 'key', 'secret', branch='mozilla-try') res = DatazillaResult({'suite': {'test': [1, 2, 3]}}) req.add_datazilla_result(res) self.assertEqual(req.results.results, res.results)
def test_datasets(self): """Tests dataset creation for submission to datazilla""" req = DatazillaRequest( protocol='http', host='host', project='project', oauth_key='key', oauth_secret='secret', machine_name='qm-pxp01', os='linux', os_version='Ubuntu 11.10', platform='x86_64', build_name='Firefox', version='14.0a2', revision='785345035a3b', branch='Mozilla-Aurora', id='20120228122102', ) results = {'suite1': {'test1': [1]}, 'suite2': {'test2': [2]}} req.add_datazilla_result(DatazillaResult(results)) datasets = req.datasets() self.assertEqual(len(datasets), 2) for dataset in datasets: self.assertEqual( set(dataset.keys()), set(['results', 'test_build', 'test_machine', 'testrun'])) self.assertEqual( dataset['test_build'], { 'branch': 'Mozilla-Aurora', 'id': '20120228122102', 'name': 'Firefox', 'revision': '785345035a3b', 'version': '14.0a2' }) self.assertEqual( dataset['test_machine'], { 'name': 'qm-pxp01', 'os': 'linux', 'osversion': 'Ubuntu 11.10', 'platform': 'x86_64' }) self.assertEqual(set(dataset['testrun'].keys()), set(['suite', 'date'])) suite = dataset['testrun']['suite'] self.assertTrue(suite in results) self.assertEqual(dataset['results'], results[suite])
def post_to_datazilla(self): """ take test_results (json) and upload them to datazilla """ # We will attach wpt_data to the datazilla result as a top # level attribute to store out of band data about the test. submit_results = False if self.job.datazilla == "on": # Do not short circuit the function but collect # additional data for use in emailing the user # before returning. submit_results = True with open('/home/mozauto/power_logger/report.csv', 'r') as fHandle: data = fHandle.readlines() header = True browsers = [] for line in data: if header: header = False continue parts = line.split(',') if parts[1] not in browsers: browsers.append(parts[1]) for browser in browsers: result = DatazillaResult() suite_name = "PowerGadget" machine_name = "perf-windows-003" os_name = "Win" browsername = browser if browsername == "Internet Explorer": browsrename = "IE" os_version = "7 - %s" % browsername platform = "x86" result.add_testsuite(suite_name) #TODO: JMAHER: hardcoded microperf here, this project should be in a config file and a real name request = DatazillaRequest("https", "datazilla.mozilla.org", "power", self.oauth_key, self.oauth_secret, machine_name=machine_name, os=os_name, os_version=os_version, platform=platform, build_name=self.build_name, version=self.build_version, revision=self.build_revision, branch=self.build_branch, id=self.build_id) header = True for line in data: if header: header = False continue parts = line.split(',') #Skip data from other browsers if parts[1] != browser: continue result.add_test_results(suite_name, parts[13], [str(parts[14])]) print "JMAHER: added data: %s: %s = %s, %s" % (os_version, suite_name, parts[13], [str(parts[14])]) request.add_datazilla_result(result) responses = request.submit() for resp in responses: print 'server response: %d %s %s' % (resp.status, resp.reason, resp.read())
def test_submit(self, mock_send): """Submits blob of JSON data for each test suite.""" req = DatazillaRequest( protocol='http', host='host', project='project', oauth_key='key', oauth_secret='secret', machine_name='qm-pxp01', os='linux', os_version='Ubuntu 11.10', platform='x86_64', build_name='Firefox', version='14.0a2', revision='785345035a3b', branch='Mozilla-Aurora', id='20120228122102', ) req.add_datazilla_result( DatazillaResult({ 'suite1': { 'test1': [1] }, 'suite2': { 'test2': [2] } })) req.submit() self.assertEqual(mock_send.call_count, 2) data1 = mock_send.call_args_list[0][0][0] data2 = mock_send.call_args_list[1][0][0] results = sorted([data1.pop('results'), data2.pop('results')]) self.assertEqual(results, sorted([{'test1': [1]}, {'test2': [2]}])) suites = sorted( [data1['testrun'].pop('suite'), data2['testrun'].pop('suite')]) self.assertEqual(suites, sorted(['suite1', 'suite2'])) # aside from results and suite, datasets are the same self.assertEqual(data1, data2) self.assertEqual( data1['test_build'], { 'branch': 'Mozilla-Aurora', 'id': '20120228122102', 'name': 'Firefox', 'revision': '785345035a3b', 'version': '14.0a2', }, ) self.assertEqual( data1['test_machine'], { 'name': 'qm-pxp01', 'os': 'linux', 'osversion': 'Ubuntu 11.10', 'platform': 'x86_64', }, ) self.assertEqual(data1['testrun']['date'], req.test_date)
def test_add_auxiliary_results(self): """Can add auxiliary results to a suite""" res = DatazillaResult() res.add_auxiliary_results("suite", "name", [1, 2, 3]) self.assertEqual(res.results_aux, {"suite": {"name": [1, 2, 3]}})
def test_init_noargs(self): """Can initialize with no argument and get empty initial results.""" res = DatazillaResult() self.assertEqual(res.results, {})
def test_add_testsuite(self): """Can add a test suite with tests and results.""" res = DatazillaResult() res.add_testsuite("suite", {"test1": [1, 2, 3]}) self.assertEqual(res.results, {"suite": {"test1": [1, 2, 3]}})
def test_add_test_results(self): """Can add results to a suite.""" res = DatazillaResult() res.add_test_results("suite", "test", [1, 2, 3]) self.assertEqual(res.results, {"suite": {"test": [1, 2, 3]}})
def post_to_datazilla(self, test_result): """ take test_results (json) and upload them to datazilla """ # We will attach wpt_data to the datazilla result as a top # level attribute to store out of band data about the test. wpt_data = { "url": "", "firstView": {}, "repeatView": {} } wpt_data["label"] = test_result["data"]["label"] submit_results = False if self.job.datazilla == "on": # Do not short circuit the function but collect # additional data for use in emailing the user # before returning. submit_results = True self.logger.debug('Submit results to datazilla: %s' % self.job.datazilla) wpt_data["connectivity"] = test_result["data"]["connectivity"] wpt_data["location"] = test_result["data"]["location"] wpt_data["url"] = test_result["data"]["url"] runs = test_result["data"]["runs"] # runs[0] is a dummy entry # runs[1]["firstView"]["SpeedIndex"] # runs[1]["repeatView"]["SpeedIndex"] # runs[1]["firstView"]["requests"][0]["headers"]["request"][2] # "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0 PTST/125" wpt_metric_keys = ['TTFB', 'render', 'docTime', 'fullyLoaded', 'SpeedIndex', 'SpeedIndexDT', 'bytesInDoc', 'requestsDoc', 'domContentLoadedEventStart', 'visualComplete'] for wpt_key in wpt_metric_keys: for view in "firstView", "repeatView": wpt_data[view][wpt_key] = [] if len(runs) == 1: raise Exception("post_to_datazilla: no runs") os_version = "unknown" os_name = "unknown" platform = "x86" reUserAgent = re.compile('User-Agent: Mozilla/5.0 \(Windows NT ([^;]*);.*') for run in runs: for wpt_key in wpt_metric_keys: for view in "firstView", "repeatView": if not run[view]: continue if wpt_key in run[view]: if run[view][wpt_key]: wpt_data[view][wpt_key].append(run[view][wpt_key]) if os_name == "unknown": try: requests = run[view]["requests"] if requests and len(requests) > 0: request = requests[0] if request: headers = request["headers"] if headers: request_headers = headers["request"] if request_headers: for request_header in request_headers: if "User-Agent" in request_header: match = re.match(reUserAgent, request_header) if match: os_name = "WINNT" os_version = match.group(1) break except KeyError: pass machine_name = wpt_data["location"].split(":")[0] # limit suite name to 128 characters to match mysql column size suite_name = (wpt_data["location"] + "." + wpt_data["connectivity"])[:128] # limit {first,repeat}_name, to 255 characters to match mysql column size # leave protocol in the url in order to distinguish http vs https. first_name = wpt_data["url"][:252] + ":fv" repeat_name = wpt_data["url"][:252] + ":rv" result = DatazillaResult() result.add_testsuite(suite_name) result.add_test_results(suite_name, first_name, wpt_data["firstView"]["SpeedIndex"]) result.add_test_results(suite_name, repeat_name, wpt_data["repeatView"]["SpeedIndex"]) request = DatazillaRequest("https", "datazilla.mozilla.org", "webpagetest", self.oauth_key, self.oauth_secret, machine_name=machine_name, os=os_name, os_version=os_version, platform=platform, build_name=self.build_name, version=self.build_version, revision=self.build_revision, branch=self.build_branch, id=self.build_id) request.add_datazilla_result(result) datasets = request.datasets() for dataset in datasets: dataset["wpt_data"] = wpt_data if not submit_results: continue response = request.send(dataset) # print error responses if response.status != 200: # use lower-case string because buildbot is sensitive to upper case error # as in 'INTERNAL SERVER ERROR' # https://bugzilla.mozilla.org/show_bug.cgi?id=799576 reason = response.reason.lower() self.logger.debug("Error posting to %s %s %s: %s %s" % ( wpt_data["url"], wpt_data["location"], wpt_data["connectivity"], response.status, reason)) else: res = response.read() self.logger.debug("Datazilla response for %s %s %s is: %s" % ( wpt_data["url"], wpt_data["location"], wpt_data["connectivity"], res.lower())) return datasets
def test_init_with_results(self): """Can initialize with a dictionary of results.""" data = {"suite": {"test": [1, 2, 3]}} res = DatazillaResult(data) self.assertEqual(res.results, data)
def test_add_talos_auxiliary(self): """Can add auxiliary results to a suite""" res = DatazillaResult() res.add_talos_auxiliary("suite", "name", [1, 2, 3]) self.assertEqual(res.talos_aux, {"suite": {"name": [1, 2, 3]}})
def test_add_xperf_results(self): """Can add xperf results to a suite""" res = DatazillaResult() res.add_xperf_results("suite", "name", [[1, 'hello'], [2, 'world'], 3]) self.assertEqual(res.results_xperf, {"suite": {"name": [[1, 'hello'], [2, 'world'], 3]}})
def post_to_datazilla(appinfo, configinfo): """ take test_results (json) and upload them to datazilla """ with open(os.path.join(configinfo['energia_dir'], 'report.csv'), 'r') as fHandle: data = fHandle.readlines() header = True browsers = [] for line in data: if header: header = False continue parts = line.split(',') if len(parts) != 18: continue if parts[15] not in browsers: browsers.append(parts[15]) tests = {'GT Watts': 4, 'IA Watts': 8, 'Processor Watts': 13} for browser in browsers: for test in tests: result = DatazillaResult() suite_name = "PowerGadget" machine_name = "tor-win8" os_name = "Win" browsername = browser if browsername == "Internet Explorer": browsername = "IE" os_version = "8-%s (%s)" % (browsername, test) platform = "x64" result.add_testsuite(suite_name) request = DatazillaRequest("https", "datazilla.mozilla.org", "power", configinfo['oauth_key'], configinfo['oauth_secret'], machine_name=machine_name, os=os_name, os_version=os_version, platform=platform, build_name=appinfo['build_name'], version=appinfo['build_version'], revision=appinfo['build_revision'], branch=appinfo['build_branch'], id=appinfo['build_id']) header = True for line in data: if header: header = False continue if len(parts) != 18: conitinue parts = line.split(',') #Skip data from other browsers if parts[15] != browser: continue result.add_test_results(suite_name, parts[16], [str(parts[tests[test]])]) request.add_datazilla_result(result) responses = request.submit() for resp in responses: print('server response: %d %s %s' % (resp.status, resp.reason, resp.read()))