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