| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 |
|
| 20 | (define-module (test-processes)
|
| 21 | #:use-module (guix scripts processes)
|
| 22 | #:use-module (guix store)
|
| 23 | #:use-module (guix derivations)
|
| 24 | #:use-module (guix packages)
|
| 25 | #:use-module (guix gexp)
|
| 26 | #:use-module ((guix utils) #:select (call-with-temporary-directory))
|
| 27 | #:use-module (gnu packages bootstrap)
|
| 28 | #:use-module ((gnu build linux-container)
|
| 29 | #:select (unprivileged-user-namespace-supported?))
|
| 30 | #:use-module (guix tests)
|
| 31 | #:use-module (srfi srfi-1)
|
| 32 | #:use-module (srfi srfi-64)
|
| 33 | #:use-module (rnrs bytevectors)
|
| 34 | #:use-module (rnrs io ports)
|
| 35 | #:use-module (ice-9 match)
|
| 36 | #:use-module (ice-9 threads))
|
| 37 |
|
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 |
|
| 50 | (define (binfmt-misc?)
|
| 51 | (let ((pid (getpid))
|
| 52 | (cmdline (call-with-input-file "/proc/self/cmdline" get-string-all)))
|
| 53 | (match (primitive-fork)
|
| 54 | (0 (dynamic-wind
|
| 55 | (const #t)
|
| 56 | (lambda ()
|
| 57 | (exit
|
| 58 | (not (equal?
|
| 59 | (call-with-input-file (format #f "/proc/~a/cmdline" pid)
|
| 60 | get-string-all)
|
| 61 | cmdline))))
|
| 62 | (const #t)))
|
| 63 | (x (zero? (cdr (waitpid x)))))))
|
| 64 |
|
| 65 | (define-syntax-rule (test-assert* description exp)
|
| 66 | (begin
|
| 67 | (when (binfmt-misc?)
|
| 68 | (test-skip 1))
|
| 69 | (test-assert description exp)))
|
| 70 |
|
| 71 | (test-begin "processes")
|
| 72 |
|
| 73 | (test-assert* "not a client"
|
| 74 | (not (find (lambda (session)
|
| 75 | (= (getpid)
|
| 76 | (process-id (daemon-session-client session))))
|
| 77 | (daemon-sessions))))
|
| 78 |
|
| 79 | (test-assert* "client"
|
| 80 | (with-store store
|
| 81 | (let* ((session (find (lambda (session)
|
| 82 | (= (getpid)
|
| 83 | (process-id (daemon-session-client session))))
|
| 84 | (daemon-sessions)))
|
| 85 | (daemon (daemon-session-process session)))
|
| 86 | (and (kill (process-id daemon) 0)
|
| 87 | (string-suffix? "guix-daemon" (first (process-command daemon)))))))
|
| 88 |
|
| 89 | (when (unprivileged-user-namespace-supported?)
|
| 90 | |
| 91 | |
| 92 | |
| 93 | (test-skip 1))
|
| 94 | (test-assert* "client + lock"
|
| 95 | (with-store store
|
| 96 | (call-with-temporary-directory
|
| 97 | (lambda (directory)
|
| 98 | (let* ((token1 (string-append directory "/token1"))
|
| 99 | (token2 (string-append directory "/token2"))
|
| 100 | (exp #~(begin #$(random-text)
|
| 101 | (mkdir #$token1)
|
| 102 | (let loop ()
|
| 103 | (unless (file-exists? #$token2)
|
| 104 | (sleep 1)
|
| 105 | (loop)))
|
| 106 | (mkdir #$output)))
|
| 107 | (guile (package-derivation store %bootstrap-guile))
|
| 108 | (drv (run-with-store store
|
| 109 | (gexp->derivation "foo" exp
|
| 110 | #:guile-for-build guile)))
|
| 111 | (thread (call-with-new-thread
|
| 112 | (lambda ()
|
| 113 | (build-derivations store (list drv)))))
|
| 114 | (_ (let loop ()
|
| 115 | (unless (file-exists? token1)
|
| 116 | (usleep 200)
|
| 117 | (loop))))
|
| 118 | (session (find (lambda (session)
|
| 119 | (= (getpid)
|
| 120 | (process-id (daemon-session-client session))))
|
| 121 | (daemon-sessions)))
|
| 122 | (locks (daemon-session-locks-held (pk 'session session))))
|
| 123 | (call-with-output-file token2 (const #t))
|
| 124 | (equal? (list (string-append (derivation->output-path drv) ".lock"))
|
| 125 | locks))))))
|
| 126 |
|
| 127 | (test-end "processes")
|