]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Tests for gdb.InferiorThread.handle
authorKevin Buettner <kevinb@redhat.com>
Sun, 16 Sep 2018 04:15:49 +0000 (21:15 -0700)
committerKevin Buettner <kevinb@redhat.com>
Tue, 9 Apr 2019 03:16:09 +0000 (20:16 -0700)
gdb/testsuite/ChangeLog:

* gdb.python/py-thrhandle.exp: Add tests for
gdb.InferiorThread.handle.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-thrhandle.exp

index 45c5eb1762bd440f2265d41ca047a369f1b18a31..8c5739f8b2a31a5fe3cbaa43f9ddbf4eaf998d68 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-08  Kevin Buettner  <kevinb@redhat.com>
+
+       * gdb.python/py-thrhandle.exp: Add tests for
+       gdb.InferiorThread.handle.
+
 2019-04-01  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.python/py-function.exp: Check calling helper function from
index 2c905b444f3ba58053594ac8edad413c96d8902a..57b97faa1836b020c69ff4f403afc4cedb08bdae 100644 (file)
 # 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.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).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"
+    }
+}