From patchwork Tue Dec 15 09:57:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 25794 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 4401C27BC05; Tue, 15 Dec 2020 09:59:20 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D198327BC04 for ; Tue, 15 Dec 2020 09:59:19 +0000 (GMT) Received: from localhost ([::1]:53932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp771-0000Tc-1m for patchwork@mira.cbaines.net; Tue, 15 Dec 2020 04:59:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp75o-0007ie-AB for guix-patches@gnu.org; Tue, 15 Dec 2020 04:58:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44131) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kp75m-0004Xj-LA for guix-patches@gnu.org; Tue, 15 Dec 2020 04:58:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kp75m-0007BJ-FJ for guix-patches@gnu.org; Tue, 15 Dec 2020 04:58:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45253] [PATCH 1/6] tests: Check the build trace for hash mismatches on substitutes. References: <20201215093830.10322-1-ludo@gnu.org> In-Reply-To: <20201215093830.10322-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 15 Dec 2020 09:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45253 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45253@debbugs.gnu.org Received: via spool by 45253-submit@debbugs.gnu.org id=B45253.160802626427528 (code B ref 45253); Tue, 15 Dec 2020 09:58:02 +0000 Received: (at 45253) by debbugs.gnu.org; 15 Dec 2020 09:57:44 +0000 Received: from localhost ([127.0.0.1]:55664 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kp75U-00079p-8L for submit@debbugs.gnu.org; Tue, 15 Dec 2020 04:57:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42652) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kp75S-00079U-V4 for 45253@debbugs.gnu.org; Tue, 15 Dec 2020 04:57:43 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:48635) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp75N-0004Q3-00; Tue, 15 Dec 2020 04:57:37 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=44330 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kp75M-0001j8-FA; Tue, 15 Dec 2020 04:57:36 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Tue, 15 Dec 2020 10:57:25 +0100 Message-Id: <20201215095730.10954-1-ludo@gnu.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * tests/store.scm ("substitute, corrupt output hash, build trace"): New test. --- tests/store.scm | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/store.scm b/tests/store.scm index 38051bf5e5..7f1ec51875 100644 --- a/tests/store.scm +++ b/tests/store.scm @@ -787,6 +787,61 @@ (build-derivations s (list d)) #f)))))) +(test-assert "substitute, corrupt output hash, build trace" + ;; Likewise, and check the build trace. + (with-store s + (let* ((c "hello, world") ; contents of the output + (d (build-expression->derivation + s "corrupt-substitute" + `(mkdir %output) + #:guile-for-build + (package-derivation s %bootstrap-guile (%current-system)))) + (o (derivation->output-path d))) + ;; Make sure we use 'guix substitute'. + (set-build-options s + #:print-build-trace #t + #:use-substitutes? #t + #:fallback? #f + #:substitute-urls (%test-substitute-urls)) + + (with-derivation-substitute d c + (sha256 => (make-bytevector 32 0)) ;select a hash that doesn't match C + + (define output + (call-with-output-string + (lambda (port) + (parameterize ((current-build-output-port port)) + (guard (c ((store-protocol-error? c) #t)) + (build-derivations s (list d)) + #f))))) + + (define actual-hash + (let-values (((port get-hash) + (gcrypt:open-hash-port + (gcrypt:hash-algorithm gcrypt:sha256)))) + (write-file-tree "foo" port + #:file-type+size + (lambda _ + (values 'regular (string-length c))) + #:file-port + (lambda _ + (open-input-string c))) + (close-port port) + (bytevector->nix-base32-string (get-hash)))) + + (define expected-hash + (bytevector->nix-base32-string (make-bytevector 32 0))) + + (define mismatch + (string-append "@ hash-mismatch " o " sha256 " + expected-hash " " actual-hash "\n")) + + (define failure + (string-append "@ substituter-failed " o)) + + (and (string-contains output mismatch) + (string-contains output failure)))))) + (test-assert "substitute --fallback" (with-store s (let* ((t (random-text)) ; contents of the output