From patchwork Thu Jul 3 15:13:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 1881 Received: (qmail 11263 invoked by alias); 3 Jul 2014 15:13: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 10990 invoked by uid 89); 3 Jul 2014 15:13:42 -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; Thu, 03 Jul 2014 15:13:39 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s63FDb5P016351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 3 Jul 2014 11:13:37 -0400 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s63FDQOj021950 for ; Thu, 3 Jul 2014 11:13:36 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 4/9] testsuite: Introduce gdb_assert Date: Thu, 3 Jul 2014 16:13:16 +0100 Message-Id: <1404400406-16708-9-git-send-email-palves@redhat.com> In-Reply-To: <1404400406-16708-1-git-send-email-palves@redhat.com> References: <1404400406-16708-1-git-send-email-palves@redhat.com> Often we'll do something like: if {$ok} { fail "whatever" } else { pass "whatever" } This adds a helper procedure for that, and converts one random place to use it, as an example. 2014-07-02 Pedro Alves * lib/gdb.exp (gdb_assert): New procedure. * gdb.trace/backtrace.exp (gdb_backtrace_tdp_4): Use it. --- gdb/testsuite/gdb.trace/backtrace.exp | 7 ++----- gdb/testsuite/lib/gdb.exp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/gdb/testsuite/gdb.trace/backtrace.exp b/gdb/testsuite/gdb.trace/backtrace.exp index a74fc3f..cb50f06 100644 --- a/gdb/testsuite/gdb.trace/backtrace.exp +++ b/gdb/testsuite/gdb.trace/backtrace.exp @@ -256,11 +256,8 @@ proc gdb_backtrace_tdp_4 { msg depth traceframe } { # Output of 'tdump' on frame 0 and frame 1 should be # identical. - if ![string compare $output_string0 $output_string1] { - pass "tdump output" - } else { - fail "tdump output" - } + gdb_assert ![string compare $output_string0 $output_string1] \ + "tdump output" } } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 30463a9..36cbf05 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1204,6 +1204,27 @@ proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_ma } } + +# Issue a PASS and return true if evaluating CONDITION in the caller's +# frame returns true, and issue a FAIL and return false otherwise. +# MESSAGE is the pass/fail message to be printed. If MESSAGE is +# omitted or is empty, then the pass/fail messages use the condition +# string as the message. + +proc gdb_assert { condition {message ""} } { + if { $message == ""} { + set message $condition + } + + set res [uplevel 1 expr $condition] + if {!$res} { + fail $message + } else { + pass $message + } + return $res +} + proc gdb_reinitialize_dir { subdir } { global gdb_prompt