From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E6F143951C2A for ; Tue, 8 Jun 2021 13:37:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E6F143951C2A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0D2941FD2A for ; Tue, 8 Jun 2021 13:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623159424; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=mbtU0mWPrSG4j6Y19WyFuuVI+SSToRU8ftZ6a4C3ar8=; b=OJIF5BGMN6472QzgbKGCBtLCFO4yBX1451e4rasVPIEttu6qdC8PNB8hG+yjKq3QJRgA5A rYrt7uNF7jbUaIk+rWzL2MO1Q4nmSNeJi6UDjqE8WrXdddwM8qgGEjky6DTAX5m9J+tGbv a5hb0MxC7grBiBBmIJ8+oBIKPoP9Ot4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623159424; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=mbtU0mWPrSG4j6Y19WyFuuVI+SSToRU8ftZ6a4C3ar8=; b=myRdBIFg4QqkeBxdEjdtb6kCJWbPyoruGwN7trg8469o83xqul5Vl6Xudi0/EUQdRJyt1b 1i0rs3WM1TaUZpBA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id E5172118DD for ; Tue, 8 Jun 2021 13:37:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623159424; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=mbtU0mWPrSG4j6Y19WyFuuVI+SSToRU8ftZ6a4C3ar8=; b=OJIF5BGMN6472QzgbKGCBtLCFO4yBX1451e4rasVPIEttu6qdC8PNB8hG+yjKq3QJRgA5A rYrt7uNF7jbUaIk+rWzL2MO1Q4nmSNeJi6UDjqE8WrXdddwM8qgGEjky6DTAX5m9J+tGbv a5hb0MxC7grBiBBmIJ8+oBIKPoP9Ot4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623159424; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=mbtU0mWPrSG4j6Y19WyFuuVI+SSToRU8ftZ6a4C3ar8=; b=myRdBIFg4QqkeBxdEjdtb6kCJWbPyoruGwN7trg8469o83xqul5Vl6Xudi0/EUQdRJyt1b 1i0rs3WM1TaUZpBA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id /anPNn9yv2BjbQAALh3uQQ (envelope-from ) for ; Tue, 08 Jun 2021 13:37:03 +0000 Date: Tue, 8 Jun 2021 15:37:02 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/testsuite] Simplify gdb.base/info-types.exp.tcl further Message-ID: <20210608133701.GA1673@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Tue, 08 Jun 2021 13:37:06 -0000 Hi, After adding support for --any in match_line, we can simplify gdb.base/info-types.exp.tcl further: we can add the "All defined types:" regexp in the output_lines list: ... set output_lines \ [list \ + "All defined types:" \ + "--any" \ $file_re \ ... Consequently, we can simplify the state machine to track a variable "found" with values: - 0 (unmatched) - 1 (matched) - -1 (mismatch). This makes the code generic enough to factor out into a new proc gdb_test_lines. Tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb/testsuite] Simplify gdb.base/info-types.exp.tcl further gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries * gdb.base/info-types.exp.tcl (match_line): Handle --any. (gdb_test_lines): Factor out of ... (run_test): ... here. --- gdb/testsuite/gdb.base/info-types.exp.tcl | 71 +++++++++++++++++-------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/gdb/testsuite/gdb.base/info-types.exp.tcl b/gdb/testsuite/gdb.base/info-types.exp.tcl index 104fdb3a62f..eef4b078221 100644 --- a/gdb/testsuite/gdb.base/info-types.exp.tcl +++ b/gdb/testsuite/gdb.base/info-types.exp.tcl @@ -16,7 +16,8 @@ # Check that 'info types' produces the expected output for an inferior # containing a number of different types. -# Match LINE against regexp OUTPUT_LINES[IDX]. +# Match LINE against regexp OUTPUT_LINES[IDX]. Helper function for +# gdb_test_lines. proc match_line { line output_lines idx_name } { upvar $idx_name idx @@ -27,14 +28,17 @@ proc match_line { line output_lines idx_name } { } set re [lindex $output_lines $idx] + set opt 0 + set any 0 if { $re == "--optional" } { # Optional, get actual regexp. set opt 1 incr idx set re [lindex $output_lines $idx] - } else { - # Not optional. - set opt 0 + } elseif { $re == "--any" } { + set any 1 + incr idx + set re [lindex $output_lines $idx] } if { [regexp $re $line] } { @@ -55,6 +59,10 @@ proc match_line { line output_lines idx_name } { # Try next regexp on same line. incr idx continue + } elseif { $any } { + # Try again with next line. + incr idx -1 + return 0 } else { # Mismatch, bail out. return -1 @@ -67,6 +75,29 @@ proc match_line { line output_lines idx_name } { return 0 } +# Match output of COMMAND line-by-line, using PATTERNS. +# Report pass/fail with MESSAGE. + +proc gdb_test_lines { command message patterns } { + set found 0 + set idx 0 + if { $message == ""} { + set message $command + } + gdb_test_multiple $command $message { + -re "\r\n(\[^\r\n\]*)(?=\r\n)" { + if { $found == 0 } { + set line $expect_out(1,string) + set found [match_line $line $patterns idx] + } + exp_continue + } + -re -wrap "" { + gdb_assert { $found == 1 } $gdb_test_name + } + } +} + # Run 'info types' test, compiling the test file for language LANG, # which should be either 'c' or 'c++'. proc run_test { lang } { @@ -94,6 +125,8 @@ proc run_test { lang } { if { $lang == "c++" } { set output_lines \ [list \ + "All defined types:" \ + "--any" \ $file_re \ "98:\[\t \]+CL;" \ "42:\[\t \]+anon_struct_t;" \ @@ -129,6 +162,8 @@ proc run_test { lang } { } else { set output_lines \ [list \ + "All defined types:" \ + "--any" \ $file_re \ "52:\[\t \]+typedef enum {\\.\\.\\.} anon_enum_t;" \ "45:\[\t \]+typedef struct {\\.\\.\\.} anon_struct_t;" \ @@ -157,33 +192,7 @@ proc run_test { lang } { ""] } - set state 0 - set idx 0 - gdb_test_multiple "info types" "" { - -re "\r\nAll defined types:" { - if { $state == 0 } { set state 1 } else { set state -1 } - exp_continue - } - -re "^\r\n(\[^\r\n\]*)(?=\r\n)" { - if { $state == 1 } { - set line $expect_out(1,string) - set res [match_line $line $output_lines idx] - if { $res == 1 } { - set state 2 - } elseif { $res == -1 } { - set state -2 - } - } - exp_continue - } - -re -wrap "" { - if { $state == 2} { - pass $gdb_test_name - } else { - fail "$gdb_test_name (state == $state)" - } - } - } + gdb_test_lines "info types" "" $output_lines } run_test $lang