summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-06-12 23:21:24 +0200
committerLudovic Courtès <ludo@gnu.org>2017-06-12 23:34:14 +0200
commit5fa7cc5335d64a790d7f0f784a11b25b040cc443 (patch)
tree420f5a363b12c2a4c6f3c6e703e59b559f800117
parentd782de172c68119499202ddac03fdce53ad89a35 (diff)
marionette: Factorize 'wait-for-file'.
* gnu/build/marionette.scm (wait-for-file): New procedure. * gnu/tests/base.scm (run-mcron-test)[test](wait-for-file): Remove. Pass second argument in 'wait-for-file' calls. * gnu/tests/ssh.scm (run-ssh-test)[test](wait-for-file): Remove. Pass second argument in 'wait-for-file' calls. * gnu/tests/messaging.scm (run-xmpp-test)[test](guest-wait-for-file): Remove. Use 'wait-for-file' instead, with second argument.
-rw-r--r--gnu/build/marionette.scm17
-rw-r--r--gnu/tests/base.scm20
-rw-r--r--gnu/tests/messaging.scm18
-rw-r--r--gnu/tests/ssh.scm18
4 files changed, 23 insertions, 50 deletions
diff --git a/gnu/build/marionette.scm b/gnu/build/marionette.scm
index 506d6da420a..424f2b6713e 100644
--- a/gnu/build/marionette.scm
+++ b/gnu/build/marionette.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3;;; 3;;;
4;;; This file is part of GNU Guix. 4;;; This file is part of GNU Guix.
5;;; 5;;;
@@ -25,6 +25,7 @@
25 #:export (marionette? 25 #:export (marionette?
26 make-marionette 26 make-marionette
27 marionette-eval 27 marionette-eval
28 wait-for-file
28 marionette-control 29 marionette-control
29 marionette-screen-text 30 marionette-screen-text
30 wait-for-screen-text 31 wait-for-screen-text
@@ -164,6 +165,20 @@ QEMU monitor and to the guest's backdoor REPL."
164 (newline repl) 165 (newline repl)
165 (read repl)))) 166 (read repl))))
166 167
168(define* (wait-for-file file marionette #:key (timeout 10))
169 "Wait until FILE exists in MARIONETTE; 'read' its content and return it. If
170FILE has not shown up after TIMEOUT seconds, raise an error."
171 (marionette-eval
172 `(let loop ((i ,timeout))
173 (cond ((file-exists? ,file)
174 (call-with-input-file ,file read))
175 ((> i 0)
176 (sleep 1)
177 (loop (- i 1)))
178 (else
179 (error "file didn't show up" ,file))))
180 marionette))
181
167(define (marionette-control command marionette) 182(define (marionette-control command marionette)
168 "Run COMMAND in the QEMU monitor of MARIONETTE. COMMAND is a string such as 183 "Run COMMAND in the QEMU monitor of MARIONETTE. COMMAND is a string such as
169\"sendkey ctrl-alt-f1\" or \"screendump foo.ppm\" (info \"(qemu-doc) 184\"sendkey ctrl-alt-f1\" or \"screendump foo.ppm\" (info \"(qemu-doc)
diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm
index f5bbfafee35..8389b67f68f 100644
--- a/gnu/tests/base.scm
+++ b/gnu/tests/base.scm
@@ -446,20 +446,6 @@ functionality tests.")
446 (define marionette 446 (define marionette
447 (make-marionette (list #$command))) 447 (make-marionette (list #$command)))
448 448
449 (define (wait-for-file file)
450 ;; Wait until FILE exists in the guest; 'read' its content and
451 ;; return it.
452 (marionette-eval
453 `(let loop ((i 10))
454 (cond ((file-exists? ,file)
455 (call-with-input-file ,file read))
456 ((> i 0)
457 (sleep 1)
458 (loop (- i 1)))
459 (else
460 (error "file didn't show up" ,file))))
461 marionette))
462
463 (mkdir #$output) 449 (mkdir #$output)
464 (chdir #$output) 450 (chdir #$output)
465 451
@@ -478,12 +464,12 @@ functionality tests.")
478 ;; runs with the right UID/GID. 464 ;; runs with the right UID/GID.
479 (test-equal "root's job" 465 (test-equal "root's job"
480 '(0 0) 466 '(0 0)
481 (wait-for-file "/root/witness")) 467 (wait-for-file "/root/witness" marionette))
482 468
483 ;; Likewise for Alice's job. We cannot know what its GID is since 469 ;; Likewise for Alice's job. We cannot know what its GID is since
484 ;; it's chosen by 'groupadd', but it's strictly positive. 470 ;; it's chosen by 'groupadd', but it's strictly positive.
485 (test-assert "alice's job" 471 (test-assert "alice's job"
486 (match (wait-for-file "/home/alice/witness") 472 (match (wait-for-file "/home/alice/witness" marionette)
487 ((1000 gid) 473 ((1000 gid)
488 (>= gid 100)))) 474 (>= gid 100))))
489 475
@@ -492,7 +478,7 @@ functionality tests.")
492 ;; that don't have a read syntax, hence the string.) 478 ;; that don't have a read syntax, hence the string.)
493 (test-equal "root's job with command" 479 (test-equal "root's job with command"
494 "#<eof>" 480 "#<eof>"
495 (wait-for-file "/root/witness-touch")) 481 (wait-for-file "/root/witness-touch" marionette))
496 482
497 (test-end) 483 (test-end)
498 (exit (= (test-runner-fail-count (test-runner-current)) 0))))) 484 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
diff --git a/gnu/tests/messaging.scm b/gnu/tests/messaging.scm
index cefb52534ac..b76b8e84341 100644
--- a/gnu/tests/messaging.scm
+++ b/gnu/tests/messaging.scm
@@ -80,21 +80,6 @@
80 (number->string #$port) 80 (number->string #$port)
81 "-:5222")))) 81 "-:5222"))))
82 82
83 (define (guest-wait-for-file file)
84 ;; Wait until FILE exists in the guest; 'read' its content and
85 ;; return it.
86 (marionette-eval
87 `(let loop ((i 10))
88 (cond ((file-exists? ,file)
89 (call-with-input-file ,file read))
90 ((> i 0)
91 (begin
92 (sleep 1))
93 (loop (- i 1)))
94 (else
95 (error "file didn't show up" ,file))))
96 marionette))
97
98 (define (host-wait-for-file file) 83 (define (host-wait-for-file file)
99 ;; Wait until FILE exists in the host. 84 ;; Wait until FILE exists in the host.
100 (let loop ((i 60)) 85 (let loop ((i 60))
@@ -124,7 +109,8 @@
124 109
125 ;; Check XMPP service's PID. 110 ;; Check XMPP service's PID.
126 (test-assert "service process id" 111 (test-assert "service process id"
127 (let ((pid (number->string (guest-wait-for-file #$pid-file)))) 112 (let ((pid (number->string (wait-for-file #$pid-file
113 marionette))))
128 (marionette-eval `(file-exists? (string-append "/proc/" ,pid)) 114 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
129 marionette))) 115 marionette)))
130 116
diff --git a/gnu/tests/ssh.scm b/gnu/tests/ssh.scm
index 5f061510818..9c83a9cd481 100644
--- a/gnu/tests/ssh.scm
+++ b/gnu/tests/ssh.scm
@@ -69,20 +69,6 @@ When SFTP? is true, run an SFTP server test."
69 (make-marionette (list #$command "-net" 69 (make-marionette (list #$command "-net"
70 "user,hostfwd=tcp::2222-:22"))) 70 "user,hostfwd=tcp::2222-:22")))
71 71
72 (define (wait-for-file file)
73 ;; Wait until FILE exists in the guest; 'read' its content and
74 ;; return it.
75 (marionette-eval
76 `(let loop ((i 10))
77 (cond ((file-exists? ,file)
78 (call-with-input-file ,file read))
79 ((> i 0)
80 (sleep 1)
81 (loop (- i 1)))
82 (else
83 (error "file didn't show up" ,file))))
84 marionette))
85
86 (define (make-session-for-test) 72 (define (make-session-for-test)
87 "Make a session with predefined parameters for a test." 73 "Make a session with predefined parameters for a test."
88 (make-session #:user "root" 74 (make-session #:user "root"
@@ -141,7 +127,7 @@ root with an empty password."
141 127
142 ;; Check sshd's PID file. 128 ;; Check sshd's PID file.
143 (test-equal "sshd PID" 129 (test-equal "sshd PID"
144 (wait-for-file #$pid-file) 130 (wait-for-file #$pid-file marionette)
145 (marionette-eval 131 (marionette-eval
146 '(begin 132 '(begin
147 (use-modules (gnu services herd) 133 (use-modules (gnu services herd)
@@ -166,7 +152,7 @@ root with an empty password."
166 (channel-open-session channel) 152 (channel-open-session channel)
167 (channel-request-exec channel "echo hello > /root/witness") 153 (channel-request-exec channel "echo hello > /root/witness")
168 (and (zero? (channel-get-exit-status channel)) 154 (and (zero? (channel-get-exit-status channel))
169 (wait-for-file "/root/witness")))))) 155 (wait-for-file "/root/witness" marionette))))))
170 156
171 ;; Connect to the guest over SFTP. Make sure we can write and 157 ;; Connect to the guest over SFTP. Make sure we can write and
172 ;; read a file there. 158 ;; read a file there.