Fix tests-printers handling for cross compiling.
[glibc.git] / nptl / test-mutex-printers.py
blob7f542adcd7b5b5a37eab0a0dca41613cf8200a07
1 # Tests for the MutexPrinter class.
3 # Copyright (C) 2016 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
20 import sys
22 from test_printers_common import *
24 test_source = sys.argv[1]
25 test_bin = sys.argv[2]
26 printer_files = sys.argv[3:]
27 printer_names = ['global glibc-pthread-locks']
29 try:
30 init_test(test_bin, printer_files, printer_names)
31 go_to_main()
33 var = 'mutex'
34 to_string = 'pthread_mutex_t'
36 break_at(test_source, 'Test status (destroyed)')
37 continue_cmd() # Go to test_status_destroyed
38 test_printer(var, to_string, {'Status': 'Destroyed'})
40 break_at(test_source, 'Test status (non-robust)')
41 continue_cmd() # Go to test_status_no_robust
42 test_printer(var, to_string, {'Status': 'Unlocked'})
43 next_cmd()
44 thread_id = get_current_thread_lwpid()
45 test_printer(var, to_string, {'Status': 'Locked, possibly with no waiters',
46 'Owner ID': thread_id})
48 break_at(test_source, 'Test status (robust)')
49 continue_cmd() # Go to test_status_robust
50 test_printer(var, to_string, {'Status': 'Unlocked'})
52 # We'll now test the robust mutex locking states. We'll create a new
53 # thread that will lock a robust mutex and exit without unlocking it.
54 break_at(test_source, 'Create')
55 continue_cmd() # Go to test_locking_state_robust
56 # Set a breakpoint for the new thread to hit.
57 break_at(test_source, 'Thread function')
58 continue_cmd()
59 # By now the new thread is created and has hit its breakpoint.
60 set_scheduler_locking(True)
61 parent = 1
62 child = 2
63 select_thread(child)
64 child_id = get_current_thread_lwpid()
65 # We've got the new thread's ID.
66 select_thread(parent)
67 # Make the new thread finish its function while we wait.
68 continue_cmd(thread=child)
69 # The new thread should be dead by now.
70 break_at(test_source, 'Test locking (robust)')
71 continue_cmd()
72 test_printer(var, to_string, {'Owner ID': r'{0} \(dead\)'.format(child_id)})
73 # Try to lock and unlock the mutex.
74 next_cmd()
75 test_printer(var, to_string, {'Owner ID': thread_id,
76 'State protected by this mutex': 'Inconsistent'})
77 next_cmd()
78 test_printer(var, to_string, {'Status': 'Unlocked',
79 'State protected by this mutex': 'Not recoverable'})
80 set_scheduler_locking(False)
82 break_at(test_source, 'Test recursive locks')
83 continue_cmd() # Go to test_recursive_locks
84 test_printer(var, to_string, {'Times locked recursively': '2'})
85 next_cmd()
86 test_printer(var, to_string, {'Times locked recursively': '3'})
87 continue_cmd() # Exit
89 except (NoLineError, pexpect.TIMEOUT) as exception:
90 print('Error: {0}'.format(exception))
91 result = FAIL
93 else:
94 print('Test succeeded.')
95 result = PASS
97 exit(result)