| 1 |
;;;; atomic.test --- test suite for Guile's atomic operations -*- scheme -*- |
| 2 |
;;;; |
| 3 |
;;;; Copyright (C) 2016 Free Software Foundation, Inc. |
| 4 |
;;;; |
| 5 |
;;;; This library is free software; you can redistribute it and/or |
| 6 |
;;;; modify it under the terms of the GNU Lesser General Public |
| 7 |
;;;; License as published by the Free Software Foundation; either |
| 8 |
;;;; version 3 of the License, or (at your option) any later version. |
| 9 |
;;;; |
| 10 |
;;;; This library is distributed in the hope that it will be useful, |
| 11 |
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
;;;; Lesser General Public License for more details. |
| 14 |
;;;; |
| 15 |
;;;; You should have received a copy of the GNU Lesser General Public |
| 16 |
;;;; License along with this library; if not, write to the Free Software |
| 17 |
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
|
| 19 |
(define-module (test-suite atomic) |
| 20 |
#:use-module (ice-9 atomic) |
| 21 |
#:use-module ((oop goops) #:select (class-of <atomic-box>)) |
| 22 |
#:use-module (test-suite lib)) |
| 23 |
|
| 24 |
(with-test-prefix/c&e "atomics" |
| 25 |
(pass-if "predicate" (atomic-box? (make-atomic-box 42))) |
| 26 |
|
| 27 |
(pass-if-equal "ref" 42 (atomic-box-ref (make-atomic-box 42))) |
| 28 |
|
| 29 |
(pass-if-equal "swap" 42 (atomic-box-swap! (make-atomic-box 42) 10)) |
| 30 |
|
| 31 |
(pass-if-equal "set and ref" 10 |
| 32 |
(let ((box (make-atomic-box 42))) |
| 33 |
(atomic-box-set! box 10) |
| 34 |
(atomic-box-ref box))) |
| 35 |
|
| 36 |
(pass-if-equal "swap and ref" 10 |
| 37 |
(let ((box (make-atomic-box 42))) |
| 38 |
(atomic-box-swap! box 10) |
| 39 |
(atomic-box-ref box))) |
| 40 |
|
| 41 |
(pass-if-equal "compare and swap" 42 |
| 42 |
(let ((box (make-atomic-box 42))) |
| 43 |
(atomic-box-compare-and-swap! box 42 10))) |
| 44 |
|
| 45 |
(pass-if-equal "compare and swap (wrong)" 42 |
| 46 |
(let ((box (make-atomic-box 42))) |
| 47 |
(atomic-box-compare-and-swap! box 43 10))) |
| 48 |
|
| 49 |
(pass-if-equal "compare and swap and ref" 10 |
| 50 |
(let ((box (make-atomic-box 42))) |
| 51 |
(atomic-box-compare-and-swap! box 42 10) |
| 52 |
(atomic-box-ref box))) |
| 53 |
|
| 54 |
(pass-if-equal "compare and swap (wrong) and ref" 42 |
| 55 |
(let ((box (make-atomic-box 42))) |
| 56 |
(atomic-box-compare-and-swap! box 43 10) |
| 57 |
(atomic-box-ref box))) |
| 58 |
|
| 59 |
(pass-if-equal "class-of" <atomic-box> |
| 60 |
(class-of (make-atomic-box 42)))) |