From 958dd3ce68733bcd5c1231424c7e4ad39e67594a Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 4 May 2016 17:35:47 +0200 Subject: utils: Move combinators to (guix combinators). * guix/utils.scm (compile-time-value, memoize, fold2) (fold-tree, fold-tree-leaves): Move to... * guix/combinators: ... here. New file. * tests/utils.scm ("fold2, 1 list", "fold2, 2 lists") (fold-tree tests): Move to... * tests/combinators.scm: ... here. New file. * Makefile.am (MODULES, SCM_TESTS): Add them. * gnu/packages.scm, gnu/packages/bootstrap.scm, gnu/services/herd.scm, guix/build-system/gnu.scm, guix/build-system/python.scm, guix/derivations.scm, guix/gnu-maintenance.scm, guix/import/elpa.scm, guix/scripts/archive.scm, guix/scripts/build.scm, guix/scripts/graph.scm, guix/scripts/lint.scm, guix/scripts/size.scm, guix/scripts/substitute.scm, guix/serialization.scm, guix/store.scm, guix/ui.scm: Adjust imports accordingly. --- Makefile.am | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Makefile.am') diff --git a/Makefile.am b/Makefile.am index d0c1826782..4685fe1650 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,7 @@ MODULES = \ guix/hash.scm \ guix/pk-crypto.scm \ guix/pki.scm \ + guix/combinators.scm \ guix/utils.scm \ guix/sets.scm \ guix/download.scm \ @@ -231,6 +232,7 @@ SCM_TESTS = \ tests/ui.scm \ tests/records.scm \ tests/upstream.scm \ + tests/combinators.scm \ tests/utils.scm \ tests/build-utils.scm \ tests/packages.scm \ -- cgit 1.4.1 From 4d9ed58498e3acb5bad1c5b862853f72bd3312aa Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 4 May 2016 17:49:32 +0200 Subject: build: Preserve stderr for shell tests. Fixes a regression introduced in a9edb211e733b8b34e67ec3b4450567e9376986f where the .log files of the .sh tests would not contain stderr. * build-aux/test-env.in: Redirect stderr only when --quiet-stderr is passed. * Makefile.am (SCM_LOG_DRIVER): Add --quiet-stderr. --- Makefile.am | 7 +++++-- build-aux/test-env.in | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'Makefile.am') diff --git a/Makefile.am b/Makefile.am index 4685fe1650..6e8dfd318f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -297,8 +297,11 @@ TESTS = $(SCM_TESTS) $(SH_TESTS) AM_TESTS_ENVIRONMENT = abs_top_srcdir="$(abs_top_srcdir)" GUILE_AUTO_COMPILE=0 -SCM_LOG_DRIVER = $(top_builddir)/test-env $(GUILE) --no-auto-compile \ - -e main $(top_srcdir)/build-aux/test-driver.scm +SCM_LOG_DRIVER = \ + $(top_builddir)/test-env --quiet-stderr \ + $(GUILE) --no-auto-compile -e main \ + $(top_srcdir)/build-aux/test-driver.scm + AM_SCM_LOG_DRIVER_FLAGS = --brief=yes SH_LOG_COMPILER = $(top_builddir)/test-env $(SHELL) diff --git a/build-aux/test-env.in b/build-aux/test-env.in index c3f60f7283..c153763a56 100644 --- a/build-aux/test-env.in +++ b/build-aux/test-env.in @@ -29,12 +29,18 @@ # stdout. unset CDPATH +case "$1" in + --quiet-stderr) + # Silence the daemon's output, which is often useless, as well as that + # of Bash (such as "Terminated" messages when 'guix-daemon' is + # killed.) + exec 2> /dev/null + shift + ;; +esac + if [ -x "@abs_top_builddir@/guix-daemon" ] then - # Silence the daemon's output, which is often useless, as well as that of - # Bash (such as "Terminated" messages when 'guix-daemon' is killed.) - exec 2> /dev/null - NIX_STORE_DIR="@GUIX_TEST_ROOT@/store" # Do that because store.scm calls `canonicalize-path' on it. -- cgit 1.4.1 From e9f693d06f94bd96488c3910dba6504f94a6b6f9 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 4 May 2016 23:33:59 +0200 Subject: tests: Add whole-system test. * gnu/system/vm.scm (virtualized-operating-system): Export. * gnu/tests/base.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. * Makefile.am (check-system): New target. --- Makefile.am | 7 +++ gnu/local.mk | 3 +- gnu/system/vm.scm | 1 + gnu/tests/base.scm | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 gnu/tests/base.scm (limited to 'Makefile.am') diff --git a/Makefile.am b/Makefile.am index 6e8dfd318f..e0be844bfd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -330,6 +330,13 @@ check-local: endif !CAN_RUN_TESTS +check-system: $(GOBJECTS) + $(AM_V_at)echo "Running system tests..." + $(AM_V_at)$(top_builddir)/pre-inst-env \ + $(GUILE) --no-auto-compile \ + -e '(@@ (run-system-tests) run-system-tests)' \ + $(top_srcdir)/build-aux/run-system-tests.scm + # Public key used to sign substitutes from hydra.gnu.org. dist_pkgdata_DATA = hydra.gnu.org.pub diff --git a/gnu/local.mk b/gnu/local.mk index d7797602e9..0292b39508 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -401,7 +401,8 @@ GNU_SYSTEM_MODULES = \ gnu/build/marionette.scm \ gnu/build/vm.scm \ \ - gnu/tests.scm + gnu/tests.scm \ + gnu/tests/base.scm patchdir = $(guilemoduledir)/gnu/packages/patches diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index e6ce42467a..676e89df98 100644 --- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -58,6 +58,7 @@ #:export (expression->derivation-in-linux-vm qemu-image + virtualized-operating-system system-qemu-image system-qemu-image/shared-store diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm new file mode 100644 index 0000000000..bf2d095709 --- /dev/null +++ b/gnu/tests/base.scm @@ -0,0 +1,168 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2016 Ludovic Courtès +;;; +;;; 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 . + +(define-module (gnu tests base) + #:use-module (gnu tests) + #:use-module (gnu system) + #:use-module (gnu system grub) + #:use-module (gnu system file-systems) + #:use-module (gnu system shadow) + #:use-module (gnu system vm) + #:use-module (gnu services) + #:use-module (gnu services shepherd) + #:use-module (guix gexp) + #:use-module (guix store) + #:use-module (guix monads) + #:use-module (guix packages) + #:use-module (srfi srfi-1) + #:export (%test-basic-os)) + +(define %simple-os + (operating-system + (host-name "komputilo") + (timezone "Europe/Berlin") + (locale "en_US.UTF-8") + + (bootloader (grub-configuration (device "/dev/sdX"))) + (file-systems (cons (file-system + (device "my-root") + (title 'label) + (mount-point "/") + (type "ext4")) + %base-file-systems)) + (firmware '()) + + (users (cons (user-account + (name "alice") + (comment "Bob's sister") + (group "users") + (supplementary-groups '("wheel" "audio" "video")) + (home-directory "/home/alice")) + %base-user-accounts)))) + + +(define %test-basic-os + ;; Monadic derivation that instruments %SIMPLE-OS, runs it in a VM, and runs + ;; a series of basic functionality tests. + (mlet* %store-monad ((os -> (marionette-operating-system + %simple-os + #:imported-modules '((gnu services herd) + (guix combinators)))) + (run (system-qemu-image/shared-store-script + os #:graphic? #f))) + (define test + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-1) + (srfi srfi-26) + (srfi srfi-64) + (ice-9 match)) + + (define marionette + (make-marionette (list #$run))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "basic") + + (test-assert "uname" + (match (marionette-eval '(uname) marionette) + (#("Linux" "komputilo" version _ "x86_64") + (string-prefix? #$(package-version + (operating-system-kernel os)) + version)))) + + (test-assert "shell and user commands" + ;; Is everything in $PATH? + (zero? (marionette-eval '(system " +. /etc/profile +set -e -x +guix --version +ls --version +grep --version +info --version") + marionette))) + + (test-assert "accounts" + (let ((users (marionette-eval '(begin + (use-modules (ice-9 match)) + (let loop ((result '())) + (match (getpw) + (#f (reverse result)) + (x (loop (cons x result)))))) + marionette))) + (lset= string=? + (map passwd:name users) + (list + #$@(map user-account-name + (operating-system-user-accounts os)))))) + + (test-assert "shepherd services" + (let ((services (marionette-eval '(begin + (use-modules (gnu services herd)) + (call-with-values current-services + append)) + marionette))) + (lset= eq? + (pk 'services services) + '(root #$@(operating-system-shepherd-service-names + (virtualized-operating-system os '())))))) + + (test-equal "login on tty1" + "root\n" + (begin + (marionette-control "sendkey ctrl-alt-f1" marionette) + ;; Wait for the 'term-tty1' service to be running + (marionette-eval + '(begin + (use-modules (gnu services herd)) + + (let loop ((i 0)) + (when (> i 10) + (error "terminal service not running" (current-services))) + (unless (memq 'term-tty1 (current-services)) + (sleep 1) + (loop (+ i 1))))) + marionette) + + ;; Now we can type. + (marionette-type "root\n\nid -un > logged-in\n" marionette) + + ;; It can take a while before the shell commands are executed. + (let loop ((i 0)) + (unless (or (file-exists? "/root/logged-in") (> i 15)) + (sleep 1) + (loop (+ i 1)))) + (marionette-eval '(use-modules (rnrs io ports)) marionette) + (marionette-eval '(call-with-input-file "/root/logged-in" + get-string-all) + marionette))) + + (test-assert "screendump" + (begin + (marionette-control (string-append "screendump " #$output + "/tty1.ppm") + marionette) + (file-exists? "tty1.ppm"))) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0)))) + + (gexp->derivation "basic" test + #:modules '((gnu build marionette))))) -- cgit 1.4.1 From 41c569d9b9c47ce8f2fb280f24c0a6d4e76f8bc7 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 4 May 2016 23:56:42 +0200 Subject: build: Add 'run-system-tests.scm'. This file was meant to be added as part of commit e9f693d06f94bd96488c3910dba6504f94a6b6f9. * build-aux/run-system-tests.scm: New file. * Makefile.am (EXTRA_DIST): Add it. --- Makefile.am | 1 + build-aux/run-system-tests.scm | 71 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 build-aux/run-system-tests.scm (limited to 'Makefile.am') diff --git a/Makefile.am b/Makefile.am index e0be844bfd..dfd486b256 100644 --- a/Makefile.am +++ b/Makefile.am @@ -361,6 +361,7 @@ EXTRA_DIST = \ build-aux/make-binary-tarball.scm \ build-aux/generate-authors.scm \ build-aux/test-driver.scm \ + build-aux/run-system-tests.scm \ srfi/srfi-37.scm.in \ srfi/srfi-64.scm \ srfi/srfi-64.upstream.scm \ diff --git a/build-aux/run-system-tests.scm b/build-aux/run-system-tests.scm new file mode 100644 index 0000000000..e98de9cb7e --- /dev/null +++ b/build-aux/run-system-tests.scm @@ -0,0 +1,71 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2016 Ludovic Courtès +;;; +;;; 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 . + +(define-module (run-system-tests) + #:use-module (gnu tests base) + #:use-module (guix store) + #:use-module (guix monads) + #:use-module (guix derivations) + #:use-module (guix ui) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-34) + #:export (run-system-tests)) + +(define (built-derivations* drv) + (lambda (store) + (guard (c ((nix-protocol-error? c) + (values #f store))) + (values (build-derivations store drv) store)))) + +(define (filterm mproc lst) ;XXX: move to (guix monads) + (with-monad %store-monad + (>>= (foldm %store-monad + (lambda (item result) + (mlet %store-monad ((keep? (mproc item))) + (return (if keep? + (cons item result) + result)))) + '() + lst) + (lift1 reverse %store-monad)))) + +(define %system-tests + (list %test-basic-os)) + +(define (run-system-tests . args) + (with-store store + (run-with-store store + (mlet* %store-monad ((drv (sequence %store-monad %system-tests)) + (out -> (map derivation->output-path drv))) + (mbegin %store-monad + (show-what-to-build* drv) + (set-build-options* #:keep-going? #t #:keep-failed? #t) + (built-derivations* drv) + (mlet %store-monad ((valid (filterm (store-lift valid-path?) + out)) + (failed (filterm (store-lift + (negate valid-path?)) + out))) + (format #t "TOTAL: ~a\n" (length drv)) + (for-each (lambda (item) + (format #t "PASS: ~a~%" item)) + valid) + (for-each (lambda (item) + (format #t "FAIL: ~a~%" item)) + failed) + (exit (null? failed)))))))) -- cgit 1.4.1