Commit | Line | Data |
---|---|---|
15aa2c38 | 1 | ;;; GNU Guix --- Functional package management for GNU |
b178fc23 | 2 | ;;; Copyright © 2015, 2018 Ludovic Courtès <ludo@gnu.org> |
15aa2c38 LC |
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 | ||
19 | (define-module (test-gremlin) | |
20 | #:use-module (guix elf) | |
b178fc23 | 21 | #:use-module ((guix utils) #:select (call-with-temporary-directory)) |
15aa2c38 LC |
22 | #:use-module (guix build utils) |
23 | #:use-module (guix build gremlin) | |
24 | #:use-module (srfi srfi-1) | |
cd91504d | 25 | #:use-module (srfi srfi-26) |
15aa2c38 LC |
26 | #:use-module (srfi srfi-64) |
27 | #:use-module (rnrs io ports) | |
b178fc23 | 28 | #:use-module (ice-9 popen) |
15aa2c38 LC |
29 | #:use-module (ice-9 match)) |
30 | ||
31 | (define %guile-executable | |
f7dfda2c LC |
32 | (match (false-if-exception (readlink "/proc/self/exe")) |
33 | ((? string? program) | |
15aa2c38 LC |
34 | (and (file-exists? program) (elf-file? program) |
35 | program)) | |
36 | (_ | |
37 | #f))) | |
38 | ||
39 | (define read-elf | |
40 | (compose parse-elf get-bytevector-all)) | |
41 | ||
b178fc23 LC |
42 | (define c-compiler |
43 | (or (which "gcc") (which "cc") (which "g++"))) | |
44 | ||
15aa2c38 LC |
45 | \f |
46 | (test-begin "gremlin") | |
47 | ||
48 | (unless %guile-executable (test-skip 1)) | |
49 | (test-assert "elf-dynamic-info-needed, executable" | |
50 | (let* ((elf (call-with-input-file %guile-executable read-elf)) | |
51 | (dyninfo (elf-dynamic-info elf))) | |
52 | (or (not dyninfo) ;static executable | |
53 | (lset<= string=? | |
54 | (list (string-append "libguile-" (effective-version)) | |
6b974159 | 55 | "libc") |
15aa2c38 LC |
56 | (map (lambda (lib) |
57 | (string-take lib (string-contains lib ".so"))) | |
58 | (elf-dynamic-info-needed dyninfo)))))) | |
59 | ||
cd91504d LC |
60 | (test-equal "expand-origin" |
61 | '("OOO/../lib" | |
62 | "OOO" | |
63 | "../OOO/bar/OOO/baz" | |
64 | "ORIGIN/foo") | |
65 | (map (cut expand-origin <> "OOO") | |
66 | '("$ORIGIN/../lib" | |
67 | "${ORIGIN}" | |
68 | "../${ORIGIN}/bar/$ORIGIN/baz" | |
69 | "ORIGIN/foo"))) | |
70 | ||
b178fc23 LC |
71 | (unless c-compiler |
72 | (test-skip 1)) | |
73 | (test-equal "strip-runpath" | |
74 | "hello\n" | |
75 | (call-with-temporary-directory | |
76 | (lambda (directory) | |
77 | (with-directory-excursion directory | |
78 | (call-with-output-file "t.c" | |
79 | (lambda (port) | |
80 | (display "int main () { puts(\"hello\"); }" port))) | |
81 | (invoke c-compiler "t.c" | |
6b974159 | 82 | "-Wl,--enable-new-dtags" "-Wl,-rpath=/foo" "-Wl,-rpath=/bar") |
b178fc23 LC |
83 | (let* ((dyninfo (elf-dynamic-info |
84 | (parse-elf (call-with-input-file "a.out" | |
85 | get-bytevector-all)))) | |
86 | (old (elf-dynamic-info-runpath dyninfo)) | |
87 | (new (strip-runpath "a.out")) | |
88 | (new* (strip-runpath "a.out"))) | |
89 | (validate-needed-in-runpath "a.out") | |
90 | (and (member "/foo" old) (member "/bar" old) | |
91 | (not (member "/foo" new)) | |
92 | (not (member "/bar" new)) | |
93 | (equal? new* new) | |
94 | (let* ((pipe (open-input-pipe "./a.out")) | |
95 | (str (get-string-all pipe))) | |
96 | (close-pipe pipe) | |
97 | str))))))) | |
98 | ||
15aa2c38 | 99 | (test-end "gremlin") |