From patchwork Fri May 5 12:34:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 68820 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAE303856DF1 for ; Fri, 5 May 2023 12:34:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAE303856DF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683290084; bh=arKn6A2Ky4a1cG3hZin59C+Q+DvsA0oW5MnRjbd5b3A=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=etaFTRQhS/OthISC7oy8x414GuxmNwuPoz9OwMkU/S2JyuG4mQ4KWsePz6vDmyOTC 7rENxhNFJOtMKR4TlMqNAIR2NR3Mnc7MKQJSwt24lLGTL1cLiKWv5zPLF8XZEJeq3t bUK3WFykulbxdVkX0gqGAEN7kzr8FPm1VHPYZ0RA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 621FB3858D33 for ; Fri, 5 May 2023 12:34:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 621FB3858D33 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9446F1FF23; Fri, 5 May 2023 12:34:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7BDAC13513; Fri, 5 May 2023 12:34:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6g0hHcz3VGRFOgAAMHmgww (envelope-from ); Fri, 05 May 2023 12:34:20 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [pushed] [gdb/testsuite] Add gdb.base/wrap-line.exp Date: Fri, 5 May 2023 14:34:24 +0200 Message-Id: <20230505123424.25354-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Add a test-case that tests prompt edit wrapping in CLI, both for TERM=xterm and TERM=ansi, both with auto-detected and hard-coded width. In the TERM=ansi case with auto-detected width we run into PR cli/30346, so add a KFAIL for that failure mode. Tested on x86_64-linux. --- gdb/testsuite/gdb.base/wrap-line.exp | 169 +++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 gdb/testsuite/gdb.base/wrap-line.exp base-commit: c2a0fca06af371adc360c2da6bafc23651e5761e diff --git a/gdb/testsuite/gdb.base/wrap-line.exp b/gdb/testsuite/gdb.base/wrap-line.exp new file mode 100644 index 00000000000..938b5c44099 --- /dev/null +++ b/gdb/testsuite/gdb.base/wrap-line.exp @@ -0,0 +1,169 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test prompt edit wrapping in CLI. + +# We set TERM on build, but we need to set it on host. That only works if +# build == host. +require {!is_remote host} + +# Test both ansi (no auto-wrap) and xterm (auto-wrap). +set terms {ansi xterm} + +# Fill line, assuming we start after the gdb prompt. +proc fill_line { width } { + set res "" + + # Take into account that the prompt also takes space. + set prefix [string length "(gdb) "] + set start [expr $prefix + 1] + + # Print chars. + for { set i $start } { $i <= $width } { incr i } { + set c [expr $i % 10] + send_gdb $c + append res $c + } + + return $res +} + +proc get_screen_width { } { + upvar gdb_width gdb_width + upvar readline_width readline_width + upvar env_width env_width + set gdb_width 0 + set readline_width 0 + set env_width 0 + set re1 "Number of characters gdb thinks are in a line is ($::decimal)\[^\r\n\]*\\." + set re2 \ + "Number of characters readline reports are in a line is ($::decimal)\[^\r\n\]*\\." + set re3 \ + "Number of characters curses thinks are in a line is $::decimal\\." + set re4 \ + "Number of characters environment thinks are in a line is ($::decimal) \\(COLUMNS\\)." + set cmd "maint info screen" + set re \ + [multi_line \ + ^$cmd \ + $re1 \ + $re2 \ + "(?:$re3" \ + ")?$re4" \ + .*] + gdb_test_multiple $cmd "" { + -re -wrap $re { + set gdb_width $expect_out(1,string) + set readline_width $expect_out(2,string) + set env_width $expect_out(3,string) + pass $gdb_test_name + } + } +} + +proc test_wrap { width_auto_detected } { + if { ! [readline_is_used] } { + return + } + + get_screen_width + + if { $::term == "xterm" } { + gdb_assert { $gdb_width == $readline_width } + } else { + gdb_assert { $gdb_width == [expr $readline_width + 1] } + } + + if { $width_auto_detected && $::term == "ansi" } { + if { $gdb_width == [expr $env_width - 1] || $gdb_width == $env_width } { + # Generate KFAIL or KPASS. + setup_kfail "cli/30346" "*-*-*" + } + } + gdb_assert { $gdb_width == $env_width } "width" + + # New prompt, but avoid emitting a pass in order to avoid ending the line + # after the prompt in gdb.log. This make it a bit easier in gdb.log to + # understand where wrapping occurred. + gdb_test_multiple "print 1" "" { + -re -wrap " = 1" { + } + } + + # Fill the line to just before wrapping. + set str [fill_line $readline_width] + + # Now print the first char we expect to wrap. + send_gdb "W" + + # Note the difference between autowrap and no autowrap. In the autowrap + # case, readline doesn't emit a '\n', the terminal takes care of that. + if { $::term == "xterm" } { + # xterm, autowrap. + set re "^${str}( |W)\rW" + } else { + # ansi, no autowrap. + set re "^$str\r\n\rW" + } + + gdb_test_multiple "" "wrap" { + -re $re { + pass $gdb_test_name + } + } + + # Generate a prompt. + send_gdb "\003" + gdb_test "" "Quit" "prompt after wrap" +} + +foreach_with_prefix term $terms { + save_vars { env(TERM) INTERNAL_GDBFLAGS } { + + setenv TERM $term + + with_test_prefix width-hard-coded { + clean_restart + + # Env_width should match whatever was set in default_gdb_init + # using stty_init. + with_test_prefix initial { + get_screen_width + } + gdb_test_no_output "set width $env_width" + + test_wrap 0 + } + + with_test_prefix width-auto-detected { + # Avoid "set width 0" argument. + set INTERNAL_GDBFLAGS \ + [string map {{-iex "set width 0"} ""} $INTERNAL_GDBFLAGS] + + # Avoid "set width 0" in default_gdb_start. + gdb_exit + gdb_spawn + + set test "initial prompt" + gdb_test_multiple "" $test { + -re "^$gdb_prompt $" { + pass "$test" + } + } + + test_wrap 1 + } + } +}