52{
62 double ratio1,ratio2;
63
64
66
67
71 }
72
73
75 test_fail( __FILE__, __LINE__,
"PAPI_get_component_info", 0 );
76 }
77
78 if ( cmpinfo->
attach == 0 ) {
80 "Platform does not support attaching", 0 );
81 }
82
83
87 }
90 }
91
92
93 pid2 = fork( );
94 if ( pid2 < 0 ) {
96 }
97 if ( pid2 == 0 ) {
99 }
100
101
102
103
104
107
109 if ( ptrace( PTRACE_ATTACH,
pid, NULL, NULL ) == -1 ) {
110 perror( "ptrace(PTRACE_ATTACH)" );
111 return 1 ;
112 }
113 if ( waitpid(
pid, &status, 0 ) == -1 ) {
114 perror( "waitpid()" );
115 exit( 1 );
116 }
117 if ( WIFSTOPPED( status ) == 0 ) {
119 "Child process didnt return true to WIFSTOPPED", 0 );
120 }
121
122 if ( ptrace( PTRACE_ATTACH, pid2, NULL, NULL ) == -1 ) {
123 perror( "ptrace(PTRACE_ATTACH)" );
124 return 1;
125 }
126 if ( waitpid( pid2, &status, 0 ) == -1 ) {
127 perror( "waitpid()" );
128 exit( 1 );
129 }
130 if ( WIFSTOPPED( status ) == 0 ) {
132 "Child process didnt return true to WIFSTOPPED", 0 );
133 }
134 }
135
139 }
140
144 }
145
147 sprintf( add_event_str,
"PAPI_add_event[%s]",
event_name );
148
149
150
152
153
158
159
161 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
162 perror( "ptrace(PTRACE_CONT)" );
163 return 1;
164 }
165 if ( waitpid(
pid, &status, 0 ) == -1 ) {
166 perror( "waitpid()" );
167 exit( 1 );
168 }
169 if ( WIFSTOPPED( status ) == 0 ) {
171 "Child process didn't return true to WIFSTOPPED", 0 );
172 }
173 if ( WSTOPSIG( status ) != SIGSTOP ) {
175 "Child process didn't stop on SIGSTOP", 0 );
176 }
177
178 if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
179 perror( "ptrace(PTRACE_CONT)" );
180 return 1;
181 }
182 if ( waitpid( pid2, &status, 0 ) == -1 ) {
183 perror( "waitpid()" );
184 exit( 1 );
185 }
186 if ( WIFSTOPPED( status ) == 0 ) {
188 "Child process didn't return true to WIFSTOPPED", 0 );
189 }
190 if ( WSTOPSIG( status ) != SIGSTOP ) {
192 "Child process didn't stop on SIGSTOP", 0 );
193 }
194 }
195
196
200 }
201
202
206 }
207
208
210 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
211 perror( "ptrace(PTRACE_ATTACH)" );
212 return 1;
213 }
214 if ( waitpid(
pid, &status, 0 ) == -1 ) {
215 perror( "waitpid()" );
216 exit( 1 );
217 }
218 if ( WIFSTOPPED( status ) == 0 ) {
220 "Child process didn't return true to WIFSTOPPED", 0 );
221 }
222 if ( WSTOPSIG( status ) != SIGSTOP ) {
224 "Child process didn't stop on SIGSTOP", 0 );
225 }
226
227
228 if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
229 perror( "ptrace(PTRACE_ATTACH)" );
230 return 1;
231 }
232 if ( waitpid( pid2, &status, 0 ) == -1 ) {
233 perror( "waitpid()" );
234 exit( 1 );
235 }
236 if ( WIFSTOPPED( status ) == 0 ) {
238 "Child process didn't return true to WIFSTOPPED", 0 );
239 }
240 if ( WSTOPSIG( status ) != SIGSTOP ) {
242 "Child process didn't stop on SIGSTOP", 0 );
243 }
244 }
245
250
251
254 printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
256 }
257
258
261 printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
263 }
264
265
268
269
271 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
272 perror( "ptrace(PTRACE_CONT)" );
273 return 1;
274 }
275 if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
276 perror( "ptrace(PTRACE_CONT)" );
277 return 1;
278 }
279 }
280
281 if ( waitpid(
pid, &status, 0 ) == -1 ) {
282 perror( "waitpid()" );
283 exit( 1 );
284 }
285 if ( WIFEXITED( status ) == 0 ) {
287 "Child process didn't return true to WIFEXITED", 0 );
288 }
289
290 if ( waitpid( pid2, &status, 0 ) == -1 ) {
291 perror( "waitpid()" );
292 exit( 1 );
293 }
294 if ( WIFEXITED( status ) == 0 ) {
296 "Child process didn't return true to WIFEXITED", 0 );
297 }
298
299
300
301
302
304 printf( "Test case: multiple 3rd party attach start, stop.\n" );
305 printf( "-----------------------------------------------\n" );
307 printf(
"Default domain is: %d (%s)\n",
tmp,
310 printf(
"Default granularity is: %d (%s)\n",
tmp,
312 printf(
"Using %d iterations of c += a*b\n",
NUM_FLOPS );
313 printf( "-------------------------------------------------------------------------\n" );
314
315 sprintf( add_event_str,
"(PID %jd) %-12s : \t", ( intmax_t )
pid,
318 sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t",
321 sprintf( add_event_str, "(PID %jd) %-12s : \t", ( intmax_t ) pid2,
324 sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t",
325 ( intmax_t ) pid2 );
329 printf(
TAB1,
"Virt usec : \t", elapsed_virt_us );
330 printf(
TAB1,
"Virt cycles : \t", elapsed_virt_cyc );
331
332 printf( "-------------------------------------------------------------------------\n" );
333
334 printf("Verification: pid %d results should be %dx pid %d\n",
336 }
337
338
340
341
343
345 printf("\tFLOPS ratio %lld/%lld = %lf\n",
347 }
348
349 double ratio1_high,ratio1_low,ratio2_high,ratio2_low;
350
353
354 if ((ratio1 > ratio1_high ) || (ratio1 < ratio1_low)) {
355 printf("Ratio out of range, should be ~%lf not %lf\n",
358 "Error: Counter ratio not two", 0 );
359 }
360
362 printf("\tCycles ratio %lld/%lld = %lf\n",
364 }
365
368
369 if ((ratio2 > ratio2_high ) || (ratio2 < ratio2_low )) {
370 printf("Ratio out of range, should be ~%lf, not %lf\n",
373 "Known issue: Counter ratio not two", 0 );
374 }
375
377
378 return 0;
379}
static int wait_for_attach_and_loop(void)
Attach PAPI event set to the specified thread id.
get information about a specific software component
Get PAPI library or event set options.
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
get virtual time counter value in clock cycles
get virtual time counter values in microseconds
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
char event_name[2][PAPI_MAX_STR_LEN]
#define PAPI_2MAX_STR_LEN
static long long values[NUM_EVENTS]
int tests_quiet(int argc, char **argv)
char * stringify_all_domains(int domains)
char * stringify_granularity(int granularity)
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
long long ** allocate_test_space(int num_tests, int num_events)
void PAPI_NORETURN test_pass(const char *filename)
int add_two_events(int *num_events, int *papi_event, int *mask)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
int remove_test_events(int *EventSet, int mask)
unsigned int attach_must_ptrace