vm.test 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;;;; vm.test --- tests for the ELF machinery and VM -*- scheme -*-
  2. ;;;; Copyright (C) 2017 Free Software Foundation, Inc.
  3. ;;;;
  4. ;;;; This library is free software; you can redistribute it and/or
  5. ;;;; modify it under the terms of the GNU Lesser General Public
  6. ;;;; License as published by the Free Software Foundation; either
  7. ;;;; version 3 of the License, or (at your option) any later version.
  8. ;;;;
  9. ;;;; This library is distributed in the hope that it will be useful,
  10. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;;;; Lesser General Public License for more details.
  13. ;;;;
  14. ;;;; You should have received a copy of the GNU Lesser General Public
  15. ;;;; License along with this library; if not, write to the Free Software
  16. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. (define-module (tests vm)
  18. #:use-module (test-suite lib)
  19. #:use-module (system vm loader)
  20. #:use-module (system vm elf)
  21. #:use-module (rnrs bytevectors))
  22. (define (elf->bytevector elf)
  23. (let ((bv (make-bytevector 1000)))
  24. (write-elf-header bv elf)
  25. bv))
  26. (with-test-prefix "load-thunk-from-memory"
  27. (pass-if-exception "wrong byte order"
  28. '(misc-error . "does not have native byte order")
  29. ;; This used to throw to 'system-error' with whatever value errno had.
  30. (begin
  31. (false-if-exception (open-output-file "/does-not-exist"))
  32. (load-thunk-from-memory
  33. (elf->bytevector
  34. (make-elf #:byte-order (if (eq? (native-endianness)
  35. (endianness little))
  36. (endianness big)
  37. (endianness
  38. little))
  39. #:shoff 0)))))
  40. (pass-if-exception "wrong OS ABI"
  41. '(misc-error . "OS ABI")
  42. ;; This used to throw to 'system-error' with whatever value errno had.
  43. (begin
  44. (false-if-exception (open-output-file "/does-not-exist"))
  45. (load-thunk-from-memory
  46. (elf->bytevector
  47. (make-elf #:abi ELFOSABI_TRU64 ;RIP
  48. #:shoff 0))))))