status.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-status)
  19. #:use-module (guix status)
  20. #:use-module (srfi srfi-1)
  21. #:use-module (srfi srfi-11)
  22. #:use-module (srfi srfi-64)
  23. #:use-module (rnrs bytevectors)
  24. #:use-module (rnrs io ports)
  25. #:use-module (ice-9 match))
  26. (test-begin "status")
  27. (test-equal "compute-status, no-op"
  28. (build-status)
  29. (let-values (((port get-status)
  30. (build-event-output-port compute-status)))
  31. (display "foo\nbar\n\baz\n" port)
  32. (get-status)))
  33. (test-equal "compute-status, builds + substitutes"
  34. (list (build-status
  35. (building (list (build "foo.drv" "x86_64-linux")))
  36. (downloading (list (download "bar" "http://example.org/bar"
  37. #:size 500
  38. #:start 'now))))
  39. (build-status
  40. (building (list (build "foo.drv" "x86_64-linux")))
  41. (downloading (list (download "bar" "http://example.org/bar"
  42. #:size 500
  43. #:transferred 42
  44. #:start 'now))))
  45. (build-status
  46. (builds-completed (list (build "foo.drv" "x86_64-linux")))
  47. (downloads-completed (list (download "bar" "http://example.org/bar"
  48. #:size 500
  49. #:transferred 500
  50. #:start 'now
  51. #:end 'now)))))
  52. (let-values (((port get-status)
  53. (build-event-output-port (lambda (event status)
  54. (compute-status event status
  55. #:current-time
  56. (const 'now))))))
  57. (display "@ build-started foo.drv - x86_64-linux \n" port)
  58. (display "@ substituter-started bar\n" port)
  59. (display "@ download-started bar http://example.org/bar 500\n" port)
  60. (display "various\nthings\nget\nwritten\n" port)
  61. (let ((first (get-status)))
  62. (display "@ download-progress bar http://example.org/bar 500 42\n"
  63. port)
  64. (let ((second (get-status)))
  65. (display "@ download-progress bar http://example.org/bar 500 84\n"
  66. port)
  67. (display "@ build-succeeded foo.drv\n" port)
  68. (display "@ download-succeeded bar http://example.org/bar 500\n" port)
  69. (display "Almost done!\n" port)
  70. (display "@ substituter-succeeded bar\n" port)
  71. (list first second (get-status))))))
  72. (test-equal "compute-status, missing events"
  73. (list (build-status
  74. (building (list (build "foo.drv" "x86_64-linux"
  75. #:log-file "foo.log")))
  76. (downloading (list (download "baz" "http://example.org/baz"
  77. #:size 500
  78. #:transferred 42
  79. #:start 'now)
  80. (download "bar" "http://example.org/bar"
  81. #:size 999
  82. #:transferred 0
  83. #:start 'now))))
  84. (build-status
  85. (builds-completed (list (build "foo.drv" "x86_64-linux"
  86. #:log-file "foo.log")))
  87. (downloads-completed (list (download "baz" "http://example.org/baz"
  88. #:size 500
  89. #:transferred 500
  90. #:start 'now
  91. #:end 'now)
  92. (download "bar" "http://example.org/bar"
  93. #:size 999
  94. #:transferred 999
  95. #:start 'now
  96. #:end 'now)))))
  97. ;; Below we omit 'substituter-started' events and the like.
  98. (let-values (((port get-status)
  99. (build-event-output-port (lambda (event status)
  100. (compute-status event status
  101. #:current-time
  102. (const 'now))))))
  103. (display "@ build-started foo.drv - x86_64-linux foo.log\n" port)
  104. (display "@ download-started bar http://example.org/bar 999\n" port)
  105. (display "various\nthings\nget\nwritten\n" port)
  106. (display "@ download-progress baz http://example.org/baz 500 42\n"
  107. port)
  108. (let ((first (get-status)))
  109. (display "@ build-succeeded foo.drv\n" port)
  110. (display "@ download-succeeded bar http://example.org/bar 999\n" port)
  111. (display "Almost done!\n" port)
  112. (display "@ substituter-succeeded baz\n" port)
  113. (list first (get-status)))))
  114. (test-equal "build-output-port, UTF-8"
  115. '((build-log #f "lambda is λ!\n"))
  116. (let-values (((port get-status) (build-event-output-port cons '()))
  117. ((bv) (string->utf8 "lambda is λ!\n")))
  118. (put-bytevector port bv)
  119. (force-output port)
  120. (get-status)))
  121. (test-equal "current-build-output-port, UTF-8 + garbage"
  122. ;; What about a mixture of UTF-8 + garbage?
  123. (let ((replacement "�"))
  124. `((build-log #f ,(string-append "garbage: " replacement "lambda: λ\n"))))
  125. (let-values (((port get-status) (build-event-output-port cons '())))
  126. (display "garbage: " port)
  127. (put-bytevector port #vu8(128))
  128. (put-bytevector port (string->utf8 "lambda: λ\n"))
  129. (force-output port)
  130. (get-status)))
  131. (test-equal "compute-status, multiplexed build output"
  132. (list (build-status
  133. (building (list (build "foo.drv" "x86_64-linux" #:id 121)))
  134. (downloading (list (download "bar" "http://example.org/bar"
  135. #:size 999
  136. #:start 'now))))
  137. (build-status
  138. (building (list (build "foo.drv" "x86_64-linux" #:id 121)))
  139. (downloading (list (download "bar" "http://example.org/bar"
  140. #:size 999
  141. #:transferred 42
  142. #:start 'now))))
  143. (build-status
  144. ;; "bar" is now only listed as a download.
  145. (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121)))
  146. (downloads-completed (list (download "bar" "http://example.org/bar"
  147. #:size 999
  148. #:transferred 999
  149. #:start 'now
  150. #:end 'now)))))
  151. (let-values (((port get-status)
  152. (build-event-output-port (lambda (event status)
  153. (compute-status event status
  154. #:current-time
  155. (const 'now)
  156. #:derivation-path->output-path
  157. (match-lambda
  158. ("bar.drv" "bar")))))))
  159. (display "@ build-started foo.drv - x86_64-linux 121\n" port)
  160. (display "@ build-started bar.drv - armhf-linux bar.log 144\n" port)
  161. (display "@ build-log 121 6\nHello!" port)
  162. (display "@ build-log 144 50
  163. @ download-started bar http://example.org/bar 999\n" port)
  164. (let ((first (get-status)))
  165. (display "@ build-log 121 30\n@ build-started FAKE!.drv 555\n")
  166. (display "@ build-log 144 54
  167. @ download-progress bar http://example.org/bar 999 42\n"
  168. port)
  169. (let ((second (get-status)))
  170. (display "@ download-succeeded bar http://example.org/bar 999\n" port)
  171. (display "@ build-succeeded foo.drv\n" port)
  172. (display "@ build-succeeded bar.drv\n" port)
  173. (list first second (get-status))))))
  174. (test-equal "compute-status, build completion"
  175. (list (build-status
  176. (building (list (build "foo.drv" "x86_64-linux" #:id 121))))
  177. (build-status
  178. (building (list (build "foo.drv" "x86_64-linux" #:id 121
  179. #:completion 0.))))
  180. (build-status
  181. (building (list (build "foo.drv" "x86_64-linux" #:id 121
  182. #:completion 50.))))
  183. (build-status
  184. (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121
  185. #:completion 100.)))))
  186. (let-values (((port get-status)
  187. (build-event-output-port (lambda (event status)
  188. (compute-status event status
  189. #:current-time
  190. (const 'now))))))
  191. (display "@ build-started foo.drv - x86_64-linux 121\n" port)
  192. (display "@ build-log 121 6\nHello!" port)
  193. (let ((first (get-status)))
  194. (display "@ build-log 121 20\n[ 0/100] building X\n" port)
  195. (display "@ build-log 121 6\nHello!" port)
  196. (let ((second (get-status)))
  197. (display "@ build-log 121 20\n[50/100] building Y\n" port)
  198. (display "@ build-log 121 6\nHello!" port)
  199. (let ((third (get-status)))
  200. (display "@ build-log 121 21\n[100/100] building Z\n" port)
  201. (display "@ build-log 121 6\nHello!" port)
  202. (display "@ build-succeeded foo.drv\n" port)
  203. (list first second third (get-status)))))))
  204. (test-equal "compute-status, build phase"
  205. (list (build-status
  206. (building (list (build "foo.drv" "x86_64-linux" #:id 121
  207. #:phase 'configure))))
  208. (build-status
  209. (building (list (build "foo.drv" "x86_64-linux" #:id 121
  210. #:phase 'configure
  211. #:completion 50.))))
  212. (build-status
  213. (building (list (build "foo.drv" "x86_64-linux" #:id 121
  214. #:phase 'install))))
  215. (build-status
  216. (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121
  217. #:phase 'install)))))
  218. (let-values (((port get-status)
  219. (build-event-output-port (lambda (event status)
  220. (compute-status event status
  221. #:current-time
  222. (const 'now))))))
  223. (display "@ build-started foo.drv - x86_64-linux 121\n" port)
  224. (display "@ build-log 121 27\nstarting phase `configure'\n" port)
  225. (display "@ build-log 121 6\nabcde!" port)
  226. (let ((first (get-status)))
  227. (display "@ build-log 121 20\n[50/100] building Y\n" port)
  228. (display "@ build-log 121 6\nfghik!" port)
  229. (let ((second (get-status)))
  230. (display "@ build-log 121 21\n[100/100] building Z\n" port)
  231. (display "@ build-log 121 25\nstarting phase `install'\n" port)
  232. (display "@ build-log 121 6\nlmnop!" port)
  233. (let ((third (get-status)))
  234. (display "@ build-succeeded foo.drv\n" port)
  235. (list first second third (get-status)))))))
  236. (test-end "status")