2 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
9 class SyscallThreadTest(gdb_test.GdbTest):
11 def CheckBacktrace(self, backtrace, functions):
12 all_functions = [frame['frame']['func'] for frame in backtrace]
13 # Check that 'functions' is a subsequence of 'all_functions'
14 s1 = '|' + '|'.join(all_functions) + '|'
15 s2 = '|' + '|'.join(functions) + '|'
16 self.assertIn(s2, s1, '%s not in %s' % (functions, all_functions))
18 def test_syscall_thread(self):
19 self.gdb.Command('break inside_f3')
20 self.gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
21 # Check we stopped in inside_f3
22 backtrace = self.gdb.Command('-stack-list-frames')
23 self.CheckBacktrace(backtrace['stack'], ['inside_f3', 'f3'])
24 # Check we have one more thread
25 thread_info = self.gdb.Command('-thread-info')
26 self.assertEquals(len(thread_info['threads']), 2)
27 # Select another thread
28 syscall_thread_id = thread_info['threads'][0]['id']
29 if syscall_thread_id == thread_info['current-thread-id']:
30 syscall_thread_id = thread_info['threads'][1]['id']
31 self.gdb.Command('-thread-select %s' % syscall_thread_id)
32 # Check that thread waits in usleep
33 backtrace = self.gdb.Command('-stack-list-frames')
35 backtrace['stack'], ['pthread_join', 'test_syscall_thread'])
38 if __name__ == '__main__':