X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-introspect%2Ftest-driver.lisp;h=322ca918dcf37dee127a0988b23bbd8814c9599a;hb=d351f80b1076dd54e5aee3dacab82d59c2e58060;hp=c38d9f576a8dc62a22f700de68a2e9e6c7c1f24e;hpb=6700a33813a2cd586accbf2bb2b9ae86c9c3934a;p=sbcl.git diff --git a/contrib/sb-introspect/test-driver.lisp b/contrib/sb-introspect/test-driver.lisp index c38d9f5..322ca91 100644 --- a/contrib/sb-introspect/test-driver.lisp +++ b/contrib/sb-introspect/test-driver.lisp @@ -1,30 +1,47 @@ -(require :sb-introspect) +;;;; This software is part of the SBCL system. See the README file for +;;;; more information. +;;;; +;;;; This software is derived from the CMU CL system, which was +;;;; written at Carnegie Mellon University and released into the +;;;; public domain. The software is in the public domain and is +;;;; provided with absolutely no warranty. See the COPYING and CREDITS +;;;; files for more information. (defpackage :sb-introspect-test - (:use "SB-INTROSPECT" "CL")) -(in-package :sb-introspect-test) - -(with-compilation-unit (:source-plist (list :test-outer "OUT")) - (load (compile-file (merge-pathnames "test.lisp" *load-pathname*)))) - -(assert (equal (function-lambda-list 'cl-user::one) - '(cl-user::a cl-user::b cl-user::c))) -(assert (equal (function-lambda-list 'the) - '(sb-c::value-type sb-c::form))) + (:use "SB-INTROSPECT" "CL" "SB-RT")) -(assert (equal (function-lambda-list #'(sb-pcl::slow-method cl-user::j (t))) - '(sb-pcl::method-args sb-pcl::next-methods))) - -(let ((source (find-definition-source #'cl-user::one))) - (assert (= (definition-source-file-write-date source) - (file-write-date (merge-pathnames "test.lisp" *load-pathname*)))) - (assert (equal (getf (definition-source-plist source) :test-outer) - "OUT"))) +(in-package :sb-introspect-test) -(let ((plist (definition-source-plist - (find-definition-source #'cl-user::four)))) - (assert (equal (getf plist :test-outer) "OUT")) - (assert (equal (getf plist :test-inner) "IN"))) +(deftest function-lambda-list.1 + (function-lambda-list 'cl-user::one) + (cl-user::a cl-user::b cl-user::c)) + +(deftest function-lambda-list.2 + (function-lambda-list 'the) + (sb-c::value-type sb-c::form)) + +(deftest function-lambda-list.3 + (function-lambda-list #'(sb-pcl::slow-method cl-user::j (t))) + (sb-pcl::method-args sb-pcl::next-methods)) + +(deftest definition-source-plist.1 + (let* ((source (find-definition-source #'cl-user::one)) + (plist (definition-source-plist source))) + (values (= (definition-source-file-write-date source) + (file-write-date "test.lisp")) + (or (equal (getf plist :test-outer) + "OUT") + plist))) + t t) + +(deftest definition-source-plist.2 + (let ((plist (definition-source-plist + (find-definition-source #'cl-user::four)))) + (values (or (equal (getf plist :test-outer) "OUT") + plist) + (or (equal (getf plist :test-inner) "IN") + plist))) + t t) (defun matchp (object form-number) (let ((ds (sb-introspect:find-definition-source object))) @@ -42,50 +59,136 @@ (let ((ds (sb-introspect:find-definition-sources-by-name object type))) (= (length ds) form-numbers))) -(assert (matchp-name :function 'cl-user::one 2)) -(assert (matchp #'cl-user::one 2)) -(assert (matchp-name :generic-function 'cl-user::two 3)) -(assert (matchp (car (sb-pcl:generic-function-methods #'cl-user::two)) 4)) - -(assert (matchp-name :variable 'cl-user::*a* 8)) -(assert (matchp-name :variable 'cl-user::*b* 9)) -(assert (matchp-name :class 'cl-user::a 10)) -(assert (matchp-name :condition 'cl-user::b 11)) -(assert (matchp-name :structure 'cl-user::c 12)) -(assert (matchp-name :function 'cl-user::make-c 12)) -(assert (matchp-name :function 'cl-user::c-e 12)) -(assert (matchp-name :structure 'cl-user::d 13)) -(assert (matchp-name :function 'cl-user::make-d 13)) -(assert (matchp-name :function 'cl-user::d-e 13)) -(assert (matchp-name :package 'cl-user::e 14)) -(assert (matchp-name :symbol-macro 'cl-user::f 15)) -(assert (matchp-name :type 'cl-user::g 16)) -(assert (matchp-name :constant 'cl-user::+h+ 17)) -(assert (matchp-length :method 'cl-user::j 2)) -(assert (matchp-name :macro 'cl-user::l 20)) -(assert (matchp-name :compiler-macro 'cl-user::m 21)) -(assert (matchp-name :setf-expander 'cl-user::n 22)) -(assert (matchp-name :function '(setf cl-user::o) 23)) -(assert (matchp-name :method '(setf cl-user::p) 24)) -(assert (matchp-name :macro 'cl-user::q 25)) -(assert (matchp-name :method-combination 'cl-user::r 26)) -(assert (matchp-name :setf-expander 'cl-user::s 27)) - -(let ((fin (make-instance 'sb-mop:funcallable-standard-object))) - (sb-mop:set-funcallable-instance-function fin #'cl-user::one) - (assert (matchp fin 2))) - -(sb-profile:profile cl-user::one) -(assert (matchp-name :function 'cl-user::one 2)) -(sb-profile:unprofile cl-user::one) - - -;;;; Check correctness of FUNCTION-LAMBDA-LIST. - -(assert (equal (function-lambda-list 'cl-user::one) - '(cl-user::a cl-user::b cl-user::c))) -(assert (equal (function-lambda-list 'the) - '(sb-c::value-type sb-c::form))) +(deftest find-source-stuff.1 + (matchp-name :function 'cl-user::one 2) + t) + +(deftest find-source-stuff.2 + (matchp #'cl-user::one 2) + t) + +(deftest find-source-stuff.3 + (matchp-name :generic-function 'cl-user::two 3) + t) + +(deftest find-source-stuff.4 + (matchp (car (sb-pcl:generic-function-methods #'cl-user::two)) 4) + t) + +(deftest find-source-stuff.5 + (matchp-name :variable 'cl-user::*a* 8) + t) + +(deftest find-source-stuff.6 + (matchp-name :variable 'cl-user::*b* 9) + t) + +(deftest find-source-stuff.7 + (matchp-name :class 'cl-user::a 10) + t) + +(deftest find-source-stuff.8 + (matchp-name :condition 'cl-user::b 11) + t) + +(deftest find-source-stuff.9 + (matchp-name :structure 'cl-user::c 12) + t) + +(deftest find-source-stuff.10 + (matchp-name :function 'cl-user::make-c 12) + t) + +(deftest find-source-stuff.11 + (matchp-name :function 'cl-user::c-e 12) + t) + +(deftest find-source-stuff.12 + (matchp-name :structure 'cl-user::d 13) + t) + +(deftest find-source-stuff.13 + (matchp-name :function 'cl-user::make-d 13) + t) + +(deftest find-source-stuff.14 + (matchp-name :function 'cl-user::d-e 13) + t) + +(deftest find-source-stuff.15 + (matchp-name :package 'cl-user::e 14) + t) + +(deftest find-source-stuff.16 + (matchp-name :symbol-macro 'cl-user::f 15) + t) + +(deftest find-source-stuff.17 + (matchp-name :type 'cl-user::g 16) + t) + +(deftest find-source-stuff.18 + (matchp-name :constant 'cl-user::+h+ 17) + t) + +(deftest find-source-stuff.19 + (matchp-length :method 'cl-user::j 2) + t) + +(deftest find-source-stuff.20 + (matchp-name :macro 'cl-user::l 20) + t) + +(deftest find-source-stuff.21 + (matchp-name :compiler-macro 'cl-user::m 21) + t) + +(deftest find-source-stuff.22 + (matchp-name :setf-expander 'cl-user::n 22) + t) + +(deftest find-source-stuff.23 + (matchp-name :function '(setf cl-user::o) 23) + t) + + +(deftest find-source-stuff.24 + (matchp-name :method '(setf cl-user::p) 24) + t) + + +(deftest find-source-stuff.25 + (matchp-name :macro 'cl-user::q 25) + t) + + +(deftest find-source-stuff.26 + (matchp-name :method-combination 'cl-user::r 26) + t) + + +(deftest find-source-stuff.27 + (matchp-name :setf-expander 'cl-user::s 27) + t) + +(deftest find-source-stuff.28 + (let ((fin (make-instance 'sb-mop:funcallable-standard-object))) + (sb-mop:set-funcallable-instance-function fin #'cl-user::one) + (matchp fin 2)) + t) + +(deftest find-source-stuff.29 + (unwind-protect + (progn + (sb-profile:profile cl-user::one) + (matchp-name :function 'cl-user::one 2)) + (sb-profile:unprofile cl-user::one)) + t) + +(deftest find-source-stuff.30 + ;; Test finding a type that isn't one + (not (find-definition-sources-by-name 'fboundp :type)) + t) ;;; Check wrt. interplay of generic functions and their methods. @@ -101,30 +204,32 @@ ;; ;; (GF.A GF.B &REST GF.REST &KEY GF.K-X M1.K-Z M1.K-Y M2.K-Q) ;; -(multiple-value-bind (required optional restp rest keyp keys allowp - auxp aux morep more-context more-count) - (sb-int:parse-lambda-list (function-lambda-list #'xuuq)) - (assert (equal required '(gf.a gf.b))) - (assert (null optional)) - (assert (and restp (eql rest 'gf.rest))) - (assert (and keyp - (member 'gf.k-X keys) - (member 'm1.k-Y keys) - (member 'm1.k-Z keys) - (member 'm2.k-Q keys))) - (assert (not allowp)) - (assert (and (not auxp) (null aux))) - (assert (and (not morep) (null more-context) (not more-count)))) +(deftest gf-interplay.1 + (multiple-value-bind (required optional restp rest keyp keys allowp + auxp aux morep more-context more-count) + (sb-int:parse-lambda-list (function-lambda-list #'xuuq)) + (and (equal required '(gf.a gf.b)) + (null optional) + (and restp (eql rest 'gf.rest)) + (and keyp + (member 'gf.k-X keys) + (member 'm1.k-Y keys) + (member 'm1.k-Z keys) + (member 'm2.k-Q keys)) + (not allowp) + (and (not auxp) (null aux)) + (and (not morep) (null more-context) (not more-count)))) + t) ;;; Check what happens when there's no explicit DEFGENERIC. (defmethod kroolz (r1 r2 &optional opt &aux aux) (declare (ignore r1 r2 opt aux)) 'kroolz) -(assert (equal (function-lambda-list #'kroolz) '(r1 r2 &optional opt))) -;;;; Test finding a type that isn't one -(assert (not (find-definition-sources-by-name 'fboundp :type))) +(deftest gf-interplay.2 + (equal (function-lambda-list #'kroolz) '(r1 r2 &optional opt)) + t) ;;;; Check correctness of DEFTYPE-LAMBDA-LIST. (deftype foobar-type @@ -132,18 +237,17 @@ (declare (ignore w e r1 r2 o rest k1 k2 k3)) nil) -(assert (multiple-value-bind (arglist found?) (deftype-lambda-list 'foobar-type) +(deftest deftype-lambda-list.1 + (multiple-value-bind (arglist found?) (deftype-lambda-list 'foobar-type) (and found? (equal arglist '(&whole w &environment e - r1 r2 &optional o &rest rest &key k1 k2 k3))))) - -(assert (equal (multiple-value-list (deftype-lambda-list (gensym))) - '(nil nil))) + r1 r2 &optional o &rest rest &key k1 k2 k3)))) + t) - -;;;; Test the xref facility - -(load (merge-pathnames "xref-test.lisp" *load-pathname*)) +(deftest deftype-lambda-list.2 + (equal (multiple-value-list (deftype-lambda-list (gensym))) + '(nil nil)) + t) ;;; Test allocation-information @@ -151,60 +255,78 @@ (multiple-value-bind (kind2 info2) (sb-introspect:allocation-information x) (unless (eq kind kind2) (error "wanted ~S, got ~S" kind kind2)) - (assert (equal info info2)))) - -(tai nil :heap '(:space :static)) -(tai t :heap '(:space :static)) -(tai 42 :immediate nil) -(tai #'cons :heap - #+(and (not ppc) gencgc) - ;; FIXME: This is the canonical GENCGC result, the one below for PPC is - ;; what we get there, but :LARGE T doesn't seem right. Figure out what's - ;; going on. - '(:space :dynamic :generation 6 :write-protected t :pinned nil :large nil) - #+(and ppc gencgc) - '(:space :dynamic :generation 6 :write-protected t :pinned nil :large t) - ;; FIXME: Figure out what's the right cheney-result, and which platforms - ;; return something else. The SPARC version here is what we get there, - ;; but quite possibly that is the result on all non-GENCGC platforms. - #+(and sparc (not gencgc)) - '(:space :read-only) - #+(and (not sparc) (not gencgc)) - '(:space :dynamic)) -#+sb-thread -(let ((x (list 1 2 3))) - (declare (dynamic-extent x)) - (tai x :stack sb-thread:*current-thread*)) + (equal info info2))) + +(deftest allocation-infromation.1 + (tai nil :heap '(:space :static)) + t) + +(deftest allocation-information.2 + (tai t :heap '(:space :static)) + t) + +(deftest allocation-information.3 + (tai 42 :immediate nil) + t) + +(deftest allocation-information.4 + (tai #'cons :heap + #+(and (not ppc) gencgc) + ;; FIXME: This is the canonical GENCGC result, the one below for PPC is + ;; what we get there, but :LARGE T doesn't seem right. Figure out what's + ;; going on. + '(:space :dynamic :generation 6 :write-protected t :pinned nil :large nil) + #+(and ppc gencgc) + '(:space :dynamic :generation 6 :write-protected t :pinned nil :large t) + ;; FIXME: Figure out what's the right cheney-result, and which platforms + ;; return something else. The SPARC version here is what we get there, + ;; but quite possibly that is the result on all non-GENCGC platforms. + #+(and sparc (not gencgc)) + '(:space :read-only) + #+(and (not sparc) (not gencgc)) + '(:space :dynamic)) + t) + #+sb-thread -(progn - (defun thread-tai () +(deftest allocation-information.thread.1 (let ((x (list 1 2 3))) (declare (dynamic-extent x)) - (let ((child (sb-thread:make-thread - (lambda () - (sb-introspect:allocation-information x))))) - (assert (equal (list :stack sb-thread:*current-thread*) - (multiple-value-list (sb-thread:join-thread child))))))) - (thread-tai) - (defun thread-tai2 () - (let* ((sem (sb-thread:make-semaphore)) - (obj nil) - (child (sb-thread:make-thread - (lambda () - (let ((x (list 1 2 3))) - (declare (dynamic-extent x)) - (setf obj x) - (sb-thread:wait-on-semaphore sem))) - :name "child"))) - (loop until obj) - (assert (equal (list :stack child) - (multiple-value-list - (sb-introspect:allocation-information obj)))) - (sb-thread:signal-semaphore sem) - (sb-thread:join-thread child) - nil)) - (thread-tai2)) - -;;;; Unix success convention for exit codes -(sb-ext:quit :unix-status 0) + (tai x :stack sb-thread:*current-thread*)) + t) +#+sb-thread +(progn + (defun thread-tai () + (let ((x (list 1 2 3))) + (declare (dynamic-extent x)) + (let ((child (sb-thread:make-thread + (lambda () + (sb-introspect:allocation-information x))))) + (equal (list :stack sb-thread:*current-thread*) + (multiple-value-list (sb-thread:join-thread child)))))) + + (deftest allocation-information.thread.2 + (thread-tai) + t) + + (defun thread-tai2 () + (let* ((sem (sb-thread:make-semaphore)) + (obj nil) + (child (sb-thread:make-thread + (lambda () + (let ((x (list 1 2 3))) + (declare (dynamic-extent x)) + (setf obj x) + (sb-thread:wait-on-semaphore sem))) + :name "child"))) + (loop until obj) + (assert (equal (list :stack child) + (multiple-value-list + (sb-introspect:allocation-information obj)))) + (sb-thread:signal-semaphore sem) + (sb-thread:join-thread child) + nil)) + + (deftest allocation-information.thread.3 + (thread-tai2) + t))