cross-compilation.test 3.9 KB

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