[v4,4/6] Tests for gdb.InferiorThread.handle

Message ID 20190404165854.17343-5-kevinb@redhat.com
State New
Headers show
Series
  • Add python method gdb.InferiorThread.handle
Related show

Commit Message

Kevin Buettner April 4, 2019, 4:58 p.m.
gdb/testsuite/ChangeLog:

	* gdb.python/py-thrhandle.exp: Add tests for
	gdb.InferiorThread.handle.
---
 gdb/testsuite/gdb.python/py-thrhandle.exp | 42 +++++++++++++++++++++--
 1 file changed, 39 insertions(+), 3 deletions(-)

-- 
2.20.1

Comments

Sergio Durigan Junior May 3, 2019, 12:04 a.m. | #1
On Thursday, April 04 2019, Kevin Buettner wrote:

> gdb/testsuite/ChangeLog:

>

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

> 	gdb.InferiorThread.handle.


Hey Kevin,

I've just noticed that this patch series has introduced new FAILs when
testing a 64-bit GDB with --target_board unix/-m32:

new FAIL: gdb.python/py-thrhandle.exp: thread 0: fetch thread handle from thread
new FAIL: gdb.python/py-thrhandle.exp: thread 0: verify that handles are the same
new FAIL: gdb.python/py-thrhandle.exp: thread 1: fetch thread handle from thread
new FAIL: gdb.python/py-thrhandle.exp: thread 1: verify that handles are the same
new FAIL: gdb.python/py-thrhandle.exp: thread 2: fetch thread handle from thread
new FAIL: gdb.python/py-thrhandle.exp: thread 2: verify that handles are the same

The build logs:

https://gdb-build.sergiodj.net/builders/Fedora-x86_64-m32/builds/12263

And the testsuite logs:

https://gdb-build.sergiodj.net/results/Fedora-x86_64-m32/94/947210e5690c61b395ccd887bc58bcb45ccd357b/

I haven't been able to investigate further, sorry.

Thanks,

> ---

>  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..57b97faa18 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.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"

> +    }

> +}

> -- 

> 2.20.1


-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

Patch

diff --git a/gdb/testsuite/gdb.python/py-thrhandle.exp b/gdb/testsuite/gdb.python/py-thrhandle.exp
index 2c905b444f..57b97faa18 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.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"
+    }
+}