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
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
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.
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 (with-test (:name
(documentation :cl
) :skipped-on
(:not
:sb-doc
))
26 (when (documentation s
'function
)
30 ;;;; tests of interface machinery
32 ;;; APROPOS should accept a package designator, not just a package, and
33 ;;; furthermore do the right thing when it gets a package designator.
34 ;;; (bug reported and fixed by Alexey Dejneka sbcl-devel 2001-10-17)
35 (with-test (:name
(apropos-list :package-designator
))
37 (length (apropos-list "PRINT" :cl
))
38 (length (apropos-list "PRINT")))))
39 ;;; Further, it should correctly deal with the external-only flag (bug
40 ;;; reported by cliini on #lisp IRC 2003-05-30, fixed in sbcl-0.8.0.1x
42 (with-test (:name
(apropos-list :external-only
))
43 (assert (= (length (apropos-list "" "CL"))
44 (length (apropos-list "" "CL" t
))))
46 (length (apropos-list "" "SB-VM" t
))
47 (length (apropos-list "" "SB-VM")))))
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 (with-test (:name
(typep :environment nil
))
53 (typep 1 'fixnum nil
))
55 (with-test (:name
(subtypep :environment nil
))
56 (subtypep 'fixnum
'integer nil
))
58 (with-test (:name
(upgraded-array-element-type :environment nil
))
59 (upgraded-array-element-type '(mod 5) nil
))
61 (with-test (:name
(upgraded-complex-part-type :environment nil
))
62 (upgraded-complex-part-type '(single-float 0.0 1.0) nil
))
65 (with-test (:name
(documentation :sb-ext
))
66 ;; We should have documentation for our extension package:
67 (assert (documentation (find-package "SB-EXT") t
)))
69 ;;; DECLARE should not be a special operator
70 (with-test (:name
(declare :not special-operator-p
))
71 (assert (not (special-operator-p 'declare
))))
73 ;;; WITH-TIMEOUT should accept more than one form in its body.
74 (with-test (:name
(sb-ext:with-timeout
:forms
))
75 (handler-bind ((sb-ext:timeout
#'continue
))
76 (sb-ext:with-timeout
3
80 ;;; SLEEP should not cons except on 32-bit platforms when
81 ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9))
82 (with-test (:name
(sleep :non-consing
)
83 :skipped-on
:interpreter
)
84 (handler-case (sb-ext:with-timeout
5
85 (ctu:assert-no-consing
(sleep 0.00001s0
))
86 (locally (declare (notinline sleep
))
87 (ctu:assert-no-consing
(sleep 0.00001s0
))
88 (ctu:assert-no-consing
(sleep 0.00001d0
))
89 (ctu:assert-no-consing
(sleep 1/100000003))))
92 ;;; Changes to make SLEEP cons less led to SLEEP
93 ;;; not sleeping at all on 32-bit platforms when
94 ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9)).
95 (with-test (:name
(sleep :bug-1194673
))
103 ;;; SLEEP should work with large integers as well
104 (with-test (:name
(sleep :pretty-much-forever
))
107 (sb-ext:with-timeout
1
108 (sleep (ash 1 (* 2 sb-vm
:n-word-bits
))))
112 ;;; DOCUMENTATION should return nil, not signal slot-unbound
113 (with-test (:name
(documentation :return nil
))
114 (flet ((test (thing doc-type
)
115 (assert (eq nil
(documentation thing doc-type
)))))
118 (test (find-class 'class
) 'type
)
119 (test 'foo
'structure
)))
121 ;;; DECODE-UNIVERSAL-TIME should accept second-resolution time-zones.
122 (with-test (:name
(decode-universal-time :second-resolution
:time-zone
))
123 (macrolet ((test (ut time-zone list
)
124 (destructuring-bind (sec min hr date mon yr day tz
)
126 `(multiple-value-bind (sec min hr date mon yr day dst tz
)
127 (decode-universal-time ,ut
,time-zone
)
128 (declare (ignore dst
))
129 (assert (= sec
,sec
))
130 (assert (= min
,min
))
132 (assert (= date
,date
))
133 (assert (= mon
,mon
))
135 (assert (= day
,day
))
136 (assert (= tz
,tz
))))))
137 (test (* 86400 365) -
1/3600 (1 0 0 1 1 1901 1 -
1/3600))
138 (test (* 86400 365) 0 (0 0 0 1 1 1901 1 0))
139 (test (* 86400 365) 1/3600 (59 59 23 31 12 1900 0 1/3600))))
141 ;;; DECODE-UNIVERSAL-TIME shouldn't fail when the time is outside UNIX
142 ;;; 32-bit time_t and a timezone wasn't passed
143 (with-test (:name
(decode-universal-time :decode
0))
144 (decode-universal-time 0 nil
))
146 ;;; ENCODE-UNIVERSAL-TIME should be able to encode the universal time
147 ;;; 0 when passed a representation in a timezone where the
148 ;;; representation of 0 as a decoded time is in 1899.
149 (with-test (:name
(encode-universal-time :encode
0))
150 (encode-universal-time 0 0 23 31 12 1899 1))
152 ;;; DISASSEMBLE shouldn't fail on purified functions
153 (with-test (:name
(disassemble :purified
))
154 (disassemble 'cl
:+ :stream
(make-broadcast-stream))
155 (disassemble 'sb-ext
:run-program
:stream
(make-broadcast-stream)))
157 ;;; minimal test of GC: see stress-gc.{sh,lisp} for a more
158 ;;; comprehensive test.
159 (with-test (:name
(sb-ext:gc
:minimal
:stress
))
161 do
(checked-compile '(lambda (x) x
))
162 do
(sb-ext:gc
:full t
)))
164 ;;; On x86-64, the instruction definitions for CMP*[PS][SD] were broken
165 ;;; so that the disassembler threw an error when they were used with
166 ;;; one operand in memory.
167 (with-test (:name
(disassemble :bug-814702
))
168 ;; Quote the lambdas, because WITH-TEST produces a hairy lexical environment
169 ;; which make an interpreted lambda uncompilable.
170 (disassemble '(lambda (x)
172 (the (complex single-float
) x
)))
173 :stream
(make-broadcast-stream))
174 (disassemble '(lambda (x y
)
175 (= (the (complex single-float
) x
)
176 (the (complex single-float
) y
)))
177 :stream
(make-broadcast-stream)))
179 ;;; Data in the high bits of a fun header caused CODE-N-UNBOXED-DATA-WORDS
180 ;;; to return a ridiculously huge value.
181 (with-test (:name
(disassemble :unboxed-data
))
182 (assert (< (sb-kernel:code-n-unboxed-data-words
183 (sb-kernel:fun-code-header
#'expt
))
184 100))) ; The exact value is irrelevant.
187 ;; The labeler for LEA would choke on an illegal encoding
188 ;; instead of showing what it illegally encodes, such as LEA RAX, RSP
189 (with-test (:name
(disassemble :x86-lea
:illegal-op
))
190 (let ((a (coerce '(#x48
#x8D
#xC4
) '(array (unsigned-byte 8) (3)))))
191 (sb-sys:with-pinned-objects
(a)
192 (sb-disassem::disassemble-memory
(sb-sys:sap-int
(sb-sys:vector-sap a
)) 3
193 :stream
(make-broadcast-stream)))))
195 ;; Assert that disassemblies of identically-acting functions are identical
196 ;; if address printing is turned off. Should work on any backend, I think.
197 (with-test (:name
(disassemble :without-addresses
))
198 (flet ((disassembly-text (lambda-expr)
200 (let ((sb-disassem::*disassem-location-column-width
* 0)
201 (*print-pretty
* nil
)) ; prevent function name wraparound
202 (with-output-to-string (s)
203 (disassemble lambda-expr
:stream s
)))))
204 ;; Return all except the first two lines. This is subject to change
205 ;; any time we muck with the layout unfortunately.
207 (1+ (position #\Newline string
208 :start
(1+ (position #\Newline string
))))))))
209 (let ((string1 (disassembly-text '(lambda (x) (car x
))))
210 (string2 (disassembly-text '(lambda (y) (car y
)))))
211 (assert (string= string1 string2
)))))
213 (with-test (:name
:disassemble-assembly-routine
)
214 (sb-disassem:disassemble-code-component sb-fasl
:*assembler-routines
*
215 :stream
(make-broadcast-stream)))
217 ;;; This tests that the x86-64 disasembler does not crash
218 ;;; on LEA with a rip-relative operand and no label.
219 (with-test (:name
(disassemble :no-labels
)
220 :skipped-on
(not :x86-64
))
223 (with-output-to-string (stream)
224 ;; A smallish function whose code happens to contain
225 ;; the thing under test.
226 (disassemble 'sb-impl
::inspector
:stream stream
))
228 (line (find "; = L0" lines
:test
'search
)))
229 (assert (search "LEA " line
)) ; verify our test precondition
230 ;; Now just disassemble without labels and see that we don't crash
231 (disassemble 'sb-impl
::inspector
233 :stream
(make-broadcast-stream))))
235 ;;; Check that SLEEP called with ratios (with no common factors with
236 ;;; 1000000000, and smaller than 1/1000000000) works more or less as
238 (with-test (:name
(sleep ratio
))
239 (let ((fun0a (checked-compile '(lambda () (sleep 1/7))))
240 (fun0b (checked-compile '(lambda () (sleep 1/100000000000000000000000000))))
241 (fun1 (checked-compile '(lambda (x) (sleep x
))))
242 (start-time (get-universal-time)))
244 (sleep 1/100000000000000000000000000)
248 (funcall fun1
1/100000000000000000000000000)
249 (assert (< (- (get-universal-time) start-time
) 2))))
251 (with-test (:name
(sb-ext:assert-version-
>= :ok
))
252 (sb-ext:assert-version-
>= 1 1 13))
254 (with-test (:name
(sb-ext:assert-version-
>= :fails
))
256 (sb-ext:assert-version-
>= most-positive-fixnum
)))
258 (with-test (:name
:bug-1095483
)
259 (assert-error (fboundp '(cas "foo"))))
261 (with-test (:name
(sleep :return-value
))
262 (checked-compile-and-assert ()
263 `(lambda () (sleep 0.001))
266 (with-test (:name
(time :no
*print-length
* :abbreviation
))
267 (let ((s (make-string-output-stream)))
268 (let ((*trace-output
* s
))
270 (let ((str (get-output-stream-string s
)))
271 (assert (and (>= (count #\newline str
) 4)
272 (search "bytes consed" str
))))))
274 (with-test (:name
:split-seconds-for-sleep
)
275 (assert (< (nth-value 1 (sb-impl::split-seconds-for-sleep
7.2993028420866d7
))
278 (with-test (:name
:restart-invalid-arg-counts
.1)
279 (handler-bind ((error (lambda (c)
280 (invoke-restart (find-restart 'sb-kernel
::replace-function c
) 'list
))))
281 (assert (equal (eval '(cons 324)) '(324)))))
284 (with-test (:name
:restart-invalid-arg-counts
.2)
285 (handler-bind ((error (lambda (c)
286 (invoke-restart (find-restart 'sb-kernel
::call-form c
) 123))))
287 (assert (= (eval '(cons 1)) 123))))
289 (with-test (:name
:restart-bogus-arg-to-values-list-error
)
290 (let ((fun (checked-compile `(lambda (x) (values-list x
)))))
291 (assert (equal (handler-bind ((sb-kernel::values-list-argument-error
294 (funcall fun
'(1 2 3 4 5 6 7 8 .
10))))
295 '(1 2 3 4 5 6 7 8)))))