11# This Source Code Form is subject to the terms of the Mozilla Public
22# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33# You can obtain one at http://mozilla.org/MPL/2.0/.
4+ # pylint: disable=protected-access
45"""ffpuppet minidump parser tests"""
56
67from copy import deepcopy
@@ -91,7 +92,6 @@ def test_minidump_parser_01(mocker, tmp_path, symbols):
9192mocker .patch .object (MinidumpParser ,"MDSW_BIN" ,"minidump-stackwalk" )
9293with MinidumpParser (symbols = tmp_path if symbols else None )as parser :
9394assert parser
94- # pylint: disable=protected-access
9595cmd = parser ._cmd (tmp_path )
9696assert cmd
9797assert "minidump-stackwalk" in cmd
@@ -118,7 +118,6 @@ def test_minidump_parser_02(mocker, code, token, timeout):
118118"""test MinidumpParser.create_log()"""
119119mocker .patch .object (MinidumpParser ,"_cmd" ,return_value = [executable ,"-c" ,code ])
120120with MinidumpParser ()as parser :
121- # pylint: disable=protected-access
122121assert parser ._storage .is_dir ()
123122output = parser .create_log (Path ("foo.dmp" ),"minidump_00.txt" ,timeout = timeout )
124123assert output
@@ -154,8 +153,7 @@ def test_minidump_parser_02(mocker, code, token, timeout):
154153def test_minidump_parser_03 (tmp_path ,data ,reg ,operating_system ,cpu ,crash ,frame ):
155154"""test MinidumpParser._fmt_output() - un-symbolized"""
156155with (tmp_path / "out.txt" ).open ("w+b" )as ofp :
157- # pylint: disable=protected-access
158- MinidumpParser ._fmt_output (data ,ofp ,limit = 2 )
156+ MinidumpParser ._fmt_output (data ,ofp , {},limit = 2 )
159157ofp .seek (0 )
160158formatted = ofp .read ().rstrip ().decode ().split ("\n " )
161159assert len (formatted )== 5
@@ -206,19 +204,19 @@ def test_minidump_parser_04(tmp_path):
206204 }
207205
208206with (tmp_path / "out.txt" ).open ("w+b" )as ofp :
209- # pylint: disable=protected-access
210- MinidumpParser ._fmt_output (data ,ofp ,limit = 2 )
207+ MinidumpParser ._fmt_output (data ,ofp , {"metadata" :"foo" },limit = 2 )
211208ofp .seek (0 )
212209formatted = ofp .read ().rstrip ().decode ().split ("\n " )
213- assert len (formatted )== 8
210+ assert len (formatted )== 9
214211assert formatted [0 ]== "r10 = 0x12345678\t r11 = 0x0badf00d\t r12 = 0x00000000"
215212assert formatted [1 ]== "r13 = 0x000000dceebfc2e8"
216- assert formatted [2 ]== "OS|Windows NT|10.0.19044"
217- assert formatted [3 ]== "CPU|amd64|family 6 model 70 stepping 1|8"
218- assert formatted [4 ]== "Crash|EXCEPTION_BREAKPOINT|0x00007ffe4e09af8d|0"
219- assert formatted [5 ]== "0|0|xul.dll|function00()|file0.cpp|47|0x1ed"
220- assert formatted [6 ]== "0|1|xul.dll|function01()|file1.cpp|210|0x1bb"
221- assert formatted [7 ]== "WARNING: Hit stack size output limit!"
213+ assert formatted [2 ]== "metadata|foo"
214+ assert formatted [3 ]== "OS|Windows NT|10.0.19044"
215+ assert formatted [4 ]== "CPU|amd64|family 6 model 70 stepping 1|8"
216+ assert formatted [5 ]== "Crash|EXCEPTION_BREAKPOINT|0x00007ffe4e09af8d|0"
217+ assert formatted [6 ]== "0|0|xul.dll|function00()|file0.cpp|47|0x1ed"
218+ assert formatted [7 ]== "0|1|xul.dll|function01()|file1.cpp|210|0x1bb"
219+ assert formatted [8 ]== "WARNING: Hit stack size output limit!"
222220
223221
224222@mark .parametrize (
@@ -294,11 +292,23 @@ def test_minidump_parser_06(tmp_path):
294292def test_minidump_parser_missing_crashing_thread (tmp_path ):
295293"""test MinidumpParser._fmt_output() - missing crashing thread"""
296294with (tmp_path / "out.txt" ).open ("w+b" )as ofp :
297- # pylint: disable=protected-access
298- MinidumpParser ._fmt_output (MD_BASE_AMD64_WIN ,ofp )
295+ MinidumpParser ._fmt_output (MD_BASE_AMD64_WIN ,ofp , {})
299296ofp .seek (0 )
300297formatted = ofp .read ().rstrip ().decode ().split ("\n " )
301298assert len (formatted )== 3
302299assert formatted [0 ]== "OS|Windows NT|10.0.19044"
303300assert formatted [1 ]== "CPU|amd64|family 6 model 70 stepping 1|8"
304301assert formatted [2 ]== "Crash|EXCEPTION_BREAKPOINT|0x00007ffe4e09af8d|?"
302+
303+
304+ def test_minidump_parser_metadata (tmp_path ):
305+ """test MinidumpParser._metadata()"""
306+ # collect metadata from .extra file
307+ (tmp_path / "out.extra" ).write_text (dumps ({"a" :"1" ,"b" :"2" ,"c" :"3" }))
308+ result = MinidumpParser ._metadata (tmp_path / "out.dmp" , ("a" ,"c" ))
309+ assert "a" in result
310+ assert "b" not in result
311+ assert "c" in result
312+ # invalid .extra file
313+ (tmp_path / "out.extra" ).write_text ("!" )
314+ assert not MinidumpParser ._metadata (tmp_path / "out.dmp" , ("a" ,"c" ))