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 ;;; 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)
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
37 (assert (= (length (apropos-list "" "CL"))
38 (length (apropos-list "" "CL" t
))))
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)
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
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 ;;; We should have documentation for our extension package:
58 (assert (documentation (find-package "SB-EXT") t
))
60 ;;; DECLARE should not be a special operator
61 (assert (not (special-operator-p 'declare
)))
63 ;;; WITH-TIMEOUT should accept more than one form in its body.
64 (with-test (:name
:with-timeout-forms
)
65 (handler-bind ((sb-ext:timeout
#'continue
))
66 (sb-ext:with-timeout
3
70 ;;; SLEEP should not cons except on 32-bit platforms when
71 ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9))
72 (with-test (:name
(sleep :non-consing
) :fails-on
:win32
)
73 (handler-case (sb-ext:with-timeout
5
74 (ctu:assert-no-consing
(sleep 0.00001s0
))
75 (locally (declare (notinline sleep
))
76 (ctu:assert-no-consing
(sleep 0.00001s0
))
77 (ctu:assert-no-consing
(sleep 0.00001d0
))
78 (ctu:assert-no-consing
(sleep 1/100000003))))
81 ;;; Changes to make SLEEP cons less led to SLEEP
82 ;;; not sleeping at all on 32-bit platforms when
83 ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9)).
84 (with-test (:name
:bug-1194673
)
92 ;;; SLEEP should work with large integers as well
93 (with-test (:name
(sleep :pretty-much-forever
))
96 (sb-ext:with-timeout
1
97 (sleep (ash 1 (* 2 sb-vm
:n-word-bits
))))
101 ;;; DOCUMENTATION should return nil, not signal slot-unbound
102 (documentation 'fixnum
'type
)
103 (documentation 'class
'type
)
104 (documentation (find-class 'class
) 'type
)
105 (documentation 'foo
'structure
)
107 ;;; DECODE-UNIVERSAL-TIME should accept second-resolution time-zones.
108 (macrolet ((test (ut time-zone list
)
109 (destructuring-bind (sec min hr date mon yr day tz
)
111 `(multiple-value-bind (sec min hr date mon yr day dst tz
)
112 (decode-universal-time ,ut
,time-zone
)
113 (declare (ignore dst
))
114 (assert (= sec
,sec
))
115 (assert (= min
,min
))
117 (assert (= date
,date
))
118 (assert (= mon
,mon
))
120 (assert (= day
,day
))
121 (assert (= tz
,tz
))))))
122 (test (* 86400 365) -
1/3600 (1 0 0 1 1 1901 1 -
1/3600))
123 (test (* 86400 365) 0 (0 0 0 1 1 1901 1 0))
124 (test (* 86400 365) 1/3600 (59 59 23 31 12 1900 0 1/3600)))
126 ;;; DECODE-UNIVERSAL-TIME shouldn't fail when the time is outside UNIX
127 ;;; 32-bit time_t and a timezone wasn't passed
128 (decode-universal-time 0 nil
)
130 ;;; ENCODE-UNIVERSAL-TIME should be able to encode the universal time
131 ;;; 0 when passed a representation in a timezone where the
132 ;;; representation of 0 as a decoded time is in 1899.
133 (encode-universal-time 0 0 23 31 12 1899 1)
135 ;;; DISASSEMBLE shouldn't fail on purified functions
137 (disassemble 'sb-ext
:run-program
)
139 ;;; minimal test of GC: see stress-gc.{sh,lisp} for a more
140 ;;; comprehensive test.
142 do
(compile nil
'(lambda (x) x
))
143 do
(sb-ext:gc
:full t
))
145 ;;; On x86-64, the instruction definitions for CMP*[PS][SD] were broken
146 ;;; so that the disassembler threw an error when they were used with
147 ;;; one operand in memory.
148 (with-test (:name
:bug-814702
)
149 (disassemble (lambda (x)
151 (the (complex single-float
) x
))))
152 (disassemble (lambda (x y
)
153 (= (the (complex single-float
) x
)
154 (the (complex single-float
) y
)))))
157 ;; The labeler for LEA would choke on an illegal encoding
158 ;; instead of showing what it illegally encodes, such as LEA RAX, RSP
159 (with-test (:name
:x86-lea-disassemble-illegal-op
)
160 (let ((a (coerce '(#x48
#x8D
#xC4
) '(array (unsigned-byte 8) (3)))))
161 (sb-sys:with-pinned-objects
(a)
162 (sb-disassem::disassemble-memory
(sb-sys:sap-int
(sb-sys:vector-sap a
)) 3))))
164 ;; Assert that disassemblies of identically-acting functions are identical
165 ;; if address printing is turned off. Should work on any backend, I think.
166 (with-test (:name
:disassemble-without-addresses
)
167 (flet ((disassembly-text (lambda-expr)
169 (let ((sb-disassem::*disassem-location-column-width
* 0)
170 (*print-pretty
* nil
)) ; prevent function name wraparound
171 (with-output-to-string (s)
172 (disassemble lambda-expr
:stream s
)))))
173 ;; Return all except the first two lines. This is subject to change
174 ;; any time we muck with the layout unfortunately.
176 (1+ (position #\Newline string
177 :start
(1+ (position #\Newline string
))))))))
178 (let ((string1 (disassembly-text '(lambda (x) (car x
))))
179 (string2 (disassembly-text '(lambda (y) (car y
)))))
180 (assert (string= string1 string2
)))))
182 ;;; Check that SLEEP called with ratios (with no common factors with
183 ;;; 1000000000, and smaller than 1/1000000000) works more or less as
185 (with-test (:name
:sleep-ratios
)
186 (let ((fun0a (compile nil
'(lambda () (sleep 1/7))))
187 (fun0b (compile nil
'(lambda () (sleep 1/100000000000000000000000000))))
188 (fun1 (compile nil
'(lambda (x) (sleep x
))))
189 (start-time (get-universal-time)))
191 (sleep 1/100000000000000000000000000)
195 (funcall fun1
1/100000000000000000000000000)
196 (assert (< (- (get-universal-time) start-time
) 2))))
198 (with-test (:name
:version-assert-ok
)
199 (sb-ext:assert-version-
>= 1 1 13))
201 (with-test (:name
:version-assert-fails
)
203 (sb-ext:assert-version-
>= most-positive-fixnum
)))
205 (with-test (:name
:bug-1095483
)
206 (assert-error (fboundp '(cas "foo"))))