aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarius Bakke <mbakke@fastmail.com>2018-08-25 16:44:07 +0200
committerMarius Bakke <mbakke@fastmail.com>2018-08-25 16:44:07 +0200
commit839167ff9d74fc490b32f6a197591964f73b65e5 (patch)
treed193bfad7c9ef5597c5cd7d2ea25fd007d01f88a /tests
parent27c1df05a866b639a61e16d48b3f2da8fa5eb767 (diff)
parent030c912616c8ee1595218e304460041bcb4f1ceb (diff)
downloadpatches-839167ff9d74fc490b32f6a197591964f73b65e5.tar
patches-839167ff9d74fc490b32f6a197591964f73b65e5.tar.gz
Merge branch 'staging' into core-updates
Diffstat (limited to 'tests')
-rw-r--r--tests/cpan.scm2
-rw-r--r--tests/debug-link.scm158
-rw-r--r--tests/gremlin.scm4
3 files changed, 161 insertions, 3 deletions
diff --git a/tests/cpan.scm b/tests/cpan.scm
index e5bd0ae3a4..396744e529 100644
--- a/tests/cpan.scm
+++ b/tests/cpan.scm
@@ -97,7 +97,7 @@
('propagated-inputs
('quasiquote
(("perl-test-script" ('unquote 'perl-test-script)))))
- ('home-page "http://search.cpan.org/dist/Foo-Bar/")
+ ('home-page "https://metacpan.org/release/Foo-Bar")
('synopsis "Fizzle Fuzz")
('description 'fill-in-yourself!)
('license 'perl-license))
diff --git a/tests/debug-link.scm b/tests/debug-link.scm
new file mode 100644
index 0000000000..2dde3cb460
--- /dev/null
+++ b/tests/debug-link.scm
@@ -0,0 +1,158 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix 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 General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (test-debug-link)
+ #:use-module (guix elf)
+ #:use-module (guix build utils)
+ #:use-module (guix build debug-link)
+ #:use-module (guix gexp)
+ #:use-module (guix store)
+ #:use-module (guix tests)
+ #:use-module (guix monads)
+ #:use-module (guix derivations)
+ #:use-module (gnu packages bootstrap)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-64)
+ #:use-module (rnrs io ports)
+ #:use-module (ice-9 match))
+
+(define %guile-executable
+ (match (false-if-exception (readlink "/proc/self/exe"))
+ ((? string? program)
+ (and (file-exists? program) (elf-file? program)
+ program))
+ (_
+ #f)))
+
+(define read-elf
+ (compose parse-elf get-bytevector-all))
+
+(define %store
+ (open-connection-for-tests))
+
+(define-syntax-rule (test-assertm name exp)
+ (test-assert name
+ (run-with-store %store exp
+ #:guile-for-build (%guile-for-build))))
+
+
+(test-begin "debug-link")
+
+(unless %guile-executable (test-skip 1))
+(test-assert "elf-debuglink"
+ (let ((elf (call-with-input-file %guile-executable read-elf)))
+ (match (call-with-values (lambda () (elf-debuglink elf)) list)
+ ((#f #f) ;no '.gnu_debuglink' section
+ (pk 'no-debuglink #t))
+ (((? string? file) (? integer? crc))
+ (string-suffix? ".debug" file)))))
+
+;; Since we need %BOOTSTRAP-GCC and co., we have to skip the following tests
+;; when networking is unreachable because we'd fail to download it.
+(unless (network-reachable?) (test-skip 1))
+(test-assertm "elf-debuglink"
+ ;; Check whether we can compute the CRC just like objcopy, and whether we
+ ;; can retrieve it.
+ (let* ((code (plain-file "test.c" "int main () { return 42; }"))
+ (exp (with-imported-modules '((guix build utils)
+ (guix build debug-link)
+ (guix elf))
+ #~(begin
+ (use-modules (guix build utils)
+ (guix build debug-link)
+ (guix elf)
+ (rnrs io ports))
+
+ (define read-elf
+ (compose parse-elf get-bytevector-all))
+
+ (setenv "PATH" (string-join '(#$%bootstrap-gcc
+ #$%bootstrap-binutils)
+ "/bin:" 'suffix))
+ (invoke "gcc" "-O0" "-g" #$code "-o" "exe")
+ (copy-file "exe" "exe.debug")
+ (invoke "strip" "--only-keep-debug" "exe.debug")
+ (invoke "strip" "--strip-debug" "exe")
+ (invoke "objcopy" "--add-gnu-debuglink=exe.debug"
+ "exe")
+ (call-with-values (lambda ()
+ (elf-debuglink
+ (call-with-input-file "exe"
+ read-elf)))
+ (lambda (file crc)
+ (call-with-output-file #$output
+ (lambda (port)
+ (let ((expected (call-with-input-file "exe.debug"
+ debuglink-crc32)))
+ (write (list file (= crc expected))
+ port))))))))))
+ (mlet* %store-monad ((drv (gexp->derivation "debuglink" exp))
+ (x (built-derivations (list drv))))
+ (call-with-input-file (derivation->output-path drv)
+ (lambda (port)
+ (return (match (read port)
+ (("exe.debug" #t) #t)
+ (x (pk 'fail x #f)))))))))
+
+(unless (network-reachable?) (test-skip 1))
+(test-assertm "set-debuglink-crc"
+ ;; Check whether 'set-debuglink-crc' successfully updates the CRC.
+ (let* ((code (plain-file "test.c" "int main () { return 42; }"))
+ (debug (plain-file "exe.debug" "a"))
+ (exp (with-imported-modules '((guix build utils)
+ (guix build debug-link)
+ (guix elf))
+ #~(begin
+ (use-modules (guix build utils)
+ (guix build debug-link)
+ (guix elf)
+ (rnrs io ports))
+
+ (define read-elf
+ (compose parse-elf get-bytevector-all))
+
+ (setenv "PATH" (string-join '(#$%bootstrap-gcc
+ #$%bootstrap-binutils)
+ "/bin:" 'suffix))
+ (invoke "gcc" "-O0" "-g" #$code "-o" "exe")
+ (copy-file "exe" "exe.debug")
+ (invoke "strip" "--only-keep-debug" "exe.debug")
+ (invoke "strip" "--strip-debug" "exe")
+ (invoke "objcopy" "--add-gnu-debuglink=exe.debug"
+ "exe")
+ (set-debuglink-crc "exe" #$debug)
+ (call-with-values (lambda ()
+ (elf-debuglink
+ (call-with-input-file "exe"
+ read-elf)))
+ (lambda (file crc)
+ (call-with-output-file #$output
+ (lambda (port)
+ (write (list file crc) port)))))))))
+ (mlet* %store-monad ((drv (gexp->derivation "debuglink" exp))
+ (x (built-derivations (list drv))))
+ (call-with-input-file (derivation->output-path drv)
+ (lambda (port)
+ (return (match (read port)
+ (("exe.debug" crc)
+ (= crc (debuglink-crc32 (open-input-string "a"))))
+ (x
+ (pk 'fail x #f)))))))))
+
+(test-end "debug-link")
diff --git a/tests/gremlin.scm b/tests/gremlin.scm
index 1b47d5c384..77a5dc1998 100644
--- a/tests/gremlin.scm
+++ b/tests/gremlin.scm
@@ -29,8 +29,8 @@
#:use-module (ice-9 match))
(define %guile-executable
- (match (command-line)
- ((program . _)
+ (match (false-if-exception (readlink "/proc/self/exe"))
+ ((? string? program)
(and (file-exists? program) (elf-file? program)
program))
(_