update copyright year range in GDB files
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cell / bt.c
CommitLineData
1ea34204
UW
1/* This testcase is part of GDB, the GNU debugger.
2
61baf725 3 Copyright 2009-2017 Free Software Foundation, Inc.
1ea34204
UW
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 Contributed by Markus Deuling <deuling@de.ibm.com> */
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <libspe2.h>
23#include <pthread.h>
24#include <sys/wait.h>
25
26extern spe_program_handle_t bt_spu;
27extern spe_program_handle_t bt2_spu;
28#define nr_t 5
29
30void *
31spe_thread (void * arg)
32{
33 int flags = 0;
34 unsigned int entry = SPE_DEFAULT_ENTRY;
35 spe_context_ptr_t *ctx = (spe_context_ptr_t *) arg;
36
37 spe_program_load (*ctx, &bt_spu);
38 spe_context_run (*ctx, &entry, flags, NULL, NULL, NULL);
39
40 pthread_exit (NULL);
41}
42
43int
44indirect_handler (unsigned char *base, unsigned long offset)
45{
46 int flags = 0;
47 unsigned int entry = SPE_DEFAULT_ENTRY;
48 spe_context_ptr_t ctx = spe_context_create (0, NULL);
49
50 spe_program_load (ctx, &bt2_spu);
51 spe_context_run (ctx, &entry, flags, NULL, NULL, NULL);
52
53 return 0;
54}
55
56static pthread_mutex_t crash_mutex = PTHREAD_MUTEX_INITIALIZER;
57static int crash_count = 0;
58
59int
60crash_handler (unsigned char *base, unsigned long offset)
61{
62 int count;
63
64 pthread_mutex_lock (&crash_mutex);
65 count = ++crash_count;
66 pthread_mutex_unlock (&crash_mutex);
67
68 while (count < nr_t)
69 ;
70
71 abort ();
72}
73
74int
75main (void)
76{
77 int thread_id[nr_t];
78 pthread_t pts[nr_t];
79 spe_context_ptr_t ctx[nr_t];
80 int value = 1;
81 int cnt;
82
83 spe_callback_handler_register (indirect_handler, 0x11, SPE_CALLBACK_NEW);
84 spe_callback_handler_register (crash_handler, 0x12, SPE_CALLBACK_NEW);
85
86 for (cnt = 0; cnt < nr_t; cnt++)
87 {
88 ctx[cnt] = spe_context_create (0, NULL);
89 thread_id[cnt]
90 = pthread_create (&pts[cnt], NULL, &spe_thread, &ctx[cnt]);
91 }
92
93 for (cnt = 0; cnt < nr_t; cnt++)
94 pthread_join (pts[cnt], NULL);
95
96 for (cnt = 0; cnt < nr_t; cnt++)
97 spe_context_destroy (ctx[cnt]);
98
99 return 0;
100}
101
This page took 0.885259 seconds and 4 git commands to generate.