(use fuse posix test) (define u+rwx/reg (bitwise-ior file/reg perm/irusr perm/iwusr perm/ixusr)) (define u+rwx/dir (bitwise-ior file/dir perm/irusr perm/iwusr perm/ixusr)) (define (process-terminate! pid) (process-signal pid signal/term) (process-wait pid)) (define (read-file f) (call-with-input-file f (lambda (p) (read-string #f p)))) (define (test-hello path) (define str "Hello world!\n") (define now (current-seconds)) (define fs (make-filesystem getattr: (lambda (path) (cond ((string=? path "/") (vector u+rwx/dir 2 (current-user-id) (current-group-id) 0 now now now)) ((string=? path "/hello") (vector u+rwx/reg 1 (current-user-id) (current-group-id) (string-length str) now now now)) (else #f))) readdir: (lambda (path) (and (string=? path "/") (list "." ".." "hello"))) open: (lambda (path mode) (string=? path "/hello")) read: (lambda (_ size offset) (let ((len (string-length str))) (if (>= offset len) 0 (substring str offset (min size (- len offset)))))))) (define pid (process-fork (lambda () (set-signal-handler! signal/term (lambda (_) (filesystem-stop! path fs))) (filesystem-start! path fs) (filesystem-wait! path fs)))) (sleep 1) (let* ((file (string-append path "/hello")) (stat (file-stat file))) (test-assert (equal? (vector-ref stat 1) u+rwx/reg)) (test-assert (equal? (vector-ref stat 2) 1)) (test-assert (equal? (vector-ref stat 3) (current-user-id))) (test-assert (equal? (vector-ref stat 4) (current-group-id))) (test-assert (equal? (vector-ref stat 5) (string-length str))) (test-assert (equal? (vector-ref stat 6) now)) (test-assert (equal? (vector-ref stat 7) now)) (test-assert (equal? (vector-ref stat 8) now)) (test-assert (equal? (directory path) '("hello"))) (test-assert (equal? (read-file file) str)) (process-terminate! pid) (test-assert (equal? (directory path) '())))) (test-assert (create-directory "path" #t)) (test-hello "path") (test-assert (delete-directory "path" #t))