From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id yIbkK4I+LWOfXwAAbAwnHQ (envelope-from ) for ; Fri, 23 Sep 2022 07:05:06 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id CHbsK4I+LWPrxQAA9RJhRA (envelope-from ) for ; Fri, 23 Sep 2022 07:05:06 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5F4DA2AB60 for ; Fri, 23 Sep 2022 07:05:06 +0200 (CEST) Received: from localhost ([::1]:41316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obas5-0004xc-FL for larch@yhetil.org; Fri, 23 Sep 2022 01:05:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obapC-0003Vm-3J for guix-patches@gnu.org; Fri, 23 Sep 2022 01:02:09 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obapB-00027N-R4 for guix-patches@gnu.org; Fri, 23 Sep 2022 01:02:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1obapB-00055R-Mh for guix-patches@gnu.org; Fri, 23 Sep 2022 01:02:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58014] [PATCH 09/15] marionette: Preserve screen dumps on failures. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 23 Sep 2022 05:02:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58014 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58014@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 58014-submit@debbugs.gnu.org id=B58014.166390930119422 (code B ref 58014); Fri, 23 Sep 2022 05:02:05 +0000 Received: (at 58014) by debbugs.gnu.org; 23 Sep 2022 05:01:41 +0000 Received: from localhost ([127.0.0.1]:39022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1obaom-00053A-Tj for submit@debbugs.gnu.org; Fri, 23 Sep 2022 01:01:41 -0400 Received: from mail-qk1-f176.google.com ([209.85.222.176]:35795) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1obaok-00052k-95 for 58014@debbugs.gnu.org; Fri, 23 Sep 2022 01:01:39 -0400 Received: by mail-qk1-f176.google.com with SMTP id u28so7622048qku.2 for <58014@debbugs.gnu.org>; Thu, 22 Sep 2022 22:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=yxTJ0RHjxT2PAZ/e46LJmnN5mf7/op5i0642uJjm5ho=; b=Vq/GKIuVWIR4ABBiwllXxcyUT5AsjHdE6cxXu1opN0DP38FpUj2GP330PzgyDxMRrd Yd9GPwKfYJOtaNMFF6NX7r6h3B/ZFfDIbcZBZLGWOS736mXBxnaOXrE0av8NYciwkaYT 7VlgmjTCg3sNfeL1+seZmXJyEwQ5x04bhKf0mxre8GqTt2xGBKCS1tkna++xYWLpAjM4 IHr7tNoBJXmKhRfDNEYp9qIzEBjG75sv94LiNMH1U6/otqRWVBZh5UlkbuoT5mpGr5Mf PuwsjAyptPHbXmD5xJcW9ME+L4RhbNtQBkSpubivmyqIF9f0amwcmEQ+O64iKqNVbW/8 zyvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=yxTJ0RHjxT2PAZ/e46LJmnN5mf7/op5i0642uJjm5ho=; b=U1CZbOhFlnqmPjgyNVbDMW5jsjKrhODAoFKLxoQVrfsB6mZp+tkS03eW7MG81QKQO3 fmBFktlZJ2PtlpAJLQ1YBLKVWxgSdDka3iLLHUS930wm9j7JgxKIg0bBgF8t9CsVPBt+ fRuCN9196IETNPQROI6mSHyHoLuLgzIF3W/RSAq3jYE/c+ZFU67/nMrSDixj7/ttqNJC Bqpb3B7VbldMd5UyrwLt8j0kahGcWerf4tE2CqoxO4NlVaH5EPoAlH/31l6JiQWX8xaB S2BvCP8JQhZ5EmnwUmlumMFX76NRo6BA8Zgw7HyngOdg7BVt+DR06JfXKgJ7f0zzQd/q Lpkg== X-Gm-Message-State: ACrzQf0BMyU3IKXfP1oNVCtYiq0RM28kIiSUsrfZC0xEsn7FDRJtq2en 1PX6kzCtIxSVWQo8TpmQaEcB3NNLk18= X-Google-Smtp-Source: AMsMyM6iLz85No34uDd0aXO243P2nWTVUIWrPKafNVcHqWuKKA6COaNtPO5tkm/ClDIE2bdWKGm4lA== X-Received: by 2002:a05:620a:4155:b0:6ce:3e4f:9b1c with SMTP id k21-20020a05620a415500b006ce3e4f9b1cmr4453443qko.744.1663909292237; Thu, 22 Sep 2022 22:01:32 -0700 (PDT) Received: from localhost.localdomain ([2607:fad8:4:3::1001]) by smtp.gmail.com with ESMTPSA id de4-20020a05620a370400b006bbb07ebd83sm5263534qkb.108.2022.09.22.22.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 22:01:31 -0700 (PDT) From: Maxim Cournoyer Date: Fri, 23 Sep 2022 01:00:36 -0400 Message-Id: <20220923050042.29893-9-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220923050042.29893-1-maxim.cournoyer@gmail.com> References: <20220923050042.29893-1-maxim.cournoyer@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1663909506; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=yxTJ0RHjxT2PAZ/e46LJmnN5mf7/op5i0642uJjm5ho=; b=l0Vni5q9FdmTz9vfPzEXXkAMvOOaZOXgKbTTb3aJohfViVuSRfmSK/Ng1+rSK+jJMWMjKI PRRP4NleMjwJNV9NJa7SMrWt2rQd4Fg6MrVPVxhzwZyqwfcTta/0Ejnc34QfantD17/A15 Kn3BcLPphXyzNFGPBra/jmNU2I6pSeTaulvPdyr4MLLoQ+zB1tymMEIKLwV7uzx68eE1SW GFkwJl/t+50MqQFNxVftc/9dKBYtaAoLA+Q35y0+scgteVIfo9HDdRmUTT5AK67wms5Z/C xKmqNC9lwwYUMCthmcfq6+x13iIKvTHJBvyXHm4ET8Eu/8NWld0F+wgcjHLSLA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663909506; a=rsa-sha256; cv=none; b=bimPp8+Dpr5TRE0X6RSb5rlqt1GY0DqjOt6oKV8ZXaMG8v4tTG7M2IvPUI9U9AA5tkkQUc c2zS8fKJkm6By/lXLEnrIlp3KL6kaZ+wG2vQR/ZfeqElJWS32EhYUEKLt1ETsm0LjsSQs5 YSxz6KLgybtIK2Xn5ffb4G0wCkBYk+ZqP+59wSzmJNZpSgPU4ob7h7XoLb61xPvJD8yA6C bGumVOo3vtC/HWyN6yYOpGm2er0YYWk1X+lzbvD0Llyiuim4G5GJKFVE/KjnEGGgQF8hpY pr4qG7QHhtV9nbk/9XERQPqSNpsgWKZULdC09NEalrT/EWsZWMXME4mDFP6oGQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="Vq/GKIuV"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 6.75 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="Vq/GKIuV"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 5F4DA2AB60 X-Spam-Score: 6.75 X-Migadu-Scanner: scn0.migadu.com X-TUID: 7oaMuTcpwPzT This is to make it easier to debug test failures involving 'wait-for-screen-text': the screendump image used for the OCR is now preserved for inspection when 'wait-for-screen-text' fails. * gnu/build/marionette.scm (marionette-screen-text): Return the screendump image file as the second value. Adjust doc. (wait-for-screen-text): Add the preserved screendump image file name to the error message. Adjust doc. --- gnu/build/marionette.scm | 42 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/gnu/build/marionette.scm b/gnu/build/marionette.scm index aba6fb8146..5f8a74717a 100644 --- a/gnu/build/marionette.scm +++ b/gnu/build/marionette.scm @@ -22,6 +22,7 @@ (define-module (gnu build marionette) #:use-module (srfi srfi-9) #:use-module (srfi srfi-26) #:use-module (srfi srfi-64) + #:use-module (srfi srfi-71) #:use-module (rnrs io ports) #:use-module (ice-9 match) #:use-module (ice-9 popen) @@ -311,18 +312,20 @@ (define* (invoke-tesseract-ocr image #:key (tesseract "tesseract")) (define* (marionette-screen-text marionette #:key (ocr "ocrad")) "Take a screenshot of MARIONETTE, perform optical character -recognition (OCR), and return the text read from the screen as a string. Do -this by invoking OCR, which should be the file name of GNU Ocrad's -@command{ocrad} or Tesseract OCR's @command{tesseract} command." +recognition (OCR), and return the text read from the screen as a string, along +the screen dump image used. Do this by invoking OCR, which should be the file +name of GNU Ocrad's@command{ocrad} or Tesseract OCR's @command{tesseract} +command. The screen dump image returned as the second value should be deleted +if it is not needed." (define image (string-append (tmpnam) ".ppm")) ;; Use the QEMU Monitor to save an image of the screen to the host. (marionette-control (string-append "screendump " image) marionette) ;; Process it via the OCR. (cond ((string-contains ocr "ocrad") - (invoke-ocrad-ocr image #:ocrad ocr)) + (values (invoke-ocrad-ocr image #:ocrad ocr) image)) ((string-contains ocr "tesseract") - (invoke-tesseract-ocr image #:tesseract ocr)) + (values (invoke-tesseract-ocr image #:tesseract ocr) image)) (else (error "unsupported ocr command")))) (define* (wait-for-screen-text marionette predicate @@ -330,21 +333,34 @@ (define* (wait-for-screen-text marionette predicate (ocr "ocrad") (timeout 30)) "Wait for TIMEOUT seconds or until the screen text on MARIONETTE matches -PREDICATE, whichever comes first. Raise an error when TIMEOUT is exceeded." +PREDICATE, whichever comes first. Raise an error when TIMEOUT is exceeded. +The error contains the recognized text along the preserved file name of the +screen dump, which is relative to the current working directory." (define start (car (gettimeofday))) (define end (+ start timeout)) - (let loop ((last-text #f)) + (let loop ((last-text #f) + (last-screendump #f)) (if (> (car (gettimeofday)) end) - (error "'wait-for-screen-text' timeout" 'ocr-text: last-text) - (let ((text (marionette-screen-text marionette #:ocr ocr))) - (or (predicate text) - (begin - (sleep 1) - (loop text))))))) + (let ((screendump-backup (string-drop last-screendump 5))) + ;; Move the file from /tmp/fileXXXXXX.pmm to the current working + ;; directory, so that it is preserved in the test derivation output. + (copy-file last-screendump screendump-backup) + (delete-file last-screendump) + (error "'wait-for-screen-text' timeout" + 'ocr-text: last-text + 'screendump: screendump-backup)) + (let* ((text screendump (marionette-screen-text marionette #:ocr ocr)) + (result (predicate text))) + (cond (result + (delete-file screendump) + result) + (else + (sleep 1) + (loop text screendump))))))) (define %qwerty-us-keystrokes ;; Maps "special" characters to their keystrokes. -- 2.37.3