Bug 1251196 - [mozcrash] If no symbols path is specified let stackwalk download the symbols. r?ted draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 26 Feb 2016 23:34:56 +0100
changeset 336870 7452343b12f7ccb8470e2034bc5624eeabeeca90
parent 335732 a3f70cbceb6c77d529e720d0aefa6c86b181c63b
child 336871 9458273db072b7dac3046b5820633f14ce36a97c
push id12202
push userbmo:hskupin@gmail.com
push dateFri, 04 Mar 2016 09:37:33 +0000
reviewersted
bugs1251196
milestone47.0a1
Bug 1251196 - [mozcrash] If no symbols path is specified let stackwalk download the symbols. r?ted MozReview-Commit-ID: 89bOoLwHMgK
testing/mozbase/mozcrash/mozcrash/mozcrash.py
testing/mozbase/mozcrash/tests/test.py
--- a/testing/mozbase/mozcrash/mozcrash/mozcrash.py
+++ b/testing/mozbase/mozcrash/mozcrash/mozcrash.py
@@ -39,17 +39,17 @@ StackInfo = namedtuple("StackInfo",
 def get_logger():
     structured_logger = mozlog.get_default_logger("mozcrash")
     if structured_logger is None:
         return mozlog.unstructured.getLogger('mozcrash')
     return structured_logger
 
 
 def check_for_crashes(dump_directory,
-                      symbols_path,
+                      symbols_path=None,
                       stackwalk_binary=None,
                       dump_save_path=None,
                       test_name=None,
                       quiet=False):
     """
     Print a stack trace for minidump files left behind by a crashing program.
 
     `dump_directory` will be searched for minidump files. Any minidump files found will
@@ -158,18 +158,24 @@ class CrashInfo(object):
         if stackwalk_binary is None:
             stackwalk_binary = os.environ.get('MINIDUMP_STACKWALK', None)
         self.stackwalk_binary = stackwalk_binary
 
         self.logger = get_logger()
         self._dump_files = None
 
     def _get_symbols(self):
-        # This updates self.symbols_path so we only download once
-        if self.symbols_path and mozfile.is_url(self.symbols_path):
+        # If no symbols path has been set create a temporary folder to let the
+        # minidump stackwalk download the symbols.
+        if not self.symbols_path:
+            self.symbols_path = tempfile.mkdtemp()
+            self.remove_symbols = True
+
+        # This updates self.symbols_path so we only download once.
+        if mozfile.is_url(self.symbols_path):
             self.remove_symbols = True
             self.logger.info("Downloading symbols from: %s" % self.symbols_path)
             # Get the symbols and write them to a temporary zipfile
             data = urllib2.urlopen(self.symbols_path)
             with tempfile.TemporaryFile() as symbols_file:
                 symbols_file.write(data.read())
                 # extract symbols to a temporary directory (which we'll delete after
                 # processing all crashes)
--- a/testing/mozbase/mozcrash/tests/test.py
+++ b/testing/mozbase/mozcrash/tests/test.py
@@ -51,70 +51,70 @@ class TestCrash(unittest.TestCase):
             yield iter(s)
 
     def test_nodumps(self):
         """
         Test that check_for_crashes returns False if no dumps are present.
         """
         self.stdouts.append(["this is some output"])
         self.assertFalse(mozcrash.check_for_crashes(self.tempdir,
-                                                    'symbols_path',
+                                                    symbols_path='symbols_path',
                                                     stackwalk_binary=self.stackwalk,
                                                     quiet=True))
 
     def test_simple(self):
         """
         Test that check_for_crashes returns True if a dump is present.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         self.stdouts.append(["this is some output"])
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                'symbols_path',
+                                                symbols_path='symbols_path',
                                                 stackwalk_binary=self.stackwalk,
                                                 quiet=True))
 
     def test_stackwalk_envvar(self):
         """
         Test that check_for_crashes uses the MINIDUMP_STACKWALK environment var.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         self.stdouts.append(["this is some output"])
         os.environ['MINIDUMP_STACKWALK'] = self.stackwalk
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                'symbols_path',
+                                                symbols_path='symbols_path',
                                                 quiet=True))
         del os.environ['MINIDUMP_STACKWALK']
 
     def test_save_path(self):
         """
         Test that dump_save_path works.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         open(os.path.join(self.tempdir, "test.extra"), "w").write("bar")
         save_path = os.path.join(self.tempdir, "saved")
         os.mkdir(save_path)
         self.stdouts.append(["this is some output"])
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                'symbols_path',
+                                                symbols_path='symbols_path',
                                                 stackwalk_binary=self.stackwalk,
                                                 dump_save_path=save_path,
                                                 quiet=True))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.extra")))
 
     def test_save_path_not_present(self):
         """
         Test that dump_save_path works when the directory doesn't exist.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         open(os.path.join(self.tempdir, "test.extra"), "w").write("bar")
         save_path = os.path.join(self.tempdir, "saved")
         self.stdouts.append(["this is some output"])
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                'symbols_path',
+                                                symbols_path='symbols_path',
                                                 stackwalk_binary=self.stackwalk,
                                                 dump_save_path=save_path,
                                                 quiet=True))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.extra")))
 
     def test_save_path_isfile(self):
         """
@@ -122,17 +122,17 @@ class TestCrash(unittest.TestCase):
         but a file with the same name exists.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         open(os.path.join(self.tempdir, "test.extra"), "w").write("bar")
         save_path = os.path.join(self.tempdir, "saved")
         open(save_path, "w").write("junk")
         self.stdouts.append(["this is some output"])
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                'symbols_path',
+                                                symbols_path='symbols_path',
                                                 stackwalk_binary=self.stackwalk,
                                                 dump_save_path=save_path,
                                                 quiet=True))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.extra")))
 
     def test_save_path_envvar(self):
         """
@@ -140,23 +140,31 @@ class TestCrash(unittest.TestCase):
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         open(os.path.join(self.tempdir, "test.extra"), "w").write("bar")
         save_path = os.path.join(self.tempdir, "saved")
         os.mkdir(save_path)
         self.stdouts.append(["this is some output"])
         os.environ['MINIDUMP_SAVE_PATH'] = save_path
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                'symbols_path',
+                                                symbols_path='symbols_path',
                                                 stackwalk_binary=self.stackwalk,
                                                 quiet=True))
         del os.environ['MINIDUMP_SAVE_PATH']
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.extra")))
 
+    def test_symbol_path_not_present(self):
+        open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
+        self.stdouts.append(["this is some output"])
+        self.assert_(mozcrash.check_for_crashes(self.tempdir,
+                                                symbols_path=None,
+                                                stackwalk_binary=self.stackwalk,
+                                                quiet=True))
+
     def test_symbol_path_url(self):
         """
         Test that passing a URL as symbols_path correctly fetches the URL.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         self.stdouts.append(["this is some output"])
 
         def make_zipfile():