23#include <sys/ptrace.h>
33#define _LINUX_SOURCE_COMPAT
36#if defined(__FreeBSD__)
37# define PTRACE_ATTACH PT_ATTACH
38# define PTRACE_TRACEME PT_TRACE_ME
45 char newpath[PATH_MAX];
46 path = getenv(
"PATH");
48 sprintf(newpath,
"PATH=./:%s", (path)?path:
"\0" );
51 if (ptrace(PTRACE_TRACEME, 0, 0, 0) == 0) {
52 execlp(
"attach_target",
"attach_target",
"100000000",NULL);
53 perror(
"execl(attach_target) failed");
55 perror(
"PTRACE_TRACEME");
60main(
int argc,
char **argv )
92 test_fail( __FILE__, __LINE__,
"PAPI_get_component_info", 0 );
94 if ( cmpinfo->
attach == 0 )
95 test_skip( __FILE__, __LINE__,
"Platform does not support attaching",
100 test_fail( __FILE__, __LINE__,
"PAPI_get_hardware_info", 0 );
114 test_fail( __FILE__, __LINE__,
"PAPI_assign_eventset_component",
128 if (!
quiet) printf(
"Could not add PAPI_TOT_CYC\n");
154 pid_t child = wait( &status );
155 if (!
quiet) printf(
"Debugger exited wait() with %d\n",child );
156 if (WIFSTOPPED( status ))
158 if (!
quiet) printf(
"Child has stopped due to signal %d (%s)\n",
159 WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
161 if (WIFSIGNALED( status ))
163 if (!
quiet) printf(
"Child %ld received signal %d (%s)\n",
165 WTERMSIG(status) , strsignal(WTERMSIG( status )) );
173 if (!
quiet) printf(
"Continuing\n");
174#if defined(__FreeBSD__)
175 if ( ptrace( PT_CONTINUE,
pid, (
vptr_t) 1, 0 ) == -1 ) {
177 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
179 perror(
"ptrace(PTRACE_CONT)" );
185 child = wait( &status );
186 if (!
quiet) printf(
"Debugger exited wait() with %d\n", child);
187 if (WIFSTOPPED( status ))
189 if (!
quiet) printf(
"Child has stopped due to signal %d (%s)\n",
190 WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
192 if (WIFSIGNALED( status ))
194 if (!
quiet) printf(
"Child %ld received signal %d (%s)\n",
196 WTERMSIG(status) , strsignal(WTERMSIG( status )) );
198 }
while (!WIFEXITED( status ));
200 if (!
quiet) printf(
"Child exited with value %d\n",WEXITSTATUS(status));
201 if (WEXITSTATUS(status) != 0) {
225 printf(
"Test case: 3rd party attach start, stop.\n" );
226 printf(
"-----------------------------------------------\n" );
230 printf(
"Default granularity is: %d (%s)\n",
tmp,
232 printf(
"Using %d iterations of c += a*b\n",
NUM_FLOPS );
233 printf(
"-------------------------------------------------------------------------\n" );
235 printf(
"Test type : \t 1\n" );
237 printf(
TAB1,
"PAPI_TOT_CYC : \t", (
values[0] )[0] );
241 printf(
TAB1,
"Virt usec : \t", elapsed_virt_us );
242 printf(
TAB1,
"Virt cycles : \t", elapsed_virt_cyc );
244 printf(
"-------------------------------------------------------------------------\n" );
246 printf(
"Verification: none\n" );
static int wait_for_attach_and_loop(void)
static const PAPI_hw_info_t * hw_info
add PAPI preset or native hardware event to an event set
add PAPI preset or native hardware event by name to an EventSet
Assign a component index to an existing but empty EventSet.
Attach PAPI event set to the specified thread id.
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
get information about a specific software component
get information about the system hardware
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.
Returns a string describing the PAPI error code.
char event_name[2][PAPI_MAX_STR_LEN]
static long long values[NUM_EVENTS]
Return codes and api definitions.
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)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
unsigned int attach_must_ptrace