From patchwork Sat Jul 25 15:04:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1336259 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=cU+aLR/G; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BDTrz3ZY6z9sR4 for ; Sun, 26 Jul 2020 01:05:23 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0EDEC82209; Sat, 25 Jul 2020 17:05:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de 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; secure) header.d=gmx.net header.i=@gmx.net header.b="cU+aLR/G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3710082214; Sat, 25 Jul 2020 17:05:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 62B61821BE for ; Sat, 25 Jul 2020 17:05:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1595689498; bh=x+DRQQRFcen2+YFuGWgWn71pykt9GWDrhiruuQsjUpc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=cU+aLR/GGYrctOUfFkZV/OL3hm0VS0ckInnpMkg0AL2tQpJVFDQ+5OkqrmzhkZy/z Pk7J82E7r6+o0kfmEEKnTRramCmDYr70UxfZMoLGqHl7T8O54foLub+RU0atOfccH3 NZTbvCGt1a/jWFd9RYgJn0moVDQsEQwAC1XZAzVo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from workstation5.fritz.box ([178.202.41.107]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1Mlw7V-1kiLKj07xz-00j4wk; Sat, 25 Jul 2020 17:04:58 +0200 From: Heinrich Schuchardt To: Simon Glass Cc: Rasmus Villemoes , Andy Shevchenko , Bin Meng , Walter Lozano , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/1] sandbox: support CTRL-C processing in U-Boot Date: Sat, 25 Jul 2020 17:04:50 +0200 Message-Id: <20200725150450.177051-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-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+PdHEP5mqLqvhnil/kOiMvWok0N MefZQMMJ60+yz4etqih8Eo1l4XI7elwTnk63Ae13VPOBWFOMeyFakGS6lFx1QoFNjjx1fVWSV yWfCC2Gijfc5FaI67Dz9HSui+9gwvMgdVPg77CKzEKXbHeFomnFbmfS7hPfIbQeDfXzQSmv8P LkwkHQn1S3LYQRgyhb9rnR+H0RFJHIZxoR8fjwoMCTc8ZzgUq0P2eJf48euW0ssZwC/B/aYqt S5hu/O1r1kp02+7Spl4RJuGKOqABA9Dec1iB2eEpsLBaclrHFO/TKEWToY4OZcszJFcjTHL2N aKrjnS1GX+NmO62trMHEnRYu023HBelzLrm9bCaB8C68rEZewZgxXPSZB/CJm8i1pwb15Nnve w/D5Q+mX0UUrWLR5Bha3zU1ZNzfBk+3jHRViGKldQkxYEniG2kB5M0uKIw6EDQfBLqPcoSDcS 5mz7QA+3BY7vR9cMpxGUeX1FMBdujvgwQ9WGgXQ== 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.102.3 at phobos.denx.de X-Virus-Status: Clean Currently if SIGINT is received, it terminates U-Boot. This does not allow testing the handling of CTRL-C in U-Boot and in UEFI applications. Let the serial console driver provide character 0x03 if SIGINT occurs. We can still exit U-Boot using the poweroff command. Adjust the sandbox test_ctrl_c() Python test accordingly. Signed-off-by: Heinrich Schuchardt --- arch/sandbox/cpu/os.c | 15 ++++++++++++--- drivers/serial/sandbox.c | 11 ++++++++--- include/os.h | 14 ++++++++++++++ test/py/tests/test_sandbox_exit.py | 9 ++++++++- 4 files changed, 42 insertions(+), 7 deletions(-) -- 2.27.0 diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index e7ec892bdf..e7528f46a4 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -161,6 +161,7 @@ err: static struct termios orig_term; static bool term_setup; static bool term_nonblock; +static bool pending_ctrlc; void os_fd_restore(void) { @@ -176,11 +177,19 @@ void os_fd_restore(void) } } +void os_clear_ctrlc() +{ + pending_ctrlc = false; +} + +bool os_get_ctrlc() +{ + return pending_ctrlc; +} + static void os_sigint_handler(int sig) { - os_fd_restore(); - signal(SIGINT, SIG_DFL); - raise(SIGINT); + pending_ctrlc = true; } /* Put tty into raw mode so and work */ diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index f09d291e04..e510d51e27 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -72,9 +72,6 @@ static int sandbox_serial_probe(struct udevice *dev) os_tty_raw(0, state->term_raw == STATE_TERM_RAW_WITH_SIGS); priv->start_of_line = 0; - if (state->term_raw != STATE_TERM_RAW) - disable_ctrlc(1); - return 0; } @@ -118,6 +115,9 @@ static int sandbox_serial_pending(struct udevice *dev, bool input) increment_buffer_index(serial_buf_write); ssize_t count; + if (os_get_ctrlc()) + return true; + if (!input) return 0; @@ -139,6 +139,11 @@ static int sandbox_serial_getc(struct udevice *dev) { int result; + if (os_get_ctrlc()) { + os_clear_ctrlc(); + return 0x03; + } + if (!sandbox_serial_pending(dev, true)) return -EAGAIN; /* buffer empty */ diff --git a/include/os.h b/include/os.h index 1874ae674f..0cbf737d57 100644 --- a/include/os.h +++ b/include/os.h @@ -355,4 +355,18 @@ int os_read_file(const char *name, void **bufp, int *sizep); */ void *os_find_text_base(void); +/** + * os_get_ctrlc() - check if a CTRL+C has occurred + * + * Return: true if CTRL+C has occurred + */ +bool os_get_ctrlc(void); + +/** + * os_clear_ctrlc() - clear CTRL+C + * + * Mark a previous CTRL+C event as handled. + */ +void os_clear_ctrlc(void); + #endif diff --git a/test/py/tests/test_sandbox_exit.py b/test/py/tests/test_sandbox_exit.py index a301f4b559..691f7442b8 100644 --- a/test/py/tests/test_sandbox_exit.py +++ b/test/py/tests/test_sandbox_exit.py @@ -15,7 +15,14 @@ def test_reset(u_boot_console): @pytest.mark.boardspec('sandbox') def test_ctrl_c(u_boot_console): - """Test that sending SIGINT to sandbox causes it to exit.""" + """Test that SIGINT is handled as CTRL-C.""" u_boot_console.kill(signal.SIGINT) + u_boot_console.wait_for('') + u_boot_console.run_command('') + + output = u_boot_console.run_command('\x03', wait_for_echo=False) + assert '' in output + + u_boot_console.kill(signal.SIGKILL) assert(u_boot_console.validate_exited())