gremlin.scm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2018 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-gremlin)
  19. #:use-module (guix elf)
  20. #:use-module ((guix utils) #:select (call-with-temporary-directory))
  21. #:use-module (guix build utils)
  22. #:use-module (guix build gremlin)
  23. #:use-module (srfi srfi-1)
  24. #:use-module (srfi srfi-26)
  25. #:use-module (srfi srfi-64)
  26. #:use-module (rnrs io ports)
  27. #:use-module (ice-9 popen)
  28. #:use-module (ice-9 match))
  29. (define %guile-executable
  30. (match (false-if-exception (readlink "/proc/self/exe"))
  31. ((? string? program)
  32. (and (file-exists? program) (elf-file? program)
  33. program))
  34. (_
  35. #f)))
  36. (define read-elf
  37. (compose parse-elf get-bytevector-all))
  38. (define c-compiler
  39. (or (which "gcc") (which "cc") (which "g++")))
  40. (test-begin "gremlin")
  41. (unless %guile-executable (test-skip 1))
  42. (test-assert "elf-dynamic-info-needed, executable"
  43. (let* ((elf (call-with-input-file %guile-executable read-elf))
  44. (dyninfo (elf-dynamic-info elf)))
  45. (or (not dyninfo) ;static executable
  46. (lset<= string=?
  47. (list (string-append "libguile-" (effective-version))
  48. "libc")
  49. (map (lambda (lib)
  50. (string-take lib (string-contains lib ".so")))
  51. (elf-dynamic-info-needed dyninfo))))))
  52. (test-equal "expand-origin"
  53. '("OOO/../lib"
  54. "OOO"
  55. "../OOO/bar/OOO/baz"
  56. "ORIGIN/foo")
  57. (map (cut expand-origin <> "OOO")
  58. '("$ORIGIN/../lib"
  59. "${ORIGIN}"
  60. "../${ORIGIN}/bar/$ORIGIN/baz"
  61. "ORIGIN/foo")))
  62. (unless c-compiler
  63. (test-skip 1))
  64. (test-equal "strip-runpath"
  65. "hello\n"
  66. (call-with-temporary-directory
  67. (lambda (directory)
  68. (with-directory-excursion directory
  69. (call-with-output-file "t.c"
  70. (lambda (port)
  71. (display "int main () { puts(\"hello\"); }" port)))
  72. (invoke c-compiler "t.c"
  73. "-Wl,--enable-new-dtags" "-Wl,-rpath=/foo" "-Wl,-rpath=/bar")
  74. (let* ((dyninfo (elf-dynamic-info
  75. (parse-elf (call-with-input-file "a.out"
  76. get-bytevector-all))))
  77. (old (elf-dynamic-info-runpath dyninfo))
  78. (new (strip-runpath "a.out"))
  79. (new* (strip-runpath "a.out")))
  80. (validate-needed-in-runpath "a.out")
  81. (and (member "/foo" old) (member "/bar" old)
  82. (not (member "/foo" new))
  83. (not (member "/bar" new))
  84. (equal? new* new)
  85. (let* ((pipe (open-input-pipe "./a.out"))
  86. (str (get-string-all pipe)))
  87. (close-pipe pipe)
  88. str)))))))
  89. (test-end "gremlin")