From dc0f74e5fc26977a3ee6c4f2aa74a141f4359982 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 18 Jan 2017 23:21:29 +0100 Subject: Add (guix status) and use it for pretty colored output. * guix/progress.scm (progress-reporter/trace): New procedure. (%progress-interval): New variable. (progress-reporter/file): Use it. * guix/scripts/build.scm (set-build-options-from-command-line): Pass #:print-extended-build-trace?. (%default-options): Add 'print-extended-build-trace?'. (guix-build): Parameterize CURRENT-TERMINAL-COLUMNS. Use 'build-status-updater'. * guix/scripts/environment.scm (%default-options): Add 'print-extended-build-trace?'. (guix-environment): Wrap body in 'with-status-report'. * guix/scripts/pack.scm (%default-options): Add 'print-build-trace?' and 'print-extended-build-trace?'. (guix-pack): Wrap body in 'with-status-report'. * guix/scripts/package.scm (%default-options, guix-package): Likewise. * guix/scripts/system.scm (%default-options, guix-system): Likewise. * guix/scripts/pull.scm (%default-options, guix-pull): Likewise. * guix/scripts/substitute.scm (progress-report-port): Don't call STOP when TOTAL is zero. (process-substitution): Add #:print-build-trace? and honor it. (guix-substitute)[print-build-trace?]: New variable. Pass #:print-build-trace? to 'process-substitution'. * guix/status.scm: New file. * guix/store.scm (set-build-options): Add #:print-extended-build-trace?; pass it into PAIRS. (%protocol-version): Bump. (protocol-version, nix-server-version): New procedures. (current-store-protocol-version): New variable. (with-store, build-things): Parameterize it. * guix/ui.scm (build-output-port): Remove. (colorize-string): Export. * po/guix/POTFILES.in: Add guix/status.scm. * tests/status.scm: New file. * Makefile.am (SCM_TESTS): Add it. * nix/libstore/worker-protocol.hh (PROTOCOL_VERSION): Bump to 0x162. * nix/libstore/build.cc (DerivationGoal::registerOutputs) (SubstitutionGoal::finished): Print a "@ hash-mismatch" trace before throwing. --- tests/status.scm | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/status.scm (limited to 'tests') diff --git a/tests/status.scm b/tests/status.scm new file mode 100644 index 0000000000..04dedb702c --- /dev/null +++ b/tests/status.scm @@ -0,0 +1,115 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2018 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (test-status) + #:use-module (guix status) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) + #:use-module (srfi srfi-64)) + +(test-begin "status") + +(test-equal "compute-status, no-op" + (build-status) + (let-values (((port get-status) + (build-event-output-port compute-status))) + (display "foo\nbar\n\baz\n" port) + (get-status))) + +(test-equal "compute-status, builds + substitutes" + (list (build-status + (building '("foo.drv")) + (downloading (list (download "bar" "http://example.org/bar" + #:size 500 + #:start 'now)))) + (build-status + (building '("foo.drv")) + (downloading (list (download "bar" "http://example.org/bar" + #:size 500 + #:transferred 42 + #:start 'now)))) + (build-status + (builds-completed '("foo.drv")) + (downloads-completed (list (download "bar" "http://example.org/bar" + #:size 500 + #:transferred 500 + #:start 'now + #:end 'now))))) + (let-values (((port get-status) + (build-event-output-port (lambda (event status) + (compute-status event status + #:current-time + (const 'now)))))) + (display "@ build-started foo.drv\n" port) + (display "@ substituter-started bar\n" port) + (display "@ download-started bar http://example.org/bar 500\n" port) + (display "various\nthings\nget\nwritten\n" port) + (let ((first (get-status))) + (display "@ download-progress bar http://example.org/bar 500 42\n" + port) + (let ((second (get-status))) + (display "@ download-progress bar http://example.org/bar 500 84\n" + port) + (display "@ build-succeeded foo.drv\n" port) + (display "@ download-succeeded bar http://example.org/bar 500\n" port) + (display "Almost done!\n" port) + (display "@ substituter-succeeded bar\n" port) + (list first second (get-status)))))) + +(test-equal "compute-status, missing events" + (list (build-status + (building '("foo.drv")) + (downloading (list (download "baz" "http://example.org/baz" + #:size 500 + #:transferred 42 + #:start 'now) + (download "bar" "http://example.org/bar" + #:size 999 + #:transferred 0 + #:start 'now)))) + (build-status + (builds-completed '("foo.drv")) + (downloads-completed (list (download "baz" "http://example.org/baz" + #:size 500 + #:transferred 500 + #:start 'now + #:end 'now) + (download "bar" "http://example.org/bar" + #:size 999 + #:transferred 999 + #:start 'now + #:end 'now))))) + ;; Below we omit 'substituter-started' events and the like. + (let-values (((port get-status) + (build-event-output-port (lambda (event status) + (compute-status event status + #:current-time + (const 'now)))))) + (display "@ build-started foo.drv\n" port) + (display "@ download-started bar http://example.org/bar 999\n" port) + (display "various\nthings\nget\nwritten\n" port) + (display "@ download-progress baz http://example.org/baz 500 42\n" + port) + (let ((first (get-status))) + (display "@ build-succeeded foo.drv\n" port) + (display "@ download-succeeded bar http://example.org/bar 999\n" port) + (display "Almost done!\n" port) + (display "@ substituter-succeeded baz\n" port) + (list first (get-status))))) + +(test-end "status") -- cgit v1.2.3 From d4e9317b9de29f77eb8559bd99e0e2fe20d5f1fe Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 27 Sep 2018 23:46:44 +0200 Subject: tests: Update (guix build store-copy) tests. This is a followup to a387b0bebb151a766ca6a454a891f2370c96703c. * tests/gexp.scm ("gexp->derivation, store copy") ("gexp->derivation #:references-graphs"): Add (guix progress) and (guix records) to the imported modules. --- tests/gexp.scm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/gexp.scm b/tests/gexp.scm index 5d049cd5fc..813ea2ff6f 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -615,6 +615,8 @@ `(("graph" ,two)) #:modules '((guix build store-copy) + (guix progress) + (guix records) (guix sets) (guix build utils)))) (ok? (built-derivations (list drv))) @@ -817,6 +819,8 @@ (two (gexp->derivation "two" #~(symlink #$one #$output:chbouib))) (build -> (with-imported-modules '((guix build store-copy) + (guix progress) + (guix records) (guix sets) (guix build utils)) #~(begin -- cgit v1.2.3 From 7fed9353ece5974ff431fa666a530da237a12085 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 27 Sep 2018 23:58:05 +0200 Subject: tests: Adjust services tests to new 'shepherd-service-upgrade'. This is a followup to 4245ddcbc9f935804c17c97872b90ec1050c2d75. * tests/services.scm ("shepherd-service-upgrade: one unchanged, one upgraded, one new") ("shepherd-service-upgrade: service depended on is not unloaded") ("shepherd-service-upgrade: obsolete services that depend on each other"): Adjust to changes in 'shepherd-service-upgrade'. --- tests/services.scm | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/services.scm b/tests/services.scm index 1ad577e601..5827dee80d 100644 --- a/tests/services.scm +++ b/tests/services.scm @@ -207,13 +207,14 @@ list)) (test-equal "shepherd-service-upgrade: one unchanged, one upgraded, one new" - '(((bar)) ;unload - ((bar) (baz))) ;load + '(() ;unload + ((foo))) ;restart (call-with-values (lambda () - ;; Here 'foo' is not upgraded because it is still running, whereas - ;; 'bar' is upgraded because it is not currently running. 'baz' is - ;; loaded because it's a new service. + ;; Here 'foo' is replaced and must be explicitly restarted later + ;; because it is still running, whereas 'bar' is upgraded right away + ;; because it is not currently running. 'baz' is loaded because it's + ;; a new service. (shepherd-service-upgrade (list (live-service '(foo) '() #t) (live-service '(bar) '() #f) @@ -224,30 +225,31 @@ (start #t)) (shepherd-service (provision '(baz)) (start #t))))) - (lambda (unload load) + (lambda (unload restart) (list (map live-service-provision unload) - (map shepherd-service-provision load))))) + (map shepherd-service-provision restart))))) (test-equal "shepherd-service-upgrade: service depended on is not unloaded" '(((baz)) ;unload - ()) ;load + ((foo))) ;restart (call-with-values (lambda () ;; Service 'bar' is not among the target services; yet, it must not be - ;; unloaded because 'foo' depends on it. + ;; unloaded because 'foo' depends on it. 'foo' gets replaced but it + ;; must be restarted manually. (shepherd-service-upgrade (list (live-service '(foo) '(bar) #t) (live-service '(bar) '() #t) ;still used! (live-service '(baz) '() #t)) (list (shepherd-service (provision '(foo)) (start #t))))) - (lambda (unload load) + (lambda (unload restart) (list (map live-service-provision unload) - (map shepherd-service-provision load))))) + (map shepherd-service-provision restart))))) (test-equal "shepherd-service-upgrade: obsolete services that depend on each other" '(((foo) (bar) (baz)) ;unload - ((qux))) ;load + ()) ;restart (call-with-values (lambda () ;; 'foo', 'bar', and 'baz' depend on each other, but all of them are @@ -258,9 +260,9 @@ (live-service '(baz) '() #t)) ;obsolete (list (shepherd-service (provision '(qux)) (start #t))))) - (lambda (unload load) + (lambda (unload restart) (list (map live-service-provision unload) - (map shepherd-service-provision load))))) + (map shepherd-service-provision restart))))) (test-eq "lookup-service-types" system-service-type -- cgit v1.2.3