Commit | Line | Data |
---|---|---|
e9f693d0 LC |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2016 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 (gnu tests base) | |
20 | #:use-module (gnu tests) | |
21 | #:use-module (gnu system) | |
22 | #:use-module (gnu system grub) | |
23 | #:use-module (gnu system file-systems) | |
24 | #:use-module (gnu system shadow) | |
25 | #:use-module (gnu system vm) | |
26 | #:use-module (gnu services) | |
27 | #:use-module (gnu services shepherd) | |
28 | #:use-module (guix gexp) | |
29 | #:use-module (guix store) | |
30 | #:use-module (guix monads) | |
31 | #:use-module (guix packages) | |
32 | #:use-module (srfi srfi-1) | |
33 | #:export (%test-basic-os)) | |
34 | ||
35 | (define %simple-os | |
36 | (operating-system | |
37 | (host-name "komputilo") | |
38 | (timezone "Europe/Berlin") | |
39 | (locale "en_US.UTF-8") | |
40 | ||
41 | (bootloader (grub-configuration (device "/dev/sdX"))) | |
42 | (file-systems (cons (file-system | |
43 | (device "my-root") | |
44 | (title 'label) | |
45 | (mount-point "/") | |
46 | (type "ext4")) | |
47 | %base-file-systems)) | |
48 | (firmware '()) | |
49 | ||
50 | (users (cons (user-account | |
51 | (name "alice") | |
52 | (comment "Bob's sister") | |
53 | (group "users") | |
54 | (supplementary-groups '("wheel" "audio" "video")) | |
55 | (home-directory "/home/alice")) | |
56 | %base-user-accounts)))) | |
57 | ||
58 | \f | |
59 | (define %test-basic-os | |
60 | ;; Monadic derivation that instruments %SIMPLE-OS, runs it in a VM, and runs | |
61 | ;; a series of basic functionality tests. | |
62 | (mlet* %store-monad ((os -> (marionette-operating-system | |
63 | %simple-os | |
64 | #:imported-modules '((gnu services herd) | |
65 | (guix combinators)))) | |
66 | (run (system-qemu-image/shared-store-script | |
67 | os #:graphic? #f))) | |
68 | (define test | |
69 | #~(begin | |
70 | (use-modules (gnu build marionette) | |
71 | (srfi srfi-1) | |
72 | (srfi srfi-26) | |
73 | (srfi srfi-64) | |
74 | (ice-9 match)) | |
75 | ||
76 | (define marionette | |
77 | (make-marionette (list #$run))) | |
78 | ||
79 | (mkdir #$output) | |
80 | (chdir #$output) | |
81 | ||
82 | (test-begin "basic") | |
83 | ||
84 | (test-assert "uname" | |
85 | (match (marionette-eval '(uname) marionette) | |
86 | (#("Linux" "komputilo" version _ "x86_64") | |
87 | (string-prefix? #$(package-version | |
88 | (operating-system-kernel os)) | |
89 | version)))) | |
90 | ||
91 | (test-assert "shell and user commands" | |
92 | ;; Is everything in $PATH? | |
93 | (zero? (marionette-eval '(system " | |
94 | . /etc/profile | |
95 | set -e -x | |
96 | guix --version | |
97 | ls --version | |
98 | grep --version | |
99 | info --version") | |
100 | marionette))) | |
101 | ||
102 | (test-assert "accounts" | |
103 | (let ((users (marionette-eval '(begin | |
104 | (use-modules (ice-9 match)) | |
105 | (let loop ((result '())) | |
106 | (match (getpw) | |
107 | (#f (reverse result)) | |
108 | (x (loop (cons x result)))))) | |
109 | marionette))) | |
110 | (lset= string=? | |
111 | (map passwd:name users) | |
112 | (list | |
113 | #$@(map user-account-name | |
114 | (operating-system-user-accounts os)))))) | |
115 | ||
116 | (test-assert "shepherd services" | |
117 | (let ((services (marionette-eval '(begin | |
118 | (use-modules (gnu services herd)) | |
119 | (call-with-values current-services | |
120 | append)) | |
121 | marionette))) | |
122 | (lset= eq? | |
123 | (pk 'services services) | |
124 | '(root #$@(operating-system-shepherd-service-names | |
125 | (virtualized-operating-system os '())))))) | |
126 | ||
127 | (test-equal "login on tty1" | |
128 | "root\n" | |
129 | (begin | |
130 | (marionette-control "sendkey ctrl-alt-f1" marionette) | |
131 | ;; Wait for the 'term-tty1' service to be running | |
132 | (marionette-eval | |
133 | '(begin | |
134 | (use-modules (gnu services herd)) | |
135 | ||
136 | (let loop ((i 0)) | |
137 | (when (> i 10) | |
138 | (error "terminal service not running" (current-services))) | |
139 | (unless (memq 'term-tty1 (current-services)) | |
140 | (sleep 1) | |
141 | (loop (+ i 1))))) | |
142 | marionette) | |
143 | ||
144 | ;; Now we can type. | |
145 | (marionette-type "root\n\nid -un > logged-in\n" marionette) | |
146 | ||
147 | ;; It can take a while before the shell commands are executed. | |
148 | (let loop ((i 0)) | |
149 | (unless (or (file-exists? "/root/logged-in") (> i 15)) | |
150 | (sleep 1) | |
151 | (loop (+ i 1)))) | |
152 | (marionette-eval '(use-modules (rnrs io ports)) marionette) | |
153 | (marionette-eval '(call-with-input-file "/root/logged-in" | |
154 | get-string-all) | |
155 | marionette))) | |
156 | ||
157 | (test-assert "screendump" | |
158 | (begin | |
159 | (marionette-control (string-append "screendump " #$output | |
160 | "/tty1.ppm") | |
161 | marionette) | |
162 | (file-exists? "tty1.ppm"))) | |
163 | ||
164 | (test-end) | |
165 | (exit (= (test-runner-fail-count (test-runner-current)) 0)))) | |
166 | ||
167 | (gexp->derivation "basic" test | |
168 | #:modules '((gnu build marionette))))) |