Define %RAW-INSTANCE-foo based on *RAW-SLOT-DATA* automatically
[sbcl.git] / tests / system.impure.lisp
blob2b9629f0e73feaee51b3ee57f3fe7d271d074c55
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; While most of SBCL is derived from the CMU CL system, the test
5 ;;;; files (like this one) were written from scratch after the fork
6 ;;;; from CMU CL.
7 ;;;;
8 ;;;; This software is in the public domain and is provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
10 ;;;; more information.
12 (in-package "SB-VM")
14 ;;; This file defines a structure, so is an 'impure' test
15 (defstruct my-struct one two three four)
17 #-(and (or x86 x86-64) (not interpreter)) (sb-ext:exit :code 104)
19 (test-util:with-test (:name :basic-cpuid)
20 (flet ((to-ascii (bits)
21 (let ((s (make-array 4 :element-type 'base-char)))
22 (setf (sap-ref-32 (vector-sap s) 0) bits)
23 s)))
24 (multiple-value-bind (a b c d)
25 (%cpu-identification 0 0)
26 ;; There's nothing to assert here since the result can vary
27 (format t "~S (max function = ~D)~%"
28 (concatenate 'string (to-ascii b) (to-ascii d) (to-ascii c))
29 a))))
31 (progn
32 (defun test-a-cons (acons oldcar oldcdr newcar newcdr)
33 (declare (optimize (safety 0)))
34 (%cons-cas-pair acons oldcar oldcdr newcar newcdr))
35 (defun test-a-vect (avect ind old1 old2 new1 new2)
36 (declare (optimize (safety 0)))
37 (%vector-cas-pair avect ind old1 old2 new1 new2))
38 (defun test-a-struct (inst ind old1 old2 new1 new2)
39 (declare (optimize (safety 0)))
40 (%instance-cas-pair inst ind old1 old2 new1 new2))
42 (defun test-wide-cmpxchg ()
43 (let ((x (cons 'a 'b)))
44 (multiple-value-bind (old1 old2) (test-a-cons x 'a 'b 'foo 'bar)
45 (assert (and (eq old1 'a) (eq old2 'b) (equal x '(foo . bar)))))
46 (multiple-value-bind (old1 old2) (test-a-cons x 0 0 1 2)
47 (assert (and (eq old1 'foo) (eq old2 'bar) (equal x '(foo . bar))))))
49 ;; This is just testing that the offsets are correct.
50 ;; Correct working of the instruction is tested by the CONS example.
51 (let ((x (make-array 6 :initial-element nil)))
52 (multiple-value-bind (old1 old2) (test-a-vect x 2 nil nil 'foo 'bar)
53 (assert (and (null old1) (null old2) (equalp x #(nil nil foo bar nil nil))))))
55 ;; Same remark applies - just check that the offset to the slot is right.
56 (let ((s (make-my-struct :three 'the :four 'floor)))
57 ;; in slots 3 and 4 put your bootee (a baby shoe, i.e.) on the floor
58 (multiple-value-bind (old1 old2) (test-a-struct s 3 'the 'floor 'your 'bootee)
59 (assert (and (eq old1 'the) (eq old2 'floor)
60 (eq (my-struct-three s) 'your)
61 (eq (my-struct-four s) 'bootee)))))
62 t))
64 (test-util:with-test (:name :wide-compare-and-exchange)
65 (multiple-value-bind (a b c d) (%cpu-identification 0 0)
66 (declare (ignore b c d))
67 ;; paranoidly check for whether we can execute function ID 1
68 (or (and (>= a 1) ; the highest function ID
69 (multiple-value-bind (a b c d) (%cpu-identification 1 0)
70 (declare (ignore a b) (ignorable c d))
71 ;; paranoidly check for CMPXCHGxB presence
72 ;; constants from Table 3-20 and 3-21 of Intel manual
73 (and #+x86(logbitp 8 d) #+x86-64(logbitp 13 c)
74 (test-wide-cmpxchg))))
75 (format t "Double-width compare-and-swap NOT TESTED~%"))))