From d23077dc5ca1517bd6d1600664fe2303b86eb16c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 4 Dec 2012 23:16:11 +0100 Subject: daemon: Add test. * daemon.am (test_root, AM_TESTS_ENVIRONMENT): New variables. (clean-local): New target. * tests/guix-daemon.sh: New file. --- tests/guix-daemon.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/guix-daemon.sh (limited to 'tests') diff --git a/tests/guix-daemon.sh b/tests/guix-daemon.sh new file mode 100644 index 0000000000..d7926b2376 --- /dev/null +++ b/tests/guix-daemon.sh @@ -0,0 +1,46 @@ +# Guix --- Nix package management from Guile. -*- coding: utf-8 -*- +# Copyright (C) 2012 Ludovic Courtès +# +# This file is part of Guix. +# +# 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. +# +# 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 Guix. If not, see . + +# +# Test the daemon. +# + +set -e + +NIX_SUBSTITUTERS="" # don't resort to substituters +NIX_IGNORE_SYMLINK_STORE=1 # in case the store is a symlink +NIX_STORE_DIR="$TEST_ROOT/store" +NIX_LOCALSTATE_DIR="$TEST_ROOT/var" +NIX_LOG_DIR="$TEST_ROOT/var/log/nix" +NIX_STATE_DIR="$TEST_ROOT/var/nix" +NIX_DB_DIR="$TEST_ROOT/db" +export NIX_SUBSTITUTERS NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \ + NIX_LOCALSTATE_DIR NIX_LOG_DIR NIX_STATE_DIR NIX_DB_DIR + +guix-daemon --version +guix-build --version + +# Launch the daemon without chroot support because is may be +# unavailable, for instance if we're not running as root. +guix-daemon --disable-chroot & + +daemon_pid=$! +trap "kill $daemon_pid" EXIT + +guix-build -e '(@ (distro packages bootstrap) %bootstrap-guile)' +guix-build coreutils -n -- cgit v1.2.3 From f5c82e15e0e76b855bc4cc88ffb79331b7083f39 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 5 Dec 2012 16:29:28 +0100 Subject: daemon: Add `list-runtime-roots' script. * nix/scripts/list-runtime-roots.in: New file. * config-daemon.ac: Add `AC_CONFIG_FILES' invocation for it. * daemon.am (nodist_pkglibexec_SCRIPTS): New variable. (AM_TESTS_ENVIRONMENT): Define `top_builddir'. * tests/guix-daemon.sh: Export `NIX_ROOT_FINDER'. * nix/sync-with-upstream: Substitute the path to the root finder in libstore/gc.cc. --- .gitignore | 1 + config-daemon.ac | 3 + daemon.am | 4 ++ nix/scripts/list-runtime-roots.in | 116 ++++++++++++++++++++++++++++++++++++++ nix/sync-with-upstream | 4 ++ tests/guix-daemon.sh | 4 +- 6 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 nix/scripts/list-runtime-roots.in (limited to 'tests') diff --git a/.gitignore b/.gitignore index d39ad6ed96..3ef17152ba 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,4 @@ stamp-h[0-9] /libutil.a /guix-daemon /test-tmp +/nix/scripts/list-runtime-roots diff --git a/config-daemon.ac b/config-daemon.ac index a10be14632..946f6e453d 100644 --- a/config-daemon.ac +++ b/config-daemon.ac @@ -91,6 +91,9 @@ if test "x$guix_build_daemon" = "xyes"; then dnl Check for (for immutable file support). AC_CHECK_HEADERS([linux/fs.h]) + + AC_CONFIG_FILES([nix/scripts/list-runtime-roots], + [chmod +x nix/scripts/list-runtime-roots]) fi AM_CONDITIONAL([BUILD_DAEMON], [test "x$guix_build_daemon" = "xyes"]) diff --git a/daemon.am b/daemon.am index 48b0871a97..f5d58ea275 100644 --- a/daemon.am +++ b/daemon.am @@ -146,6 +146,9 @@ nix/libstore/schema.sql.hh: nix/libstore/schema.sql (lambda (in) \ (write (get-string-all in) out)))))" +nodist_pkglibexec_SCRIPTS = \ + nix/scripts/list-runtime-roots + EXTRA_DIST += \ nix/sync-with-upstream \ nix/libstore/schema.sql \ @@ -156,6 +159,7 @@ EXTRA_DIST += \ test_root = $(abs_top_builddir)/test-tmp AM_TESTS_ENVIRONMENT += \ + top_builddir="$(abs_top_builddir)" \ TEST_ROOT="$(test_root)" TESTS += \ diff --git a/nix/scripts/list-runtime-roots.in b/nix/scripts/list-runtime-roots.in new file mode 100644 index 0000000000..5c21ae543d --- /dev/null +++ b/nix/scripts/list-runtime-roots.in @@ -0,0 +1,116 @@ +#!@GUILE@ -ds +!# +;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*- +;;; Copyright (C) 2012 Ludovic Courtès +;;; +;;; This file is part of Guix. +;;; +;;; 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. +;;; +;;; 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 Guix. If not, see . + +;;; +;;; List files being used at run time; these files are garbage collector +;;; roots. This is equivalent to `find-runtime-roots.pl' in Nix. +;;; + +(use-modules (ice-9 ftw) + (ice-9 regex) + (ice-9 rdelim) + (ice-9 popen) + (srfi srfi-1) + (srfi srfi-26)) + +(define %proc-directory + ;; Mount point of Linuxish /proc file system. + "/proc") + +(define (proc-file-roots dir file) + "Return a one-element list containing the file pointed to by DIR/FILE, +or the empty list." + (or (and=> (false-if-exception (readlink (string-append dir "/" file))) + list) + '())) + +(define proc-exe-roots (cut proc-file-roots <> "exe")) +(define proc-cwd-roots (cut proc-file-roots <> "cwd")) + +(define (proc-fd-roots dir) + "Return the list of store files referenced by DIR, which is a +/proc/XYZ directory." + (let ((dir (string-append dir "/fd"))) + (filter-map (lambda (file) + (let ((target (false-if-exception + (readlink (string-append dir "/" file))))) + (and target + (string-prefix? "/" target) + target))) + (scandir dir string->number)))) + +(define (proc-maps-roots dir) + "Return the list of store files referenced by DIR, which is a +/proc/XYZ directory." + (define %file-mapping-line + (make-regexp "^.*[[:blank:]]+/([^ ]+)$")) + + (call-with-input-file (string-append dir "/maps") + (lambda (maps) + (let loop ((line (read-line maps)) + (roots '())) + (cond ((eof-object? line) + roots) + ((regexp-exec %file-mapping-line line) + => + (lambda (match) + (let ((file (string-append "/" + (match:substring match 1)))) + (loop (read-line maps) + (cons file roots))))) + (else + (loop (read-line maps) roots))))))) + +(define (lsof-roots) + "Return the list of roots as found by calling `lsof'." + (catch 'system + (lambda () + (let ((pipe (open-pipe* OPEN_READ "lsof" "-n" "-w" "-F" "n"))) + (define %file-rx + (make-regexp "^n/(.*)$")) + + (let loop ((line (read-line pipe)) + (roots '())) + (cond ((eof-object? line) + (begin + (close-pipe pipe) + roots)) + ((regexp-exec %file-rx line) + => + (lambda (match) + (loop (read-line pipe) + (cons (string-append "/" + (match:substring match 1)) + roots)))) + (else + (loop (read-line pipe) roots)))))) + (lambda _ + '()))) + +(let ((proc (format #f "~a/~a" %proc-directory (getpid)))) + (for-each (cut simple-format #t "~a~%" <>) + (delete-duplicates + (let ((proc-roots (if (file-exists? proc) + (append (proc-exe-roots proc) + (proc-cwd-roots proc) + (proc-fd-roots proc) + (proc-maps-roots proc)) + '()))) + (append proc-roots (lsof-roots)))))) diff --git a/nix/sync-with-upstream b/nix/sync-with-upstream index 324dcb27c9..69bd1fbee7 100755 --- a/nix/sync-with-upstream +++ b/nix/sync-with-upstream @@ -62,3 +62,7 @@ do done cp -v "$top_srcdir/nix-upstream/"{COPYING,AUTHORS} "$top_srcdir/nix" + +# Substitutions. +sed -i "$top_srcdir/nix/libstore/gc.cc" \ + -e 's|/nix/find-runtime-roots\.pl|/guix/list-runtime-roots|g' diff --git a/tests/guix-daemon.sh b/tests/guix-daemon.sh index d7926b2376..b6b92a78d4 100644 --- a/tests/guix-daemon.sh +++ b/tests/guix-daemon.sh @@ -29,8 +29,10 @@ NIX_LOCALSTATE_DIR="$TEST_ROOT/var" NIX_LOG_DIR="$TEST_ROOT/var/log/nix" NIX_STATE_DIR="$TEST_ROOT/var/nix" NIX_DB_DIR="$TEST_ROOT/db" +NIX_ROOT_FINDER="$top_builddir/nix/scripts/list-runtime-roots" export NIX_SUBSTITUTERS NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \ - NIX_LOCALSTATE_DIR NIX_LOG_DIR NIX_STATE_DIR NIX_DB_DIR + NIX_LOCALSTATE_DIR NIX_LOG_DIR NIX_STATE_DIR NIX_DB_DIR \ + NIX_ROOT_FINDER guix-daemon --version guix-build --version -- cgit v1.2.3 From b980f0f9fd6f926f2a1130f77bd3cdb70e741429 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 5 Dec 2012 22:41:58 +0100 Subject: tests: Remove hard-coded /nix/store. * tests/utils.scm ("store-path-package-name"): Use (%store-prefix) instead of a hard-coded "/nix/store". --- tests/utils.scm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/utils.scm b/tests/utils.scm index 0a6e8a0833..ba04e281eb 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -18,7 +18,7 @@ (define-module (test-utils) #:use-module (guix utils) - #:use-module ((guix store) #:select (store-path-package-name)) + #:use-module ((guix store) #:select (%store-prefix store-path-package-name)) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-64) @@ -127,7 +127,8 @@ (test-equal "store-path-package-name" "bash-4.2-p24" (store-path-package-name - "/nix/store/qvs2rj2ia5vci3wsdb7qvydrmacig4pg-bash-4.2-p24")) + (string-append (%store-prefix) + "/qvs2rj2ia5vci3wsdb7qvydrmacig4pg-bash-4.2-p24"))) (test-end) -- cgit v1.2.3 From 69cfce50dbb2000c5f5d98f0f364fe324004bf99 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 6 Dec 2012 00:03:26 +0100 Subject: build: Run all the tests against the just-built daemon. * test-env.in: New file. * configure.ac: Add it to `AC_CONFIG_FILES' and `commands-exec'. * config-daemon.ac: Set and substitute `GUIX_TEST_ROOT'. * Makefile.am (SCM_LOG_COMPILER, SH_LOG_COMPILER): Use it in lieu of `pre-inst-env'. * daemon.am (test_root): Remove (AM_TESTS_ENVIRONMENT): Remove `TEST_ROOT'. (clean-local): Use $(GUIX_TEST_ROOT); make files writable before removing them.guix_test_root * tests/guix-daemon.sh: Remove `NIX_' variable settings; don't launch `guix-daemon'. --- .gitignore | 1 + Makefile.am | 4 ++-- config-daemon.ac | 6 ++++++ configure.ac | 5 +++-- daemon.am | 9 +++------ test-env.in | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/guix-daemon.sh | 19 ------------------- 7 files changed, 68 insertions(+), 29 deletions(-) create mode 100644 test-env.in (limited to 'tests') diff --git a/.gitignore b/.gitignore index 3ef17152ba..8f224467c9 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ stamp-h[0-9] /guix-daemon /test-tmp /nix/scripts/list-runtime-roots +/test-env diff --git a/Makefile.am b/Makefile.am index 101ac1dfdb..bb5dfbe0f9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -181,10 +181,10 @@ TEST_EXTENSIONS = .scm .sh AM_TESTS_ENVIRONMENT = abs_top_srcdir="$(abs_top_srcdir)" -SCM_LOG_COMPILER = $(top_builddir)/pre-inst-env $(GUILE) +SCM_LOG_COMPILER = $(top_builddir)/test-env $(GUILE) AM_SCM_LOG_FLAGS = --no-auto-compile -L "$(top_srcdir)" -SH_LOG_COMPILER = $(top_builddir)/pre-inst-env $(SHELL) +SH_LOG_COMPILER = $(top_builddir)/test-env $(SHELL) AM_SH_LOG_FLAGS = -x -e EXTRA_DIST = \ diff --git a/config-daemon.ac b/config-daemon.ac index 946f6e453d..edd372fba9 100644 --- a/config-daemon.ac +++ b/config-daemon.ac @@ -92,6 +92,12 @@ if test "x$guix_build_daemon" = "xyes"; then dnl Check for (for immutable file support). AC_CHECK_HEADERS([linux/fs.h]) + dnl Temporary directory used to store the daemon's data. + AC_MSG_CHECKING([for unit test root]) + GUIX_TEST_ROOT="`pwd`/test-tmp" + AC_MSG_RESULT([$GUIX_TEST_ROOT]) + AC_SUBST([GUIX_TEST_ROOT]) + AC_CONFIG_FILES([nix/scripts/list-runtime-roots], [chmod +x nix/scripts/list-runtime-roots]) fi diff --git a/configure.ac b/configure.ac index 6c7be59895..5509735d8e 100644 --- a/configure.ac +++ b/configure.ac @@ -104,9 +104,10 @@ AC_CONFIG_FILES([Makefile guix-download guix-import guix-package - pre-inst-env]) + pre-inst-env + test-env]) AC_CONFIG_COMMANDS([commands-exec], - [chmod +x guix-build guix-download guix-import guix-package pre-inst-env]) + [chmod +x guix-build guix-download guix-import guix-package pre-inst-env test-env]) AC_OUTPUT diff --git a/daemon.am b/daemon.am index f5d58ea275..8c2c22dd88 100644 --- a/daemon.am +++ b/daemon.am @@ -155,15 +155,12 @@ EXTRA_DIST += \ nix/AUTHORS \ nix/COPYING -# Temporary directory used to store the daemon's data. -test_root = $(abs_top_builddir)/test-tmp - AM_TESTS_ENVIRONMENT += \ - top_builddir="$(abs_top_builddir)" \ - TEST_ROOT="$(test_root)" + top_builddir="$(abs_top_builddir)" TESTS += \ tests/guix-daemon.sh clean-local: - -rm -rf "$(test_root)" + -find "$(GUIX_TEST_ROOT)" | xargs chmod +w + -rm -rf "$(GUIX_TEST_ROOT)" diff --git a/test-env.in b/test-env.in new file mode 100644 index 0000000000..9eb03dd498 --- /dev/null +++ b/test-env.in @@ -0,0 +1,53 @@ +#!/bin/sh + +# Guix --- Nix package management from Guile. -*- coding: utf-8 -*- +# Copyright (C) 2012 Ludovic Courtès +# +# This file is part of Guix. +# +# 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. +# +# 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 Guix. If not, see . + +# Usage: ./test-env COMMAND ARG... +# +# Run the daemon in the build directory, and run COMMAND within +# `pre-inst-env'. This is used to run unit tests with the just-built +# daemon, unless `--disable-daemon' was passed at configure time. + +if [ -x "@abs_top_builddir@/guix-daemon" ] +then + NIX_SUBSTITUTERS="" # don't resort to substituters + NIX_IGNORE_SYMLINK_STORE=1 # in case the store is a symlink + NIX_STORE_DIR="@GUIX_TEST_ROOT@/store" + NIX_LOCALSTATE_DIR="@GUIX_TEST_ROOT@/var" + NIX_LOG_DIR="@GUIX_TEST_ROOT@/var/log/nix" + NIX_STATE_DIR="@GUIX_TEST_ROOT@/var/nix-$$" # allow for parallel tests + NIX_DB_DIR="@GUIX_TEST_ROOT@/db" + NIX_ROOT_FINDER="@abs_top_builddir@/nix/scripts/list-runtime-roots" + export NIX_SUBSTITUTERS NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \ + NIX_LOCALSTATE_DIR NIX_LOG_DIR NIX_STATE_DIR NIX_DB_DIR \ + NIX_ROOT_FINDER + + # Do that because store.scm calls `canonicalize-path' on it. + mkdir -p "$NIX_STORE_DIR" + + # Launch the daemon without chroot support because is may be + # unavailable, for instance if we're not running as root. + "@abs_top_builddir@/guix-daemon" --disable-chroot & + + daemon_pid=$! + trap "kill $daemon_pid ; rm -rf $NIX_STATE_DIR" EXIT +fi + +"@abs_top_builddir@/pre-inst-env" "$@" +exit $? diff --git a/tests/guix-daemon.sh b/tests/guix-daemon.sh index b6b92a78d4..b942cbd546 100644 --- a/tests/guix-daemon.sh +++ b/tests/guix-daemon.sh @@ -22,27 +22,8 @@ set -e -NIX_SUBSTITUTERS="" # don't resort to substituters -NIX_IGNORE_SYMLINK_STORE=1 # in case the store is a symlink -NIX_STORE_DIR="$TEST_ROOT/store" -NIX_LOCALSTATE_DIR="$TEST_ROOT/var" -NIX_LOG_DIR="$TEST_ROOT/var/log/nix" -NIX_STATE_DIR="$TEST_ROOT/var/nix" -NIX_DB_DIR="$TEST_ROOT/db" -NIX_ROOT_FINDER="$top_builddir/nix/scripts/list-runtime-roots" -export NIX_SUBSTITUTERS NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \ - NIX_LOCALSTATE_DIR NIX_LOG_DIR NIX_STATE_DIR NIX_DB_DIR \ - NIX_ROOT_FINDER - guix-daemon --version guix-build --version -# Launch the daemon without chroot support because is may be -# unavailable, for instance if we're not running as root. -guix-daemon --disable-chroot & - -daemon_pid=$! -trap "kill $daemon_pid" EXIT - guix-build -e '(@ (distro packages bootstrap) %bootstrap-guile)' guix-build coreutils -n -- cgit v1.2.3 From 29833b26eba0b02fd25d84b9999be3048c3f60d3 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 6 Dec 2012 00:05:11 +0100 Subject: build: Update skip count in `tests/derivations.scm'. * tests/derivations.scm: When %STORE if #f, skip 11 tests. --- tests/derivations.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/derivations.scm b/tests/derivations.scm index 14e1863a12..203bd9032f 100644 --- a/tests/derivations.scm +++ b/tests/derivations.scm @@ -76,7 +76,7 @@ (and (equal? b1 b2) (equal? d1 d2)))) -(test-skip (if %store 0 4)) +(test-skip (if %store 0 11)) (test-assert "add-to-store, flat" (let* ((file (search-path %load-path "language/tree-il/spec.scm")) -- cgit v1.2.3 From fdb50f8d8aba87e48c00a9633ed3e43b13792c3e Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 13 Dec 2012 00:23:20 +0100 Subject: tests: base32: Work around `system*' bug. * tests/base32.scm (%nix-hash): When `getenv' returns the empty string, ignore it. (%have-nix-hash?): New variable. Update `test-skip' clause to use it. --- tests/base32.scm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/base32.scm b/tests/base32.scm index b8b9ebb0dd..d1bbaa1764 100644 --- a/tests/base32.scm +++ b/tests/base32.scm @@ -23,15 +23,24 @@ #:use-module (srfi srfi-64) #:use-module (ice-9 rdelim) #:use-module (ice-9 popen) + #:use-module (ice-9 match) #:use-module (rnrs bytevectors) #:use-module (rnrs io ports)) ;; Test the (guix base32) module. (define %nix-hash - (or (getenv "NIX_HASH") + (or (and=> (getenv "NIX_HASH") + (match-lambda + ("" #f) + (val val))) "nix-hash")) +(define %have-nix-hash? + ;; Note: Use `system', not `system*', because of . + (false-if-exception + (zero? (system (string-append %nix-hash " --version"))))) + (test-begin "base32") (test-assert "bytevector->base32-string" @@ -67,10 +76,9 @@ ;; Examples from RFC 4648. (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar")))) -;; The following tests requires `nix-hash' in $PATH. -(test-skip (if (false-if-exception (system* %nix-hash "--version")) - 0 - 1)) +;; The following test requires `nix-hash' in $PATH. +(unless %have-nix-hash? + (test-skip 1)) (test-assert "sha256 & bytevector->nix-base32-string" (let ((file (search-path %load-path "tests/test.drv"))) -- cgit v1.2.3 From ad1ebab379dbd68e006197e8609c67de4734dbde Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 13 Dec 2012 22:06:45 +0100 Subject: tests: Skip network-dependent tests when the network is unreachable. * tests/builders.scm (network-reachable?): New variable. ("url-fetch", "gnu-build"): Skip unless NETWORK-REACHABLE?. * tests/derivations.scm (%coreutils): Check for network access. ("build-expression->derivation with one input"): Skip when %COREUTILS is #f. * tests/guix-package.sh: Skip installation of GNU Make when the network is unreachable. * tests/packages.scm ("GNU Make, bootstrap"): Likewise. * tests/union.scm ("union-build"): Likewise. --- tests/builders.scm | 5 +++++ tests/derivations.scm | 6 ++++-- tests/guix-package.sh | 46 +++++++++++++++++++++++++--------------------- tests/packages.scm | 2 ++ tests/union.scm | 6 +++++- 5 files changed, 41 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/builders.scm b/tests/builders.scm index 12841d5690..6035032d5d 100644 --- a/tests/builders.scm +++ b/tests/builders.scm @@ -50,9 +50,13 @@ (list name (package-derivation %store package)))) (@@ (distro packages base) %boot0-inputs)))) +(define network-reachable? + (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))) + (test-begin "builders") +(unless network-reachable? (test-skip 1)) (test-assert "url-fetch" (let* ((url '("http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz" "ftp://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz")) @@ -69,6 +73,7 @@ (and (build-system? gnu-build-system) (eq? gnu-build (build-system-builder gnu-build-system)))) +(unless network-reachable? (test-skip 1)) (test-assert "gnu-build" (let* ((url "http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz") (hash (nix-base32-string->bytevector diff --git a/tests/derivations.scm b/tests/derivations.scm index 203bd9032f..46bab4e19d 100644 --- a/tests/derivations.scm +++ b/tests/derivations.scm @@ -290,8 +290,9 @@ (define %coreutils (false-if-exception - (or (package-derivation %store %bootstrap-coreutils&co) - (nixpkgs-derivation "coreutils")))) + (and (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV) + (or (package-derivation %store %bootstrap-coreutils&co) + (nixpkgs-derivation "coreutils"))))) (test-skip (if %coreutils 0 1)) @@ -385,6 +386,7 @@ (and (equal? '(hello) (call-with-input-file one read)) (equal? '(world) (call-with-input-file two read))))))) +(test-skip (if %coreutils 0 1)) (test-assert "build-expression->derivation with one input" (let* ((builder '(call-with-output-file %output (lambda (p) diff --git a/tests/guix-package.sh b/tests/guix-package.sh index 2bc8c573ec..598ea62aaa 100644 --- a/tests/guix-package.sh +++ b/tests/guix-package.sh @@ -31,31 +31,35 @@ test -L "$profile" && test -L "$profile-1-link" test -f "$profile/bin/guile" -guix-package -b -p "$profile" \ - -i `guix-build -e '(@@ (distro packages base) gnu-make-boot0)'` -test -L "$profile-2-link" -test -f "$profile/bin/make" && test -f "$profile/bin/guile" +# Check whether we have network access. +if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null +then + guix-package -b -p "$profile" \ + -i `guix-build -e '(@@ (distro packages base) gnu-make-boot0)'` + test -L "$profile-2-link" + test -f "$profile/bin/make" && test -f "$profile/bin/guile" -# Check whether `--list-installed' works. -# XXX: Change the tests when `--install' properly extracts the package -# name and version string. -installed="`guix-package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`" -case "x$installed" in - "guile-bootstrap make-boot0") - true;; - "make-boot0 guile-bootstrap") - true;; - "*") - false;; -esac + # Check whether `--list-installed' works. + # XXX: Change the tests when `--install' properly extracts the package + # name and version string. + installed="`guix-package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`" + case "x$installed" in + "guile-bootstrap make-boot0") + true;; + "make-boot0 guile-bootstrap") + true;; + "*") + false;; + esac -test "`guix-package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap" + test "`guix-package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap" -# Remove a package. -guix-package -b -p "$profile" -r "guile-bootstrap-2.0" -test -L "$profile-3-link" -test -f "$profile/bin/make" && ! test -f "$profile/bin/guile" + # Remove a package. + guix-package -b -p "$profile" -r "guile-bootstrap-2.0" + test -L "$profile-3-link" + test -f "$profile/bin/make" && ! test -f "$profile/bin/guile" +fi # Make sure the `:' syntax works. guix-package -b -i "libsigsegv:lib" -n diff --git a/tests/packages.scm b/tests/packages.scm index c89f6e7721..5b0cd79b0f 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -125,6 +125,8 @@ (let ((p (pk 'drv d (derivation-path->output-path d)))) (eq? 'hello (call-with-input-file p read)))))) +(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)) + (test-skip 1)) (test-assert "GNU Make, bootstrap" ;; GNU Make is the first program built during bootstrap; we choose it ;; here so that the test doesn't last for too long. diff --git a/tests/union.scm b/tests/union.scm index 73b95c49b8..c839855ef4 100644 --- a/tests/union.scm +++ b/tests/union.scm @@ -64,7 +64,11 @@ (bin make) (share (doc (make README)))))) -(test-skip (if %store 0 1)) +(test-skip (if (and %store + (false-if-exception + (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))) + 0 + 1)) (test-assert "union-build" (let* ((inputs (map (match-lambda -- cgit v1.2.3