123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- (define-module (test-processes)
- #:use-module (guix scripts processes)
- #:use-module (guix store)
- #:use-module (guix derivations)
- #:use-module (guix packages)
- #:use-module (guix gexp)
- #:use-module ((guix utils) #:select (call-with-temporary-directory))
- #:use-module (gnu packages bootstrap)
- #:use-module (guix tests)
- #:use-module (srfi srfi-1)
- #:use-module (srfi srfi-64)
- #:use-module (rnrs bytevectors)
- #:use-module (rnrs io ports)
- #:use-module (ice-9 match)
- #:use-module (ice-9 threads))
- (define (binfmt-misc?)
- (let ((pid (getpid))
- (cmdline (call-with-input-file "/proc/self/cmdline" get-string-all)))
- (match (primitive-fork)
- (0 (dynamic-wind
- (const #t)
- (lambda ()
- (exit
- (not (equal?
- (call-with-input-file (format #f "/proc/~a/cmdline" pid)
- get-string-all)
- cmdline))))
- (const #t)))
- (x (zero? (cdr (waitpid x)))))))
- (define-syntax-rule (test-assert* description exp)
- (begin
- (when (binfmt-misc?)
- (test-skip 1))
- (test-assert description exp)))
- (test-begin "processes")
- (test-assert* "not a client"
- (not (find (lambda (session)
- (= (getpid)
- (process-id (daemon-session-client session))))
- (daemon-sessions))))
- (test-assert* "client"
- (with-store store
- (let* ((session (find (lambda (session)
- (= (getpid)
- (process-id (daemon-session-client session))))
- (daemon-sessions)))
- (daemon (daemon-session-process session)))
- (and (kill (process-id daemon) 0)
- (string-suffix? "guix-daemon" (first (process-command daemon)))))))
- (test-assert* "client + lock"
- (with-store store
- (call-with-temporary-directory
- (lambda (directory)
- (let* ((token1 (string-append directory "/token1"))
- (token2 (string-append directory "/token2"))
- (exp #~(begin #$(random-text)
- (mkdir #$token1)
- (let loop ()
- (unless (file-exists? #$token2)
- (sleep 1)
- (loop)))
- (mkdir #$output)))
- (guile (package-derivation store %bootstrap-guile))
- (drv (run-with-store store
- (gexp->derivation "foo" exp
- #:guile-for-build guile)))
- (thread (call-with-new-thread
- (lambda ()
- (build-derivations store (list drv)))))
- (_ (let loop ()
- (unless (file-exists? token1)
- (usleep 200)
- (loop))))
- (session (find (lambda (session)
- (= (getpid)
- (process-id (daemon-session-client session))))
- (daemon-sessions)))
- (locks (daemon-session-locks-held (pk 'session session))))
- (call-with-output-file token2 (const #t))
- (equal? (list (string-append (derivation->output-path drv) ".lock"))
- locks))))))
- (test-end "processes")
|