test-atomics.scm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ;;; Copyright (C) 2023, 2024 Igalia, S.L.
  2. ;;;
  3. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;;; you may not use this file except in compliance with the License.
  5. ;;; You may obtain a copy of the License at
  6. ;;;
  7. ;;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;;
  9. ;;; Unless required by applicable law or agreed to in writing, software
  10. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;;; See the License for the specific language governing permissions and
  13. ;;; limitations under the License.
  14. ;;; Commentary:
  15. ;;;
  16. ;;; Atomic box tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-atomics")
  22. (with-additional-imports
  23. ((hoot atomics))
  24. (test-call "42" (lambda (box)
  25. (let ((val (atomic-box-ref box)))
  26. val))
  27. (make-atomic-box 42))
  28. (test-call "(42 10 10 69 69 69 69 2)"
  29. (lambda (box)
  30. (let ((v0 (atomic-box-ref box)))
  31. (atomic-box-set! box 10)
  32. (let* ((v1 (atomic-box-ref box))
  33. (v2 (atomic-box-swap! box 69))
  34. (v3 (atomic-box-ref box))
  35. (v4 (atomic-box-compare-and-swap! box 1 2))
  36. (v5 (atomic-box-ref box))
  37. (v6 (atomic-box-compare-and-swap! box v4 2))
  38. (v7 (atomic-box-ref box)))
  39. (list v0 v1 v2 v3 v4 v5 v6 v7))))
  40. (make-atomic-box 42)))
  41. (test-end* "test-atomics")