X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fdebug.impure.lisp;h=a1d1e19d0c8539f4beff7c0e3816b550bd363262;hb=67dc5cf478dfe5e3f517001febb9a8f7b922eacf;hp=defd34696e24b7d40e3bd953ce6eaa0ebde76c2d;hpb=66187cb2c39eb11c33451c64d90a644961fd0b46;p=sbcl.git diff --git a/tests/debug.impure.lisp b/tests/debug.impure.lisp index defd346..a1d1e19 100644 --- a/tests/debug.impure.lisp +++ b/tests/debug.impure.lisp @@ -1,5 +1,5 @@ ;;;; This file is for testing debugging functionality, using -;;;; test machinery which might have side-effects (e.g. +;;;; test machinery which might have side effects (e.g. ;;;; executing DEFUN). ;;;; This software is part of the SBCL system. See the README file for @@ -23,7 +23,7 @@ (declare (type function fun)) ;; The Lisp-level type FUNCTION can conceal a multitude of sins.. (case (sb-kernel:widetag-of fun) - ((#.sb-vm:simple-fun-header-widetag #.sb-vm:closure-fun-header-widetag) + (#.sb-vm:simple-fun-header-widetag (sb-kernel:%simple-fun-arglist fun)) (#.sb-vm:closure-header-widetag (get-arglist (sb-kernel:%closure-fun fun))) @@ -57,3 +57,89 @@ (assert (symbolp control-sym)) (assert (eql &rest-sym '&rest)) (assert (symbolp format-args-sym))) + +;;; Check for backtraces generally being correct. Ensure that the +;;; actual backtrace finishes (doesn't signal any errors on its own), +;;; and that it contains the frames we expect, doesn't contain any +;;; "bogus stack frame"s, and contains the appropriate toplevel call +;;; and hasn't been cut off anywhere. +(defun verify-backtrace (test-function frame-name + &key (key #'first) (test #'eql) + (allow-bogus-frames nil)) + (let ((result nil) + (return-value nil)) + (block outer-handler + (handler-bind + ((error #'(lambda (condition) + (let ((backtrace (ignore-errors + (sb-debug:backtrace-as-list)))) + ;; Make sure we find what we're looking for. + (when (member frame-name backtrace + :key key :test test) + (setf result (list :error condition))) + ;; Make sure there's no bogus stack frames + ;; unless they're explicitly allowed. + (when (and (not allow-bogus-frames) + (member "bogus stack frame" backtrace + :key #'first :test #'equal)) + (setf result nil)) + ;; Make sure the backtrace isn't stunted in + ;; any way. (Depends on running in the main + ;; thread.) + (unless (member 'sb-impl::toplevel-init backtrace + :key #'first :test #'equal) + (setf result nil))) + (return-from outer-handler)))) + (funcall test-function))) + (values result return-value))) + +;;; Test for "undefined function" (undefined_tramp) working properly. +;;; Try it with and without tail call elimination, since they can have +;;; different effects. (Specifically, if undefined_tramp is incorrect +;;; a stunted stack can result from the tail call variant.) +#-(or alpha x86) ; bug 345 +(progn + (flet ((test-function () + (declare (optimize (speed 2) (debug 1))) ; tail call elimination + (#:undefined-function 42))) + (assert (verify-backtrace #'test-function "undefined function" + :test #'equal))) + + (flet ((test-function () + (declare (optimize (speed 1) (debug 2))) ; no tail call elimination + (#:undefined-function 42))) + (assert (verify-backtrace #'test-function "undefined function" + :test #'equal)))) + +;;; Division by zero was a common error on PPC. It depended on the +;;; return function either being before INTEGER-/-INTEGER in memory, +;;; or more than MOST-POSITIVE-FIXNUM bytes ahead. It also depends on +;;; INTEGER-/-INTEGER calling SIGNED-TRUNCATE. I believe Raymond Toy +;;; says that the Sparc backend (at least for CMUCL) inlines this, so +;;; if SBCL does the same this test is probably not good for the +;;; Sparc. +;;; +;;; Disabling tail call elimination on this will probably ensure that +;;; the return value (to the flet or the enclosing top level form) is +;;; more than MOST-POSITIVE-FIXNUM with the current spaces on OS X. +;;; Enabling it might catch other problems, so do it anyway. +#-alpha ; bug 346 +(progn + (flet ((test-function () + (declare (optimize (speed 2) (debug 1))) ; tail call elimination + (/ 42 0))) + (assert (verify-backtrace #'test-function '/))) + + (flet ((test-function () + (declare (optimize (speed 1) (debug 2))) ; no tail call elimination + (/ 42 0))) + (assert (verify-backtrace #'test-function '/)))) + +#-(or x86 alpha) ; bug 61 +(progn + (defun throw-test () + (throw 'no-such-tag t)) + (assert (verify-backtrace #'throw-test 'throw-test))) + +;;; success +(quit :unix-status 104)