1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; tests.lisp --- trivial-features tests.
;;;
;;; Copyright (C) 2007, Luis Oliveira <loliveira@common-lisp.net>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
(in-package :trivial-features-tests)
(defun run ()
(let ((*package* (find-package :trivial-features-tests)))
(do-tests)
(null (regression-test:pending-tests))))
;;;; Support Code
#-windows
(progn
;; Hmm, why not just use OSICAT-POSIX:UNAME?
(defcfun ("uname" %uname) :int
(buf :pointer))
;; Get system identification.
(defun uname ()
(with-foreign-object (buf '(:struct utsname))
(when (= (%uname buf) -1)
(error "uname() returned -1"))
(macrolet ((utsname-slot (name)
`(foreign-string-to-lisp
(foreign-slot-pointer buf 'utsname ',name))))
(values (utsname-slot sysname)
;; (utsname-slot nodename)
;; (utsname-slot release)
;; (utsname-slot version)
(utsname-slot machine))))))
(defun mutually-exclusive-p (features)
(= 1 (loop for feature in features when (featurep feature) count 1)))
;;;; Tests
(deftest endianness.1
(with-foreign-object (p :uint16)
(setf (mem-ref p :uint16) #xfeff)
(ecase (mem-ref p :uint8)
(#xfe (featurep :big-endian))
(#xff (featurep :little-endian))))
t)
(defparameter *bsds* '(:darwin :netbsd :openbsd :freebsd))
(defparameter *unices* (list* :linux *bsds*))
#+windows
(deftest os.1
(featurep (list* :or :unix *unices*))
nil)
#-windows
(deftest os.1
(featurep (make-keyword (string-upcase (uname))))
t)
(deftest os.2
(if (featurep :bsd)
(mutually-exclusive-p *bsds*)
(featurep `(:not (:or ,@*bsds*))))
t)
(deftest os.3
(if (featurep `(:or ,@*unices*))
(featurep :unix)
t)
t)
(deftest os.4
(if (featurep :windows)
(not (featurep :unix))
t)
t)
(deftest cpu.1
(mutually-exclusive-p '(:ppc :ppc64 :x86 :x86-64 :alpha :mips :arm :arm64))
t)
#+windows
(deftest cpu.2
(case (get-system-info)
(:intel (featurep :x86))
(:amd64 (featurep :x86-64))
(:ia64 nil) ; add this feature later!
(t t))
t)
#-windows
(deftest cpu.2
(let ((machine (nth-value 1 (uname))))
(cond ((member machine '("x86" "x86_64") :test #'string=)
(ecase (foreign-type-size :pointer)
(4 (featurep :x86))
(8 (featurep :x86-64))))
(t
(format *debug-io*
"~&; NOTE: unhandled machine type, ~a, in CPU.2 test.~%"
machine)
t)))
t)
(deftest cpu.3
(ecase (foreign-type-size :pointer)
(4 (featurep :32-bit))
(8 (featurep :64-bit)))
t)
;; regression test: sometimes, silly logic leads to pushing nil to
;; *features*.
(deftest nil.1 (featurep nil) nil)
(deftest nil.2 (featurep :nil) nil)
|