PAPI 7.1.0.0
Loading...
Searching...
No Matches
attach_validate.c File Reference
Include dependency graph for attach_validate.c:

Go to the source code of this file.

Functions

static int wait_for_attach_and_loop (int quiet)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 46 of file attach_validate.c.

46 {
47
48 int status, retval, tmp;
49 int EventSet1 = PAPI_NULL;
50 long long values[1];
52 const PAPI_component_info_t *cmpinfo;
53 pid_t pid;
54 int quiet;
55 int i,result;
56
57 /* Set TESTS_QUIET variable */
58 quiet=tests_quiet( argc, argv );
59
60 /* Fork before doing anything with the PMU */
61 setbuf(stdout,NULL);
62 pid = fork( );
63 if ( pid < 0 ) {
64 test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS );
65 }
66
67 /* If child */
68 if ( pid == 0 ) {
70 }
71
72
73 /* Parent process below here */
74
76 if ( retval != PAPI_VER_CURRENT ) {
77 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
78 }
79
80 if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL ) {
81 test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 0 );
82 }
83
84 if ( cmpinfo->attach == 0 ) {
85 test_skip( __FILE__, __LINE__, "Platform does not support attaching",
86 0 );
87 }
88
90 if ( hw_info == NULL ) {
91 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
92 }
93
94 /* Create Eventset */
96 if ( retval != PAPI_OK ) {
97 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
98 }
99
101 if ( retval != PAPI_OK ) {
102 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
103 retval );
104 }
105
106 /* Attach to our child */
107 retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
108 if ( retval != PAPI_OK ) {
109 if (!quiet) printf("Cannot attach: %s\n",PAPI_strerror(retval));
110 test_skip( __FILE__, __LINE__, "PAPI_attach", retval );
111 }
112
113 /* Add instructions event */
115 if ( retval != PAPI_OK ) {
116 if (!quiet) printf("Problem adding PAPI_TOT_INS\n");
117 test_skip( __FILE__, __LINE__, "PAPI_add_event", retval );
118 }
119
120
121 if (!quiet) {
122 printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace);
123 }
124
125 /* Wait for child to stop for debugging */
126 pid_t child = wait( &status );
127
128 if (!quiet) printf( "Debugger exited wait() with %d\n",child );
129 if (WIFSTOPPED( status )) {
130 if (!quiet) {
131 printf( "Child has stopped due to signal %d (%s)\n",
132 WSTOPSIG( status ),
133 strsignal(WSTOPSIG( status )) );
134 }
135 }
136
137 if (WIFSIGNALED( status )) {
138 if (!quiet) {
139 printf( "Child %ld received signal %d (%s)\n",
140 (long)child,
141 WTERMSIG(status),
142 strsignal(WTERMSIG( status )) );
143 }
144 }
145 if (!quiet) {
146 printf("After %d\n",retval);
147 }
148
149 /* Start eventset */
151 if ( retval != PAPI_OK ) {
152 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
153 }
154
155 if (!quiet) {
156 printf("Continuing\n");
157 }
158
159#if defined(__FreeBSD__)
160 if ( ptrace( PT_CONTINUE, pid, (vptr_t) 1, 0 ) == -1 ) {
161 perror( "ptrace(PTRACE_CONT)" );
162 test_fail( __FILE__, __LINE__,
163 "Continuing", PAPI_EMISC);
164 return 1;
165 }
166#else
167 if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
168 perror( "ptrace(PTRACE_CONT)" );
169 test_fail( __FILE__, __LINE__,
170 "Continuing", PAPI_EMISC);
171 }
172#endif
173
174
175 /* Run a billion instructions, should not appear in count */
176
177 for(i=0;i<1000;i++) {
179 }
180
181 /* Wait for child to finish */
182 do {
183 child = wait( &status );
184 if (!quiet) {
185 printf( "Debugger exited wait() with %d\n", child);
186 }
187 if (WIFSTOPPED( status )) {
188 if (!quiet) {
189 printf( "Child has stopped due to signal "
190 "%d (%s)\n",
191 WSTOPSIG( status ),
192 strsignal(WSTOPSIG( status )) );
193 }
194 }
195 if (WIFSIGNALED( status )) {
196 if (!quiet) {
197 printf( "Child %ld received signal "
198 "%d (%s)\n",
199 (long)child,
200 WTERMSIG(status),
201 strsignal(WTERMSIG( status )) );
202 }
203 }
204 } while (!WIFEXITED( status ));
205
206 if (!quiet) {
207 printf("Child exited with value %d\n",WEXITSTATUS(status));
208 }
209
210 if (WEXITSTATUS(status) != 0) {
211 test_fail( __FILE__, __LINE__,
212 "Exit status of child to attach to", PAPI_EMISC);
213 }
214
215 /* Stop counts */
217 if ( retval != PAPI_OK ) {
218 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
219 }
220
222 if (retval != PAPI_OK) {
223 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
224 }
225
227 if (retval != PAPI_OK) {
228 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
229 }
230
231 if (!quiet) {
232 printf( "Test case: attach validation.\n" );
233 printf( "-----------------------------------------------\n" );
234 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
235 printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) );
236 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
237 printf( "Default granularity is: %d (%s)\n", tmp,
239 printf( "Using 50 million instructions\n");
240 printf( "-------------------------------------------------------------------------\n" );
241
242 printf( "Test type : \t 1\n" );
243
244 printf( TAB1, "PAPI_TOT_INS : \t", ( values[0] ) );
245
246 printf( "-------------------------------------------------------------------------\n" );
247
248 }
249
250 if (values[0]<100) {
251 test_fail( __FILE__, __LINE__, "wrong result", PAPI_EMISC );
252 }
253
254 if (values[0]>60000000) {
255 test_fail( __FILE__, __LINE__, "wrong result", PAPI_EMISC );
256 }
257
258 (void)result;
259
260 test_pass( __FILE__ );
261
262 return 0;
263
264}
volatile int result
double tmp
int i
static int wait_for_attach_and_loop(void)
Definition: attach2.c:41
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
add PAPI preset or native hardware event to an event set
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.
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.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DEFGRN
Definition: f90papi.h:26
#define PAPI_EMISC
Definition: f90papi.h:122
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_TOT_INS
Definition: f90papi.h:317
#define PAPI_DEFDOM
Definition: f90papi.h:188
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int instructions_million(void)
void * vptr_t
Definition: papi.h:576
FILE * stdout
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define TAB1
Definition: papi_test.h:98
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
static int pid
unsigned int attach
Definition: papi.h:658
unsigned int attach_must_ptrace
Definition: papi.h:659
Hardware info structure.
Definition: papi.h:774
int EventSet1
Definition: zero_fork.c:47
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ wait_for_attach_and_loop()

static int wait_for_attach_and_loop ( int  quiet)
static

Definition at line 26 of file attach_validate.c.

26 {
27
28 int i,result;
29
30 if (ptrace(PTRACE_TRACEME, 0, 0, 0) == 0) {
31 raise(SIGSTOP);
32
33 if (!quiet) printf("Child running 50 million instructions\n");
34
35 /* Run 50 million instructions */
36 for(i=0;i<50;i++) {
38 }
39 }
40 perror("PTRACE_TRACEME");
41 (void)result;
42
43 return 0;
44}
int raise(int __sig) __attribute__((__nothrow__
Here is the call graph for this function: