| 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 |
|
| 18 |
(define-module (tests vm) |
| 19 |
#:use-module (test-suite lib) |
| 20 |
#:use-module (system vm loader) |
| 21 |
#:use-module (system vm elf) |
| 22 |
#:use-module (rnrs bytevectors)) |
| 23 |
|
| 24 |
(define (elf->bytevector elf) |
| 25 |
(let ((bv (make-bytevector 1000))) |
| 26 |
(write-elf-header bv elf) |
| 27 |
bv)) |
| 28 |
|
| 29 |
|
| 30 |
(with-test-prefix "load-thunk-from-memory" |
| 31 |
|
| 32 |
(pass-if-exception "wrong byte order" |
| 33 |
'(misc-error . "does not have native byte order") |
| 34 |
;; This used to throw to 'system-error' with whatever value errno had. |
| 35 |
(begin |
| 36 |
(false-if-exception (open-output-file "/does-not-exist")) |
| 37 |
(load-thunk-from-memory |
| 38 |
(elf->bytevector |
| 39 |
(make-elf #:byte-order (if (eq? (native-endianness) |
| 40 |
(endianness little)) |
| 41 |
(endianness big) |
| 42 |
(endianness |
| 43 |
little)) |
| 44 |
#:shoff 0))))) |
| 45 |
|
| 46 |
(pass-if-exception "wrong OS ABI" |
| 47 |
'(misc-error . "OS ABI") |
| 48 |
;; This used to throw to 'system-error' with whatever value errno had. |
| 49 |
(begin |
| 50 |
(false-if-exception (open-output-file "/does-not-exist")) |
| 51 |
(load-thunk-from-memory |
| 52 |
(elf->bytevector |
| 53 |
(make-elf #:abi ELFOSABI_TRU64 ;RIP |
| 54 |
#:shoff 0)))))) |