;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès ;;; Copyright © 2018 Clément Lassieur ;;; ;;; 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 shadow) #:use-module (gnu system nss) #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services base) #:use-module (gnu services dbus) #:use-module (gnu services avahi) #:use-module (gnu services mcron) #:use-module (gnu services shepherd) #:use-module (gnu services networking) #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages imagemagick) #:use-module (gnu packages ocr) #:use-module (gnu packages package-management) #:use-module (gnu packages linux) #:use-module (gnu packages tmux) #:use-module (guix gexp) #:use-module (guix store) #:use-module (guix monads) #:use-module (guix packages) #:use-module (srfi srfi-1) #:use-module (ice-9 match) #:export (run-basic-test %test-basic-os %test-halt %test-cleanup %test-mcron %test-nss-mdns)) (define %simple-os (simple-operating-system)) (define* (run-basic-test os command #:optional (name "basic") #:key initialization root-password desktop?) "Return a derivation called NAME that tests basic features of the OS started using COMMAND, a gexp that evaluates to a list of strings. Compare some properties of running system to what's declared in OS, an . When INITIALIZATION is true, it must be a one-argument procedure that is passed a gexp denoting the marionette, and it must return gexp that is inserted before the first test. This is used to introduce an extra initialization step, such as entering a LUKS passphrase. When ROOT-PASSWORD is true, enter it as the root password when logging in. Otherwise assume that there is no password for root." (define special-files (service-value (fold-services (operating-system-services os) #:target-type special-files-service-type))) (define guix&co (match (package-transitive-propagated-inputs guix) (((labels packages) ...) (cons guix packages)))) (define test (with-imported-modules '((gnu build marionette) (guix build syscalls)) #~(begin (use-modules (gnu build marionette) (guix build syscalls) (srfi srfi-1) (srfi srfi-26) (srfi srfi-64) (ice-9 match)) (define marionette (make-marionette #$command)) (mkdir #$output) (chdir #$output) (test-begin "basic") #$(and initialization (initialization #~marionette)) (test-assert "uname" (match (marionette-eval '(uname) marionette) (#("Linux" host-name version _ architecture) (and (string=? host-name #$(operating-system-host-name os)) (string-prefix? #$(package-version (operating-system-kernel os)) version) (string-prefix? architecture %host-type))))) ;; Shepherd reads the config file *before* binding its control ;; socket, so /var/run/shepherd/socket might not exist yet when the ;; 'marionette' service is started. (test-assert "shepherd socket ready" (marionette-eval `(begin (use-modules (gnu services herd)) (let loop ((i 10)) (cond ((file-exists? (%shepherd-socket-file)) #t) ((> i 0) (sleep 1) (loop (- i 1))) (else #f)))) marionette)) (test-eq "stdin is /dev/null" 'eof ;; Make sure services can no longer read from stdin once the ;; system has booted. (marionette-eval `(begin (use-modules (gnu services herd)) (start 'user-processes) ((@@ (gnu services herd) eval-there) '(let ((result (read (current-input-port)))) (if (eof-object? result) 'eof result)))) marionette)) (test-assert "shell and use