From patchwork Thu Feb 28 02:34:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 31682 Received: (qmail 14983 invoked by alias); 28 Feb 2019 02:34:14 -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 14963 invoked by uid 89); 28 Feb 2019 02:34:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=binfile, Itd, It'd, itd 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 ESMTP; Thu, 28 Feb 2019 02:34:12 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40633317257A for ; Thu, 28 Feb 2019 02:34:11 +0000 (UTC) Received: from f29-4.lan (ovpn-117-11.phx2.redhat.com [10.3.117.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F7E2679DC for ; Thu, 28 Feb 2019 02:34:11 +0000 (UTC) Date: Wed, 27 Feb 2019 19:34:10 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH v2 4/5] Tests for gdb.InferiorThread.thread_handle Message-ID: <20190227193410.25a300f7@f29-4.lan> In-Reply-To: <20190227192416.613752c8@f29-4.lan> References: <20190227192416.613752c8@f29-4.lan> MIME-Version: 1.0 X-IsSubscribed: yes gdb/testsuite/ChangeLog: * gdb.python/py-thrhandle.exp: Add tests for gdb.InferiorThread.thread_handle. --- gdb/testsuite/gdb.python/py-thrhandle.exp | 42 ++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-thrhandle.exp b/gdb/testsuite/gdb.python/py-thrhandle.exp index 2c905b444f..ec6852b333 100644 --- a/gdb/testsuite/gdb.python/py-thrhandle.exp +++ b/gdb/testsuite/gdb.python/py-thrhandle.exp @@ -16,11 +16,12 @@ # Please email any bugs, comments, and/or additions to this file to: # bug-gdb@gnu.org -# This file verifies that gdb.Inferior.thread_from_thread_handle works -# as expected. +# This file verifies that methods Inferior.thread_from_thread_handle +# and InferiorThread.thread_handle work as expected. -standard_testfile +load_lib gdb-python.exp +standard_testfile if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } { return -1 @@ -104,3 +105,38 @@ gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.par gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('\"S\"')))" \ ".*Thread handle size mismatch.*" \ "Pass too small of an object to thread_from_thread_handle" + +# Test the thread_handle method + +gdb_py_test_silent_cmd "python tp=gdb.lookup_type('pthread_t')" \ + "Get pthread_t type" 0 +gdb_py_test_silent_cmd "python inf=gdb.selected_inferior()" "Get inferior" 0 + +foreach thrN {0 1 2} { + with_test_prefix "thread $thrN" { + + gdb_py_test_silent_cmd \ + "python hand = gdb.parse_and_eval('thrs\[$thrN\]')" \ + "fetch thread handle from inferior" \ + 1 + + gdb_py_test_silent_cmd \ + "python hand_bytes = inf.thread_from_thread_handle(hand).thread_handle()" \ + "fetch thread handle from thread" \ + 1 + + + # It'd be nice to be able to use this comparison expression: + # + # hand == hand_bytes + # + # But this won't work because hand is a gdb.Value and hand_bytes + # is a Python bytes object. Therefore, we convert the bytes + # object into a gdb.value by calling the two argument form of + # its constructor. + + gdb_test "python print(gdb.Value(hand_bytes, tp) == hand)" \ + "True" \ + "verify that handles are the same" + } +}