GDB 15 does not like exit() anymore:
    (gdb) python exit(0)
    Python Exception <class 'SystemExit'>: 0
    Error occurred in Python: 0
Use the GDB's own exit command, like it's already done in a couple
places, everywhere. This is the same fix as commit 93a3048dcf45
("tests: Gently exit from GDB when tests complete"), but applied to
more places.
Acked-by: Gustavo Romero <gustavo.romero@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Message-Id: <20241022113939.19989-1-iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
		
	
			
		
			
				
	
	
		
			61 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from __future__ import print_function
 | 
						|
#
 | 
						|
# Test some of the system debug features with the multiarch memory
 | 
						|
# test. It is a port of the original vmlinux focused test case but
 | 
						|
# using the "memory" test instead.
 | 
						|
#
 | 
						|
# This is launched via tests/guest-debug/run-test.py
 | 
						|
#
 | 
						|
 | 
						|
import gdb
 | 
						|
from test_gdbstub import gdb_exit, main, report
 | 
						|
 | 
						|
 | 
						|
def check_interrupt(thread):
 | 
						|
    """
 | 
						|
    Check that, if thread is resumed, we go back to the same thread when the
 | 
						|
    program gets interrupted.
 | 
						|
    """
 | 
						|
 | 
						|
    # Switch to the thread we're going to be running the test in.
 | 
						|
    print("thread ", thread.num)
 | 
						|
    gdb.execute("thr %d" % thread.num)
 | 
						|
 | 
						|
    # Enter the loop() function on this thread.
 | 
						|
    #
 | 
						|
    # While there are cleaner ways to do this, we want to minimize the number of
 | 
						|
    # side effects on the gdbstub's internal state, since those may mask bugs.
 | 
						|
    # Ideally, there should be no difference between what we're doing here and
 | 
						|
    # the program reaching the loop() function on its own.
 | 
						|
    #
 | 
						|
    # For this to be safe, we only need the prologue of loop() to not have
 | 
						|
    # instructions that may have problems with what we're doing here. We don't
 | 
						|
    # have to worry about anything else, as this function never returns.
 | 
						|
    gdb.execute("set $pc = loop")
 | 
						|
 | 
						|
    # Continue and then interrupt the task.
 | 
						|
    gdb.post_event(lambda: gdb.execute("interrupt"))
 | 
						|
    gdb.execute("c")
 | 
						|
 | 
						|
    # Check whether the thread we're in after the interruption is the same we
 | 
						|
    # ran continue from.
 | 
						|
    return (thread.num == gdb.selected_thread().num)
 | 
						|
 | 
						|
 | 
						|
def run_test():
 | 
						|
    """
 | 
						|
    Test if interrupting the code always lands us on the same thread when
 | 
						|
    running with scheduler-lock enabled.
 | 
						|
    """
 | 
						|
    if len(gdb.selected_inferior().threads()) == 1:
 | 
						|
        print("SKIP: set to run on a single thread")
 | 
						|
        gdb_exit(0)
 | 
						|
 | 
						|
    gdb.execute("set scheduler-locking on")
 | 
						|
    for thread in gdb.selected_inferior().threads():
 | 
						|
        report(check_interrupt(thread),
 | 
						|
               "thread %d resumes correctly on interrupt" % thread.num)
 | 
						|
 | 
						|
 | 
						|
main(run_test)
 |