From patchwork Tue Apr 21 18:08:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 6354 Received: (qmail 92879 invoked by alias); 21 Apr 2015 18:08:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 92765 invoked by uid 89); 21 Apr 2015 18:08:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 21 Apr 2015 18:08:42 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3LI8epj009171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 21 Apr 2015 14:08:40 -0400 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3LI8WKu028722 for ; Tue, 21 Apr 2015 14:08:40 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 07/24] Introduce gdb_test_stdio Date: Tue, 21 Apr 2015 19:08:14 +0100 Message-Id: <1429639711-16459-8-git-send-email-palves@redhat.com> In-Reply-To: <1429639711-16459-1-git-send-email-palves@redhat.com> References: <1429639711-16459-1-git-send-email-palves@redhat.com> This adds a new helper procedure to be used by tests that rely on stdio. gdb/testsuite/ChangeLog: 2015-04-21 Pedro Alves * lib/gdb.exp (gdb_test_stdio): New procedure. --- gdb/testsuite/lib/gdb.exp | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 73e55e3..44f41c7 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1230,6 +1230,73 @@ proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_ma } } } + +# gdb_test_stdio COMMAND INFERIOR_PATTERN GDB_PATTERN MESSAGE +# Send a command to gdb; expect inferior and gdb output. +# +# See gdb_test_multiple for a description of the COMMAND and MESSAGE +# parameters. +# +# INFERIOR_PATTERN is the pattern to match against inferior output. +# +# GDB_PATTERN is the pattern to match against gdb output, and must NOT +# include the \r\n sequence immediately before the gdb prompt, nor the +# prompt. The default is empty. +# +# Both inferior and gdb patterns must match for a PASS. +# +# If MESSAGE is ommitted, then COMMAND will be used as the message. +# +# Returns: +# 1 if the test failed, +# 0 if the test passes, +# -1 if there was an internal error. +# + +proc gdb_test_stdio {command inferior_pattern {gdb_pattern ""} {message ""}} { + global inferior_spawn_id gdb_spawn_id + global gdb_prompt + + if {$message == ""} { + set message $command + } + + set inferior_matched 0 + set gdb_matched 0 + + # Use an indirect spawn id list, and remove the inferior spawn id + # from the expected output as soon as it matches, in case + # $inferior_pattern happens to be a prefix of the resulting full + # gdb pattern below (e.g., "\r\n"). + global gdb_test_stdio_spawn_id_list + set gdb_test_stdio_spawn_id_list "$inferior_spawn_id" + + # Note that if $inferior_spawn_id and $gdb_spawn_id are different, + # then we may see gdb's output arriving before the inferior's + # output. + set res [gdb_test_multiple $command $message { + -i gdb_test_stdio_spawn_id_list -re "$inferior_pattern" { + set inferior_matched 1 + if {!$gdb_matched} { + set gdb_test_stdio_spawn_id_list "" + exp_continue + } + } + -i $gdb_spawn_id -re "$gdb_pattern\r\n$gdb_prompt $" { + set gdb_matched 1 + if {!$inferior_matched} { + exp_continue + } + } + }] + if {$res == 0} { + pass $message + } else { + verbose -log "inferior_matched=$inferior_matched, gdb_matched=$gdb_matched" + } + return $res +} + # Issue a PASS and return true if evaluating CONDITION in the caller's