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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 227DEC433EF for ; Wed, 6 Oct 2021 02:59:31 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 32A3B611F0 for ; Wed, 6 Oct 2021 02:59:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 32A3B611F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 92373807CD; Wed, 6 Oct 2021 04:59:27 +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="mhAik2kB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 854B78033A; Wed, 6 Oct 2021 04:59:26 +0200 (CEST) Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) (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 20ABD807CD for ; Wed, 6 Oct 2021 04:59:23 +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-x32a.google.com with SMTP id c26-20020a056830349a00b0054d96d25c1eso1341987otu.9 for ; Tue, 05 Oct 2021 19:59:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LAppzC8w1fwA2nj2QI5ihFiV19Y03R5p9d84+G2kZIQ=; b=mhAik2kBseIAEfU1BJtIv6mkY6UQ0gn2SFT1ZT0BGxabGTtYUbZ4TF1V6XMi4KZn8y xM2Cr3T+lSGtwl6d8G8oBkz2XqN+KH3b6BKuyVWiaGRLB4zUbMc4b4wSZAHXXMpl+f/l nF9BybBDFuBksRSOEEJljXiwHiUiZNQJtPU5M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LAppzC8w1fwA2nj2QI5ihFiV19Y03R5p9d84+G2kZIQ=; b=fKYbY8HWAXbVDn3E1HF8gURVtaw8BWica/gAabD8gxClmcVKRGd9QROihqJnvHaOfA ZN930dtFeiB7u5z0oXjOJqZHSHovSy0/LzETM8rNUWyaESOqZ2eeBdGcTL0oxI1EjaNR SdhB32eEfvk2Bnff5vLnL8z44m6QA5HT+69Dl15jsN74655FzadZOr5N2PBRptNl7IMK 91GmbTZuuAeCrPWUHLjZR+gd5I4+WK1Dv1ZIpKMlrRbUkrKhLoGY7/iTcId+71sNnl6H d7c/QVw/usxW34l+KFRv/X/ZZlcRxLk2BiFfEgP5oiRc+fmpVendLwQt64SxK3RFCwmu BTHA== X-Gm-Message-State: AOAM531sKONy5RSejnAUqNu1XQmPSre2jMR8ry5sioHyClC/TWHThl6S iO2mOLIHPYyNywaw5fa2stocQLWY8hDHTQ== X-Google-Smtp-Source: ABdhPJzghXCWz4tS7olLysnlXu5OVtaTQf9FDU1aFRi5wHL9Cfu7jdH821OoRMOXxHK/qdE09SpSUQ== X-Received: by 2002:a9d:f04:: with SMTP id 4mr16378701ott.307.1633489161357; Tue, 05 Oct 2021 19:59:21 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id h23sm1820190otl.54.2021.10.05.19.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 19:59:20 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Marek Vasut , Simon Glass , Heinrich Schuchardt , Stephen Warren Subject: [PATCH] pytest: Show a message when sandbox crashes Date: Tue, 5 Oct 2021 20:59:16 -0600 Message-Id: <20211006025916.2679121-1-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean When a test hands on a real board there is no way on the console to obtain any information about why it hung. With sandbox we can actually find out that it died and get a signal or exit code. Add this to make it easier to figure out what happened. So instead of: test/py/u_boot_spawn.py:171: in expect c = os.read(self.fd, 1024).decode(errors='replace') E OSError: [Errno 5] Input/output error We get: test/py/u_boot_spawn.py:171: in expect c = os.read(self.fd, 1024).decode(errors='replace') E ValueError: U-Boot exited with signal 11 (Signals.SIGSEGV) Signed-off-by: Simon Glass --- doc/develop/py_testing.rst | 8 ++++++ test/py/u_boot_spawn.py | 56 ++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/doc/develop/py_testing.rst b/doc/develop/py_testing.rst index 52238ca54d3..06f919609b5 100644 --- a/doc/develop/py_testing.rst +++ b/doc/develop/py_testing.rst @@ -103,6 +103,14 @@ will be written to `${build_dir}/test-log.html`. This is best viewed in a web browser, but may be read directly as plain text, perhaps with the aid of the `html2text` utility. +If sandbox crashes (e.g. with a segfault) you will see message like this:: + + + test/py/u_boot_spawn.py:171: in expect + c = os.read(self.fd, 1024).decode(errors='replace') + E ValueError: U-Boot exited with signal 11 (Signals.SIGSEGV) + + Controlling output ~~~~~~~~~~~~~~~~~~ diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index 6991b78cca8..b6ab544eaa1 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -35,6 +35,8 @@ class Spawn(object): """ self.waited = False + self.exit_code = 0 + self.exit_info = '' self.buf = '' self.output = '' self.logfile_read = None @@ -80,25 +82,44 @@ class Spawn(object): os.kill(self.pid, sig) - def isalive(self): + def checkalive(self): """Determine whether the child process is still running. - Args: - None. - Returns: - Boolean indicating whether process is alive. + tuple: + True if process is alive, else False + 0 if process is alive, else exit code of process + string describing what happened ('' or 'status/signal n') """ if self.waited: - return False + return False, exit_code, self.exit_info w = os.waitpid(self.pid, os.WNOHANG) if w[0] == 0: - return True - + return True, 0, 'running' + status = w[1] + + if os.WIFEXITED(status): + self.exit_code = os.WEXITSTATUS(status) + self.exit_info = 'status %d' % self.exit_code + elif os.WIFSIGNALED(status): + signum = os.WTERMSIG(status) + self.exit_code = -signum + self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum)) self.waited = True - return False + return False, self.exit_code, self.exit_info + + def isalive(self): + """Determine whether the child process is still running. + + Args: + None. + + Returns: + Boolean indicating whether process is alive. + """ + return self.checkalive()[0] def send(self, data): """Send data to the sub-process's stdin. @@ -168,9 +189,20 @@ class Spawn(object): events = self.poll.poll(poll_maxwait) if not events: raise Timeout() - c = os.read(self.fd, 1024).decode(errors='replace') - if not c: - raise EOFError() + try: + c = os.read(self.fd, 1024).decode(errors='replace') + except OSError as err: + # With sandbox, try to detect when U-Boot exits when it + # shouldn't and explain why. This is much more friendly than + # just dying with an I/O error + if err.errno == 5: # Input/output error + alive, exit_code, info = self.checkalive() + if alive: + raise + else: + raise ValueError('U-Boot exited with %s' % info) + else: + raise if self.logfile_read: self.logfile_read.write(c) self.buf += c -- 2.33.0.800.g4c38ced690-goog