summaryrefslogtreecommitdiff
path: root/test-suite/tests/cross-compilation.test
blob: e520e02f47f961fadbd490e373bf6a8141935962 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;;; Cross compilation   -*- mode: scheme; coding: utf-8; -*-
;;;;
;;;; 	Copyright (C) 2010-2014, 2020, 2022 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;;
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

(define-module (tests cross-compilation)
  #:use-module (test-suite lib)
  #:use-module (rnrs bytevectors)
  #:use-module (system vm elf)
  #:use-module (system base compile)
  #:use-module (system base target))

(define (test-triplet cpu vendor os)
  (let ((triplet (string-append cpu "-" vendor "-" os)))
    (pass-if (format #f "triplet ~a" triplet)
      (with-target triplet
        (lambda ()
          (and (string=? (target-cpu) cpu)
               (string=? (target-vendor) vendor)
               (string=? (target-os) os)))))))

(define (native-cpu)
  (with-target %host-type target-cpu))

(define (native-os)
  (with-target %host-type target-os))

(define (native-word-size)
  ((@ (system foreign) sizeof) '*))

(define (test-target triplet endian word-size)
  (pass-if (format #f "target `~a' honored" triplet)
    (with-target triplet
      (lambda ()
        (let ((word-size
               ;; When the target is the native CPU, rather trust
               ;; the native CPU's word size.  This is because
               ;; Debian's `sparc64-linux-gnu' port, for instance,
               ;; actually has a 32-bit user-land, for instance (see
               ;; <http://www.debian.org/ports/sparc/#sparc64bit>
               ;; for details.)
               (if (and (string=? (native-cpu) (target-cpu))
                        (string=? (native-os) (target-os)))
                   (native-word-size)
                   word-size))
              (bv (compile '(hello-world) #:warning-level 0 #:to 'bytecode)))
          (and=> (parse-elf bv)
                 (lambda (elf)
                   (and (equal? (elf-byte-order elf) endian)
                        (equal? (elf-word-size elf) word-size)))))))))

(with-test-prefix "cross-compilation"

  (test-triplet "i586" "pc" "gnu0.3")
  (test-triplet "x86_64" "unknown" "linux-gnu")
  (test-triplet "x86_64" "unknown" "kfreebsd-gnu")
  (test-triplet "x86_64" "" "netbsd")   ;NetBSD/pkgsrc with empty vendor

  (test-target "i586-pc-gnu0.3" (endianness little) 4)
  (test-target "x86_64-pc-linux-gnu" (endianness little) 8)
  (test-target "powerpc-unknown-linux-gnu" (endianness big) 4)
  (test-target "sparc64-unknown-freebsd8.2" (endianness big) 8)
  (test-target "x86_64--netbsd" (endianness little) 8)

  (test-target "mips64el-unknown-linux-gnu"       ; n32 or o32 ABI
               (endianness little) 4)
  (test-target "mips64el-unknown-linux-gnuabi64"  ; n64 ABI (Debian tuplet)
               (endianness little) 8)
  (test-target "x86_64-unknown-linux-gnux32"      ; x32 ABI (Debian tuplet)
               (endianness little) 4)
  (test-target "arm-unknown-linux-androideabi"
               (endianness little) 4)
  (test-target "armeb-unknown-linux-gnu"
               (endianness big) 4)
  (test-target "aarch64-linux-gnu"
               (endianness little) 8)
  (test-target "aarch64_be-linux-gnu"
               (endianness big) 8)

  (pass-if-exception "unknown target" exception:miscellaneous-error
    (with-target "fcpu-unknown-gnu1.0"
      (lambda ()
        (compile '(ohai) #:warning-level 0 #:to 'bytecode)))))

;; Local Variables:
;; eval: (put 'with-target 'scheme-indent-function 1)
;; End: