Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-infthread.exp
CommitLineData
88b9d363 1# Copyright (C) 2009-2022 Free Software Foundation, Inc.
595939de
PM
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# This file is part of the GDB testsuite. It tests the mechanism
17# exposing inferior threads to Python.
18
6c162d5e
TT
19load_lib gdb-python.exp
20
b4a58790
TT
21standard_testfile
22
5b362f04 23if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
595939de
PM
24 return -1
25}
26
27# Start with a fresh gdb.
28clean_restart ${testfile}
29
30# Skip all tests if Python scripting is not enabled.
31if { [skip_python_tests] } { continue }
32
2a17c803 33gdb_test_multiline "install new_thread event handler" \
7c96f8c1
TT
34 "python" "" \
35 "seen_a_thread = False" "" \
36 "def thread_handler(evt):" "" \
37 " if evt.inferior_thread is not None:" "" \
38 " global seen_a_thread" "" \
39 " seen_a_thread = True" "" \
40 "gdb.events.new_thread.connect(thread_handler)" "" \
41 "end" ""
42
595939de
PM
43# The following tests require execution.
44
45if ![runto_main] then {
bc6c7af4 46 fail "can't run to main"
595939de
PM
47 return 0
48}
49
7c96f8c1
TT
50gdb_test "python print(seen_a_thread)" "True"
51
595939de
PM
52# Test basic gdb.Inferior attributes and methods.
53
484d8d36
MD
54# Make sure that InferiorThread.inferior returns a new reference (see PR 21213).
55
56gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 1" 1
57gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 2" 1
58gdb_test_no_output "python import gc; gc.collect()" "call Python garbage collection"
59gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 3" 1
60gdb_py_test_silent_cmd "python gdb.selected_thread ().inferior" "test InferiorThread.inferior 4" 1
61
62
595939de 63gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1
9325cb04 64gdb_test "python print (t0)" "\\<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
79bc59cb 65gdb_test "python print ('result = %s' % t0.num)" " = 1" "test InferiorThread.num"
22a02324 66gdb_test "python print ('result = %s' % t0.global_num)" " = 1" "test InferiorThread.global_num"
9325cb04 67gdb_test "python print ('result = %s' % str (t0.ptid))" " = \\(\[0-9\]+, \[0-9\]+, \[0-9\]+\\)" "test InferiorThread.ptid"
595939de 68
84654457
PA
69gdb_py_test_silent_cmd "python i0 = t0.inferior" "test InferiorThread.inferior" 1
70gdb_test "python print ('result = %s' % i0.num)" " = 1" "test Inferior.num"
71
4694da01
TT
72gdb_py_test_silent_cmd "python name = gdb.selected_thread().name" \
73 "get supplied name of current thread" 1
74gdb_py_test_silent_cmd "python gdb.selected_thread().name = 'hibob'" \
75 "set name of current thread" 1
9325cb04 76gdb_test "python print (gdb.selected_thread().name)" "hibob" \
4694da01
TT
77 "check name of current thread"
78gdb_py_test_silent_cmd "python gdb.selected_thread().name = None" \
79 "reset name of current thread" 1
9325cb04 80gdb_test "python print (gdb.selected_thread().name == name)" "True" \
4694da01
TT
81 "check name of current thread again"
82
9325cb04
PK
83gdb_test "python print ('result = %s' % t0.is_stopped ())" " = True" "test InferiorThread.is_stopped"
84gdb_test "python print ('result = %s' % t0.is_running ())" " = False" "test InferiorThread.is_running"
85gdb_test "python print ('result = %s' % t0.is_exited ())" " = False" "test InferiorThread.is_exited"
29703da4
PM
86
87# Test InferiorThread is_valid. This must always be the last test in
88# this testcase as it kills the inferior.
89
9325cb04 90gdb_test "python print ('result = %s' % t0.is_valid ())" " = True" "test InferiorThread.is_valid"
29703da4 91gdb_test_no_output "kill inferior 1" "kill inferior 1"
7f99d636
AB
92gdb_test "python print ('result = %s' % t0.is_valid ())" " = False" \
93 "test InferiorThread.is_valid after thread has been killed"
This page took 1.419791 seconds and 4 git commands to generate.