X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-posix%2Fposix-tests.lisp;h=a82bd7e085dea0dcce9f2800af993afff2f960cd;hb=85dc70440d40a589365323c63e0dad039a578b6f;hp=1a3eb6fc4ab90a425d018c9fcb4fa4a516b5ab69;hpb=c7b7abe4e260e8d3239da24516ce7b0101dde544;p=sbcl.git diff --git a/contrib/sb-posix/posix-tests.lisp b/contrib/sb-posix/posix-tests.lisp index 1a3eb6f..a82bd7e 100644 --- a/contrib/sb-posix/posix-tests.lisp +++ b/contrib/sb-posix/posix-tests.lisp @@ -17,6 +17,14 @@ (defconstant +mode-rwx-all+ (logior sb-posix::s-irusr sb-posix::s-iwusr sb-posix::s-ixusr sb-posix::s-irgrp sb-posix::s-iwgrp sb-posix::s-ixgrp sb-posix::s-iroth sb-posix::s-iwoth sb-posix::s-ixoth))) + +(defmacro define-eacces-test (name form &rest values) + `(deftest ,name + (block ,name + (when (= (sb-posix:geteuid) 0) + (return-from ,name (values ,@values))) + ,form) + ,@values)) (deftest chdir.1 (sb-posix:chdir *test-directory*) @@ -38,6 +46,18 @@ (sb-posix:chdir *current-directory*) 0) +(deftest chdir.6 + (sb-posix:chdir "/../") + 0) + +(deftest chdir.7 + (sb-posix:chdir #p"/../") + 0) + +(deftest chdir.8 + (sb-posix:chdir (make-pathname :directory '(:absolute :up))) + 0) + (deftest chdir.error.1 (let ((dne (make-pathname :directory '(:relative "chdir.does-not-exist")))) (handler-case @@ -81,14 +101,25 @@ (sb-posix:mkdir "/" 0) (sb-posix:syscall-error (c) (sb-posix:syscall-errno c))) - #-bsd #.sb-posix::eexist - #+bsd #.sb-posix::eisdir) + #.sb-posix::eexist) -(deftest mkdir.error.3 - (handler-case - (sb-posix:mkdir "/almost-certainly-does-not-exist" 0) - (sb-posix:syscall-error (c) - (sb-posix:syscall-errno c))) +(define-eacces-test mkdir.error.3 + (let* ((dir (merge-pathnames + (make-pathname :directory '(:relative "mkdir.error.3")) + *test-directory*)) + (dir2 (merge-pathnames + (make-pathname :directory '(:relative "does-not-exist")) + dir))) + (sb-posix:mkdir dir 0) + (handler-case + (sb-posix:mkdir dir2 0) + (sb-posix:syscall-error (c) + (sb-posix:rmdir dir) + (sb-posix:syscall-errno c)) + (:no-error (result) + (sb-posix:rmdir dir2) + (sb-posix:rmdir dir) + result))) #.sb-posix::eacces) (deftest rmdir.1 @@ -118,14 +149,12 @@ (sb-posix:syscall-errno c))) #.sb-posix::enotdir) -#-sunos ; Apparently gives EINVAL on SunOS 8, which doesn't make sense (deftest rmdir.error.3 (handler-case (sb-posix:rmdir "/") (sb-posix:syscall-error (c) (sb-posix:syscall-errno c))) - #-bsd #.sb-posix::ebusy - #+bsd #.sb-posix::eisdir) + #.sb-posix::ebusy) (deftest rmdir.error.4 (let* ((dir (ensure-directories-exist @@ -145,7 +174,7 @@ (or (= errno sb-posix::eexist) (= errno sb-posix::enotempty)))))) t) -(deftest rmdir.error.5 +(define-eacces-test rmdir.error.5 (let* ((dir (merge-pathnames (make-pathname :directory '(:relative "rmdir.error.5")) *test-directory*)) @@ -161,7 +190,11 @@ (sb-posix:chmod dir (logior sb-posix::s-iread sb-posix::s-iwrite sb-posix::s-iexec)) (sb-posix:rmdir dir2) (sb-posix:rmdir dir) - (sb-posix:syscall-errno c)))) + (sb-posix:syscall-errno c)) + (:no-error (result) + (sb-posix:chmod dir (logior sb-posix::s-iread sb-posix::s-iwrite sb-posix::s-iexec)) + (sb-posix:rmdir dir) + result))) #.sb-posix::eacces) (deftest stat.1 @@ -190,6 +223,15 @@ (< (- atime unix-now) 10)) t) +(deftest stat.4 + (let* ((stat (sb-posix:stat (make-pathname :directory '(:absolute :up)))) + (mode (sb-posix::stat-mode stat))) + ;; it's logically possible for / to be writeable by others... but + ;; if it is, either someone is playing with strange security + ;; modules or they want to know about it anyway. + (logand mode sb-posix::s-iwoth)) + 0) + ;;; FIXME: add tests for carrying a stat structure around in the ;;; optional argument to SB-POSIX:STAT @@ -199,7 +241,7 @@ (sb-posix:syscall-errno c))) #.sb-posix::enoent) -(deftest stat.error.2 +(define-eacces-test stat.error.2 (let* ((dir (merge-pathnames (make-pathname :directory '(:relative "stat.error.2")) *test-directory*)) @@ -216,7 +258,12 @@ (sb-posix:chmod dir (logior sb-posix::s-iread sb-posix::s-iwrite sb-posix::s-iexec)) (sb-posix:unlink file) (sb-posix:rmdir dir) - (sb-posix:syscall-errno c)))) + (sb-posix:syscall-errno c)) + (:no-error (result) + (sb-posix:chmod dir (logior sb-posix::s-iread sb-posix::s-iwrite sb-posix::s-iexec)) + (sb-posix:unlink file) + (sb-posix:rmdir dir) + result))) #.sb-posix::eacces) ;;; stat-mode tests @@ -295,4 +342,40 @@ (let ((*default-pathname-defaults* *test-directory*)) (sb-posix:unlink (car (directory "*.txt"))))) 0) - + +(deftest open.1 + (let ((fd (sb-posix:open *test-directory* sb-posix::o-rdonly))) + (ignore-errors (sb-posix:close fd)) + (< fd 0)) + nil) + +(deftest open.error.1 + (handler-case (sb-posix:open *test-directory* sb-posix::o-wronly) + (sb-posix:syscall-error (c) + (sb-posix:syscall-errno c))) + #.sb-posix::eisdir) + +(deftest fcntl.1 + (let ((fd (sb-posix:open "/dev/null" sb-posix::o-nonblock))) + (= (sb-posix:fcntl fd sb-posix::f-getfl) sb-posix::o-nonblock)) + t) + + +(deftest opendir.1 + (let ((dir (sb-posix:opendir "/"))) + (unwind-protect (sb-alien:null-alien dir) + (unless (sb-alien:null-alien dir) + (sb-posix:closedir dir)))) + nil) + +(deftest readdir.1 + (let ((dir (sb-posix:opendir "/"))) + (unwind-protect + (block dir-loop + (loop for dirent = (sb-posix:readdir dir) + until (sb-alien:null-alien dirent) + when (not (stringp (sb-posix:dirent-name dirent))) + do (return-from dir-loop nil) + finally (return t))) + (sb-posix:closedir dir))) + t)