summaryrefslogtreecommitdiff
path: root/tests/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-05-06 13:12:45 +0200
committerLudovic Courtès <ludo@gnu.org>2016-05-06 13:25:30 +0200
commit4e0ea3eb288c2143b44bf324c64047762c72d3b3 (patch)
treea261da4f5d972b0a90827347a3a987534ab80ac7 /tests/utils.scm
parentba2613bb4e47938044a3c96b92debf1bddcf0140 (diff)
utils: Move 'fcntl-flock' to (guix build syscalls).
* guix/utils.scm (%struct-flock, F_SETLKW, F_SETLK, F_xxLCK) (fcntl-flock): Move to... * guix/build/syscalls.scm: ... here. New variables. * guix/nar.scm: Adjust imports accordingly. * tests/utils.scm ("fcntl-flock wait", "fcntl-flock non-blocking"): Move to... * tests/syscalls.scm: ... here. New tests. (temp-file): New variable.
Diffstat (limited to 'tests/utils.scm')
-rw-r--r--tests/utils.scm82
1 files changed, 0 insertions, 82 deletions
diff --git a/tests/utils.scm b/tests/utils.scm
index a54482e94ce..6590ed91cf8 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -168,88 +168,6 @@
168 (call-with-decompressed-port 'xz (open-file temp-file "r0b") 168 (call-with-decompressed-port 'xz (open-file temp-file "r0b")
169 get-bytevector-all)))) 169 get-bytevector-all))))
170 170
171(false-if-exception (delete-file temp-file))
172(test-equal "fcntl-flock wait"
173 42 ; the child's exit status
174 (let ((file (open-file temp-file "w0b")))
175 ;; Acquire an exclusive lock.
176 (fcntl-flock file 'write-lock)
177 (match (primitive-fork)
178 (0
179 (dynamic-wind
180 (const #t)
181 (lambda ()
182 ;; Reopen FILE read-only so we can have a read lock.
183 (let ((file (open-file temp-file "r0b")))
184 ;; Wait until we can acquire the lock.
185 (fcntl-flock file 'read-lock)
186 (primitive-exit (read file)))
187 (primitive-exit 1))
188 (lambda ()
189 (primitive-exit 2))))
190 (pid
191 ;; Write garbage and wait.
192 (display "hello, world!" file)
193 (force-output file)
194 (sleep 1)
195
196 ;; Write the real answer.
197 (seek file 0 SEEK_SET)
198 (truncate-file file 0)
199 (write 42 file)
200 (force-output file)
201
202 ;; Unlock, which should let the child continue.
203 (fcntl-flock file 'unlock)
204
205 (match (waitpid pid)
206 ((_ . status)
207 (let ((result (status:exit-val status)))
208 (close-port file)
209 result)))))))
210
211(test-equal "fcntl-flock non-blocking"
212 EAGAIN ; the child's exit status
213 (match (pipe)
214 ((input . output)
215 (match (primitive-fork)
216 (0
217 (dynamic-wind
218 (const #t)
219 (lambda ()
220 (close-port output)
221
222 ;; Wait for the green light.
223 (read-char input)
224
225 ;; Open FILE read-only so we can have a read lock.
226 (let ((file (open-file temp-file "w0")))
227 (catch 'flock-error
228 (lambda ()
229 ;; This attempt should throw EAGAIN.
230 (fcntl-flock file 'write-lock #:wait? #f))
231 (lambda (key errno)
232 (primitive-exit (pk 'errno errno)))))
233 (primitive-exit -1))
234 (lambda ()
235 (primitive-exit -2))))
236 (pid
237 (close-port input)
238 (let ((file (open-file temp-file "w0")))
239 ;; Acquire an exclusive lock.
240 (fcntl-flock file 'write-lock)
241
242 ;; Tell the child to continue.
243 (write 'green-light output)
244 (force-output output)
245
246 (match (waitpid pid)
247 ((_ . status)
248 (let ((result (status:exit-val status)))
249 (fcntl-flock file 'unlock)
250 (close-port file)
251 result)))))))))
252
253;; This is actually in (guix store). 171;; This is actually in (guix store).
254(test-equal "store-path-package-name" 172(test-equal "store-path-package-name"
255 "bash-4.2-p24" 173 "bash-4.2-p24"