| 1 |
;;;; Cross compilation -*- mode: scheme; coding: utf-8; -*- |
| 2 |
;;;; |
| 3 |
;;;; Copyright (C) 2010-2014, 2020, 2022 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 (tests cross-compilation) |
| 20 |
#:use-module (test-suite lib) |
| 21 |
#:use-module (rnrs bytevectors) |
| 22 |
#:use-module (system vm elf) |
| 23 |
#:use-module (system base compile) |
| 24 |
#:use-module (system base target)) |
| 25 |
|
| 26 |
(define (test-triplet cpu vendor os) |
| 27 |
(let ((triplet (string-append cpu "-" vendor "-" os))) |
| 28 |
(pass-if (format #f "triplet ~a" triplet) |
| 29 |
(with-target triplet |
| 30 |
(lambda () |
| 31 |
(and (string=? (target-cpu) cpu) |
| 32 |
(string=? (target-vendor) vendor) |
| 33 |
(string=? (target-os) os))))))) |
| 34 |
|
| 35 |
(define (native-cpu) |
| 36 |
(with-target %host-type target-cpu)) |
| 37 |
|
| 38 |
(define (native-os) |
| 39 |
(with-target %host-type target-os)) |
| 40 |
|
| 41 |
(define (native-word-size) |
| 42 |
((@ (system foreign) sizeof) '*)) |
| 43 |
|
| 44 |
(define (test-target triplet endian word-size) |
| 45 |
(pass-if (format #f "target `~a' honored" triplet) |
| 46 |
(with-target triplet |
| 47 |
(lambda () |
| 48 |
(let ((word-size |
| 49 |
;; When the target is the native CPU, rather trust |
| 50 |
;; the native CPU's word size. This is because |
| 51 |
;; Debian's `sparc64-linux-gnu' port, for instance, |
| 52 |
;; actually has a 32-bit user-land, for instance (see |
| 53 |
;; <http://www.debian.org/ports/sparc/#sparc64bit> |
| 54 |
;; for details.) |
| 55 |
(if (and (string=? (native-cpu) (target-cpu)) |
| 56 |
(string=? (native-os) (target-os))) |
| 57 |
(native-word-size) |
| 58 |
word-size)) |
| 59 |
(bv (compile '(hello-world) #:warning-level 0 #:to 'bytecode))) |
| 60 |
(and=> (parse-elf bv) |
| 61 |
(lambda (elf) |
| 62 |
(and (equal? (elf-byte-order elf) endian) |
| 63 |
(equal? (elf-word-size elf) word-size))))))))) |
| 64 |
|
| 65 |
(with-test-prefix "cross-compilation" |
| 66 |
|
| 67 |
(test-triplet "i586" "pc" "gnu0.3") |
| 68 |
(test-triplet "x86_64" "unknown" "linux-gnu") |
| 69 |
(test-triplet "x86_64" "unknown" "kfreebsd-gnu") |
| 70 |
(test-triplet "x86_64" "" "netbsd") ;NetBSD/pkgsrc with empty vendor |
| 71 |
|
| 72 |
(test-target "i586-pc-gnu0.3" (endianness little) 4) |
| 73 |
(test-target "x86_64-pc-linux-gnu" (endianness little) 8) |
| 74 |
(test-target "powerpc-unknown-linux-gnu" (endianness big) 4) |
| 75 |
(test-target "sparc64-unknown-freebsd8.2" (endianness big) 8) |
| 76 |
(test-target "x86_64--netbsd" (endianness little) 8) |
| 77 |
|
| 78 |
(test-target "mips64el-unknown-linux-gnu" ; n32 or o32 ABI |
| 79 |
(endianness little) 4) |
| 80 |
(test-target "mips64el-unknown-linux-gnuabi64" ; n64 ABI (Debian tuplet) |
| 81 |
(endianness little) 8) |
| 82 |
(test-target "x86_64-unknown-linux-gnux32" ; x32 ABI (Debian tuplet) |
| 83 |
(endianness little) 4) |
| 84 |
(test-target "arm-unknown-linux-androideabi" |
| 85 |
(endianness little) 4) |
| 86 |
(test-target "armeb-unknown-linux-gnu" |
| 87 |
(endianness big) 4) |
| 88 |
(test-target "aarch64-linux-gnu" |
| 89 |
(endianness little) 8) |
| 90 |
(test-target "aarch64_be-linux-gnu" |
| 91 |
(endianness big) 8) |
| 92 |
|
| 93 |
(pass-if-exception "unknown target" exception:miscellaneous-error |
| 94 |
(with-target "fcpu-unknown-gnu1.0" |
| 95 |
(lambda () |
| 96 |
(compile '(ohai) #:warning-level 0 #:to 'bytecode))))) |
| 97 |
|
| 98 |
;; Local Variables: |
| 99 |
;; eval: (put 'with-target 'scheme-indent-function 1) |
| 100 |
;; End: |