Commit | Line | Data |
---|---|---|
0afb26cc AW |
1 | ;;;; Cross compilation -*- mode: scheme; coding: utf-8; -*- |
2 | ;;;; | |
856d318a | 3 | ;;;; Copyright (C) 2010-2014 Free Software Foundation, Inc. |
0afb26cc AW |
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)) | |
691697de | 59 | (bv (compile '(hello-world) #:to 'bytecode))) |
0afb26cc AW |
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 | ||
71 | (test-target "i586-pc-gnu0.3" (endianness little) 4) | |
72 | (test-target "x86_64-pc-linux-gnu" (endianness little) 8) | |
73 | (test-target "powerpc-unknown-linux-gnu" (endianness big) 4) | |
74 | (test-target "sparc64-unknown-freebsd8.2" (endianness big) 8) | |
75 | ||
76 | (test-target "mips64el-unknown-linux-gnu" ; n32 or o32 ABI | |
77 | (endianness little) 4) | |
78 | (test-target "mips64el-unknown-linux-gnuabi64" ; n64 ABI (Debian tuplet) | |
79 | (endianness little) 8) | |
80 | (test-target "x86_64-unknown-linux-gnux32" ; x32 ABI (Debian tuplet) | |
81 | (endianness little) 4) | |
856d318a MW |
82 | (test-target "arm-unknown-linux-androideabi" |
83 | (endianness little) 4) | |
84 | (test-target "armeb-unknown-linux-gnu" | |
85 | (endianness big) 4) | |
86 | (test-target "aarch64-linux-gnu" | |
87 | (endianness little) 8) | |
88 | (test-target "aarch64_be-linux-gnu" | |
89 | (endianness big) 8) | |
0afb26cc AW |
90 | |
91 | (pass-if-exception "unknown target" exception:miscellaneous-error | |
92 | (with-target "fcpu-unknown-gnu1.0" | |
93 | (lambda () | |
691697de | 94 | (compile '(ohai) #:to 'bytecode))))) |
0afb26cc AW |
95 | |
96 | ;; Local Variables: | |
97 | ;; eval: (put 'with-target 'scheme-indent-function 1) | |
98 | ;; End: |