Commit | Line | Data |
---|---|---|
0d2cf5b5 KR |
1 | ;;;; posix.test --- Test suite for Guile POSIX functions. -*- scheme -*- |
2 | ;;;; | |
668ba7c9 | 3 | ;;;; Copyright 2003, 2004, 2006, 2007, 2010, 2012 Free Software Foundation, Inc. |
0d2cf5b5 | 4 | ;;;; |
53befeb7 NJ |
5 | ;;;; This library is free software; you can redistribute it and/or |
6 | ;;;; modify it under the terms of the GNU Lesser General Public | |
7 | ;;;; License as published by the Free Software Foundation; either | |
8 | ;;;; version 3 of the License, or (at your option) any later version. | |
9 | ;;;; | |
10 | ;;;; This library is distributed in the hope that it will be useful, | |
0d2cf5b5 | 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
53befeb7 NJ |
12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | ;;;; Lesser General Public License for more details. | |
14 | ;;;; | |
15 | ;;;; You should have received a copy of the GNU Lesser General Public | |
16 | ;;;; License along with this library; if not, write to the Free Software | |
17 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
0d2cf5b5 | 18 | |
a1ef7406 LC |
19 | (define-module (test-suite test-posix) |
20 | :use-module (test-suite lib)) | |
0d2cf5b5 KR |
21 | |
22 | ||
c2d31141 KR |
23 | ;; FIXME: The following exec tests are disabled since on an i386 debian with |
24 | ;; glibc 2.3.2 they seem to interact badly with threads.test, the latter | |
25 | ;; dies with signal 32 (one of the SIGRTs). Don't know how or why, or who's | |
26 | ;; at fault (though it seems to happen with or without the recent memory | |
27 | ;; leak fix in these error cases). | |
28 | ||
32bb5bd8 KR |
29 | ;; |
30 | ;; execl | |
31 | ;; | |
32 | ||
c2d31141 KR |
33 | ;; (with-test-prefix "execl" |
34 | ;; (pass-if-exception "./nosuchprog" '(system-error . ".*") | |
35 | ;; (execl "./nosuchprog" "./nosuchprog" "some arg"))) | |
32bb5bd8 KR |
36 | |
37 | ;; | |
38 | ;; execlp | |
39 | ;; | |
40 | ||
c2d31141 KR |
41 | ;; (with-test-prefix "execlp" |
42 | ;; (pass-if-exception "./nosuchprog" '(system-error . ".*") | |
43 | ;; (execlp "./nosuchprog" "./nosuchprog" "some arg"))) | |
32bb5bd8 KR |
44 | |
45 | ;; | |
46 | ;; execle | |
47 | ;; | |
48 | ||
c2d31141 KR |
49 | ;; (with-test-prefix "execle" |
50 | ;; (pass-if-exception "./nosuchprog" '(system-error . ".*") | |
51 | ;; (execle "./nosuchprog" '() "./nosuchprog" "some arg")) | |
52 | ;; (pass-if-exception "./nosuchprog" '(system-error . ".*") | |
53 | ;; (execle "./nosuchprog" '("FOO=1" "BAR=2") "./nosuchprog" "some arg"))) | |
54 | ||
32bb5bd8 | 55 | |
95c098dd KR |
56 | ;; |
57 | ;; mkstemp! | |
58 | ;; | |
59 | ||
60 | (with-test-prefix "mkstemp!" | |
61 | ||
62 | ;; the temporary names used in the tests here are kept to 8 characters so | |
63 | ;; they'll work on a DOS 8.3 file system | |
64 | ||
65 | (define (string-copy str) | |
66 | (list->string (string->list str))) | |
67 | ||
68 | (pass-if-exception "number arg" exception:wrong-type-arg | |
69 | (mkstemp! 123)) | |
70 | ||
71 | (pass-if "filename string modified" | |
72 | (let* ((template "T-XXXXXX") | |
73 | (str (string-copy template)) | |
74 | (port (mkstemp! str)) | |
75 | (result (not (string=? str template)))) | |
76 | (delete-file str) | |
77 | result))) | |
78 | ||
0d2cf5b5 KR |
79 | ;; |
80 | ;; putenv | |
81 | ;; | |
82 | ||
83 | (with-test-prefix "putenv" | |
84 | ||
85 | (pass-if "something" | |
86 | (putenv "FOO=something") | |
87 | (equal? "something" (getenv "FOO"))) | |
88 | ||
89 | (pass-if "replacing" | |
90 | (putenv "FOO=one") | |
91 | (putenv "FOO=two") | |
92 | (equal? "two" (getenv "FOO"))) | |
93 | ||
94 | (pass-if "empty" | |
95 | (putenv "FOO=") | |
96 | (equal? "" (getenv "FOO"))) | |
97 | ||
98 | (pass-if "removing" | |
99 | (putenv "FOO=bar") | |
100 | (putenv "FOO") | |
101 | (not (getenv "FOO"))) | |
102 | ||
103 | (pass-if "modifying string doesn't change env" | |
104 | (let ((s (string-copy "FOO=bar"))) | |
105 | (putenv s) | |
106 | (string-set! s 5 #\x) | |
107 | (equal? "bar" (getenv "FOO"))))) | |
108 | ||
109 | ;; | |
110 | ;; setenv | |
111 | ;; | |
112 | ||
113 | (with-test-prefix "setenv" | |
114 | ||
115 | (pass-if "something" | |
116 | (setenv "FOO" "something") | |
117 | (equal? "something" (getenv "FOO"))) | |
118 | ||
119 | (pass-if "replacing" | |
120 | (setenv "FOO" "one") | |
121 | (setenv "FOO" "two") | |
122 | (equal? "two" (getenv "FOO"))) | |
123 | ||
124 | (pass-if "empty" | |
125 | (setenv "FOO" "") | |
126 | (equal? "" (getenv "FOO"))) | |
127 | ||
128 | (pass-if "removing" | |
129 | (setenv "FOO" "something") | |
130 | (setenv "FOO" #f) | |
131 | (not (getenv "FOO")))) | |
132 | ||
133 | ;; | |
134 | ;; unsetenv | |
135 | ;; | |
136 | ||
137 | (with-test-prefix "unsetenv" | |
138 | ||
139 | (pass-if "something" | |
140 | (putenv "FOO=something") | |
141 | (unsetenv "FOO") | |
142 | (not (getenv "FOO"))) | |
143 | ||
144 | (pass-if "empty" | |
145 | (putenv "FOO=") | |
146 | (unsetenv "FOO") | |
147 | (not (getenv "FOO")))) | |
a1ef7406 LC |
148 | |
149 | ;; | |
150 | ;; ttyname | |
151 | ;; | |
152 | ||
153 | (with-test-prefix "ttyname" | |
154 | ||
155 | (pass-if-exception "non-tty argument" exception:system-error | |
156 | ;; This used to crash in 1.8.1 and earlier. | |
157 | (let ((file (false-if-exception | |
158 | (open-output-file "/dev/null")))) | |
159 | (if (not file) | |
160 | (throw 'unsupported) | |
161 | (ttyname file))))) | |
162 | ||
adfb4284 LC |
163 | ;; |
164 | ;; utimes | |
165 | ;; | |
166 | ||
167 | (with-test-prefix "utime" | |
a1ef7406 | 168 | |
adfb4284 LC |
169 | (pass-if "valid argument (second resolution)" |
170 | (let ((file "posix.test-utime")) | |
171 | (dynamic-wind | |
172 | (lambda () | |
173 | (close-port (open-output-file file))) | |
174 | (lambda () | |
175 | (let* ((accessed (+ (current-time) 3600)) | |
176 | (modified (- accessed 1000))) | |
177 | (utime file accessed modified) | |
178 | (let ((info (stat file))) | |
179 | (and (= (stat:atime info) accessed) | |
180 | (= (stat:mtime info) modified))))) | |
181 | (lambda () | |
182 | (delete-file file)))))) | |
fe613fe2 LC |
183 | |
184 | ;; | |
185 | ;; affinity | |
186 | ;; | |
187 | ||
188 | (with-test-prefix "affinity" | |
189 | ||
190 | (pass-if "getaffinity" | |
191 | (if (defined? 'getaffinity) | |
192 | (> (bitvector-length (getaffinity (getpid))) 0) | |
193 | (throw 'unresolved))) | |
194 | ||
195 | (pass-if "setaffinity" | |
196 | (if (and (defined? 'setaffinity) (defined? 'getaffinity)) | |
197 | (let ((mask (getaffinity (getpid)))) | |
198 | (setaffinity (getpid) mask) | |
199 | (equal? mask (getaffinity (getpid)))) | |
200 | (throw 'unresolved)))) | |
668ba7c9 LC |
201 | |
202 | ;; | |
203 | ;; system* | |
204 | ;; | |
205 | ||
206 | (with-test-prefix "system*" | |
207 | ||
208 | (pass-if "http://bugs.gnu.org/13166" | |
209 | ;; With Guile up to 2.0.7 included, the child process launched by | |
210 | ;; `system*' would remain alive after an `execvp' failure. | |
211 | (let ((me (getpid))) | |
c23fb152 | 212 | (and (not (zero? (system* "something-that-does-not-exist"))) |
668ba7c9 | 213 | (= me (getpid)))))) |