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