Bug 1251196 - [mozcrash] If no symbols path is specified let stackwalk download the symbols. r=ted, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Fri, 26 Feb 2016 23:34:56 +0100
changeset 338846 4361e9c2485e6a5e79e162e0194a78f1e263cfad
parent 338845 fb3494d06dfb73e26df72ca7a4bc4ef5ebf8795c
child 338847 45a841d2c188cb3dd958b0e0611d910ec1abffa8
push id12588
push userbmo:rail@mozilla.com
push dateThu, 10 Mar 2016 01:58:26 +0000
reviewersted, test-only
bugs1251196
milestone46.0
Bug 1251196 - [mozcrash] If no symbols path is specified let stackwalk download the symbols. r=ted, a=test-only 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():