From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 29A213857BA4 for ; Wed, 8 Nov 2023 16:56:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29A213857BA4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 29A213857BA4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699462620; cv=none; b=FWsoQhJrPh3x5/JeDspdOcsM6kWEAVtKruBxK/qk4bjI3EElBz/d6tVHkZ7z+GVQcj28NrMr4flQVVgm3w0UgSv4EkArIXbDzJx39TI1QUdoK4DZNHAwU+G2GmSOp2wpOVCniE3OCDGr3fjspUp6bCyrAAlwOVrQqdVaM0hgBWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699462620; c=relaxed/simple; bh=ptDuJlYUoWacc6EYkaVDE3C4D23qmRilyvJPfumnsCw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=M6vt8Q+cD4fL4MxF/97MW2+aqhvwqMqyabInF+3LuIfhqRn2Tc78XSAxbquMlK3JrvyVte/hTVLs2WZqC0e57qFPoUsV3LmDCfLGgXgpYpd0jdqWC29XL2YGgftRmONgkXXOwZeZcwPOqK4JKfO8/6CMKf48pihksGnJ/tzWeiw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699462617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dxuUAhcQy5PtzsUhy/wln/CWkiEXTd9x5KyTiVHhH+M=; b=irphw0t/ERoudYc0uI8Rbfq+mrkp8UA+syBF/ljiu49V+HNWAQU8rhirDgsqdJWC3b/hci yjPUJ3KwsIqatGCEVAdlxcDE48/MKkzKcnUOPWp4cKKbQigeO2YtB2+oYYRpLZjweohAiA YnNd8dDOIuT7JIsJ4pD45v/UEGfgqaE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-445-JVyOps9tNr6v5Wfe-ONh6w-1; Wed, 08 Nov 2023 11:56:56 -0500 X-MC-Unique: JVyOps9tNr6v5Wfe-ONh6w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D00B101A529 for ; Wed, 8 Nov 2023 16:56:56 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B742A492BE9; Wed, 8 Nov 2023 16:56:55 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH v4] gdb/testsuite: fix completion tests when using READ1 Date: Wed, 8 Nov 2023 17:56:50 +0100 Message-ID: <20231108165650.1224706-1-blarsen@redhat.com> In-Reply-To: <20230828113026.76323-1-blarsen@redhat.com> References: <20230828113026.76323-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: The commit a3da2e7e550c4fe79128b5e532dbb90df4d4f418 has introduced regressions when testing using the READ1 mechanism. The reason for that is the new failure path in proc test_gdb_complete_tab_unique, which looks for GDB suggesting more than what the test inputted, but not the correct answer, followed by a white space. Consider the following case: int foo(int bar, int baz); Sending the command "break foo" to GDB will return break foo(int, int) which easily fits the buffer in normal testing, so everything works, but when reading one character at a time, the test will find the partial "break foo(int, " and assume that there was a mistake, so we get a spurious FAIL. That change was added because we wanted to avoid forcing a completion failure to fail through timeout, which it had to do because there is no way to verify that the output is done, mostly because when I was trying to solve a different problem I kept getting reading errors and testing completion was frustrating. This commit implements a better way to avoid that frustration, by first testing gdb's complete command and only if that passes we will test tab completion. The difference is that when testing with the complete command, we can tell when the output is over when we receive the GDB prompt again, so we don't need to rely on timeouts. With this, the change to test_gdb_complete_tab_unique has been removed as that test will only be run and fail in the very unlikely scenario that tab completion is different than command completion. --- gdb/testsuite/lib/completion-support.exp | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp index fdc512838c3..cc34ef51e22 100644 --- a/gdb/testsuite/lib/completion-support.exp +++ b/gdb/testsuite/lib/completion-support.exp @@ -111,15 +111,11 @@ proc test_gdb_complete_tab_unique { input_line complete_line_re append_char_re } set test "tab complete \"$input_line\"" send_gdb "$input_line\t" - set partial_complete [string_to_regexp $input_line] set res 1 gdb_test_multiple "" "$test" { -re "^$complete_line_re$append_char_re$" { pass "$test" } - -re "$partial_complete\[^ \]+ $" { - fail "$test" - } timeout { fail "$test (timeout)" set res -1 @@ -190,21 +186,26 @@ proc test_gdb_complete_cmd_none { line } { # Test that completing LINE with the complete command completes to # COMPLETE_LINE_RE. +# Returns 1 if the test passed, 0 if it failed, -1 if it timed out. proc test_gdb_complete_cmd_unique { input_line complete_line_re } { global gdb_prompt + set res -1 set cmd "complete $input_line" set cmd_re [string_to_regexp $cmd] set test "cmd complete \"$input_line\"" gdb_test_multiple $cmd $test { -re "^$cmd_re\r\n$complete_line_re\r\n$gdb_prompt $" { pass $test + set res 1 } -re "$gdb_prompt $" { fail "$test" + set res 0 } } + return $res } # Test that completing "CMD_PREFIX + COMPLETION_WORD" with the @@ -263,12 +264,6 @@ proc test_gdb_complete_none { input_line } { proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "} {max_completions 0}} { set append_char_re [string_to_regexp $append_char] - if { [readline_is_used] } { - if { [test_gdb_complete_tab_unique $input_line $complete_line_re \ - $append_char_re] == -1 } { - return -1 - } - } # Trim COMPLETE LINE, for the case we're completing a command with leading # whitespace. Leading command whitespace is discarded by GDB. @@ -288,7 +283,22 @@ proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "} "\r\n$input_line_re $max_completion_reached_msg_re" } - test_gdb_complete_cmd_unique $input_line $expected_output_re + # First test completion with the command, then with tab. + # It is done in this order because cmd_complete knows when the output + # from GDB is over, so it can fail without requiring a timeout, which + # speeds up testing if necessary. + + set test_result [test_gdb_complete_cmd_unique $input_line\ + $expected_output_re] + if { $test_result != 1 } { + return $test_result + } + + if { [readline_is_used] } { + set test_result [test_gdb_complete_tab_unique $input_line \ + $complete_line_re $append_char_re] + } + } return 1 } -- 2.41.0