Bug 487494 - Add an xpcshell selftest for readable stacks from assertions.;r=ted
authorChris Manchester <cmanchester@mozilla.com>
Thu, 11 Jun 2015 11:21:12 -0700
changeset 267922 182ac56399c47c0b5df657596db53064b107594d
parent 267921 8376812621b2732e6014d7a90929ff81cb341eff
child 267923 98e985a2d950eef472bc67a7555237f43f326d66
push id8157
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:36:23 +0000
treeherdermozilla-aurora@d480e05bd276 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs487494
milestone41.0a1
Bug 487494 - Add an xpcshell selftest for readable stacks from assertions.;r=ted
testing/xpcshell/selftest.py
--- a/testing/xpcshell/selftest.py
+++ b/testing/xpcshell/selftest.py
@@ -1,16 +1,16 @@
 #!/usr/bin/env python
 #
 # Any copyright is dedicated to the Public Domain.
 # http://creativecommons.org/publicdomain/zero/1.0/
 #
 
 from __future__ import with_statement
-import sys, os, unittest, tempfile, shutil
+import sys, os, unittest, tempfile, shutil, re, pprint
 import mozinfo
 
 from StringIO import StringIO
 
 from mozlog import structured
 from mozbuild.base import MozbuildObject
 os.environ.pop('MOZ_OBJDIR', None)
 build_obj = MozbuildObject.from_environment()
@@ -461,16 +461,44 @@ tail =
         self.assertTestResult(False)
         self.assertEquals(1, self.x.testCount)
         self.assertEquals(0, self.x.passCount)
         self.assertEquals(1, self.x.failCount)
         self.assertEquals(0, self.x.todoCount)
         self.assertInLog(TEST_FAIL_STRING)
         self.assertNotInLog(TEST_PASS_STRING)
 
+    @unittest.skipIf(mozinfo.isWin or not mozinfo.info.get('debug'),
+                     'We don\'t have a stack fixer on hand for windows.')
+    def testAssertStack(self):
+        """
+        When an assertion is hit, we should produce a useful stack.
+        """
+        self.writeFile("test_assert.js", '''
+          add_test(function test_asserts_immediately() {
+            Components.classes["@mozilla.org/xpcom/debug;1"]
+                      .getService(Components.interfaces.nsIDebug2)
+                      .assertion("foo", "assertion failed", "test.js", 1)
+            run_next_test();
+          });
+        ''')
+
+        self.writeManifest(["test_assert.js"])
+
+        self.assertTestResult(False)
+
+        self.assertInLog("###!!! ASSERTION")
+        log_lines = self.log.getvalue().splitlines()
+        line_pat = "#\d\d:"
+        unknown_pat = "#\d\d\: \?\?\?\[.* \+0x[a-f0-9]+\]"
+        self.assertFalse(any(re.search(unknown_pat, line) for line in log_lines),
+                         "An stack frame without symbols was found in\n%s" % pprint.pformat(log_lines))
+        self.assertTrue(any(re.search(line_pat, line) for line in log_lines),
+                        "No line resembling a stack frame was found in\n%s" % pprint.pformat(log_lines))
+
     @unittest.skipIf(build_obj.defines.get('MOZ_B2G'),
                      'selftests with child processes fail on b2g desktop builds')
     def testChildPass(self):
         """
         Check that a simple test running in a child process passes.
         """
         self.writeFile("test_pass.js", SIMPLE_PASSING_TEST)
         self.writeFile("test_child_pass.js", CHILD_TEST_PASSING)