test_chrome_trace.py (2075B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import os 6 import shutil 7 import sys 8 import tarfile 9 import tempfile 10 from unittest.mock import patch 11 12 import mozunit 13 14 # need this so raptor imports work both from /raptor and via mach 15 here = os.path.abspath(os.path.dirname(__file__)) 16 17 raptor_dir = os.path.join(os.path.dirname(here), "raptor") 18 sys.path.insert(0, raptor_dir) 19 20 from chrome_trace import ChromeTrace 21 22 23 @patch("logger.logger.RaptorLogger.info") 24 @patch("logger.logger.RaptorLogger.critical") 25 def test_browsertime_trace_collection(mock_log_info, mock_log_critical): 26 """Test the ability to collect existing trace files into a zip archive 27 for viewing in the firefox profiler 28 """ 29 result_dir = tempfile.mkdtemp() 30 # untar chrome trace tar file, which contains a chimera run of wikipedia 31 with tarfile.open(os.path.join(here, "chromeTraceTest.tar")) as f: 32 f.extractall(path=result_dir) 33 34 # Makes sure we can run the profile process against a browsertime-generated 35 # trace (trace-1.json in this test dir) 36 upload_dir = tempfile.mkdtemp() 37 raptor_config = { 38 "browsertime": True, 39 "browsertime_result_dir": os.path.join(result_dir, "wikipedia"), 40 "extra_profiler_run": True, 41 "chimera": True, 42 } 43 test_config = {"name": "tp6", "type": "pageload"} 44 try: 45 profile = ChromeTrace(upload_dir, raptor_config, test_config) 46 assert len(profile.collect_profiles()) == 2, ( 47 "We have two profiles for a cold & warm run" 48 ) 49 profile.output_trace() 50 profile.clean() 51 arcname = os.environ["RAPTOR_LATEST_GECKO_PROFILE_ARCHIVE"] 52 assert os.stat(arcname).st_size > 900000, "We got a ~0.9mb+ zip" 53 except: 54 assert False, "Failed to collect Traces" 55 raise 56 finally: 57 shutil.rmtree(upload_dir) 58 shutil.rmtree(result_dir) 59 60 61 if __name__ == "__main__": 62 mozunit.main()