Commit | Line | Data |
---|---|---|
e9f693d0 | 1 | ;;; GNU Guix --- Functional package management for GNU |
91ba90c1 | 2 | ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
c24b1547 | 3 | ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org> |
e9f693d0 LC |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
8 | ;;; under the terms of the GNU General Public License as published by | |
9 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
10 | ;;; your option) any later version. | |
11 | ;;; | |
12 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
13 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;;; GNU General Public License for more details. | |
16 | ;;; | |
17 | ;;; You should have received a copy of the GNU General Public License | |
18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | (define-module (gnu tests base) | |
21 | #:use-module (gnu tests) | |
22 | #:use-module (gnu system) | |
e9f693d0 | 23 | #:use-module (gnu system shadow) |
d2fa61bc | 24 | #:use-module (gnu system nss) |
e9f693d0 LC |
25 | #:use-module (gnu system vm) |
26 | #:use-module (gnu services) | |
d2fa61bc LC |
27 | #:use-module (gnu services base) |
28 | #:use-module (gnu services dbus) | |
29 | #:use-module (gnu services avahi) | |
c311089b | 30 | #:use-module (gnu services mcron) |
e9f693d0 | 31 | #:use-module (gnu services shepherd) |
d2fa61bc | 32 | #:use-module (gnu services networking) |
76c321d8 LC |
33 | #:use-module (gnu packages base) |
34 | #:use-module (gnu packages bash) | |
fe933833 LC |
35 | #:use-module (gnu packages imagemagick) |
36 | #:use-module (gnu packages ocr) | |
e2f9832f | 37 | #:use-module (gnu packages package-management) |
7f090203 LC |
38 | #:use-module (gnu packages linux) |
39 | #:use-module (gnu packages tmux) | |
e9f693d0 LC |
40 | #:use-module (guix gexp) |
41 | #:use-module (guix store) | |
76c321d8 | 42 | #:use-module (guix monads) |
e9f693d0 LC |
43 | #:use-module (guix packages) |
44 | #:use-module (srfi srfi-1) | |
4ab6a2f2 | 45 | #:use-module (ice-9 match) |
e3de272a | 46 | #:export (run-basic-test |
c311089b | 47 | %test-basic-os |
7f090203 | 48 | %test-halt |
76c321d8 | 49 | %test-cleanup |
d2fa61bc LC |
50 | %test-mcron |
51 | %test-nss-mdns)) | |
e9f693d0 LC |
52 | |
53 | (define %simple-os | |
892d9089 | 54 | (simple-operating-system)) |
e9f693d0 LC |
55 | |
56 | \f | |
f7f292d3 | 57 | (define* (run-basic-test os command #:optional (name "basic") |
6e71514a MO |
58 | #:key |
59 | initialization | |
60 | root-password | |
61 | desktop?) | |
e3de272a LC |
62 | "Return a derivation called NAME that tests basic features of the OS started |
63 | using COMMAND, a gexp that evaluates to a list of strings. Compare some | |
f7f292d3 LC |
64 | properties of running system to what's declared in OS, an <operating-system>. |
65 | ||
66 | When INITIALIZATION is true, it must be a one-argument procedure that is | |
67 | passed a gexp denoting the marionette, and it must return gexp that is | |
68 | inserted before the first test. This is used to introduce an extra | |
91ba90c1 LC |
69 | initialization step, such as entering a LUKS passphrase. |
70 | ||
71 | When ROOT-PASSWORD is true, enter it as the root password when logging in. | |
72 | Otherwise assume that there is no password for root." | |
387e1754 | 73 | (define special-files |
efe7d19a | 74 | (service-value |
387e1754 LC |
75 | (fold-services (operating-system-services os) |
76 | #:target-type special-files-service-type))) | |
77 | ||
4ab6a2f2 LC |
78 | (define guix&co |
79 | (match (package-transitive-propagated-inputs guix) | |
80 | (((labels packages) ...) | |
81 | (cons guix packages)))) | |
82 | ||
e3de272a | 83 | (define test |
caa78166 LC |
84 | (with-imported-modules '((gnu build marionette) |
85 | (guix build syscalls)) | |
4ee96a79 LC |
86 | #~(begin |
87 | (use-modules (gnu build marionette) | |
caa78166 | 88 | (guix build syscalls) |
4ee96a79 LC |
89 | (srfi srfi-1) |
90 | (srfi srfi-26) | |
91 | (srfi srfi-64) | |
92 | (ice-9 match)) | |
93 | ||
94 | (define marionette | |
95 | (make-marionette #$command)) | |
96 | ||
97 | (mkdir #$output) | |
98 | (chdir #$output) | |
99 | ||
100 | (test-begin "basic") | |
101 | ||
f7f292d3 LC |
102 | #$(and initialization |
103 | (initialization #~marionette)) | |
104 | ||
4ee96a79 LC |
105 | (test-assert "uname" |
106 | (match (marionette-eval '(uname) marionette) | |
107 | (#("Linux" host-name version _ architecture) | |
108 | (and (string=? host-name | |
109 | #$(operating-system-host-name os)) | |
110 | (string-prefix? #$(package-version | |
111 | (operating-system-kernel os)) | |
112 | version) | |
113 | (string-prefix? architecture %host-type))))) | |
114 | ||
3c78f5b5 LC |
115 | ;; Shepherd reads the config file *before* binding its control |
116 | ;; socket, so /var/run/shepherd/socket might not exist yet when the | |
117 | ;; 'marionette' service is started. | |
118 | (test-assert "shepherd socket ready" | |
119 | (marionette-eval | |
120 | `(begin | |
121 | (use-modules (gnu services herd)) | |
122 | (let loop ((i 10)) | |
123 | (cond ((file-exists? (%shepherd-socket-file)) | |
124 | #t) | |
125 | ((> i 0) | |
126 | (sleep 1) | |
127 | (loop (- i 1))) | |
128 | (else | |
129 | #f)))) | |
130 | marionette)) | |
131 | ||
6ea6e147 LC |
132 | (test-eq "stdin is /dev/null" |
133 | 'eof | |
134 | ;; Make sure services can no longer read from stdin once the | |
135 | ;; system has booted. | |
136 | (marionette-eval | |
137 | `(begin | |
138 | (use-modules (gnu services herd)) | |
139 | (start 'user-processes) | |
140 | ((@@ (gnu services herd) eval-there) | |
141 | '(let ((result (read (current-input-port)))) | |
142 | (if (eof-object? result) | |
143 | 'eof | |
144 | result)))) | |
145 | marionette)) | |
146 | ||
4ee96a79 LC |
147 | (test-assert "shell and user commands" |
148 | ;; Is everything in $PATH? | |
149 | (zero? (marionette-eval '(system " | |
e3de272a LC |
150 | . /etc/profile |
151 | set -e -x | |
152 | guix --version | |
153 | ls --version | |
154 | grep --version | |
155 | info --version") | |
4ee96a79 LC |
156 | marionette))) |
157 | ||
387e1754 LC |
158 | (test-equal "special files" |
159 | '#$special-files | |
160 | (marionette-eval | |
161 | '(begin | |
162 | (use-modules (ice-9 match)) | |
163 | ||
164 | (map (match-lambda | |
165 | ((file target) | |
166 | (list file (readlink file)))) | |
167 | '#$special-files)) | |
168 | marionette)) | |
169 | ||
4ee96a79 LC |
170 | (test-assert "accounts" |
171 | (let ((users (marionette-eval '(begin | |
172 | (use-modules (ice-9 match)) | |
173 | (let loop ((result '())) | |
174 | (match (getpw) | |
175 | (#f (reverse result)) | |
176 | (x (loop (cons x result)))))) | |
177 | marionette))) | |
b2979344 LC |
178 | (lset= equal? |
179 | (map (lambda (user) | |
180 | (list (passwd:name user) | |
181 | (passwd:dir user))) | |
182 | users) | |
4ee96a79 | 183 | (list |
b2979344 LC |
184 | #$@(map (lambda (account) |
185 | `(list ,(user-account-name account) | |
186 | ,(user-account-home-directory account))) | |
4ee96a79 LC |
187 | (operating-system-user-accounts os)))))) |
188 | ||
189 | (test-assert "shepherd services" | |
183605c8 LC |
190 | (let ((services (marionette-eval |
191 | '(begin | |
192 | (use-modules (gnu services herd)) | |
193 | ||
194 | (map (compose car live-service-provision) | |
195 | (current-services))) | |
196 | marionette))) | |
4ee96a79 LC |
197 | (lset= eq? |
198 | (pk 'services services) | |
199 | '(root #$@(operating-system-shepherd-service-names os))))) | |
200 | ||
d7113bb6 LC |
201 | (test-equal "/var/log/messages is not world-readable" |
202 | #o640 ;<https://bugs.gnu.org/40405> | |
203 | (begin | |
204 | (wait-for-file "/var/log/messages" marionette | |
205 | #:read 'get-u8) | |
206 | (marionette-eval '(stat:perms (lstat "/var/log/messages")) | |
207 | marionette))) | |
208 | ||
ae763b5b LC |
209 | (test-assert "homes" |
210 | (let ((homes | |
211 | '#$(map user-account-home-directory | |
212 | (filter user-account-create-home-directory? | |
213 | (operating-system-user-accounts os))))) | |
214 | (marionette-eval | |
215 | `(begin | |
216 | (use-modules (gnu services herd) (srfi srfi-1)) | |
217 | ||
218 | ;; Home directories are supposed to exist once 'user-homes' | |
219 | ;; has been started. | |
220 | (start-service 'user-homes) | |
221 | ||
222 | (every (lambda (home) | |
223 | (and (file-exists? home) | |
224 | (file-is-directory? home))) | |
225 | ',homes)) | |
226 | marionette))) | |
227 | ||
228 | (test-assert "skeletons in home directories" | |
cf98d342 | 229 | (let ((users+homes |
ae763b5b LC |
230 | '#$(filter-map (lambda (account) |
231 | (and (user-account-create-home-directory? | |
232 | account) | |
233 | (not (user-account-system? account)) | |
cf98d342 LC |
234 | (list (user-account-name account) |
235 | (user-account-home-directory | |
236 | account)))) | |
ae763b5b LC |
237 | (operating-system-user-accounts os)))) |
238 | (marionette-eval | |
239 | `(begin | |
f9d55c49 LC |
240 | (use-modules (guix build utils) (srfi srfi-1) |
241 | (ice-9 ftw) (ice-9 match)) | |
cf98d342 LC |
242 | |
243 | (every (match-lambda | |
244 | ((user home) | |
245 | ;; Make sure HOME has all the skeletons... | |
246 | (and (null? (lset-difference string=? | |
247 | (scandir "/etc/skel/") | |
248 | (scandir home))) | |
249 | ||
250 | ;; ... and that everything is user-owned. | |
251 | (let* ((pw (getpwnam user)) | |
252 | (uid (passwd:uid pw)) | |
253 | (gid (passwd:gid pw)) | |
254 | (st (lstat home))) | |
255 | (define (user-owned? file) | |
256 | (= uid (stat:uid (lstat file)))) | |
257 | ||
258 | (and (= uid (stat:uid st)) | |
259 | (eq? 'directory (stat:type st)) | |
260 | (every user-owned? | |
261 | (find-files home | |
262 | #:directories? #t))))))) | |
263 | ',users+homes)) | |
ae763b5b LC |
264 | marionette))) |
265 | ||
41db5a75 LC |
266 | (test-equal "permissions on /root" |
267 | #o700 | |
268 | (let ((root-home #$(any (lambda (account) | |
269 | (and (zero? (user-account-uid account)) | |
270 | (user-account-home-directory | |
271 | account))) | |
272 | (operating-system-user-accounts os)))) | |
273 | (stat:perms (marionette-eval `(stat ,root-home) marionette)))) | |
274 | ||
d429878d LC |
275 | (test-equal "ownership and permissions of /var/empty" |
276 | '(0 0 #o555) | |
277 | (let ((st (marionette-eval `(stat "/var/empty") marionette))) | |
278 | (list (stat:uid st) (stat:gid st) | |
279 | (stat:perms st)))) | |
280 | ||
41f76ae0 LC |
281 | (test-equal "no extra home directories" |
282 | '() | |
283 | ||
284 | ;; Make sure the home directories that are not supposed to be | |
285 | ;; created are indeed not created. | |
286 | (let ((nonexistent | |
287 | '#$(filter-map (lambda (user) | |
288 | (and (not | |
289 | (user-account-create-home-directory? | |
290 | user)) | |
291 | (user-account-home-directory user))) | |
292 | (operating-system-user-accounts os)))) | |
293 | (marionette-eval | |
294 | `(begin | |
295 | (use-modules (srfi srfi-1)) | |
296 | ||
297 | ;; Note: Do not flag "/var/empty". | |
298 | (filter file-exists? | |
299 | ',(remove (cut string-prefix? "/var/" <>) | |
300 | nonexistent))) | |
301 | marionette))) | |
302 | ||
4ee96a79 LC |
303 | (test-equal "login on tty1" |
304 | "root\n" | |
305 | (begin | |
6e71514a MO |
306 | ;; XXX: On desktop, GDM3 will switch to TTY7. If this happens |
307 | ;; after we switched to TTY1, we won't be able to login. Make | |
308 | ;; sure to wait long enough before switching to TTY1. | |
309 | (when #$desktop? | |
310 | (sleep 30)) | |
311 | ||
4ee96a79 LC |
312 | (marionette-control "sendkey ctrl-alt-f1" marionette) |
313 | ;; Wait for the 'term-tty1' service to be running (using | |
314 | ;; 'start-service' is the simplest and most reliable way to do | |
315 | ;; that.) | |
316 | (marionette-eval | |
317 | '(begin | |
318 | (use-modules (gnu services herd)) | |
319 | (start-service 'term-tty1)) | |
320 | marionette) | |
321 | ||
322 | ;; Now we can type. | |
91ba90c1 LC |
323 | (let ((password #$root-password)) |
324 | (if password | |
325 | (begin | |
326 | (marionette-type "root\n" marionette) | |
327 | (wait-for-screen-text marionette | |
328 | (lambda (text) | |
329 | (string-contains text "Password")) | |
330 | #:ocrad | |
331 | #$(file-append ocrad "/bin/ocrad")) | |
332 | (marionette-type (string-append password "\n\n") | |
333 | marionette)) | |
334 | (marionette-type "root\n\n" marionette))) | |
335 | (marionette-type "id -un > logged-in\n" marionette) | |
4ee96a79 LC |
336 | |
337 | ;; It can take a while before the shell commands are executed. | |
4ee96a79 | 338 | (marionette-eval '(use-modules (rnrs io ports)) marionette) |
13877c34 LC |
339 | (wait-for-file "/root/logged-in" marionette |
340 | #:read 'get-string-all))) | |
4ee96a79 | 341 | |
e6b1a224 LC |
342 | (test-equal "getlogin on tty1" |
343 | "\"root\"" | |
344 | (begin | |
345 | ;; Assume we logged in in the previous test and type. | |
8b310793 LC |
346 | (marionette-type "guile -c '(write (getlogin))' > /root/login-id.tmp\n" |
347 | marionette) | |
348 | (marionette-type "mv /root/login-id{.tmp,}\n" | |
e6b1a224 LC |
349 | marionette) |
350 | ||
351 | ;; It can take a while before the shell commands are executed. | |
352 | (marionette-eval '(use-modules (rnrs io ports)) marionette) | |
353 | (wait-for-file "/root/login-id" marionette | |
354 | #:read 'get-string-all))) | |
355 | ||
caa78166 LC |
356 | ;; There should be one utmpx entry for the user logged in on tty1. |
357 | (test-equal "utmpx entry" | |
358 | '(("root" "tty1" #f)) | |
359 | (marionette-eval | |
360 | '(begin | |
361 | (use-modules (guix build syscalls) | |
362 | (srfi srfi-1)) | |
363 | ||
364 | (filter-map (lambda (entry) | |
365 | (and (equal? (login-type USER_PROCESS) | |
366 | (utmpx-login-type entry)) | |
367 | (list (utmpx-user entry) (utmpx-line entry) | |
368 | (utmpx-host entry)))) | |
369 | (utmpx-entries))) | |
370 | marionette)) | |
371 | ||
2986995b LC |
372 | ;; Likewise for /var/log/wtmp (used by 'last'). |
373 | (test-assert "wtmp entry" | |
374 | (match (marionette-eval | |
375 | '(begin | |
376 | (use-modules (guix build syscalls) | |
377 | (srfi srfi-1)) | |
378 | ||
379 | (define (entry->list entry) | |
380 | (list (utmpx-user entry) (utmpx-line entry) | |
381 | (utmpx-host entry) (utmpx-login-type entry))) | |
382 | ||
383 | (call-with-input-file "/var/log/wtmp" | |
384 | (lambda (port) | |
385 | (let loop ((result '())) | |
386 | (if (eof-object? (peek-char port)) | |
387 | (map entry->list (reverse result)) | |
388 | (loop (cons (read-utmpx port) result))))))) | |
389 | marionette) | |
390 | (((users lines hosts types) ..1) | |
391 | (every (lambda (type) | |
392 | (eqv? type (login-type LOGIN_PROCESS))) | |
393 | types)))) | |
394 | ||
4ee96a79 LC |
395 | (test-assert "host name resolution" |
396 | (match (marionette-eval | |
397 | '(begin | |
398 | ;; Wait for nscd or our requests go through it. | |
399 | (use-modules (gnu services herd)) | |
400 | (start-service 'nscd) | |
401 | ||
402 | (list (getaddrinfo "localhost") | |
403 | (getaddrinfo #$(operating-system-host-name os)))) | |
404 | marionette) | |
405 | ((((? vector?) ..1) ((? vector?) ..1)) | |
406 | #t) | |
407 | (x | |
408 | (pk 'failure x #f)))) | |
409 | ||
d3f75179 LC |
410 | (test-equal "nscd invalidate action" |
411 | '(#t) ;one value, #t | |
412 | (marionette-eval '(with-shepherd-action 'nscd ('invalidate "hosts") | |
413 | result | |
414 | result) | |
415 | marionette)) | |
416 | ||
33572a36 LC |
417 | ;; FIXME: The 'invalidate' action can't reliably obtain the exit |
418 | ;; code of 'nscd' so skip this test. | |
419 | (test-skip 1) | |
d3f75179 LC |
420 | (test-equal "nscd invalidate action, wrong table" |
421 | '(#f) ;one value, #f | |
422 | (marionette-eval '(with-shepherd-action 'nscd ('invalidate "xyz") | |
423 | result | |
424 | result) | |
425 | marionette)) | |
426 | ||
4ee96a79 LC |
427 | (test-equal "host not found" |
428 | #f | |
e3de272a | 429 | (marionette-eval |
4ee96a79 LC |
430 | '(false-if-exception (getaddrinfo "does-not-exist")) |
431 | marionette)) | |
432 | ||
ab3a6450 LC |
433 | (test-equal "locale" |
434 | "en_US.utf8" | |
cc73339b LC |
435 | (marionette-eval '(let ((before (setlocale LC_ALL "en_US.utf8"))) |
436 | (setlocale LC_ALL before)) | |
ab3a6450 LC |
437 | marionette)) |
438 | ||
d5094c81 LC |
439 | (test-eq "/run/current-system is a GC root" |
440 | 'success! | |
40d28609 LC |
441 | (marionette-eval '(begin |
442 | ;; Make sure the (guix …) modules are found. | |
4ab6a2f2 LC |
443 | (eval-when (expand load eval) |
444 | (set! %load-path | |
445 | (append (map (lambda (package) | |
446 | (string-append package | |
447 | "/share/guile/site/" | |
448 | (effective-version))) | |
449 | '#$guix&co) | |
450 | %load-path))) | |
40d28609 LC |
451 | |
452 | (use-modules (srfi srfi-34) (guix store)) | |
453 | ||
454 | (let ((system (readlink "/run/current-system"))) | |
ba926e35 | 455 | (guard (c ((store-protocol-error? c) |
d5094c81 LC |
456 | (and (file-exists? system) |
457 | 'success!))) | |
40d28609 LC |
458 | (with-store store |
459 | (delete-paths store (list system)) | |
460 | #f)))) | |
461 | marionette)) | |
462 | ||
334bda9a LC |
463 | ;; This symlink is currently unused, but better have it point to the |
464 | ;; right place. See | |
465 | ;; <https://lists.gnu.org/archive/html/guix-devel/2016-08/msg01641.html>. | |
466 | (test-equal "/var/guix/gcroots/profiles is a valid symlink" | |
467 | "/var/guix/profiles" | |
468 | (marionette-eval '(readlink "/var/guix/gcroots/profiles") | |
469 | marionette)) | |
470 | ||
3302e03b LC |
471 | (test-equal "guix-daemon set-http-proxy action" |
472 | '(#t) ;one value, #t | |
473 | (marionette-eval '(with-shepherd-action 'guix-daemon | |
474 | ('set-http-proxy "http://localhost:8118") | |
475 | result | |
476 | result) | |
477 | marionette)) | |
478 | ||
479 | (test-equal "guix-daemon set-http-proxy action, clear" | |
480 | '(#t) ;one value, #t | |
481 | (marionette-eval '(with-shepherd-action 'guix-daemon | |
482 | ('set-http-proxy) | |
483 | result | |
484 | result) | |
485 | marionette)) | |
334bda9a | 486 | |
4ee96a79 LC |
487 | (test-assert "screendump" |
488 | (begin | |
489 | (marionette-control (string-append "screendump " #$output | |
490 | "/tty1.ppm") | |
491 | marionette) | |
492 | (file-exists? "tty1.ppm"))) | |
493 | ||
fe933833 LC |
494 | (test-assert "screen text" |
495 | (let ((text (marionette-screen-text marionette | |
496 | #:ocrad | |
497 | #$(file-append ocrad | |
498 | "/bin/ocrad")))) | |
499 | ;; Check whether the welcome message and shell prompt are | |
500 | ;; displayed. Note: OCR confuses "y" and "V" for instance, so | |
501 | ;; we cannot reliably match the whole text. | |
502 | (and (string-contains text "This is the GNU") | |
503 | (string-contains text | |
504 | (string-append | |
505 | "root@" | |
506 | #$(operating-system-host-name os)))))) | |
507 | ||
4ee96a79 LC |
508 | (test-end) |
509 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | |
510 | ||
511 | (gexp->derivation name test)) | |
e3de272a | 512 | |
e9f693d0 | 513 | (define %test-basic-os |
98b65b5f LC |
514 | (system-test |
515 | (name "basic") | |
516 | (description | |
125af57e | 517 | "Instrument %SIMPLE-OS, run it in a VM, and run a series of basic |
98b65b5f LC |
518 | functionality tests.") |
519 | (value | |
8b113790 LC |
520 | (let* ((os (marionette-operating-system |
521 | %simple-os | |
522 | #:imported-modules '((gnu services herd) | |
523 | (guix combinators)))) | |
524 | (vm (virtual-machine os))) | |
98b65b5f LC |
525 | ;; XXX: Add call to 'virtualized-operating-system' to get the exact same |
526 | ;; set of services as the OS produced by | |
527 | ;; 'system-qemu-image/shared-store-script'. | |
528 | (run-basic-test (virtualized-operating-system os '()) | |
8b113790 | 529 | #~(list #$vm)))))) |
c311089b LC |
530 | |
531 | \f | |
7f090203 LC |
532 | ;;; |
533 | ;;; Halt. | |
534 | ;;; | |
535 | ||
536 | (define (run-halt-test vm) | |
537 | ;; As reported in <http://bugs.gnu.org/26931>, running tmux would previously | |
538 | ;; lead the 'stop' method of 'user-processes' to an infinite loop, with the | |
539 | ;; tmux server process as a zombie that remains in the list of processes. | |
540 | ;; This test reproduces this scenario. | |
541 | (define test | |
542 | (with-imported-modules '((gnu build marionette)) | |
543 | #~(begin | |
544 | (use-modules (gnu build marionette)) | |
545 | ||
546 | (define marionette | |
547 | (make-marionette '(#$vm))) | |
548 | ||
549 | (define ocrad | |
550 | #$(file-append ocrad "/bin/ocrad")) | |
551 | ||
552 | ;; Wait for tty1 and log in. | |
553 | (marionette-eval '(begin | |
554 | (use-modules (gnu services herd)) | |
555 | (start-service 'term-tty1)) | |
556 | marionette) | |
557 | (marionette-type "root\n" marionette) | |
558 | (wait-for-screen-text marionette | |
559 | (lambda (text) | |
560 | (string-contains text "root@komputilo")) | |
561 | #:ocrad ocrad) | |
562 | ||
563 | ;; Start tmux and wait for it to be ready. | |
564 | (marionette-type "tmux new-session 'echo 1 > /ready; bash'\n" | |
565 | marionette) | |
566 | (wait-for-file "/ready" marionette) | |
567 | ||
568 | ;; Make sure to stop the test after a while. | |
569 | (sigaction SIGALRM (lambda _ | |
570 | (format (current-error-port) | |
571 | "FAIL: Time is up, but VM still running.\n") | |
572 | (primitive-exit 1))) | |
573 | (alarm 10) | |
574 | ||
575 | ;; Get debugging info. | |
576 | (marionette-eval '(current-output-port | |
577 | (open-file "/dev/console" "w0")) | |
578 | marionette) | |
579 | (marionette-eval '(system* #$(file-append procps "/bin/ps") | |
580 | "-eo" "pid,ppid,stat,comm") | |
581 | marionette) | |
582 | ||
583 | ;; See if 'halt' actually works. | |
584 | (marionette-eval '(system* "/run/current-system/profile/sbin/halt") | |
585 | marionette) | |
586 | ||
587 | ;; If we reach this line, that means the VM was properly stopped in | |
588 | ;; a timely fashion. | |
589 | (alarm 0) | |
590 | (call-with-output-file #$output | |
591 | (lambda (port) | |
592 | (display "success!" port)))))) | |
593 | ||
594 | (gexp->derivation "halt" test)) | |
595 | ||
596 | (define %test-halt | |
597 | (system-test | |
598 | (name "halt") | |
599 | (description | |
600 | "Use the 'halt' command and make sure it succeeds and does not get stuck | |
601 | in a loop. See <http://bugs.gnu.org/26931>.") | |
602 | (value | |
603 | (let ((os (marionette-operating-system | |
604 | (operating-system | |
605 | (inherit %simple-os) | |
606 | (packages (cons tmux %base-packages))) | |
607 | #:imported-modules '((gnu services herd) | |
608 | (guix combinators))))) | |
609 | (run-halt-test (virtual-machine os)))))) | |
610 | ||
611 | \f | |
76c321d8 LC |
612 | ;;; |
613 | ;;; Cleanup of /tmp, /var/run, etc. | |
614 | ;;; | |
615 | ||
616 | (define %cleanup-os | |
617 | (simple-operating-system | |
618 | (simple-service 'dirty-things | |
619 | boot-service-type | |
378daa8c LC |
620 | (let ((script (plain-file |
621 | "create-utf8-file.sh" | |
622 | (string-append | |
623 | "echo $0: dirtying /tmp...\n" | |
624 | "set -e; set -x\n" | |
625 | "touch /witness\n" | |
626 | "exec touch /tmp/λαμβδα")))) | |
627 | (with-imported-modules '((guix build utils)) | |
628 | #~(begin | |
629 | (setenv "PATH" | |
630 | #$(file-append coreutils "/bin")) | |
631 | (invoke #$(file-append bash "/bin/sh") | |
632 | #$script))))))) | |
76c321d8 LC |
633 | |
634 | (define (run-cleanup-test name) | |
635 | (define os | |
636 | (marionette-operating-system %cleanup-os | |
637 | #:imported-modules '((gnu services herd) | |
638 | (guix combinators)))) | |
639 | (define test | |
640 | (with-imported-modules '((gnu build marionette)) | |
641 | #~(begin | |
642 | (use-modules (gnu build marionette) | |
643 | (srfi srfi-64) | |
644 | (ice-9 match)) | |
645 | ||
646 | (define marionette | |
647 | (make-marionette (list #$(virtual-machine os)))) | |
648 | ||
649 | (mkdir #$output) | |
650 | (chdir #$output) | |
651 | ||
652 | (test-begin "cleanup") | |
653 | ||
654 | (test-assert "dirty service worked" | |
655 | (marionette-eval '(file-exists? "/witness") marionette)) | |
656 | ||
657 | (test-equal "/tmp cleaned up" | |
658 | '("." "..") | |
659 | (marionette-eval '(begin | |
660 | (use-modules (ice-9 ftw)) | |
661 | (scandir "/tmp")) | |
662 | marionette)) | |
663 | ||
664 | (test-end) | |
665 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | |
666 | ||
667 | (gexp->derivation "cleanup" test)) | |
668 | ||
669 | (define %test-cleanup | |
670 | ;; See <https://bugs.gnu.org/26353>. | |
671 | (system-test | |
672 | (name "cleanup") | |
673 | (description "Make sure the 'cleanup' service can remove files with | |
674 | non-ASCII names from /tmp.") | |
675 | (value (run-cleanup-test name)))) | |
676 | ||
677 | \f | |
c311089b LC |
678 | ;;; |
679 | ;;; Mcron. | |
680 | ;;; | |
681 | ||
682 | (define %mcron-os | |
683 | ;; System with an mcron service, with one mcron job for "root" and one mcron | |
cfbf6de1 | 684 | ;; job for an unprivileged user. |
67a51b67 | 685 | (let ((job1 #~(job '(next-second '(0 5 10 15 20 25 30 35 40 45 50 55)) |
c311089b | 686 | (lambda () |
67a51b67 LC |
687 | (unless (file-exists? "witness") |
688 | (call-with-output-file "witness" | |
689 | (lambda (port) | |
690 | (display (list (getuid) (getgid)) port))))))) | |
c311089b LC |
691 | (job2 #~(job next-second-from |
692 | (lambda () | |
693 | (call-with-output-file "witness" | |
694 | (lambda (port) | |
695 | (display (list (getuid) (getgid)) port)))) | |
696 | #:user "alice")) | |
697 | (job3 #~(job next-second-from ;to test $PATH | |
698 | "touch witness-touch"))) | |
892d9089 | 699 | (simple-operating-system |
84a2de36 LC |
700 | (service mcron-service-type |
701 | (mcron-configuration (jobs (list job1 job2 job3))))))) | |
c311089b LC |
702 | |
703 | (define (run-mcron-test name) | |
8b113790 LC |
704 | (define os |
705 | (marionette-operating-system | |
706 | %mcron-os | |
707 | #:imported-modules '((gnu services herd) | |
708 | (guix combinators)))) | |
709 | ||
710 | (define test | |
711 | (with-imported-modules '((gnu build marionette)) | |
712 | #~(begin | |
713 | (use-modules (gnu build marionette) | |
714 | (srfi srfi-64) | |
715 | (ice-9 match)) | |
716 | ||
717 | (define marionette | |
718 | (make-marionette (list #$(virtual-machine os)))) | |
719 | ||
720 | (mkdir #$output) | |
721 | (chdir #$output) | |
722 | ||
723 | (test-begin "mcron") | |
724 | ||
c24b1547 | 725 | (test-assert "service running" |
8b113790 LC |
726 | (marionette-eval |
727 | '(begin | |
728 | (use-modules (gnu services herd)) | |
c24b1547 | 729 | (start-service 'mcron)) |
8b113790 LC |
730 | marionette)) |
731 | ||
732 | ;; Make sure root's mcron job runs, has its cwd set to "/root", and | |
733 | ;; runs with the right UID/GID. | |
734 | (test-equal "root's job" | |
735 | '(0 0) | |
736 | (wait-for-file "/root/witness" marionette)) | |
737 | ||
738 | ;; Likewise for Alice's job. We cannot know what its GID is since | |
739 | ;; it's chosen by 'groupadd', but it's strictly positive. | |
740 | (test-assert "alice's job" | |
741 | (match (wait-for-file "/home/alice/witness" marionette) | |
742 | ((1000 gid) | |
743 | (>= gid 100)))) | |
744 | ||
745 | ;; Last, the job that uses a command; allows us to test whether | |
077f1e63 | 746 | ;; $PATH is sane. |
8b113790 | 747 | (test-equal "root's job with command" |
077f1e63 LC |
748 | "" |
749 | (wait-for-file "/root/witness-touch" marionette | |
750 | #:read '(@ (ice-9 rdelim) read-string))) | |
8b113790 | 751 | |
147c5aa5 LC |
752 | ;; Make sure the 'schedule' action is accepted. |
753 | (test-equal "schedule action" | |
754 | '(#t) ;one value, #t | |
755 | (marionette-eval '(with-shepherd-action 'mcron ('schedule) result | |
756 | result) | |
757 | marionette)) | |
758 | ||
8b113790 LC |
759 | (test-end) |
760 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | |
761 | ||
762 | (gexp->derivation name test)) | |
c311089b LC |
763 | |
764 | (define %test-mcron | |
765 | (system-test | |
766 | (name "mcron") | |
767 | (description "Make sure the mcron service works as advertised.") | |
768 | (value (run-mcron-test name)))) | |
d2fa61bc LC |
769 | |
770 | \f | |
771 | ;;; | |
772 | ;;; Avahi and NSS-mDNS. | |
773 | ;;; | |
774 | ||
775 | (define %avahi-os | |
776 | (operating-system | |
777 | (inherit %simple-os) | |
778 | (name-service-switch %mdns-host-lookup-nss) | |
2e04ab71 LC |
779 | (services (cons* (service avahi-service-type |
780 | (avahi-configuration (debug? #t))) | |
d2fa61bc | 781 | (dbus-service) |
39d7fdce | 782 | (service dhcp-client-service-type) ;needed for multicast |
d2fa61bc LC |
783 | |
784 | ;; Enable heavyweight debugging output. | |
785 | (modify-services (operating-system-user-services | |
786 | %simple-os) | |
787 | (nscd-service-type config | |
788 | => (nscd-configuration | |
789 | (inherit config) | |
790 | (debug-level 3) | |
791 | (log-file "/dev/console"))) | |
792 | (syslog-service-type config | |
793 | => | |
ec2e2f6c DC |
794 | (syslog-configuration |
795 | (inherit config) | |
796 | (config-file | |
797 | (plain-file | |
798 | "syslog.conf" | |
799 | "*.* /dev/console\n"))))))))) | |
d2fa61bc LC |
800 | |
801 | (define (run-nss-mdns-test) | |
802 | ;; Test resolution of '.local' names via libc. Start the marionette service | |
803 | ;; *after* nscd. Failing to do that, libc will try to connect to nscd, | |
804 | ;; fail, then never try again (see '__nss_not_use_nscd_hosts' in libc), | |
805 | ;; leading to '.local' resolution failures. | |
8b113790 LC |
806 | (define os |
807 | (marionette-operating-system | |
808 | %avahi-os | |
809 | #:requirements '(nscd) | |
810 | #:imported-modules '((gnu services herd) | |
811 | (guix combinators)))) | |
4ee96a79 | 812 | |
8b113790 LC |
813 | (define mdns-host-name |
814 | (string-append (operating-system-host-name os) | |
815 | ".local")) | |
4ee96a79 | 816 | |
8b113790 LC |
817 | (define test |
818 | (with-imported-modules '((gnu build marionette)) | |
819 | #~(begin | |
820 | (use-modules (gnu build marionette) | |
821 | (srfi srfi-1) | |
822 | (srfi srfi-64) | |
823 | (ice-9 match)) | |
824 | ||
825 | (define marionette | |
826 | (make-marionette (list #$(virtual-machine os)))) | |
827 | ||
828 | (mkdir #$output) | |
829 | (chdir #$output) | |
830 | ||
831 | (test-begin "avahi") | |
832 | ||
c24b1547 | 833 | (test-assert "nscd PID file is created" |
8b113790 LC |
834 | (marionette-eval |
835 | '(begin | |
836 | (use-modules (gnu services herd)) | |
c24b1547 CL |
837 | (start-service 'nscd)) |
838 | marionette)) | |
839 | ||
840 | (test-assert "nscd is listening on its socket" | |
841 | (marionette-eval | |
842 | ;; XXX: Work around a race condition in nscd: nscd creates its | |
843 | ;; PID file before it is listening on its socket. | |
844 | '(let ((sock (socket PF_UNIX SOCK_STREAM 0))) | |
845 | (let try () | |
846 | (catch 'system-error | |
847 | (lambda () | |
848 | (connect sock AF_UNIX "/var/run/nscd/socket") | |
849 | (close-port sock) | |
850 | (format #t "nscd is ready~%") | |
851 | #t) | |
852 | (lambda args | |
853 | (format #t "waiting for nscd...~%") | |
854 | (usleep 500000) | |
855 | (try))))) | |
856 | marionette)) | |
857 | ||
858 | (test-assert "avahi is running" | |
859 | (marionette-eval | |
860 | '(begin | |
861 | (use-modules (gnu services herd)) | |
862 | (start-service 'avahi-daemon)) | |
863 | marionette)) | |
8b113790 | 864 | |
c24b1547 CL |
865 | (test-assert "network is up" |
866 | (marionette-eval | |
867 | '(begin | |
868 | (use-modules (gnu services herd)) | |
869 | (start-service 'networking)) | |
8b113790 LC |
870 | marionette)) |
871 | ||
872 | (test-equal "avahi-resolve-host-name" | |
873 | 0 | |
874 | (marionette-eval | |
875 | '(system* | |
876 | "/run/current-system/profile/bin/avahi-resolve-host-name" | |
877 | "-v" #$mdns-host-name) | |
878 | marionette)) | |
879 | ||
880 | (test-equal "avahi-browse" | |
881 | 0 | |
882 | (marionette-eval | |
883 | '(system* "avahi-browse" "-avt") | |
884 | marionette)) | |
885 | ||
886 | (test-assert "getaddrinfo .local" | |
887 | ;; Wait for the 'avahi-daemon' service and perform a resolution. | |
888 | (match (marionette-eval | |
889 | '(getaddrinfo #$mdns-host-name) | |
890 | marionette) | |
891 | (((? vector? addrinfos) ..1) | |
892 | (pk 'getaddrinfo addrinfos) | |
893 | (and (any (lambda (ai) | |
894 | (= AF_INET (addrinfo:fam ai))) | |
895 | addrinfos) | |
896 | (any (lambda (ai) | |
897 | (= AF_INET6 (addrinfo:fam ai))) | |
898 | addrinfos))))) | |
899 | ||
900 | (test-assert "gethostbyname .local" | |
901 | (match (pk 'gethostbyname | |
902 | (marionette-eval '(gethostbyname #$mdns-host-name) | |
903 | marionette)) | |
904 | ((? vector? result) | |
905 | (and (string=? (hostent:name result) #$mdns-host-name) | |
906 | (= (hostent:addrtype result) AF_INET))))) | |
907 | ||
908 | ||
909 | (test-end) | |
910 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | |
911 | ||
912 | (gexp->derivation "nss-mdns" test)) | |
d2fa61bc LC |
913 | |
914 | (define %test-nss-mdns | |
915 | (system-test | |
916 | (name "nss-mdns") | |
917 | (description | |
918 | "Test Avahi's multicast-DNS implementation, and in particular, test its | |
919 | glibc name service switch (NSS) module.") | |
920 | (value (run-nss-mdns-test)))) |