Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC521CED611 for ; Thu, 10 Oct 2024 00:30:15 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BBA4D88EF8; Thu, 10 Oct 2024 02:29:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="exuvMa+D"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 18D5E88EB5; Thu, 10 Oct 2024 02:29:27 +0200 (CEST) Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D1BD888E3A for ; Thu, 10 Oct 2024 02:29:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-710dad96bf7so136525a34.0 for ; Wed, 09 Oct 2024 17:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728520163; x=1729124963; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rPeWe9dRah1pScSRt6SPYZLWqv2flwUxkpOA4MuYR+M=; b=exuvMa+DLLOyXZz4rNxEjzMOF7atVIvKvD6JyWBCuQlgpEK7VJ3lQWfn9JZ+jmYHyd 9qRZalrZZlLnzalrA5xRv+KmDR6iO1JFOFeMYPNGy502HgTPlzcnSVLXV+wmrPz73eYc ajuqtod63cqxCbSqmi6D0xGJVOkggP5ujYwP0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728520163; x=1729124963; 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:message-id:reply-to; bh=rPeWe9dRah1pScSRt6SPYZLWqv2flwUxkpOA4MuYR+M=; b=A4w9vYbdASKd8TzyGqlT+Ul3xcvdB15GAUercK7hPEx7AV3/3bI2FBTtyea2niWyM2 /tD+TYeeHTAanfvmQIyKk4DRtMLakkb17Tjh7e71c/S1B3TGMVNBkwwcyuSGpCytnUh9 CYjDp35IVXASb9z79AK1WENocteGiYLth9ua9JIUtOPF0xHKdDLK0sAEwZR07a63uiZj zqXjOE1e2nAIzAt1GDnhYsmJtLOqNSMx3i/bDCuJsxZaTlT0nBhhspsOOPMo66/A3iPk qUiYLUIjWNYDRi915Zrm+HOLsUp5ZynZXJ5ZAIv5cA+IeU7/RWiVmVkcb8Nk9R48Uaoz F/lQ== X-Gm-Message-State: AOJu0Yy+AperrhdO4d72SCQ+owIHxGuJEv4sLmXPGCATB3iJ0KAF0WES AhfYWcJNBKExHIqru3eRrJTSOBR6ek2+F+S+4aR82ArARAcp7YzNYdjk69enWpydBige3aV0CXf zOQ== X-Google-Smtp-Source: AGHT+IFE0yYO0ZQ/OTiDa/dtPACqIR3gYbY+yd1krk2+q49QhHXFBBdVKUTbyRxfSeCIUyuueVogtw== X-Received: by 2002:a05:6830:2583:b0:710:fbce:8b5e with SMTP id 46e09a7af769-716a41b7056mr4543634a34.11.1728520163313; Wed, 09 Oct 2024 17:29:23 -0700 (PDT) Received: from chromium.org (c-73-153-3-119.hsd1.co.comcast.net. [73.153.3.119]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-717cfed7536sm9073a34.2.2024.10.09.17.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 17:29:22 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH v7 6/8] test: Detect dead connections Date: Wed, 9 Oct 2024 18:29:03 -0600 Message-ID: <20241010002907.19383-7-sjg@chromium.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010002907.19383-1-sjg@chromium.org> References: <20241010002907.19383-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean When the connection to a board dies, assume it is dead forever until some user action is taken. Skip all remaining tests. This avoids CI runs taking an hour, with hundreds of 30-second timeouts all to no avail. Signed-off-by: Simon Glass --- (no changes since v1) test/py/conftest.py | 19 +++++++++++++++++-- test/py/u_boot_spawn.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index 85e1979dc79..46a410cf268 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -24,6 +24,7 @@ import pytest import re from _pytest.runner import runtestprotocol import sys +from u_boot_spawn import BootFail, Timeout, Unexpected, handle_exception # Globals: The HTML log file, and the connection to the U-Boot console. log = None @@ -254,6 +255,7 @@ def pytest_configure(config): ubconfig.board_identity = board_identity ubconfig.gdbserver = gdbserver ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb' + ubconfig.connection_ok = True env_vars = ( 'board_type', @@ -420,8 +422,21 @@ def u_boot_console(request): Returns: The fixture value. """ - - console.ensure_spawned() + if not ubconfig.connection_ok: + pytest.skip('Cannot get target connection') + return None + try: + console.ensure_spawned() + except OSError as err: + handle_exception(ubconfig, console, log, err, 'Lab failure', True) + except Timeout as err: + handle_exception(ubconfig, console, log, err, 'Lab timeout', True) + except BootFail as err: + handle_exception(ubconfig, console, log, err, 'Boot fail', True, + console.get_spawn_output()) + except Unexpected: + handle_exception(ubconfig, console, log, err, 'Unexpected test output', + False) return console anchors = {} diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index bcba7b5cd43..24d369035e5 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -8,6 +8,7 @@ Logic to spawn a sub-process and interact with its stdio. import os import re import pty +import pytest import signal import select import time @@ -27,6 +28,43 @@ class BootFail(Exception): class Unexpected(Exception): """An exception sub-class that indicates that unexpected test was seen.""" + +def handle_exception(ubconfig, console, log, err, name, fatal, output=''): + """Handle an exception from the console + + Exceptions can occur when there is unexpected output or due to the board + crashing or hanging. Some exceptions are likely fatal, where retrying will + just chew up time to no available. In those cases it is best to cause + further tests be skipped. + + Args: + ubconfig (ArbitraryAttributeContainer): ubconfig object + log (Logfile): Place to log errors + console (ConsoleBase): Console to clean up, if fatal + err (Exception): Exception which was thrown + name (str): Name of problem, to log + fatal (bool): True to abort all tests + output (str): Extra output to report on boot failure. This can show the + target's console output as it tried to boot + """ + msg = f'{name}: ' + if fatal: + msg += 'Marking connection bad - no other tests will run' + else: + msg += 'Assuming that lab is healthy' + print(msg) + log.error(msg) + log.error(f'Error: {err}') + + if output: + msg += f'; output {output}' + + if fatal: + ubconfig.connection_ok = False + console.cleanup_spawn() + pytest.exit(msg) + + class Spawn: """Represents the stdio of a freshly created sub-process. Commands may be sent to the process, and responses waited for. -- 2.43.0