tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_gecko_profile.py (1820B)


      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 gecko_profile import GeckoProfile
     21 
     22 
     23 @patch("logger.logger.RaptorLogger.info")
     24 @patch("logger.logger.RaptorLogger.critical")
     25 def test_browsertime_profiling(mock_log_info, mock_log_critical):
     26    result_dir = tempfile.mkdtemp()
     27    # untar geckoProfile.tar
     28    with tarfile.open(os.path.join(here, "geckoProfileTest.tar")) as f:
     29        f.extractall(path=result_dir)
     30 
     31    # Makes sure we can run the profile process against a browsertime-generated
     32    # profile (geckoProfile-1.json in this test dir)
     33    upload_dir = tempfile.mkdtemp()
     34    symbols_path = tempfile.mkdtemp()
     35    raptor_config = {
     36        "symbols_path": symbols_path,
     37        "browsertime": True,
     38        "browsertime_result_dir": os.path.join(result_dir, "amazon"),
     39    }
     40    test_config = {"name": "tp6"}
     41    try:
     42        profile = GeckoProfile(upload_dir, raptor_config, test_config)
     43        profile.symbolicate()
     44        profile.clean()
     45        arcname = os.environ["RAPTOR_LATEST_GECKO_PROFILE_ARCHIVE"]
     46        assert os.stat(arcname).st_size > 1000000, "We got a 1mb+ zip"
     47    except Exception:
     48        assert False, "Symbolication failed!"
     49        raise
     50    finally:
     51        shutil.rmtree(upload_dir)
     52        shutil.rmtree(symbols_path)
     53        shutil.rmtree(result_dir)
     54 
     55 
     56 if __name__ == "__main__":
     57    mozunit.main()