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 9A9A6C433EF for ; Fri, 8 Oct 2021 15:15:37 +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 1382660FD8 for ; Fri, 8 Oct 2021 15:15:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1382660FD8 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 3ACC2833AE; Fri, 8 Oct 2021 17:15:35 +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="YN/1fv5n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CEEFC83374; Fri, 8 Oct 2021 17:15:33 +0200 (CEST) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) (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 5E665835A4 for ; Fri, 8 Oct 2021 17:15:29 +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-x329.google.com with SMTP id 5-20020a9d0685000000b0054706d7b8e5so12090053otx.3 for ; Fri, 08 Oct 2021 08:15:29 -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=S4sNcKc0LXEVAN3/srD4Wrb3dH8dHNAf5Nc26KbpLSo=; b=YN/1fv5nvTtDczAF0Clo0+nPd8r87SDYlYf0RfURiIq+I4b2r6VDuEkTcs4vYq1SWb zgAFHVb7pcNDseq29nD/NOY3uJUmCfUxIWgNznQZkQnUEXXGoMV/QaMHeFBhtM9kpRxc 9kHEWZTE//lcstBM4TgIQO+okk1kYVMX9uQxk= 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=S4sNcKc0LXEVAN3/srD4Wrb3dH8dHNAf5Nc26KbpLSo=; b=gfLsh0OgXYK8P1cDg7QHr1DrObJVRYYnnfexLbRXDRTddaFrzm79TM8Rsh9x+/7JXD SnOUfOZlGWtKEhENnsQSqehSmpt/njV3614cgvD5vwxKT20ie5/W6+t5RqUTtot6+Uu5 a7O0IOoUL8/rZdPsDJFI5ThaLGQ/yykdF5lF+L0wkpVDQzs1BmTiYr5iJ9SQhLDyOeN5 lHmlc2Q8Y5gypFFmqwTBz3dOkUjXgZYQm9zoBlql+C8aDDLQE0JpULPUpvUpE0Uk0Km1 wcA5LssK4M15mpPKQRP9bCfaex7Rj1TxX0HnGvuQCxzozhzqdYHqb3b0iL5ajpaIpYIW shuA== X-Gm-Message-State: AOAM531bu77Z99DfZ8Tc+slpzdaeNBd7fEQypqHQUeWceBqcK4wq05Y+ jwZakugtvqzNATOFtibpqIOfRoCbB+LbVA== X-Google-Smtp-Source: ABdhPJwakul0OL04+noAUWxprVuuXyB+oTT9ryaRi//g1w/IXg1/YeXg+fRoWsH69yAww9/Oyh30nA== X-Received: by 2002:a9d:4811:: with SMTP id c17mr9219732otf.337.1633706127484; Fri, 08 Oct 2021 08:15:27 -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 bg16sm758490oib.30.2021.10.08.08.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 08:15:26 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Marek Vasut , Simon Glass , Heinrich Schuchardt , Stephen Warren Subject: [PATCH v2] pytest: Show a message when sandbox crashes Date: Fri, 8 Oct 2021 09:15:23 -0600 Message-Id: <20211008151523.3283426-1-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-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 --- Changes in v2: - Fix a few test failure it causes 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..e34cb217e84 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, self.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.882.g93a45727a2-goog