1 ;;;; posix.test --- Test suite for Guile POSIX functions. -*- scheme -*-
3 ;;;; Copyright 2003, 2004, 2006, 2007, 2010, 2012 Free Software Foundation, Inc.
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.
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
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
19 (define-module (test-suite test-posix)
20 :use-module (test-suite lib))
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).
33 ;; (with-test-prefix "execl"
34 ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
35 ;; (execl "./nosuchprog" "./nosuchprog" "some arg")))
41 ;; (with-test-prefix "execlp"
42 ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
43 ;; (execlp "./nosuchprog" "./nosuchprog" "some arg")))
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")))
60 (with-test-prefix "mkstemp!"
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
65 (define (string-copy str)
66 (list->string (string->list str)))
68 (pass-if-exception "number arg" exception:wrong-type-arg
71 (pass-if "filename string modified"
72 (let* ((template "T-XXXXXX")
73 (str (string-copy template))
75 (result (not (string=? str template))))
84 (with-test-prefix "putenv"
87 (putenv "FOO=something")
88 (equal? "something" (getenv "FOO")))
93 (equal? "two" (getenv "FOO")))
97 (equal? "" (getenv "FOO")))
102 (not (getenv "FOO")))
104 (pass-if "modifying string doesn't change env"
105 (let ((s (string-copy "FOO=bar")))
107 (string-set! s 5 #\x)
108 (equal? "bar" (getenv "FOO")))))
114 (with-test-prefix "setenv"
117 (setenv "FOO" "something")
118 (equal? "something" (getenv "FOO")))
123 (equal? "two" (getenv "FOO")))
127 (equal? "" (getenv "FOO")))
130 (setenv "FOO" "something")
132 (not (getenv "FOO"))))
138 (with-test-prefix "unsetenv"
141 (putenv "FOO=something")
143 (not (getenv "FOO")))
148 (not (getenv "FOO"))))
154 (with-test-prefix "ttyname"
156 (pass-if-exception "non-tty argument" exception:system-error
157 ;; This used to crash in 1.8.1 and earlier.
158 (let ((file (false-if-exception
159 (open-output-file "/dev/null"))))
168 (with-test-prefix "utime"
170 (pass-if "valid argument (second resolution)"
171 (let ((file "posix.test-utime"))
174 (close-port (open-output-file file)))
176 (let* ((accessed (+ (current-time) 3600))
177 (modified (- accessed 1000)))
178 (utime file accessed modified)
179 (let ((info (stat file)))
180 (and (= (stat:atime info) accessed)
181 (= (stat:mtime info) modified)))))
183 (delete-file file))))))
189 (with-test-prefix "affinity"
191 (pass-if "getaffinity"
192 (if (defined? 'getaffinity)
193 (> (bitvector-length (getaffinity (getpid))) 0)
194 (throw 'unresolved)))
196 (pass-if "setaffinity"
197 (if (and (defined? 'setaffinity) (defined? 'getaffinity))
198 (let ((mask (getaffinity (getpid))))
199 (setaffinity (getpid) mask)
200 (equal? mask (getaffinity (getpid))))
201 (throw 'unresolved))))
207 (with-test-prefix "system*"
209 (pass-if "http://bugs.gnu.org/13166"
210 ;; With Guile up to 2.0.7 included, the child process launched by
211 ;; `system*' would remain alive after an `execvp' failure.
213 (and (not (zero? (system* "something-that-does-not-exist")))