diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2018-08-21 22:39:41 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2018-08-24 18:01:05 +0200 |
| commit | 93c333895a4e2dc9baabec8ade60d9d2ac0a91e2 (patch) | |
| tree | bcf3902e7435df4334792fa59e5039776ff4bba0 /tests | |
| parent | e4297aa8b95cefa32e2595ce58886fc03b0561f7 (diff) | |
grafts: Add (guix build debug-link) and use it.
Fixes <https://bugs.gnu.org/19973>.
Reported by Mark H Weaver <mhw@netris.org>.
* guix/build/debug-link.scm: New file.
* guix/build/graft.scm (%graft-hooks): New variable.
(graft): Add #:hooks and honor it.
* guix/grafts.scm (graft-derivation/shallow): Add (guix build
debug-link) and (guix elf) to #:modules.
* tests/debug-link.scm: New file.
* Makefile.am (MODULES): Add guix/build/debug-link.scm.
(SCM_TESTS): Add tests/debug-link.scm.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/debug-link.scm | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/tests/debug-link.scm b/tests/debug-link.scm new file mode 100644 index 00000000000..2dde3cb4607 --- /dev/null +++ b/tests/debug-link.scm | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 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 | |||
| 19 | (define-module (test-debug-link) | ||
| 20 | #:use-module (guix elf) | ||
| 21 | #:use-module (guix build utils) | ||
| 22 | #:use-module (guix build debug-link) | ||
| 23 | #:use-module (guix gexp) | ||
| 24 | #:use-module (guix store) | ||
| 25 | #:use-module (guix tests) | ||
| 26 | #:use-module (guix monads) | ||
| 27 | #:use-module (guix derivations) | ||
| 28 | #:use-module (gnu packages bootstrap) | ||
| 29 | #:use-module (srfi srfi-1) | ||
| 30 | #:use-module (srfi srfi-26) | ||
| 31 | #:use-module (srfi srfi-64) | ||
| 32 | #:use-module (rnrs io ports) | ||
| 33 | #:use-module (ice-9 match)) | ||
| 34 | |||
| 35 | (define %guile-executable | ||
| 36 | (match (false-if-exception (readlink "/proc/self/exe")) | ||
| 37 | ((? string? program) | ||
| 38 | (and (file-exists? program) (elf-file? program) | ||
| 39 | program)) | ||
| 40 | (_ | ||
| 41 | #f))) | ||
| 42 | |||
| 43 | (define read-elf | ||
| 44 | (compose parse-elf get-bytevector-all)) | ||
| 45 | |||
| 46 | (define %store | ||
| 47 | (open-connection-for-tests)) | ||
| 48 | |||
| 49 | (define-syntax-rule (test-assertm name exp) | ||
| 50 | (test-assert name | ||
| 51 | (run-with-store %store exp | ||
| 52 | #:guile-for-build (%guile-for-build)))) | ||
| 53 | |||
| 54 | |||
| 55 | (test-begin "debug-link") | ||
| 56 | |||
| 57 | (unless %guile-executable (test-skip 1)) | ||
| 58 | (test-assert "elf-debuglink" | ||
| 59 | (let ((elf (call-with-input-file %guile-executable read-elf))) | ||
| 60 | (match (call-with-values (lambda () (elf-debuglink elf)) list) | ||
| 61 | ((#f #f) ;no '.gnu_debuglink' section | ||
| 62 | (pk 'no-debuglink #t)) | ||
| 63 | (((? string? file) (? integer? crc)) | ||
| 64 | (string-suffix? ".debug" file))))) | ||
| 65 | |||
| 66 | ;; Since we need %BOOTSTRAP-GCC and co., we have to skip the following tests | ||
| 67 | ;; when networking is unreachable because we'd fail to download it. | ||
| 68 | (unless (network-reachable?) (test-skip 1)) | ||
| 69 | (test-assertm "elf-debuglink" | ||
| 70 | ;; Check whether we can compute the CRC just like objcopy, and whether we | ||
| 71 | ;; can retrieve it. | ||
| 72 | (let* ((code (plain-file "test.c" "int main () { return 42; }")) | ||
| 73 | (exp (with-imported-modules '((guix build utils) | ||
| 74 | (guix build debug-link) | ||
| 75 | (guix elf)) | ||
| 76 | #~(begin | ||
| 77 | (use-modules (guix build utils) | ||
| 78 | (guix build debug-link) | ||
| 79 | (guix elf) | ||
| 80 | (rnrs io ports)) | ||
| 81 | |||
| 82 | (define read-elf | ||
| 83 | (compose parse-elf get-bytevector-all)) | ||
| 84 | |||
| 85 | (setenv "PATH" (string-join '(#$%bootstrap-gcc | ||
| 86 | #$%bootstrap-binutils) | ||
| 87 | "/bin:" 'suffix)) | ||
| 88 | (invoke "gcc" "-O0" "-g" #$code "-o" "exe") | ||
| 89 | (copy-file "exe" "exe.debug") | ||
| 90 | (invoke "strip" "--only-keep-debug" "exe.debug") | ||
| 91 | (invoke "strip" "--strip-debug" "exe") | ||
| 92 | (invoke "objcopy" "--add-gnu-debuglink=exe.debug" | ||
| 93 | "exe") | ||
| 94 | (call-with-values (lambda () | ||
| 95 | (elf-debuglink | ||
| 96 | (call-with-input-file "exe" | ||
| 97 | read-elf))) | ||
| 98 | (lambda (file crc) | ||
| 99 | (call-with-output-file #$output | ||
| 100 | (lambda (port) | ||
| 101 | (let ((expected (call-with-input-file "exe.debug" | ||
| 102 | debuglink-crc32))) | ||
| 103 | (write (list file (= crc expected)) | ||
| 104 | port)))))))))) | ||
| 105 | (mlet* %store-monad ((drv (gexp->derivation "debuglink" exp)) | ||
| 106 | (x (built-derivations (list drv)))) | ||
| 107 | (call-with-input-file (derivation->output-path drv) | ||
| 108 | (lambda (port) | ||
| 109 | (return (match (read port) | ||
| 110 | (("exe.debug" #t) #t) | ||
| 111 | (x (pk 'fail x #f))))))))) | ||
| 112 | |||
| 113 | (unless (network-reachable?) (test-skip 1)) | ||
| 114 | (test-assertm "set-debuglink-crc" | ||
| 115 | ;; Check whether 'set-debuglink-crc' successfully updates the CRC. | ||
| 116 | (let* ((code (plain-file "test.c" "int main () { return 42; }")) | ||
| 117 | (debug (plain-file "exe.debug" "a")) | ||
| 118 | (exp (with-imported-modules '((guix build utils) | ||
| 119 | (guix build debug-link) | ||
| 120 | (guix elf)) | ||
| 121 | #~(begin | ||
| 122 | (use-modules (guix build utils) | ||
| 123 | (guix build debug-link) | ||
| 124 | (guix elf) | ||
| 125 | (rnrs io ports)) | ||
| 126 | |||
| 127 | (define read-elf | ||
| 128 | (compose parse-elf get-bytevector-all)) | ||
| 129 | |||
| 130 | (setenv "PATH" (string-join '(#$%bootstrap-gcc | ||
| 131 | #$%bootstrap-binutils) | ||
| 132 | "/bin:" 'suffix)) | ||
| 133 | (invoke "gcc" "-O0" "-g" #$code "-o" "exe") | ||
| 134 | (copy-file "exe" "exe.debug") | ||
| 135 | (invoke "strip" "--only-keep-debug" "exe.debug") | ||
| 136 | (invoke "strip" "--strip-debug" "exe") | ||
| 137 | (invoke "objcopy" "--add-gnu-debuglink=exe.debug" | ||
| 138 | "exe") | ||
| 139 | (set-debuglink-crc "exe" #$debug) | ||
| 140 | (call-with-values (lambda () | ||
| 141 | (elf-debuglink | ||
| 142 | (call-with-input-file "exe" | ||
| 143 | read-elf))) | ||
| 144 | (lambda (file crc) | ||
| 145 | (call-with-output-file #$output | ||
| 146 | (lambda (port) | ||
| 147 | (write (list file crc) port))))))))) | ||
| 148 | (mlet* %store-monad ((drv (gexp->derivation "debuglink" exp)) | ||
| 149 | (x (built-derivations (list drv)))) | ||
| 150 | (call-with-input-file (derivation->output-path drv) | ||
| 151 | (lambda (port) | ||
| 152 | (return (match (read port) | ||
| 153 | (("exe.debug" crc) | ||
| 154 | (= crc (debuglink-crc32 (open-input-string "a")))) | ||
| 155 | (x | ||
| 156 | (pk 'fail x #f))))))))) | ||
| 157 | |||
| 158 | (test-end "debug-link") | ||
