diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2014-01-10 23:27:39 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2014-01-24 00:01:49 +0100 |
| commit | 2cd5c0380ed36f334114904bacf9562fc98e2090 (patch) | |
| tree | 00fa49aafd427e7539e0bd77cc6511f12b0c7aac /tests/utils.scm | |
| parent | 6bfec3edf52ed6145c3c89fb19d350498dd2b758 (diff) | |
utils: Add 'fcntl-flock'.
* guix/utils.scm (%struct-flock, F_SETLKW, F_xxLCK): New variables.
(fcntl-flock): New procedure.
* tests/utils.scm ("fcntl-flock"): New test.
Diffstat (limited to 'tests/utils.scm')
| -rw-r--r-- | tests/utils.scm | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/utils.scm b/tests/utils.scm index 017d9170fa7..b5706aa7921 100644 --- a/tests/utils.scm +++ b/tests/utils.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2012, 2013, 2014 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 | ;;; |
| @@ -139,6 +139,36 @@ | |||
| 139 | (append pids1 pids2))) | 139 | (append pids1 pids2))) |
| 140 | (equal? (get-bytevector-all decompressed) data))))) | 140 | (equal? (get-bytevector-all decompressed) data))))) |
| 141 | 141 | ||
| 142 | (test-equal "fcntl-flock" | ||
| 143 | 0 ; the child's exit status | ||
| 144 | (let ((file (open-input-file (search-path %load-path "guix.scm")))) | ||
| 145 | (fcntl-flock file 'read-lock) | ||
| 146 | (match (primitive-fork) | ||
| 147 | (0 | ||
| 148 | (dynamic-wind | ||
| 149 | (const #t) | ||
| 150 | (lambda () | ||
| 151 | ;; Taking a read lock should be OK. | ||
| 152 | (fcntl-flock file 'read-lock) | ||
| 153 | (fcntl-flock file 'unlock) | ||
| 154 | |||
| 155 | (catch 'flock-error | ||
| 156 | (lambda () | ||
| 157 | ;; Taking an exclusive lock should raise an exception. | ||
| 158 | (fcntl-flock file 'write-lock)) | ||
| 159 | (lambda args | ||
| 160 | (primitive-exit 0))) | ||
| 161 | (primitive-exit 1)) | ||
| 162 | (lambda () | ||
| 163 | (primitive-exit 2)))) | ||
| 164 | (pid | ||
| 165 | (match (waitpid pid) | ||
| 166 | ((_ . status) | ||
| 167 | (let ((result (status:exit-val status))) | ||
| 168 | (fcntl-flock file 'unlock) | ||
| 169 | (close-port file) | ||
| 170 | result))))))) | ||
| 171 | |||
| 142 | ;; This is actually in (guix store). | 172 | ;; This is actually in (guix store). |
| 143 | (test-equal "store-path-package-name" | 173 | (test-equal "store-path-package-name" |
| 144 | "bash-4.2-p24" | 174 | "bash-4.2-p24" |
