Abstract immediate loading on x86-64.
[sbcl.git] / tests / interface.pure.lisp
blob1bfb80eabaa7ddcb3b35853cfc8280512924cedf
1 ;;;; tests for problems in the interface presented to the user/programmer
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (in-package :cl-user)
16 (load "test-util.lisp")
17 (load "compiler-test-util.lisp")
18 (use-package :test-util)
20 ;;;; properties of symbols, e.g. presence of doc strings for public symbols
22 ;;; FIXME: It would probably be good to require here that every
23 ;;; external symbol either has a doc string or has some good excuse
24 ;;; (like being an accessor for a structure which has a doc string).
26 ;;;; tests of interface machinery
28 ;;; APROPOS should accept a package designator, not just a package, and
29 ;;; furthermore do the right thing when it gets a package designator.
30 ;;; (bug reported and fixed by Alexey Dejneka sbcl-devel 2001-10-17)
31 (assert (< 0
32 (length (apropos-list "PRINT" :cl))
33 (length (apropos-list "PRINT"))))
34 ;;; Further, it should correctly deal with the external-only flag (bug
35 ;;; reported by cliini on #lisp IRC 2003-05-30, fixed in sbcl-0.8.0.1x
36 ;;; by CSR)
37 (assert (= (length (apropos-list "" "CL"))
38 (length (apropos-list "" "CL" t))))
39 (assert (< 0
40 (length (apropos-list "" "SB-VM" t))
41 (length (apropos-list "" "SB-VM"))))
43 ;;; DESCRIBE shouldn't fail on rank-0 arrays (bug reported and fixed
44 ;;; by Lutz Euler sbcl-devel 2002-12-03)
45 (describe #0a0)
46 (describe #(1 2 3))
47 (describe #2a((1 2) (3 4)))
49 ;;; TYPEP, SUBTYPEP, UPGRADED-ARRAY-ELEMENT-TYPE and
50 ;;; UPGRADED-COMPLEX-PART-TYPE should be able to deal with NIL as an
51 ;;; environment argument
52 (typep 1 'fixnum nil)
53 (subtypep 'fixnum 'integer nil)
54 (upgraded-array-element-type '(mod 5) nil)
55 (upgraded-complex-part-type '(single-float 0.0 1.0) nil)
57 #+sb-doc
58 (with-test (:name :sb-ext-documentation)
59 ;;; We should have documentation for our extension package:
60 (assert (documentation (find-package "SB-EXT") t)))
62 ;; This is trying to assert that you didn't mistakenly write
63 ;; "#!+sb-doc (important-form)" in source code
64 ;; but it's an absolutely terrible test, because it is nothing more
65 ;; than a change detector. There are two possible improvements:
66 ;; 1. eliminate the change-detection nature of the test by documenting
67 ;; all functions in CL, so that the magic constant 605 goes away.
68 ;; This would still be an indirect test.
69 ;; 2. stop littering up the source code with #!+sb-doc,
70 ;; always write docstrings, and have 'make-target-2-load.lisp' remove them
71 ;; if desired. This would eliminate >1100 reader conditionals,
72 ;; comprising nearly 68% of all reader conditionals in SBCL source.
73 #+sb-doc
74 (with-test (:name :cl-documentation)
75 (let ((n 0))
76 (do-symbols (s 'cl)
77 (if (fboundp s)
78 (when (documentation s 'function)
79 (incf n))))
80 (assert (= n 605))))
82 ;;; DECLARE should not be a special operator
83 (assert (not (special-operator-p 'declare)))
85 ;;; WITH-TIMEOUT should accept more than one form in its body.
86 (with-test (:name :with-timeout-forms)
87 (handler-bind ((sb-ext:timeout #'continue))
88 (sb-ext:with-timeout 3
89 (sleep 2)
90 (sleep 2))))
92 ;;; SLEEP should not cons except on 32-bit platforms when
93 ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9))
94 (with-test (:name (sleep :non-consing) :fails-on :win32
95 :skipped-on :interpreter)
96 (handler-case (sb-ext:with-timeout 5
97 (ctu:assert-no-consing (sleep 0.00001s0))
98 (locally (declare (notinline sleep))
99 (ctu:assert-no-consing (sleep 0.00001s0))
100 (ctu:assert-no-consing (sleep 0.00001d0))
101 (ctu:assert-no-consing (sleep 1/100000003))))
102 (timeout ())))
104 ;;; Changes to make SLEEP cons less led to SLEEP
105 ;;; not sleeping at all on 32-bit platforms when
106 ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9)).
107 (with-test (:name :bug-1194673)
108 (assert (eq :timeout
109 (handler-case
110 (with-timeout 0.01
111 (sleep 0.6))
112 (timeout ()
113 :timeout)))))
115 ;;; SLEEP should work with large integers as well
116 (with-test (:name (sleep :pretty-much-forever))
117 (assert (eq :timeout
118 (handler-case
119 (sb-ext:with-timeout 1
120 (sleep (ash 1 (* 2 sb-vm:n-word-bits))))
121 (sb-ext:timeout ()
122 :timeout)))))
124 ;;; DOCUMENTATION should return nil, not signal slot-unbound
125 (documentation 'fixnum 'type)
126 (documentation 'class 'type)
127 (documentation (find-class 'class) 'type)
128 (documentation 'foo 'structure)
130 ;;; DECODE-UNIVERSAL-TIME should accept second-resolution time-zones.
131 (macrolet ((test (ut time-zone list)
132 (destructuring-bind (sec min hr date mon yr day tz)
133 list
134 `(multiple-value-bind (sec min hr date mon yr day dst tz)
135 (decode-universal-time ,ut ,time-zone)
136 (declare (ignore dst))
137 (assert (= sec ,sec))
138 (assert (= min ,min))
139 (assert (= hr ,hr))
140 (assert (= date ,date))
141 (assert (= mon ,mon))
142 (assert (= yr ,yr))
143 (assert (= day ,day))
144 (assert (= tz ,tz))))))
145 (test (* 86400 365) -1/3600 (1 0 0 1 1 1901 1 -1/3600))
146 (test (* 86400 365) 0 (0 0 0 1 1 1901 1 0))
147 (test (* 86400 365) 1/3600 (59 59 23 31 12 1900 0 1/3600)))
149 ;;; DECODE-UNIVERSAL-TIME shouldn't fail when the time is outside UNIX
150 ;;; 32-bit time_t and a timezone wasn't passed
151 (decode-universal-time 0 nil)
153 ;;; ENCODE-UNIVERSAL-TIME should be able to encode the universal time
154 ;;; 0 when passed a representation in a timezone where the
155 ;;; representation of 0 as a decoded time is in 1899.
156 (encode-universal-time 0 0 23 31 12 1899 1)
158 ;;; DISASSEMBLE shouldn't fail on purified functions
159 (disassemble 'cl:+ :stream (make-broadcast-stream))
160 (disassemble 'sb-ext:run-program :stream (make-broadcast-stream))
162 ;;; minimal test of GC: see stress-gc.{sh,lisp} for a more
163 ;;; comprehensive test.
164 (loop repeat 2
165 do (compile nil '(lambda (x) x))
166 do (sb-ext:gc :full t))
168 ;;; On x86-64, the instruction definitions for CMP*[PS][SD] were broken
169 ;;; so that the disassembler threw an error when they were used with
170 ;;; one operand in memory.
171 (with-test (:name :bug-814702)
172 ;; Quote the lambdas, because WITH-TEST produces a hairy lexical environment
173 ;; which make an interpreted lambda uncompilable.
174 (disassemble '(lambda (x)
175 (= #C(2.0f0 3.0f0)
176 (the (complex single-float) x)))
177 :stream (make-broadcast-stream))
178 (disassemble '(lambda (x y)
179 (= (the (complex single-float) x)
180 (the (complex single-float) y)))
181 :stream (make-broadcast-stream)))
183 #+x86-64
184 ;; The labeler for LEA would choke on an illegal encoding
185 ;; instead of showing what it illegally encodes, such as LEA RAX, RSP
186 (with-test (:name :x86-lea-disassemble-illegal-op)
187 (let ((a (coerce '(#x48 #x8D #xC4) '(array (unsigned-byte 8) (3)))))
188 (sb-sys:with-pinned-objects (a)
189 (sb-disassem::disassemble-memory (sb-sys:sap-int (sb-sys:vector-sap a)) 3
190 :stream (make-broadcast-stream)))))
192 ;; Assert that disassemblies of identically-acting functions are identical
193 ;; if address printing is turned off. Should work on any backend, I think.
194 (with-test (:name :disassemble-without-addresses)
195 (flet ((disassembly-text (lambda-expr)
196 (let ((string
197 (let ((sb-disassem::*disassem-location-column-width* 0)
198 (*print-pretty* nil)) ; prevent function name wraparound
199 (with-output-to-string (s)
200 (disassemble lambda-expr :stream s)))))
201 ;; Return all except the first two lines. This is subject to change
202 ;; any time we muck with the layout unfortunately.
203 (subseq string
204 (1+ (position #\Newline string
205 :start (1+ (position #\Newline string))))))))
206 (let ((string1 (disassembly-text '(lambda (x) (car x))))
207 (string2 (disassembly-text '(lambda (y) (car y)))))
208 (assert (string= string1 string2)))))
210 (with-test (:name :disassemble-assembly-routine)
211 (let ((code
212 (block nil
213 (sb-vm::map-allocated-objects
214 (lambda (obj type size)
215 (declare (ignore size))
216 (when (= type sb-vm:code-header-widetag)
217 (return obj)))
218 :read-only))))
219 (assert code) ; found something to disassemble
220 (sb-disassem:disassemble-code-component code
221 :stream (make-broadcast-stream))))
223 ;;; Check that SLEEP called with ratios (with no common factors with
224 ;;; 1000000000, and smaller than 1/1000000000) works more or less as
225 ;;; expected.
226 (with-test (:name :sleep-ratios)
227 (let ((fun0a (compile nil '(lambda () (sleep 1/7))))
228 (fun0b (compile nil '(lambda () (sleep 1/100000000000000000000000000))))
229 (fun1 (compile nil '(lambda (x) (sleep x))))
230 (start-time (get-universal-time)))
231 (sleep 1/7)
232 (sleep 1/100000000000000000000000000)
233 (funcall fun0a)
234 (funcall fun0b)
235 (funcall fun1 1/7)
236 (funcall fun1 1/100000000000000000000000000)
237 (assert (< (- (get-universal-time) start-time) 2))))
239 (with-test (:name :version-assert-ok)
240 (sb-ext:assert-version->= 1 1 13))
242 (with-test (:name :version-assert-fails)
243 (assert-error
244 (sb-ext:assert-version->= most-positive-fixnum)))
246 (with-test (:name :bug-1095483)
247 (assert-error (fboundp '(cas "foo"))))