conftest.py (3107B)
1 # coding=UTF-8 2 3 import uuid 4 5 import mozcrash 6 import pytest 7 8 9 @pytest.fixture(scope="session") 10 def stackwalk(tmpdir_factory): 11 stackwalk = tmpdir_factory.mktemp("stackwalk_binary").join("stackwalk") 12 stackwalk.write("fake binary") 13 stackwalk.chmod(0o744) 14 return stackwalk 15 16 17 @pytest.fixture 18 def check_for_crashes(tmpdir, stackwalk, monkeypatch): 19 monkeypatch.delenv("MINIDUMP_SAVE_PATH", raising=False) 20 21 def wrapper( 22 dump_directory=str(tmpdir), 23 symbols_path="symbols_path", 24 stackwalk_binary=str(stackwalk), 25 dump_save_path=None, 26 test_name=None, 27 quiet=True, 28 keep=None, 29 ): 30 return mozcrash.check_for_crashes( 31 dump_directory, 32 symbols_path, 33 stackwalk_binary, 34 dump_save_path, 35 test_name, 36 quiet, 37 keep, 38 ) 39 40 return wrapper 41 42 43 @pytest.fixture 44 def check_for_java_exception(): 45 def wrapper(logcat=None, test_name=None, quiet=True): 46 return mozcrash.check_for_java_exception(logcat, test_name, quiet) 47 48 return wrapper 49 50 51 def minidump_files(request, tmpdir): 52 files = [] 53 54 for i in range(getattr(request, "param", 1)): 55 name = uuid.uuid4() 56 57 dmp = tmpdir.join(f"{name}.dmp") 58 dmp.write("foo") 59 60 extra = tmpdir.join(f"{name}.extra") 61 62 extra.write_text( 63 """ 64 { 65 "ContentSandboxLevel":"2", 66 "TelemetryEnvironment":"{🍪}", 67 "EMCheckCompatibility":"true", 68 "ProductName":"Firefox", 69 "ContentSandboxCapabilities":"119", 70 "TelemetryClientId":"", 71 "Vendor":"Mozilla", 72 "InstallTime":"1000000000", 73 "Theme":"classic/1.0", 74 "ReleaseChannel":"default", 75 "ServerURL":"https://crash-reports.mozilla.com", 76 "SafeMode":"0", 77 "ContentSandboxCapable":"1", 78 "useragent_locale":"en-US", 79 "Version":"55.0a1", 80 "BuildID":"20170512114708", 81 "ProductID":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", 82 "MozCrashReason": "MOZ_CRASH()", 83 "TelemetryServerURL":"", 84 "DOMIPCEnabled":"1", 85 "Add-ons":"", 86 "CrashTime":"1494582646", 87 "UptimeTS":"14.9179586", 88 "ContentSandboxEnabled":"1", 89 "ProcessType":"content", 90 "StartupTime":"1000000000", 91 "URL":"about:home" 92 } 93 94 """, 95 encoding="utf-8", 96 ) 97 98 files.append({"dmp": dmp, "extra": extra}) 99 100 return files 101 102 103 @pytest.fixture(name="minidump_files") 104 def minidump_files_fixture(request, tmpdir): 105 return minidump_files(request, tmpdir) 106 107 108 @pytest.fixture(autouse=True) 109 def mock_popen(monkeypatch): 110 """Generate a class that can mock subprocess.Popen. 111 112 :param stdouts: Iterable that should return an iterable for the 113 stdout of each process in turn. 114 """ 115 116 class MockPopen: 117 def __init__(self, args, *args_rest, **kwargs): 118 # all_popens.append(self) 119 self.args = args 120 self.returncode = 0 121 122 def communicate(self): 123 return ("Stackwalk command: {}".format(" ".join(self.args)), "") 124 125 def wait(self): 126 return self.returncode 127 128 monkeypatch.setattr(mozcrash.mozcrash.subprocess, "Popen", MockPopen)