Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / gdb / syscall_thread.py
1 # -*- python -*-
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.
5
6 import gdb_test
7
8
9 class SyscallThreadTest(gdb_test.GdbTest):
10
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))
17
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')
34     self.CheckBacktrace(
35         backtrace['stack'], ['pthread_join', 'test_syscall_thread'])
36
37
38 if __name__ == '__main__':
39   gdb_test.Main()