aboutsummaryrefslogtreecommitdiff
path: root/tests/graph.scm
blob: 32317195d71ae8fd8d641d26a9879fc440de7f00 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-rw-r--r--icons/hachette.svg161
1 files changed, 161 insertions, 0 deletions
lude bootstrap binaries. (let-values (((nodes edges) (nodes+edges))) (every (lambda (name) (find (cut string=? name <>) (match nodes (((labels names) ...) names)))) (match %bootstrap-inputs (((labels packages) ...) (map package-full-name packages)))))))) (test-assert "bag DAG, including origins" (let-values (((backend nodes+edges) (make-recording-backend))) (let* ((m (lambda* (uri hash-type hash name #:key system) (text-file "foo-1.2.3.tar.gz" "This is a fake!"))) (o (origin (method m) (uri "the-uri") (sha256 #vu8(0 1 2)))) (p (dummy-package "p" (source o)))) (run-with-store %store (export-graph (list p) 'port #:node-type %bag-with-origins-node-type #:backend backend)) ;; We should see O among the nodes, with an edge coming from P. (let-values (((nodes edges) (nodes+edges))) (run-with-store %store (mlet %store-monad ((o* (lower-object o)) (p* (lower-object p)) (g (lower-object (default-guile)))) (return (and (find (match-lambda ((file "the-uri") #t) (_ #f)) nodes) (find (match-lambda ((source target) (and (string=? source (derivation-file-name p*)) (string=? target o*)))) edges) ;; There must also be an edge from O to G. (find (match-lambda ((source target) (and (string=? source o*) (string=? target (derivation-file-name g))))) edges))))))))) (test-assert "derivation DAG" (let-values (((backend nodes+edges) (make-recording-backend))) (run-with-store %store (mlet* %store-monad ((txt (text-file "text-file" "Hello!")) (guile (package->derivation %bootstrap-guile)) (drv (gexp->derivation "output" #~(symlink #$txt #$output) #:guile-for-build guile))) ;; We should get at least these 3 nodes and corresponding edges. (mbegin %store-monad (export-graph (list drv) 'port #:node-type %derivation-node-type #:backend backend) (let-values (((nodes edges) (nodes+edges))) ;; XXX: For some reason we need to throw in some 'basename'. (return (and (match nodes (((ids labels) ...) (let ((ids (map basename ids))) (every (lambda (item) (member (basename item) ids)) (list txt (derivation-file-name drv) (derivation-file-name guile)))))) (every (cut member <> (map (lambda (edge) (map basename edge)) edges)) (list (map (compose basename derivation-file-name) (list drv guile)) (list (basename (derivation-file-name drv)) (basename txt)))))))))))) (test-assert "reference DAG" (let-values (((backend nodes+edges) (make-recording-backend))) (run-with-store %store (mlet* %store-monad ((txt (text-file "text-file" "Hello!")) (guile (package->derivation %bootstrap-guile)) (drv (gexp->derivation "output" #~(symlink #$txt #$output) #:guile-for-build guile)) (out -> (derivation->output-path drv))) ;; We should see only OUT and TXT, with an edge from the former to the ;; latter. (mbegin %store-monad (built-derivations (list drv)) (export-graph (list (derivation->output-path drv)) 'port #:node-type %reference-node-type #:backend backend) (let-values (((nodes edges) (nodes+edges))) (return (and (equal? (match nodes (((ids labels) ...) ids)) (list out txt)) (equal? edges `((,out ,txt))))))))))) (test-assert "node-edges" (run-with-store %store (let ((packages (fold-packages cons '()))) (mlet %store-monad ((edges (node-edges %package-node-type packages))) (return (and (null? (edges sed)) (lset= eq? (edges guile-2.0) (match (package-direct-inputs guile-2.0) (((labels packages _ ...) ...) packages))))))))) (test-assert "node-transitive-edges + node-back-edges" (run-with-store %store (let ((packages (fold-packages cons '())) (bootstrap? (lambda (package) (string-contains (location-file (package-location package)) "bootstrap.scm"))) (trivial? (lambda (package) (eq? (package-build-system package) trivial-build-system)))) (mlet %store-monad ((edges (node-back-edges %bag-node-type packages))) (let* ((glibc (canonical-package glibc)) (dependents (node-transitive-edges (list glibc) edges)) (diff (lset-difference eq? packages dependents))) ;; All the packages depend on libc, except bootstrap packages and ;; some that use TRIVIAL-BUILD-SYSTEM. (return (null? (remove (lambda (package) (or (trivial? package) (bootstrap? package))) diff)))))))) (test-assert "node-transitive-edges, no duplicates" (run-with-store %store (let* ((p0 (dummy-package "p0")) (p1a (dummy-package "p1a" (inputs `(("p0" ,p0))))) (p1b (dummy-package "p1b" (inputs `(("p0" ,p0))))) (p2 (dummy-package "p2" (inputs `(("p1a" ,p1a) ("p1b" ,p1b)))))) (mlet %store-monad ((edges (node-edges %package-node-type (list p2 p1a p1b p0)))) (return (lset= eq? (node-transitive-edges (list p2) edges) (list p1a p1b p0))))))) (test-end "graph")