[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / openmp / libompd / gdb-plugin / ompdAPITests.c
blob912914c7b8c9b827e173b34bc6fd4d087c8cbb2c
1 #include <Python.h>
2 #include <dlfcn.h>
3 #include <errno.h>
4 #include <omp-tools.h>
5 #include <pthread.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
10 extern void *ompd_library;
12 struct _ompd_aspace_cont {
13 int id;
15 struct _ompd_thread_cont {
16 int id;
18 ompd_address_space_context_t context = {42};
19 ompd_address_space_context_t invalidcontext = {99};
21 // call back functions for ompd_initialize
22 ompd_rc_t _alloc(ompd_size_t bytes, void **ptr);
23 ompd_rc_t _free(void *ptr);
24 ompd_rc_t _sizes(ompd_address_space_context_t *_acontext,
25 ompd_device_type_sizes_t *sizes);
26 ompd_rc_t _sym_addr(ompd_address_space_context_t *context,
27 ompd_thread_context_t *tcontext, const char *symbol_name,
28 ompd_address_t *symbol_addr, const char *file_name);
29 ompd_rc_t _read(ompd_address_space_context_t *context,
30 ompd_thread_context_t *tcontext, const ompd_address_t *addr,
31 ompd_size_t nbytes, void *buffer);
32 ompd_rc_t _read_string(ompd_address_space_context_t *context,
33 ompd_thread_context_t *tcontext,
34 const ompd_address_t *addr, ompd_size_t nbytes,
35 void *buffer);
36 ompd_rc_t _endianess(ompd_address_space_context_t *address_space_context,
37 const void *input, ompd_size_t unit_size,
38 ompd_size_t count, void *output);
39 ompd_rc_t _thread_context(ompd_address_space_context_t *context,
40 ompd_thread_id_t kind, ompd_size_t sizeof_thread_id,
41 const void *thread_id,
42 ompd_thread_context_t **thread_context);
43 ompd_rc_t _print(const char *str, int category);
46 Test API: ompd_get_thread_handle
48 ompdtestapi threadandparallel
50 Program:
51 1. #include <stdio.h>
52 2. #include <omp.h>
53 3. int main () {
54 4. omp_set_num_threads(2);
55 5. #pragma omp parallel
56 6. {
57 7. printf("Parallel level 1, thread num = %d",
58 omp_get_thread_num());
59 8. }
60 9. return 0;
61 10. }
63 GDB Commands:
64 ompd init
65 b 7
67 ompdtestapi ompd_get_thread_handle
69 for ompd_rc_unavailable:
70 ompd init
71 ompdtestapi ompd_get_thread_handle
74 PyObject *test_ompd_get_thread_handle(PyObject *self, PyObject *args) {
75 printf("Testing \"ompd_get_thread_handle\"...\n");
77 PyObject *addrSpaceTup = PyTuple_GetItem(args, 0);
78 ompd_address_space_handle_t *addr_handle =
79 (ompd_address_space_handle_t *)PyCapsule_GetPointer(addrSpaceTup,
80 "AddressSpace");
82 PyObject *threadIdTup = PyTuple_GetItem(args, 1);
83 uint64_t threadID = (uint64_t)PyLong_AsLong(threadIdTup);
85 ompd_size_t sizeof_thread_id = sizeof(threadID);
86 ompd_thread_handle_t *thread_handle;
88 // should be successful
89 printf("Test: With Correct Arguments.\n");
90 ompd_rc_t rc = ompd_get_thread_handle(
91 addr_handle, 1 /*lwp*/, sizeof_thread_id, &threadID, &thread_handle);
93 if (rc == ompd_rc_unavailable) {
94 // ompd_rc_unavailable if the thread is not an OpenMP thread.
95 printf("Success. ompd_rc_unavailable, OpenMP is disabled.\n");
96 printf("This is not a Parallel Region, No more testing is possible.\n");
97 return Py_None;
98 } else if (rc != ompd_rc_ok)
99 printf("Failed, with return code = %d\n", rc);
100 else
101 printf("Success.\n");
103 // as in ompd-types.h, only 0-3 are valid for thread kind
104 // ompd_rc_unsupported if thread kind is not supported.
105 printf("Test: Unsupported thread kind.\n");
106 rc = ompd_get_thread_handle(addr_handle, 4, sizeof_thread_id, &threadID,
107 &thread_handle);
108 if (rc != ompd_rc_unsupported)
109 printf("Failed, with return code = %d\n", rc);
110 else
111 printf("Success.\n");
113 // ompd_rc_bad_input: if a different value in sizeof_thread_id is expected for
114 // a thread kind.
115 // sizeof_thread_id is validated at thread_context which is call back function
116 // "_thread_context" where we expect size to be sizeof(long int)
117 printf("Test: Wrong value for sizeof threadID.\n");
118 rc = ompd_get_thread_handle(addr_handle, 1 /*lwp*/, sizeof_thread_id - 1,
119 &threadID, &thread_handle);
120 if (rc != ompd_rc_bad_input)
121 printf("Failed, with return code = %d\n", rc);
122 else
123 printf("Success.\n");
125 // Random checks with null and invalid args.
127 ompd_rc_stale_handle: is returned when the specified handle is no
128 longer valid;
129 ompd_rc_bad_input: is returned when the input parameters
130 (other than handle) are invalid;
131 ompd_rc_error: is returned when a fatal error occurred;
134 printf("Test: Expecting ompd_rc_bad_input for NULL thread_handle.\n");
135 rc = ompd_get_thread_handle(addr_handle, 1 /*lwp*/, sizeof_thread_id,
136 &threadID, NULL);
137 if (rc != ompd_rc_bad_input)
138 printf("Failed, with return code = %d\n", rc);
139 else
140 printf("Success.\n");
142 printf(
143 "Test: Expecting ompd_rc_error or stale_handle for NULL addr_handle.\n");
144 rc = ompd_get_thread_handle(NULL, 1 /*lwp*/, sizeof_thread_id, &threadID,
145 &thread_handle);
146 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
147 printf("Failed, with return code = %d\n", rc);
148 else
149 printf("Success.\n");
151 return Py_None;
155 Test API: ompd_get_curr_parallel_handle.
157 Program:
158 1. #include <stdio.h>
159 2. #include <omp.h>
160 3. int main () {
161 4. omp_set_num_threads(2);
162 5. #pragma omp parallel
163 6. {
164 7. printf("Parallel level 1, thread num = %d",
165 omp_get_thread_num());
166 8. }
167 9. return 0;
168 10. }
170 GDB Commands:
171 ompd init
173 omptestapi ompd_get_curr_parallel_handle
175 for ompd_rc_unavailable
176 ompd init
177 omptestapi ompd_get_curr_parallel_handle (or break at line 4
178 before this)
181 PyObject *test_ompd_get_curr_parallel_handle(PyObject *self, PyObject *args) {
182 printf("Testing \"ompd_get_curr_parallel_handle\"...\n");
184 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);
185 ompd_thread_handle_t *thread_handle =
186 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,
187 "ThreadHandle"));
189 ompd_parallel_handle_t *parallel_handle;
191 printf("Test: With Correct Arguments.\n");
192 ompd_rc_t rc = ompd_get_curr_parallel_handle(thread_handle, &parallel_handle);
193 if (rc == ompd_rc_unavailable) {
194 // ompd_rc_unavailable if the thread is not currently part of a team
196 // ToCheck: Even in non parallel region, error code is stale_handle
197 // Need to find a test case for ompd_rc_unavailable ?????
198 printf("Success. ompd_rc_unavailable, Not in parallel region\n");
199 printf("No more testing is possible.\n");
200 return Py_None;
201 } else if (rc == ompd_rc_stale_handle) {
202 printf("Return code is stale_handle, may be in non-parallel region.\n");
203 printf("No more testing is possible.\n");
204 return Py_None;
205 } else if (rc != ompd_rc_ok)
206 printf("Failed, with return code = %d\n", rc);
207 else
208 printf("Success.\n");
210 // Random checks with null and invalid args.
212 ompd_rc_stale_handle: is returned when the specified handle is no
213 longer valid;
214 ompd_rc_bad_input: is returned when the input parameters
215 (other than handle) are invalid;
216 ompd_rc_error: is returned when a fatal error occurred;
219 printf("Test: Expecting ompd_rc_bad_input for NULL parallel_handle.\n");
220 rc = ompd_get_curr_parallel_handle(thread_handle, NULL);
221 if (rc != ompd_rc_bad_input)
222 printf("Failed, with return code = %d\n", rc);
223 else
224 printf("Success.\n");
226 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "
227 "thread_handle.\n");
228 rc = ompd_get_curr_parallel_handle(NULL, &parallel_handle);
229 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
230 printf("Failed, with return code = %d\n", rc);
231 else
232 printf("Success.\n");
234 return Py_None;
238 Test API: ompd_get_thread_in_parallel.
240 Program:
241 1. #include <stdio.h>
242 2. #include <omp.h>
243 3. int main () {
244 4. omp_set_num_threads(3);
245 5. #pragma omp parallel
246 6. {
247 7. printf("Parallel level 1, thread num = %d",
248 omp_get_thread_num());
249 8. }
250 9. return 0;
251 10. }
253 GDB Commands:
254 ompd init
256 omptestapi ompd_get_thread_in_parallel
258 PyObject *test_ompd_get_thread_in_parallel(PyObject *self, PyObject *args) {
259 printf("Testing \"ompd_get_thread_in_parallel\"...\n");
261 PyObject *parallelHandlePy = PyTuple_GetItem(args, 0);
262 ompd_parallel_handle_t *parallel_handle =
263 (ompd_parallel_handle_t *)(PyCapsule_GetPointer(parallelHandlePy,
264 "ParallelHandle"));
265 ompd_thread_handle_t *thread_handle;
267 printf("Test: With Correct Arguments.\n");
268 ompd_rc_t rc = ompd_get_thread_in_parallel(
269 parallel_handle, 1 /* lesser than team-size-var*/, &thread_handle);
270 if (rc != ompd_rc_ok) {
271 printf("Failed, with return code = %d\n", rc);
272 return Py_None;
273 } else
274 printf("Success.\n");
276 // ompd_rc_bad_input: if the thread_num argument is greater than or equal to
277 // the team-size-var ICV or negative
278 printf("Test: Invalid thread num (199).\n");
279 rc = ompd_get_thread_in_parallel(parallel_handle, 199, &thread_handle);
280 if (rc != ompd_rc_bad_input)
281 printf("Failed, with return code = %d\n", rc);
282 else
283 printf("Success.\n");
285 printf("Test: Invalid thread num (-5).\n");
286 rc = ompd_get_thread_in_parallel(parallel_handle, -5, &thread_handle);
287 if (rc != ompd_rc_bad_input)
288 printf("Failed, with return code = %d\n", rc);
289 else
290 printf("Success.\n");
292 // Random checks with null and invalid args.
294 ompd_rc_stale_handle: is returned when the specified handle is no
295 longer valid;
296 ompd_rc_bad_input: is returned when the input parameters
297 (other than handle) are invalid;
298 ompd_rc_error: is returned when a fatal error occurred;
301 printf("Test: Expecting ompd_rc_bad_input for NULL thread_handle.\n");
302 rc = ompd_get_thread_in_parallel(parallel_handle, 1, NULL);
303 if (rc != ompd_rc_bad_input)
304 printf("Failed, with return code = %d\n", rc);
305 else
306 printf("Success.\n");
308 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "
309 "parallel_handle.\n");
310 rc = ompd_get_thread_in_parallel(NULL, 1, &thread_handle);
311 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
312 printf("Failed, with return code = %d\n", rc);
313 else
314 printf("Success.\n");
316 return Py_None;
320 Test API: ompd_thread_handle_compare.
322 Program:
323 1. #include <stdio.h>
324 2. #include <omp.h>
325 3. int main () {
326 4. omp_set_num_threads(4);
327 5. #pragma omp parallel
328 6. {
329 7. printf("Parallel level 1, thread num = %d",
330 omp_get_thread_num());
331 8. }
332 9. return 0;
333 10. }
335 GDB Commands:
336 ompd init
338 omptestapi ompd_thread_handle_compare
341 PyObject *test_ompd_thread_handle_compare(PyObject *self, PyObject *args) {
342 printf("Testing \"ompd_thread_handle_compare\"...\n");
344 PyObject *threadHandlePy1 = PyTuple_GetItem(args, 0);
345 ompd_thread_handle_t *thread_handle1 =
346 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy1,
347 "ThreadHandle"));
348 PyObject *threadHandlePy2 = PyTuple_GetItem(args, 1);
349 ompd_thread_handle_t *thread_handle2 =
350 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy2,
351 "ThreadHandle"));
353 int cmp_value;
355 printf("Test: With Correct Arguments.\n");
356 ompd_rc_t rc =
357 ompd_thread_handle_compare(thread_handle1, thread_handle2, &cmp_value);
358 if (rc != ompd_rc_ok) {
359 printf("Failed, with return code = %d\n", rc);
360 return Py_None;
361 } else
362 printf("Success.\n");
364 if (cmp_value == 0) {
365 printf("Threads are Equal.\n");
366 } else {
367 // a value less than, equal to, or greater than 0 indicates that the thread
368 // corresponding to thread_handle_1 is, respectively, less than, equal to,
369 // or greater than that corresponding to thread_handle_2.
370 if (cmp_value <= 0) {
371 printf("Thread 1 is lesser than thread 2, cmp_val = %d\n", cmp_value);
372 printf("Test: Changing the order.\n");
373 rc = ompd_thread_handle_compare(thread_handle2, thread_handle1,
374 &cmp_value);
375 if (rc != ompd_rc_ok) {
376 printf("Failed, with return code = %d\n", rc);
377 return Py_None;
379 if (cmp_value >= 0)
380 printf("Success now cmp_value is greater, %d.\n", cmp_value);
381 else
382 printf("Failed.\n");
383 } else {
384 printf("Thread 1 is greater than thread 2.\n");
385 printf("Test: Changing the order.\n");
386 rc = ompd_thread_handle_compare(thread_handle2, thread_handle1,
387 &cmp_value);
388 if (rc != ompd_rc_ok) {
389 printf("Failed, with return code = %d\n", rc);
390 return Py_None;
392 if (cmp_value <= 0)
393 printf("Success now cmp_value is lesser, %d.\n", cmp_value);
394 else
395 printf("Failed.\n");
398 // Random checks with null and invalid args.
400 ompd_rc_stale_handle: is returned when the specified handle is no
401 longer valid;
402 ompd_rc_bad_input: is returned when the input parameters
403 (other than handle) are invalid;
404 ompd_rc_error: is returned when a fatal error occurred;
407 printf("Test: Expecting ompd_rc_bad_input for NULL cmp_value.\n");
408 rc = ompd_thread_handle_compare(thread_handle2, thread_handle1, NULL);
409 if (rc != ompd_rc_bad_input)
410 printf("Failed, with return code = %d\n", rc);
411 else
412 printf("Success.\n");
414 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "
415 "thread_handle.\n");
416 rc = ompd_thread_handle_compare(NULL, thread_handle1, &cmp_value);
417 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
418 printf("Failed, with return code = %d\n", rc);
419 else
420 printf("Success.\n");
423 return Py_None;
427 Test API: ompd_get_thread_id.
429 Program:
430 1. #include <stdio.h>
431 2. #include <omp.h>
432 3. int main () {
433 4. omp_set_num_threads(2);
434 5. #pragma omp parallel
435 6. {
436 7. printf("Parallel level 1, thread num = %d",
437 omp_get_thread_num());
438 8. }
439 9. return 0;
440 10. }
442 GDB Commands:
443 ompd init
445 omptestapi ompd_get_thread_id
448 PyObject *test_ompd_get_thread_id(PyObject *self, PyObject *args) {
449 printf("Testing \"ompd_get_thread_id\"...\n");
451 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);
452 ompd_thread_handle_t *thread_handle =
453 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,
454 "ThreadHandle"));
456 uint64_t threadID;
457 ompd_size_t sizeof_thread_id = sizeof(threadID);
459 printf("Test: With Correct Arguments.\n");
460 ompd_rc_t rc = ompd_get_thread_id(thread_handle, 0 /*OMPD_THREAD_ID_PTHREAD*/,
461 sizeof_thread_id, &threadID);
462 if (rc != ompd_rc_ok) {
463 printf("Failed, with return code = %d\n", rc);
464 return Py_None;
465 } else
466 printf("Success. Thread id = %ld\n", threadID);
468 // ompd_rc_bad_input: if a different value in sizeof_thread_id is expected for
469 // a thread kind of kind
470 printf("Test: Wrong sizeof_thread_id.\n");
471 rc = ompd_get_thread_id(thread_handle, 0 /*OMPD_THREAD_ID_PTHREAD*/,
472 sizeof_thread_id - 1, &threadID);
473 if (rc != ompd_rc_bad_input)
474 printf("Failed, with return code = %d\n", rc);
475 else
476 printf("Success.\n");
478 // ompd_rc_unsupported: if the kind of thread is not supported
479 printf("Test: Unsupported thread kind.\n");
480 // thread kind currently support from 0-3, refer in ompd-types.h
481 rc = ompd_get_thread_id(thread_handle, 4, sizeof_thread_id - 1, &threadID);
482 if (rc != ompd_rc_unsupported)
483 printf("Failed, with return code = %d\n", rc);
484 else
485 printf("Success.\n");
487 // Random checks with null and invalid args.
489 ompd_rc_stale_handle: is returned when the specified handle is no
490 longer valid;
491 ompd_rc_bad_input: is returned when the input parameters
492 (other than handle) are invalid;
493 ompd_rc_error: is returned when a fatal error occurred;
496 printf("Test: Expecting ompd_rc_bad_input for NULL threadID.\n");
497 rc = ompd_get_thread_id(thread_handle, 0 /*OMPD_THREAD_ID_PTHREAD*/,
498 sizeof_thread_id, NULL);
499 if (rc != ompd_rc_bad_input)
500 printf("Failed, with return code = %d\n", rc);
501 else
502 printf("Success.\n");
504 printf("Test: Expecting ompd_rc_error for NULL thread_handle.\n");
505 rc = ompd_get_thread_id(NULL, 0 /*OMPD_THREAD_ID_PTHREAD*/, sizeof_thread_id,
506 &threadID);
507 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
508 printf("Failed, with return code = %d\n", rc);
509 else
510 printf("Success.\n");
512 return Py_None;
516 Test API: ompd_rel_thread_handle
518 Program:
519 1. #include <stdio.h>
520 2. #include <omp.h>
521 3. int main () {
522 4. omp_set_num_threads(2);
523 5. #pragma omp parallel
524 6. {
525 7. printf("Parallel level 1, thread num = %d",
526 omp_get_thread_num());
527 8. }
528 9. return 0;
529 10. }
531 GDB Commands:
532 ompd init
534 omptestapi ompd_rel_thread_handle
537 // TODO: This might not be the right way to do,as this handle comes from
538 // python not generated by ompd API
540 PyObject *test_ompd_rel_thread_handle(PyObject *self, PyObject *args) {
541 printf("Testing Not enabled for \"ompd_rel_thread_handle\"...\n");
542 printf("Disabled.\n");
543 return Py_None;
547 Test API: ompd_get_enclosing_parallel_handle.
549 Program:
550 1. #include <stdio.h>
551 2. #include <omp.h>
552 3. int main () {
553 4. omp_set_num_threads(2);
554 5. #pragma omp parallel
555 6. {
556 7. printf("Parallel level 1, thread num = %d",
557 omp_get_thread_num());
558 8. omp_set_num_threads(3);
559 9. #pragma omp parallel
560 10. {
561 11. printf ("Parallel level 2, thread num = %d",
562 omp_get_thread_num());
563 12. }
564 13. }
565 14. return 0;
566 15. }
568 GDB Commands:
569 ompd init
570 b 11
571 ompdtestapi ompd_get_enclosing_parallel_handle
573 for "ompd_rc_unavailable":
574 ompd init
575 omptestapi ompd_get_enclosing_parallel_handle
576 (or break at line 4 before this)
579 PyObject *test_ompd_get_enclosing_parallel_handle(PyObject *self,
580 PyObject *args) {
581 printf("Testing \"ompd_get_enclosing_parallel_handle\"...\n");
583 PyObject *parallelHandlePy = PyTuple_GetItem(args, 0);
584 ompd_parallel_handle_t *parallel_handle =
585 (ompd_parallel_handle_t *)(PyCapsule_GetPointer(parallelHandlePy,
586 "ParallelHandle"));
587 ompd_parallel_handle_t *enclosing_parallel_handle;
589 printf("Test: With Correct Arguments.\n");
590 ompd_rc_t rc = ompd_get_enclosing_parallel_handle(parallel_handle,
591 &enclosing_parallel_handle);
592 if (rc == ompd_rc_unavailable) {
593 // ompd_rc_unavailable: if no enclosing parallel region exists.
594 printf("Success. return code is ompd_rc_unavailable, Not in parallel "
595 "region\n");
596 printf("No more testing is possible.\n");
597 return Py_None;
598 } else if (rc != ompd_rc_ok) {
599 printf("Failed, with return code = %d\n", rc);
600 return Py_None;
601 } else
602 printf("Success.\n");
604 // Random checks with null and invalid args.
606 ompd_rc_stale_handle: is returned when the specified handle is no
607 longer valid;
608 ompd_rc_bad_input: is returned when the input parameters
609 (other than handle) are invalid;
610 ompd_rc_error: is returned when a fatal error occurred;
613 printf("Test: Expecting ompd_rc_bad_input for NULL "
614 "enclosing_parallel_handle.\n");
615 rc = ompd_get_enclosing_parallel_handle(parallel_handle, NULL);
616 if (rc != ompd_rc_bad_input)
617 printf("Failed, with return code = %d\n", rc);
618 else
619 printf("Success.\n");
621 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "
622 "parallel_handle.\n");
623 rc = ompd_get_enclosing_parallel_handle(NULL, &enclosing_parallel_handle);
624 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
625 printf("Failed, with return code = %d\n", rc);
626 else
627 printf("Success.\n");
629 return Py_None;
633 Test API: ompd_parallel_handle_compare.
635 Program:
636 1. #include <stdio.h>
637 2. #include <omp.h>
638 3. int main () {
639 4. omp_set_num_threads(2);
640 5. #pragma omp parallel
641 6. {
642 7. printf("Parallel level 1, thread num = %d",
643 omp_get_thread_num());
644 8. omp_set_num_threads(3);
645 9. #pragma omp parallel
646 10. {
647 11. printf ("Parallel level 2, thread num = %d",
648 omp_get_thread_num());
649 12. }
650 13. }
651 14. return 0;
652 15. }
654 GDB Commands:
655 ompd init
656 b 11
657 ompdtestapi ompd_parallel_handle_compare
660 PyObject *test_ompd_parallel_handle_compare(PyObject *self, PyObject *args) {
661 printf("Testing \"ompd_parallel_handle_compare\"...\n");
663 PyObject *parallelHandlePy1 = PyTuple_GetItem(args, 0);
664 ompd_parallel_handle_t *parallel_handle1 =
665 (ompd_parallel_handle_t *)(PyCapsule_GetPointer(parallelHandlePy1,
666 "ParallelHandle"));
667 PyObject *parallelHandlePy2 = PyTuple_GetItem(args, 1);
668 ompd_parallel_handle_t *parallel_handle2 =
669 (ompd_parallel_handle_t *)(PyCapsule_GetPointer(parallelHandlePy2,
670 "ParallelHandle"));
672 int cmp_value;
674 printf("Test: With Correct Arguments.\n");
675 ompd_rc_t rc = ompd_parallel_handle_compare(parallel_handle1,
676 parallel_handle2, &cmp_value);
677 if (rc != ompd_rc_ok) {
678 printf("Failed, with return code = %d\n", rc);
679 return Py_None;
680 } else
681 printf("Success.\n");
683 if (cmp_value == 0) {
684 printf("Parallel regions are Same.\n");
685 } else {
686 // A value less than, equal to, or greater than 0 indicates that the region
687 // corresponding to parallel_handle_1 is, respectively, less than, equal to,
688 // or greater than that corresponding to parallel_handle_2
689 if (cmp_value <= 0) {
690 printf("Parallel handle 1 is lesser than handle 2, cmp_val = %d\n",
691 cmp_value);
692 printf("Test: Changing the order.\n");
693 rc = ompd_parallel_handle_compare(parallel_handle2, parallel_handle1,
694 &cmp_value);
695 if (rc != ompd_rc_ok) {
696 printf("Failed, with return code = %d\n", rc);
697 return Py_None;
699 if (cmp_value >= 0)
700 printf("Success now cmp_value is greater, %d.\n", cmp_value);
701 else
702 printf("Failed.\n");
703 } else {
704 printf("Parallel 1 is greater than handle 2.\n");
705 printf("Test: Changing the order.\n");
706 rc = ompd_parallel_handle_compare(parallel_handle2, parallel_handle1,
707 &cmp_value);
708 if (rc != ompd_rc_ok) {
709 printf("Failed, with return code = %d\n", rc);
710 return Py_None;
712 if (cmp_value <= 0)
713 printf("Success now cmp_value is lesser, %d.\n", cmp_value);
714 else
715 printf("Failed.\n");
718 // Random checks with null and invalid args.
720 ompd_rc_stale_handle: is returned when the specified handle is no
721 longer valid;
722 ompd_rc_bad_input: is returned when the input parameters
723 (other than handle) are invalid;
724 ompd_rc_error: is returned when a fatal error occurred;
727 printf("Test: Expecting ompd_rc_bad_input for NULL cmp_value.\n");
728 rc = ompd_parallel_handle_compare(parallel_handle2, parallel_handle1, NULL);
729 if (rc != ompd_rc_bad_input)
730 printf("Failed, with return code = %d\n", rc);
731 else
732 printf("Success.\n");
734 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "
735 "thread_handle.\n");
736 rc = ompd_parallel_handle_compare(NULL, parallel_handle1, &cmp_value);
737 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
738 printf("Failed, with return code = %d\n", rc);
739 else
740 printf("Success.\n");
743 return Py_None;
747 Test API: ompd_rel_parallel_handle
749 Program:
750 1. #include <stdio.h>
751 2. #include <omp.h>
752 3. int main () {
753 4. omp_set_num_threads(2);
754 5. #pragma omp parallel
755 6. {
756 7. printf("Parallel level 1, thread num = %d",
757 omp_get_thread_num());
758 8. }
759 9. return 0;
760 10. }
762 GDB Commands:
763 ompd init
765 omptestapi ompd_rel_parallel_handle
768 // TODO: Same as thread_rel_handle, might not be a right way to test
769 // What released should be provided by ompd API, this address is actually from
770 // python
771 PyObject *test_ompd_rel_parallel_handle(PyObject *self, PyObject *args) {
772 printf("Testing NOT enabled for \"ompd_rel_parallel_handle\"...\n");
773 printf("Disabled.\n");
774 return Py_None;
778 Test API: ompd_initialize
780 Program:
781 1. #include <stdio.h>
782 2. #include <omp.h>
783 3. int main () {
784 4. omp_set_num_threads(2);
785 5. #pragma omp parallel
786 6. {
787 7. printf("Parallel level 1, thread num = %d",
788 omp_get_thread_num());
789 8. }
790 9. return 0;
791 10. }
793 GDB Commands:
795 ompdtestapi ompd_initialize\
797 PyObject *test_ompd_initialize(PyObject *self, PyObject *noargs) {
798 printf("Testing \"test_ompd_initialize\"...\n");
800 ompd_word_t version;
801 ompd_rc_t rc = ompd_get_api_version(&version);
802 if (rc != ompd_rc_ok) {
803 printf("Failed in \"ompd_get_api_version\".\n");
804 return Py_None;
807 static ompd_callbacks_t table = {
808 _alloc, _free, _print, _sizes, _sym_addr, _read,
809 NULL, _read_string, _endianess, _endianess, _thread_context};
811 printf("Test: With Correct Arguments.\n");
812 ompd_rc_t (*my_ompd_init)(ompd_word_t version, ompd_callbacks_t *) =
813 dlsym(ompd_library, "ompd_initialize");
814 rc = my_ompd_init(version, &table);
815 if (rc != ompd_rc_ok) {
816 printf("Failed, with return code = %d\n", rc);
817 return Py_None;
818 } else
819 printf("Success.\n");
821 static ompd_callbacks_t invalid_table = {
822 NULL, /* _alloc, */
823 NULL, /* _free, */
824 NULL, /* _print,*/
825 NULL, /* _sizes, */
826 NULL, /* _sym_addr, */
827 NULL, /* _read,*/
828 NULL, NULL, /* _read_string, */
829 NULL, /* _endianess, */
830 NULL, /* _endianess, */
831 NULL, /* _thread_context */
834 // ompd_rc_bad_input: if invalid callbacks are provided
835 printf("Test: Invalid callbacks.\n");
836 rc = my_ompd_init(version, &invalid_table);
837 if (rc != ompd_rc_bad_input)
838 printf("Warning, with return code = %d\n", rc);
839 else
840 printf("Success.\n");
842 // ompd_rc_unsupported: if the requested API version cannot be provided
843 printf("Test: Wrong API version.\n");
844 rc = my_ompd_init(150847, &table);
845 if (rc != ompd_rc_unsupported)
846 printf("Failed, with return code = %d\n", rc);
847 else
848 printf("Success.\n");
850 // Random checks with null and invalid args.
852 ompd_rc_stale_handle: is returned when the specified handle is no
853 longer valid;
854 ompd_rc_bad_input: is returned when the input parameters
855 (other than handle) are invalid;
856 ompd_rc_error: is returned when a fatal error occurred;
859 printf("Test: Expecting ompd_rc_bad_input for NULL table.\n");
860 rc = my_ompd_init(version, NULL);
861 if (rc != ompd_rc_bad_input)
862 printf("Failed, with return code = %d\n", rc);
863 else
864 printf("Success.\n");
866 printf("Test: Expecting ompd_rc_error or ompd_rc_bad_input for NULL\n");
867 rc = my_ompd_init(0, &table);
868 if (rc != ompd_rc_unsupported && rc != ompd_rc_bad_input)
869 printf("Failed, with return code = %d\n", rc);
870 else
871 printf("Success.\n");
873 return Py_None;
877 Test API: ompd_get_api_version
879 Program:
880 1. #include <stdio.h>
881 2. #include <omp.h>
882 3. int main () {
883 4. omp_set_num_threads(2);
884 5. #pragma omp parallel
885 6. {
886 7. printf("Parallel level 1, thread num = %d",
887 omp_get_thread_num());
888 8. }
889 9. return 0;
890 10. }
892 GDB Commands:
893 ompd init
895 ompdtestapi ompd_get_version
899 PyObject *test_ompd_get_api_version(PyObject *self, PyObject *noargs) {
900 printf("Testing \"ompd_get_api_version\"...\n");
902 ompd_word_t version;
904 printf("Test: With Correct Arguments.\n");
905 ompd_rc_t rc = ompd_get_api_version(&version);
906 if (rc != ompd_rc_ok) {
907 printf("Failed, with return code = %d\n", rc);
908 return Py_None;
909 } else
910 printf("Success. API version is %ld\n", version);
912 printf(
913 "Test: Expecting ompd_rc_error or ompd_rc_bad_input for NULL version\n");
914 rc = ompd_get_api_version(NULL);
915 if (rc != ompd_rc_error && rc != ompd_rc_bad_input)
916 printf("Failed, with return code = %d\n", rc);
917 else
918 printf("Success.\n");
920 return Py_None;
924 Test API: ompd_get_version_string
926 Program:
927 1. #include <stdio.h>
928 2. #include <omp.h>
929 3. int main () {
930 4. omp_set_num_threads(2);
931 5. #pragma omp parallel
932 6. {
933 7. printf("Parallel level 1, thread num = %d",
934 omp_get_thread_num());
935 8. }
936 9. return 0;
937 10. }
939 GDB Commands:
940 ompd init
942 omptestapi ompd_get_version_string
946 PyObject *test_ompd_get_version_string(PyObject *self, PyObject *noargs) {
947 printf("Testing \"ompd_get_version_string\"...\n");
949 const char *string;
951 printf("Test: With Correct Arguments.\n");
952 ompd_rc_t rc = ompd_get_version_string(&string);
953 if (rc != ompd_rc_ok) {
954 printf("Failed, with return code = %d\n", rc);
955 return Py_None;
956 } else
957 printf("Success. API version is %s\n", string);
959 printf(
960 "Test: Expecting ompd_rc_error or ompd_rc_bad_input for NULL version\n");
961 rc = ompd_get_version_string(NULL);
962 if (rc != ompd_rc_error && rc != ompd_rc_bad_input)
963 printf("Failed, with return code = %d\n", rc);
964 else
965 printf("Success.\n");
967 return Py_None;
971 Test API: ompd_finalize
973 Program:
974 1. #include <stdio.h>
975 2. #include <omp.h>
976 3. int main () {
977 4. omp_set_num_threads(2);
978 5. #pragma omp parallel
979 6. {
980 7. printf("Parallel level 1, thread num = %d",
981 omp_get_thread_num());
982 8. }
983 9. return 0;
984 10. }
986 GDB Commands:
987 ompd init
989 ompdtestapi ompd_finalize
994 ompdtestapi ompd_finalize
997 PyObject *test_ompd_finalize(PyObject *self, PyObject *noargs) {
998 printf("Testing \"ompd_finalize\"...\n");
1000 printf("Test: With Correct Arguments.\n");
1001 ompd_rc_t rc = ompd_finalize();
1002 if (rc == ompd_rc_ok)
1003 printf("Ret code: ompd_rc_ok, Success if ompd is initialized.\n");
1004 // ompd_rc_unsupported: if the OMPD library is not initialized.
1005 else if (rc == ompd_rc_unsupported)
1006 printf(
1007 "Ret code: ompd_rc_unsupported, Success if ompd is NOT initialized.\n");
1008 else
1009 printf("Failed: Return code is %d.\n", rc);
1011 return Py_None;
1015 Test API: ompd_process_initialize
1017 Program:
1018 1. #include <stdio.h>
1019 2. #include <omp.h>
1020 3. int main () {
1021 4. omp_set_num_threads(2);
1022 5. #pragma omp parallel
1023 6. {
1024 7. printf("Parallel level 1, thread num = %d",
1025 omp_get_thread_num());
1026 8. }
1027 9. return 0;
1028 10. }
1030 GDB Commands:
1034 PyObject *test_ompd_process_initialize(PyObject *self, PyObject *noargs) {
1036 printf("Testing \"ompd_process_initialize\"....\n");
1038 ompd_address_space_handle_t *addr_handle;
1040 // ompd_address_space_context_t context = {42};
1042 printf("Test: with correct Args.\n");
1043 ompd_rc_t rc = ompd_process_initialize(&context, &addr_handle);
1044 if (rc != ompd_rc_ok) {
1045 printf("Failed, with return code = %d\n", rc);
1046 return Py_None;
1047 } else
1048 printf("Success.\n");
1050 printf("Test: With Unsupported library.\n");
1051 printf("Warning: Have to test manually with 32 and 64 bit combination.\n");
1053 // ompd_address_space_context_t invalidcontext = {99};
1054 printf("Test: with wrong context value.\n");
1055 rc = ompd_process_initialize(&invalidcontext, &addr_handle);
1056 if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_incompatible) &&
1057 (rc != ompd_rc_stale_handle))
1058 printf("Failed, with return code = %d\n", rc);
1059 else
1060 printf("Success.\n");
1062 // Random checks with null and invalid args.
1064 ompd_rc_stale_handle: is returned when the specified handle is no
1065 longer valid;
1066 ompd_rc_bad_input: is returned when the input parameters
1067 (other than handle) are invalid;
1068 ompd_rc_error: is returned when a fatal error occurred;
1071 printf("Test: Expecting stale handle or bad_input for NULL addr_handle.\n");
1072 rc = ompd_process_initialize(&context, NULL);
1073 if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_stale_handle))
1074 printf("Failed, with return code = %d\n", rc);
1075 else
1076 printf("Success.\n");
1078 return Py_None;
1082 Test API: ompd_device_initialize
1084 Program:
1085 1. #include <stdio.h>
1086 2. #include <omp.h>
1087 3. int main () {
1088 4. omp_set_num_threads(2);
1089 5. #pragma omp parallel
1090 6. {
1091 7. printf("Parallel level 1, thread num = %d",
1092 omp_get_thread_num());
1093 8. }
1094 9. return 0;
1095 10. }
1097 GDB Commands:
1101 PyObject *test_ompd_device_initialize(PyObject *self, PyObject *noargs) {
1102 printf("Testing Not enabled for \"ompd_device_initialize\".\n");
1103 printf("Disabled.\n");
1105 return Py_None;
1109 Test API: ompd_rel_address_space_handle
1111 Program:
1112 1. #include <stdio.h>
1113 2. #include <omp.h>
1114 3. int main () {
1115 4. omp_set_num_threads(2);
1116 5. #pragma omp parallel
1117 6. {
1118 7. printf("Parallel level 1, thread num = %d",
1119 omp_get_thread_num());
1120 8. }
1121 9. return 0;
1122 10. }
1124 GDB Commands:
1127 PyObject *test_ompd_rel_address_space_handle(PyObject *self, PyObject *noargs) {
1128 printf("Testing Not enabled for \"ompd_rel_address_space_handle\".\n");
1129 printf("Disabled.\n");
1131 return Py_None;
1135 Test API: ompd_get_omp_version
1137 Program:
1138 1. #include <stdio.h>
1139 2. #include <omp.h>
1140 3. int main () {
1141 4. omp_set_num_threads(2);
1142 5. #pragma omp parallel
1143 6. {
1144 7. printf("Parallel level 1, thread num = %d",
1145 omp_get_thread_num());
1146 8. }
1147 9. return 0;
1148 10. }
1150 GDB Commands:
1151 ompd init
1152 b 10
1154 ompdtestapi ompd_get_omp_version
1156 PyObject *test_ompd_get_omp_version(PyObject *self, PyObject *args) {
1157 printf("Testing \"ompd_get_omp_version\" ...\n");
1159 PyObject *addrSpaceTup = PyTuple_GetItem(args, 0);
1160 ompd_address_space_handle_t *addr_handle =
1161 (ompd_address_space_handle_t *)PyCapsule_GetPointer(addrSpaceTup,
1162 "AddressSpace");
1164 ompd_word_t omp_version;
1166 printf("Test: With Correct Arguments.\n");
1167 ompd_rc_t rc = ompd_get_omp_version(addr_handle, &omp_version);
1168 if (rc != ompd_rc_ok) {
1169 printf("Failed, with return code = %d\n", rc);
1170 return Py_None;
1171 } else
1172 printf("Success. API version is %ld\n", omp_version);
1174 // Random checks with null and invalid args.
1176 ompd_rc_stale_handle: is returned when the specified handle is no
1177 longer valid;
1178 ompd_rc_bad_input: is returned when the input parameters
1179 (other than handle) are invalid;
1180 ompd_rc_error: is returned when a fatal error occurred;
1183 printf("Test: Expecting stale handle or bad_input for NULL addr_handle.\n");
1184 rc = ompd_get_omp_version(NULL, &omp_version);
1185 if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_stale_handle))
1186 printf("Failed, with return code = %d\n", rc);
1187 else
1188 printf("Success.\n");
1190 printf("Test: Expecting ompd_rc_error or bad_input for NULL omp_version.\n");
1191 rc = ompd_get_omp_version(addr_handle, NULL);
1192 if (rc != ompd_rc_error && rc != ompd_rc_bad_input)
1193 printf("Failed, with return code = %d\n", rc);
1194 else
1195 printf("Success.\n");
1197 return Py_None;
1201 Test API: ompd_get_omp_version_string
1203 Program:
1204 1. #include <stdio.h>
1205 2. #include <omp.h>
1206 3. int main () {
1207 4. omp_set_num_threads(2);
1208 5. #pragma omp parallel
1209 6. {
1210 7. printf("Parallel level 1, thread num = %d",
1211 omp_get_thread_num());
1212 8. }
1213 9. return 0;
1214 10. }
1216 GDB Commands:
1217 ompd init
1219 ompdtestapi ompd_get_omp_version_string
1221 PyObject *test_ompd_get_omp_version_string(PyObject *self, PyObject *args) {
1222 printf("Testing \"ompd_get_omp_version_string\" ...\n");
1224 PyObject *addrSpaceTup = PyTuple_GetItem(args, 0);
1225 ompd_address_space_handle_t *addr_handle =
1226 (ompd_address_space_handle_t *)PyCapsule_GetPointer(addrSpaceTup,
1227 "AddressSpace");
1229 const char *string;
1231 printf("Test: With Correct Arguments.\n");
1232 ompd_rc_t rc = ompd_get_omp_version_string(addr_handle, &string);
1233 if (rc != ompd_rc_ok) {
1234 printf("Failed, with return code = %d\n", rc);
1235 return Py_None;
1236 } else
1237 printf("Success. API version is %s\n", string);
1239 // Random checks with null and invalid args.
1241 ompd_rc_stale_handle: is returned when the specified handle is no
1242 longer valid;
1243 ompd_rc_bad_input: is returned when the input parameters
1244 (other than handle) are invalid;
1245 ompd_rc_error: is returned when a fatal error occurred;
1248 printf("Test: Expecting stale handle or bad_input for NULL addr_handle.\n");
1249 rc = ompd_get_omp_version_string(NULL, &string);
1250 if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_stale_handle))
1251 printf("Failed, with return code = %d\n", rc);
1252 else
1253 printf("Success.\n");
1255 printf("Test: Expecting ompd_rc_error or bad_input for NULL omp_version.\n");
1256 rc = ompd_get_omp_version_string(addr_handle, NULL);
1257 if (rc != ompd_rc_error && rc != ompd_rc_bad_input)
1258 printf("Failed, with return code = %d\n", rc);
1259 else
1260 printf("Success.\n");
1262 return Py_None;
1266 Test API: ompd_get_curr_task_handle
1268 Program:
1269 1 #include <stdio.h>
1270 2 #include <omp.h>
1271 3 int get_fib_num (int num)
1273 5 int t1, t2;
1274 6 if (num < 2)
1275 7 return num;
1276 8 else {
1277 9 #pragma omp task shared(t1)
1278 10 t1 = get_fib_num(num-1);
1279 11 #pragma omp task shared(t2)
1280 12 t2 = get_fib_num(num-2);
1281 13 #pragma omp taskwait
1282 14 return t1+t2;
1283 15 }
1284 16 }
1286 18 int main () {
1287 19 int ret = 0;
1288 20 omp_set_num_threads(2);
1289 21 #pragma omp parallel
1290 22 {
1291 23 ret = get_fib_num(10);
1292 24 }
1293 25 printf ("Fib of 10 is %d", ret);
1294 26 return 0;
1295 27 }
1297 GDB Commands:
1298 ompd init
1299 b 10
1301 ompdtestapi ompd_get_curr_task_handle
1304 PyObject *test_ompd_get_curr_task_handle(PyObject *self, PyObject *args) {
1305 printf("Testing \"ompd_get_curr_task_handle\"...\n");
1307 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);
1308 ompd_thread_handle_t *thread_handle =
1309 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,
1310 "ThreadHandle"));
1312 ompd_task_handle_t *task_handle;
1314 printf("Test: With Correct Arguments.\n");
1315 ompd_rc_t rc = ompd_get_curr_task_handle(thread_handle, &task_handle);
1316 if (rc == ompd_rc_unavailable) {
1317 // ompd_rc_unavailable if the thread is not currently executing a task
1319 printf(
1320 "Success. Return code is ompd_rc_unavailable, Not executing a task.\n");
1321 printf("No more testing is possible.\n");
1322 return Py_None;
1323 } else if (rc == ompd_rc_stale_handle) {
1324 printf("Return code is stale_handle, may be in non parallel region.\n");
1325 printf("No more testing is possible.\n");
1326 return Py_None;
1327 } else if (rc != ompd_rc_ok)
1328 printf("Failed. with return code = %d\n", rc);
1329 else
1330 printf("Success.\n");
1332 // Random checks with null and invalid args.
1334 ompd_rc_stale_handle: is returned when the specified handle is no
1335 longer valid;
1336 ompd_rc_bad_input: is returned when the input parameters
1337 (other than handle) are invalid;
1338 ompd_rc_error: is returned when a fatal error occurred;
1341 printf("Test: Expecting ompd_rc_bad_input for NULL parallel_handle.\n");
1342 rc = ompd_get_curr_task_handle(thread_handle, NULL);
1343 if (rc != ompd_rc_bad_input)
1344 printf("Failed. with return code = %d\n", rc);
1345 else
1346 printf("Success.\n");
1348 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "
1349 "thread_handle.\n");
1350 rc = ompd_get_curr_task_handle(NULL, &task_handle);
1351 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
1352 printf("Failed. with return code = %d\n", rc);
1353 else
1354 printf("Success.\n");
1356 return Py_None;
1360 Test API: ompd_get_task_parallel_handle
1362 Program:
1363 1 #include <stdio.h>
1364 2 #include <omp.h>
1365 3 int get_fib_num (int num)
1367 5 int t1, t2;
1368 6 if (num < 2)
1369 7 return num;
1370 8 else {
1371 9 #pragma omp task shared(t1)
1372 10 t1 = get_fib_num(num-1);
1373 11 #pragma omp task shared(t2)
1374 12 t2 = get_fib_num(num-2);
1375 13 #pragma omp taskwait
1376 14 return t1+t2;
1377 15 }
1378 16 }
1380 18 int main () {
1381 19 int ret = 0;
1382 20 omp_set_num_threads(2);
1383 21 #pragma omp parallel
1384 22 {
1385 23 ret = get_fib_num(10);
1386 24 }
1387 25 printf ("Fib of 10 is %d", ret);
1388 26 return 0;
1389 27 }
1391 GDB Commands:
1392 ompd init
1393 b 10
1395 ompdtestapi ompd_get_task_parallel_handle
1397 PyObject *test_ompd_get_task_parallel_handle(PyObject *self, PyObject *args) {
1399 printf("Testing \"ompd_get_task_parallel_handle\"...\n");
1401 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);
1402 ompd_task_handle_t *task_handle =
1403 PyCapsule_GetPointer(taskHandlePy, "TaskHandle");
1405 ompd_parallel_handle_t *task_parallel_handle;
1407 printf("Test: With Correct Arguments.\n");
1408 ompd_rc_t rc =
1409 ompd_get_task_parallel_handle(task_handle, &task_parallel_handle);
1410 if (rc != ompd_rc_ok) {
1411 printf("Failed. with return code = %d\n", rc);
1412 return Py_None;
1413 } else
1414 printf("Success.\n");
1416 // Random checks with null and invalid args.
1418 ompd_rc_stale_handle: is returned when the specified handle is no
1419 longer valid;
1420 ompd_rc_bad_input: is returned when the input parameters
1421 (other than handle) are invalid;
1422 ompd_rc_error: is returned when a fatal error occurred;
1425 printf("Test: Expecting ompd_rc_bad_input for NULL task_parallel_handle.\n");
1426 rc = ompd_get_task_parallel_handle(task_handle, NULL);
1427 if (rc != ompd_rc_bad_input)
1428 printf("Failed. with return code = %d\n", rc);
1429 else
1430 printf("Success.\n");
1432 printf(
1433 "Test: Expecting ompd_rc_error or stale_handle for NULL task_handle.\n");
1434 rc = ompd_get_task_parallel_handle(NULL, &task_parallel_handle);
1435 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
1436 printf("Failed. with return code = %d\n", rc);
1437 else
1438 printf("Success.\n");
1440 return Py_None;
1444 Test API: ompd_get_generating_task_handle
1446 Program:
1447 1 #include <stdio.h>
1448 2 #include <omp.h>
1449 3 int get_fib_num (int num)
1451 5 int t1, t2;
1452 6 if (num < 2)
1453 7 return num;
1454 8 else {
1455 9 #pragma omp task shared(t1)
1456 10 t1 = get_fib_num(num-1);
1457 11 #pragma omp task shared(t2)
1458 12 t2 = get_fib_num(num-2);
1459 13 #pragma omp taskwait
1460 14 return t1+t2;
1461 15 }
1462 16 }
1464 18 int main () {
1465 19 int ret = 0;
1466 20 omp_set_num_threads(2);
1467 21 #pragma omp parallel
1468 22 {
1469 23 ret = get_fib_num(10);
1470 24 }
1471 25 printf ("Fib of 10 is %d", ret);
1472 26 return 0;
1473 27 }
1475 GDB Commands:
1476 ompd init
1477 b 10
1479 c // may or may not be needed
1480 ompdtestapi ompd_get_generating_task_handle
1482 PyObject *test_ompd_get_generating_task_handle(PyObject *self, PyObject *args) {
1483 printf("Testing \"ompd_get_generating_task_handle\"...\n");
1485 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);
1486 ompd_task_handle_t *task_handle =
1487 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy, "TaskHandle"));
1488 ompd_task_handle_t *generating_task_handle;
1490 printf("Test: With Correct Arguments.\n");
1491 ompd_rc_t rc =
1492 ompd_get_generating_task_handle(task_handle, &generating_task_handle);
1493 if (rc == ompd_rc_unavailable) {
1494 // ompd_rc_unavailable if no generating task handle exists.
1495 printf("Success. Return code is ompd_rc_unavailable\n");
1496 printf("No more testing is possible.\n");
1497 return Py_None;
1498 } else if (rc != ompd_rc_ok) {
1499 printf("Failed. with return code = %d\n", rc);
1500 return Py_None;
1501 } else
1502 printf("Success.\n");
1504 // Random checks with null and invalid args.
1506 ompd_rc_stale_handle: is returned when the specified handle is no
1507 longer valid;
1508 ompd_rc_bad_input: is returned when the input parameters
1509 (other than handle) are invalid;
1510 ompd_rc_error: is returned when a fatal error occurred;
1513 printf(
1514 "Test: Expecting ompd_rc_bad_input for NULL generating_task_handle.\n");
1515 rc = ompd_get_generating_task_handle(task_handle, NULL);
1516 if (rc != ompd_rc_bad_input)
1517 printf("Failed. with return code = %d\n", rc);
1518 else
1519 printf("Success.\n");
1521 printf(
1522 "Test: Expecting ompd_rc_error or stale_handle for NULL task_handle.\n");
1523 rc = ompd_get_generating_task_handle(NULL, &generating_task_handle);
1524 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
1525 printf("Failed. with return code = %d\n", rc);
1526 else
1527 printf("Success.\n");
1529 return Py_None;
1533 Test API: ompd_get_scheduling_task_handle
1535 Program:
1536 1 #include <stdio.h>
1537 2 #include <omp.h>
1538 3 int get_fib_num (int num)
1540 5 int t1, t2;
1541 6 if (num < 2)
1542 7 return num;
1543 8 else {
1544 9 #pragma omp task shared(t1)
1545 10 t1 = get_fib_num(num-1);
1546 11 #pragma omp task shared(t2)
1547 12 t2 = get_fib_num(num-2);
1548 13 #pragma omp taskwait
1549 14 return t1+t2;
1550 15 }
1551 16 }
1553 18 int main () {
1554 19 int ret = 0;
1555 20 omp_set_num_threads(2);
1556 21 #pragma omp parallel
1557 22 {
1558 23 ret = get_fib_num(10);
1559 24 }
1560 25 printf ("Fib of 10 is %d", ret);
1561 26 return 0;
1562 27 }
1564 GDB Commands:
1565 ompd init
1566 b 10
1568 ompdtestapi ompd_get_scheduling_task_handle
1570 PyObject *test_ompd_get_scheduling_task_handle(PyObject *self, PyObject *args) {
1571 printf("Testing \"ompd_get_scheduling_task_handle\"...\n");
1573 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);
1574 ompd_task_handle_t *task_handle =
1575 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy, "TaskHandle"));
1576 ompd_task_handle_t *scheduling_task_handle;
1578 printf("Test: With Correct Arguments.\n");
1579 ompd_rc_t rc =
1580 ompd_get_scheduling_task_handle(task_handle, &scheduling_task_handle);
1581 if (rc == ompd_rc_unavailable) {
1582 // ompd_rc_unavailable if no generating task handle exists.
1583 printf(
1584 "Success. Return code is ompd_rc_unavailable, No scheduling task.\n");
1585 printf("No more testing is possible.\n");
1586 return Py_None;
1587 } else if (rc != ompd_rc_ok) {
1588 printf("Failed. with return code = %d\n", rc);
1589 return Py_None;
1590 } else
1591 printf("Success.\n");
1593 // Random checks with null and invalid args.
1595 ompd_rc_stale_handle: is returned when the specified handle is no
1596 longer valid;
1597 ompd_rc_bad_input: is returned when the input parameters
1598 (other than handle) are invalid;
1599 ompd_rc_error: is returned when a fatal error occurred;
1602 printf(
1603 "Test: Expecting ompd_rc_bad_input for NULL scheduling_task_handle.\n");
1604 rc = ompd_get_scheduling_task_handle(task_handle, NULL);
1605 if (rc != ompd_rc_bad_input)
1606 printf("Failed. with return code = %d\n", rc);
1607 else
1608 printf("Success.\n");
1610 printf(
1611 "Test: Expecting ompd_rc_error or stale_handle for NULL task_handle.\n");
1612 rc = ompd_get_scheduling_task_handle(NULL, &scheduling_task_handle);
1613 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
1614 printf("Failed. with return code = %d\n", rc);
1615 else
1616 printf("Success.\n");
1618 return Py_None;
1622 Test API: ompd_get_task_in_parallel
1624 Program:
1625 Program:
1626 1. #include <stdio.h>
1627 2. #include <omp.h>
1628 3. int main () {
1629 4. omp_set_num_threads(4);
1630 5. #pragma omp parallel
1631 6. {
1632 7. printf("Parallel level 1, thread num = %d",
1633 omp_get_thread_num());
1634 8. }
1635 9. return 0;
1636 10. }
1638 GDB Commands:
1639 ompd init
1642 ompdtestapi ompd_get_task_in_parallel
1644 PyObject *test_ompd_get_task_in_parallel(PyObject *self, PyObject *args) {
1645 printf("Testing \"ompd_get_task_in_parallel\"...\n");
1647 PyObject *parallelHandlePy = PyTuple_GetItem(args, 0);
1648 ompd_parallel_handle_t *parallel_handle =
1649 (ompd_parallel_handle_t *)(PyCapsule_GetPointer(parallelHandlePy,
1650 "ParallelHandle"));
1651 ompd_task_handle_t *task_handle;
1653 printf("Test: With Correct Arguments.\n");
1654 ompd_rc_t rc = ompd_get_task_in_parallel(
1655 parallel_handle, 1 /* lesser than team-size-var*/, &task_handle);
1656 if (rc != ompd_rc_ok) {
1657 printf("Failed. with return code = %d\n", rc);
1658 return Py_None;
1659 } else
1660 printf("Success.\n");
1662 // ompd_rc_bad_input if the thread_num argument is greater than or equal to
1663 // the team-size-var ICV or negative
1664 printf("Test: Invalid thread num (199).\n");
1665 rc = ompd_get_task_in_parallel(parallel_handle, 199, &task_handle);
1666 if (rc != ompd_rc_bad_input)
1667 printf("Failed. with return code = %d\n", rc);
1668 else
1669 printf("Success.\n");
1671 printf("Test: Invalid thread num (-5).\n");
1672 rc = ompd_get_task_in_parallel(parallel_handle, -5, &task_handle);
1673 if (rc != ompd_rc_bad_input)
1674 printf("Failed. with return code = %d\n", rc);
1675 else
1676 printf("Success.\n");
1678 // Random checks with null and invalid args.
1680 ompd_rc_stale_handle: is returned when the specified handle is no
1681 longer valid;
1682 ompd_rc_bad_input: is returned when the input parameters
1683 (other than handle) are invalid;
1684 ompd_rc_error: is returned when a fatal error occurred;
1687 printf("Test: Expecting ompd_rc_bad_input for NULL task_handle.\n");
1688 rc = ompd_get_task_in_parallel(parallel_handle, 1, NULL);
1689 if (rc != ompd_rc_bad_input)
1690 printf("Failed. with return code = %d\n", rc);
1691 else
1692 printf("Success.\n");
1694 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "
1695 "parallel_handle.\n");
1696 rc = ompd_get_task_in_parallel(NULL, 1, &task_handle);
1697 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
1698 printf("Failed. with return code = %d\n", rc);
1699 else
1700 printf("Success.\n");
1702 return Py_None;
1706 Test API: ompd_rel_task_handle
1708 Program:
1709 1 #include <stdio.h>
1710 2 #include <omp.h>
1711 3 int get_fib_num (int num)
1713 5 int t1, t2;
1714 6 if (num < 2)
1715 7 return num;
1716 8 else {
1717 9 #pragma omp task shared(t1)
1718 10 t1 = get_fib_num(num-1);
1719 11 #pragma omp task shared(t2)
1720 12 t2 = get_fib_num(num-2);
1721 13 #pragma omp taskwait
1722 14 return t1+t2;
1723 15 }
1724 16 }
1726 18 int main () {
1727 19 int ret = 0;
1728 20 omp_set_num_threads(2);
1729 21 #pragma omp parallel
1730 22 {
1731 23 ret = get_fib_num(10);
1732 24 }
1733 25 printf ("Fib of 10 is %d", ret);
1734 26 return 0;
1735 27 }
1737 GDB Commands:
1738 ompd init
1739 b 10
1741 ompdtestapi ompd_rel_task_handle
1743 PyObject *test_ompd_rel_task_handle(PyObject *self, PyObject *noargs) {
1744 printf("Testing Not enabled for \"ompd_rel_task_handle\".\n");
1745 printf("Disabled.\n");
1747 return Py_None;
1751 Test API: ompd_task_handle_compare
1753 Program:
1754 1 #include <stdio.h>
1755 2 #include <omp.h>
1756 3 int get_fib_num (int num)
1758 5 int t1, t2;
1759 6 if (num < 2)
1760 7 return num;
1761 8 else {
1762 9 #pragma omp task shared(t1)
1763 10 t1 = get_fib_num(num-1);
1764 11 #pragma omp task shared(t2)
1765 12 t2 = get_fib_num(num-2);
1766 13 #pragma omp taskwait
1767 14 return t1+t2;
1768 15 }
1769 16 }
1771 18 int main () {
1772 19 int ret = 0;
1773 20 omp_set_num_threads(2);
1774 21 #pragma omp parallel
1775 22 {
1776 23 ret = get_fib_num(10);
1777 24 }
1778 25 printf ("Fib of 10 is %d", ret);
1779 26 return 0;
1780 27 }
1782 GDB Commands:
1783 ompd init
1784 b 10
1787 ompdtestapi ompd_task_handle_compare
1789 PyObject *test_ompd_task_handle_compare(PyObject *self, PyObject *args) {
1790 printf("Testing \"ompd_task_handle_compare\"...\n");
1792 PyObject *taskHandlePy1 = PyTuple_GetItem(args, 0);
1793 ompd_task_handle_t *task_handle1 =
1794 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy1, "TaskHandle"));
1795 PyObject *taskHandlePy2 = PyTuple_GetItem(args, 1);
1796 ompd_task_handle_t *task_handle2 =
1797 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy2, "TaskHandle"));
1799 int cmp_value;
1801 printf("Test: With Correct Arguments.\n");
1802 ompd_rc_t rc =
1803 ompd_task_handle_compare(task_handle1, task_handle2, &cmp_value);
1804 if (rc != ompd_rc_ok) {
1805 printf("Failed. with return code = %d\n", rc);
1806 return Py_None;
1807 } else
1808 printf("Success.\n");
1810 if (cmp_value == 0) {
1811 printf("Task Handles are Same.\n");
1812 } else {
1813 // a value less than, equal to, or greater than 0 indicates that the task
1814 // that corresponds to task_handle_1 is, respectively, less than, equal to,
1815 // or greater than the task that corresponds to task_handle_2.
1816 if (cmp_value <= 0) {
1817 printf("Task handle 1 is lesser than handle 2, cmp_val = %d\n",
1818 cmp_value);
1819 printf("Test: Changing the order.\n");
1820 rc = ompd_task_handle_compare(task_handle2, task_handle1, &cmp_value);
1821 if (rc != ompd_rc_ok) {
1822 printf("Failed. with return code = %d\n", rc);
1823 return Py_None;
1825 if (cmp_value >= 0)
1826 printf("Success now cmp_value is greater, %d.\n", cmp_value);
1827 else
1828 printf("Failed.\n");
1829 } else {
1830 printf("Task 1 is greater than handle 2.\n");
1831 printf("Test: Changing the order.\n");
1832 rc = ompd_task_handle_compare(task_handle2, task_handle1, &cmp_value);
1833 if (rc != ompd_rc_ok) {
1834 printf("Failed. with return code = %d\n", rc);
1835 return Py_None;
1837 if (cmp_value <= 0)
1838 printf("Success now cmp_value is lesser, %d.\n", cmp_value);
1839 else
1840 printf("Failed.\n");
1843 // Random checks with null and invalid args.
1845 ompd_rc_stale_handle: is returned when the specified handle is no
1846 longer valid;
1847 ompd_rc_bad_input: is returned when the input parameters
1848 (other than handle) are invalid;
1849 ompd_rc_error: is returned when a fatal error occurred;
1852 printf("Test: Expecting ompd_rc_bad_input for NULL cmp_value.\n");
1853 rc = ompd_task_handle_compare(task_handle2, task_handle1, NULL);
1854 if (rc != ompd_rc_bad_input)
1855 printf("Failed. with return code = %d\n", rc);
1856 else
1857 printf("Success.\n");
1859 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "
1860 "task_handle.\n");
1861 rc = ompd_task_handle_compare(NULL, task_handle1, &cmp_value);
1862 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
1863 printf("Failed. with return code = %d\n", rc);
1864 else
1865 printf("Success.\n");
1868 return Py_None;
1872 Test API: ompd_get_task_function
1874 Program:
1875 1 #include <stdio.h>
1876 2 #include <omp.h>
1877 3 int get_fib_num (int num)
1879 5 int t1, t2;
1880 6 if (num < 2)
1881 7 return num;
1882 8 else {
1883 9 #pragma omp task shared(t1)
1884 10 t1 = get_fib_num(num-1);
1885 11 #pragma omp task shared(t2)
1886 12 t2 = get_fib_num(num-2);
1887 13 #pragma omp taskwait
1888 14 return t1+t2;
1889 15 }
1890 16 }
1892 18 int main () {
1893 19 int ret = 0;
1894 20 omp_set_num_threads(2);
1895 21 #pragma omp parallel
1896 22 {
1897 23 ret = get_fib_num(10);
1898 24 }
1899 25 printf ("Fib of 10 is %d", ret);
1900 26 return 0;
1901 27 }
1903 GDB Commands:
1904 ompd init
1905 b 10
1907 ompdtestapi ompd_get_task_function
1909 PyObject *test_ompd_get_task_function(PyObject *self, PyObject *args) {
1910 printf("Testing \"ompd_get_task_function\"...\n");
1912 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);
1913 ompd_task_handle_t *task_handle =
1914 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy, "TaskHandle"));
1916 ompd_address_t entry_point;
1918 printf("Test: With Correct Arguments.\n");
1919 ompd_rc_t rc = ompd_get_task_function(task_handle, &entry_point);
1920 if (rc != ompd_rc_ok) {
1921 printf("Failed. with return code = %d\n", rc);
1922 return Py_None;
1923 } else
1924 printf("Success. Entry point is %lx.\n", entry_point.address);
1926 // Random checks with null and invalid args.
1928 ompd_rc_stale_handle: is returned when the specified handle is no
1929 longer valid;
1930 ompd_rc_bad_input: is returned when the input parameters
1931 (other than handle) are invalid;
1932 ompd_rc_error: is returned when a fatal error occurred;
1935 printf("Test: Expecting ompd_rc_bad_input for NULL entry_point.\n");
1936 rc = ompd_get_task_function(task_handle, NULL);
1937 if (rc != ompd_rc_bad_input)
1938 printf("Failed. with return code = %d\n", rc);
1939 else
1940 printf("Success.\n");
1942 printf(
1943 "Test: Expecting ompd_rc_error or stale_handle for NULL task_handle.\n");
1944 rc = ompd_get_task_function(NULL, &entry_point);
1945 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
1946 printf("Failed. with return code = %d\n", rc);
1947 else
1948 printf("Success.\n");
1950 return Py_None;
1954 Test API: ompd_get_task_frame
1956 Program:
1957 1 #include <stdio.h>
1958 2 #include <omp.h>
1959 3 int get_fib_num (int num)
1961 5 int t1, t2;
1962 6 if (num < 2)
1963 7 return num;
1964 8 else {
1965 9 #pragma omp task shared(t1)
1966 10 t1 = get_fib_num(num-1);
1967 11 #pragma omp task shared(t2)
1968 12 t2 = get_fib_num(num-2);
1969 13 #pragma omp taskwait
1970 14 return t1+t2;
1971 15 }
1972 16 }
1974 18 int main () {
1975 19 int ret = 0;
1976 20 omp_set_num_threads(2);
1977 21 #pragma omp parallel
1978 22 {
1979 23 ret = get_fib_num(10);
1980 24 }
1981 25 printf ("Fib of 10 is %d", ret);
1982 26 return 0;
1983 27 }
1985 GDB Commands:
1986 ompd init
1987 b 10
1989 ompdtestapi ompd_get_task_frame
1991 PyObject *test_ompd_get_task_frame(PyObject *self, PyObject *args) {
1992 printf("Testing \"ompd_get_task_frame\"...\n");
1994 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);
1995 ompd_task_handle_t *task_handle =
1996 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy, "TaskHandle"));
1998 ompd_frame_info_t exit_frame;
1999 ompd_frame_info_t enter_frame;
2001 printf("Test: With Correct Arguments.\n");
2002 ompd_rc_t rc = ompd_get_task_frame(task_handle, &exit_frame, &enter_frame);
2003 if (rc != ompd_rc_ok) {
2004 printf("Failed. with return code = %d\n", rc);
2005 return Py_None;
2006 } else
2007 printf("Success.\n");
2009 // Random checks with null and invalid args.
2011 ompd_rc_stale_handle: is returned when the specified handle is no
2012 longer valid;
2013 ompd_rc_bad_input: is returned when the input parameters
2014 (other than handle) are invalid;
2015 ompd_rc_error: is returned when a fatal error occurred;
2018 printf("Test: Expecting ompd_rc_bad_input for NULL exit and enter frame.\n");
2019 rc = ompd_get_task_frame(task_handle, NULL, NULL);
2020 if (rc != ompd_rc_bad_input)
2021 printf("Failed. with return code = %d\n", rc);
2022 else
2023 printf("Success.\n");
2025 printf(
2026 "Test: Expecting ompd_rc_error or stale handle for NULL task_handle.\n");
2027 rc = ompd_get_task_frame(NULL, &exit_frame, &enter_frame);
2028 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
2029 printf("Failed. with return code = %d\n", rc);
2030 else
2031 printf("Success.\n");
2033 return Py_None;
2037 Test API: ompd_get_state
2039 Program:
2040 Program:
2041 1. #include <stdio.h>
2042 2. #include <omp.h>
2043 3. int main () {
2044 4. omp_set_num_threads(4);
2045 5. #pragma omp parallel
2046 6. {
2047 7. printf("Parallel level 1, thread num = %d",
2048 omp_get_thread_num());
2049 8. }
2050 9. return 0;
2051 10. }
2053 GDB Commands:
2054 ompd init
2057 ompdtestapi ompd_get_state
2059 PyObject *test_ompd_get_state(PyObject *self, PyObject *args) {
2060 printf("Testing \"ompd_get_state\"...\n");
2062 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);
2063 ompd_thread_handle_t *thread_handle =
2064 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,
2065 "ThreadHandle"));
2067 ompd_word_t state;
2068 ompt_wait_id_t wait_id;
2070 printf("Test: With Correct Arguments.\n");
2071 ompd_rc_t rc = ompd_get_state(thread_handle, &state, &wait_id);
2072 if (rc != ompd_rc_ok) {
2073 printf("Failed. with return code = %d\n", rc);
2074 return Py_None;
2075 } else
2076 printf("Success.\n");
2078 // Random checks with null and invalid args.
2080 ompd_rc_stale_handle: is returned when the specified handle is no
2081 longer valid;
2082 ompd_rc_bad_input: is returned when the input parameters
2083 (other than handle) are invalid;
2084 ompd_rc_error: is returned when a fatal error occurred;
2087 printf("Test: Expecting ompd_rc_error or stale handle for NULL "
2088 "thread_handle.\n");
2089 rc = ompd_get_state(NULL, &state, &wait_id);
2090 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
2091 printf("Failed. with return code = %d\n", rc);
2092 else
2093 printf("Success.\n");
2095 return Py_None;
2099 Test API: ompd_get_display_control_vars
2101 Program:
2102 1 #include <stdio.h>
2103 2 #include <omp.h>
2104 3 int get_fib_num (int num)
2106 5 int t1, t2;
2107 6 if (num < 2)
2108 7 return num;
2109 8 else {
2110 9 #pragma omp task shared(t1)
2111 10 t1 = get_fib_num(num-1);
2112 11 #pragma omp task shared(t2)
2113 12 t2 = get_fib_num(num-2);
2114 13 #pragma omp taskwait
2115 14 return t1+t2;
2116 15 }
2117 16 }
2119 18 int main () {
2120 19 int ret = 0;
2121 20 omp_set_num_threads(2);
2122 21 #pragma omp parallel
2123 22 {
2124 23 ret = get_fib_num(10);
2125 24 }
2126 25 printf ("Fib of 10 is %d", ret);
2127 26 return 0;
2128 27 }
2130 GDB Commands:
2131 ompd init
2132 b 10
2134 ompdtestapi ompd_get_display_control_vars
2136 PyObject *test_ompd_get_display_control_vars(PyObject *self, PyObject *args) {
2137 printf("Testing \"ompd_get_display_control_vars\" ...\n");
2139 PyObject *addrSpaceTup = PyTuple_GetItem(args, 0);
2140 ompd_address_space_handle_t *addr_handle =
2141 (ompd_address_space_handle_t *)PyCapsule_GetPointer(addrSpaceTup,
2142 "AddressSpace");
2144 const char *const *control_vars;
2146 printf("Test: With Correct Arguments.\n");
2147 ompd_rc_t rc = ompd_get_display_control_vars(addr_handle, &control_vars);
2148 if (rc != ompd_rc_ok) {
2149 printf("Failed. with return code = %d\n", rc);
2150 return Py_None;
2151 } else
2152 printf("Success.\n");
2154 // Random checks with null and invalid args.
2156 ompd_rc_stale_handle: is returned when the specified handle is no
2157 longer valid;
2158 ompd_rc_bad_input: is returned when the input parameters
2159 (other than handle) are invalid;
2160 ompd_rc_error: is returned when a fatal error occurred;
2163 printf("Test: Expecting stale handle or bad_input for NULL addr_handle.\n");
2164 rc = ompd_get_display_control_vars(NULL, &control_vars);
2165 if ((rc != ompd_rc_bad_input) && (rc != ompd_rc_stale_handle))
2166 printf("Failed. with return code = %d\n", rc);
2167 else
2168 printf("Success.\n");
2170 printf("Test: Expecting ompd_rc_error or bad_input for NULL control_vars.\n");
2171 rc = ompd_get_display_control_vars(addr_handle, NULL);
2172 if (rc != ompd_rc_error && rc != ompd_rc_bad_input)
2173 printf("Failed. with return code = %d\n", rc);
2174 else
2175 printf("Success.\n");
2177 return Py_None;
2181 Test API: ompd_rel_display_control_vars
2183 Program:
2184 1 #include <stdio.h>
2185 2 #include <omp.h>
2186 3 int get_fib_num (int num)
2188 5 int t1, t2;
2189 6 if (num < 2)
2190 7 return num;
2191 8 else {
2192 9 #pragma omp task shared(t1)
2193 10 t1 = get_fib_num(num-1);
2194 11 #pragma omp task shared(t2)
2195 12 t2 = get_fib_num(num-2);
2196 13 #pragma omp taskwait
2197 14 return t1+t2;
2198 15 }
2199 16 }
2201 18 int main () {
2202 19 int ret = 0;
2203 20 omp_set_num_threads(2);
2204 21 #pragma omp parallel
2205 22 {
2206 23 ret = get_fib_num(10);
2207 24 }
2208 25 printf ("Fib of 10 is %d", ret);
2209 26 return 0;
2210 27 }
2212 GDB Commands:
2213 ompd init
2214 b 10
2216 ompdtestapi ompd_rel_display_control_vars
2218 PyObject *test_ompd_rel_display_control_vars(PyObject *self, PyObject *noargs) {
2219 printf("Testing Not enabled for \"ompd_rel_display_control_vars\".\n");
2220 printf("Disabled.\n");
2222 return Py_None;
2226 Test API: ompd_enumerate_icvs
2228 Program:
2229 Program:
2230 1. #include <stdio.h>
2231 2. #include <omp.h>
2232 3. int main () {
2233 4. omp_set_num_threads(2);
2234 5. #pragma omp parallel
2235 6. {
2236 7. printf("Parallel level 1, thread num = %d",
2237 omp_get_thread_num());
2238 8. }
2239 9. return 0;
2240 10. }
2242 GDB Commands:
2243 ompd init
2246 ompdtestapi ompd_enumerate_icvs
2249 PyObject *test_ompd_enumerate_icvs(PyObject *self, PyObject *args) {
2250 printf("Testing \"ompd_enumerate_icvs\"...\n");
2252 PyObject *addrSpaceTup = PyTuple_GetItem(args, 0);
2253 ompd_address_space_handle_t *addr_handle =
2254 (ompd_address_space_handle_t *)PyCapsule_GetPointer(addrSpaceTup,
2255 "AddressSpace");
2257 ompd_icv_id_t current = 0; // To begin enumerating the ICVs, a tool should
2258 // pass ompd_icv_undefined as the value of current
2259 ompd_icv_id_t next_id;
2260 const char *next_icv_name;
2261 ompd_scope_t next_scope;
2262 int more;
2264 printf("Test: With Correct Arguments.\n");
2265 ompd_rc_t rc = ompd_enumerate_icvs(addr_handle, current, &next_id,
2266 &next_icv_name, &next_scope, &more);
2267 if (rc != ompd_rc_ok) {
2268 printf("Failed. with return code = %d\n", rc);
2269 return Py_None;
2270 } else
2271 printf("Success.\n");
2273 // ompd_rc_bad_input if an unknown value is provided in current
2274 printf("Test: Unknown current value.\n");
2275 rc = ompd_enumerate_icvs(
2276 addr_handle,
2277 99 /*unknown current value: greater than enum "ompd_icvompd_icv" */,
2278 &next_id, &next_icv_name, &next_scope, &more);
2279 if (rc != ompd_rc_bad_input)
2280 printf("Failed. with return code = %d\n", rc);
2281 else
2282 printf("Success.\n");
2284 // Random checks with null and invalid args.
2286 ompd_rc_stale_handle: is returned when the specified handle is no
2287 longer valid;
2288 ompd_rc_bad_input: is returned when the input parameters
2289 (other than handle) are invalid;
2290 ompd_rc_error: is returned when a fatal error occurred;
2293 printf(
2294 "Test: Expecting ompd_rc_bad_input for NULL next_id and next_icv_name\n");
2295 rc =
2296 ompd_enumerate_icvs(addr_handle, current, NULL, NULL, &next_scope, &more);
2297 if (rc != ompd_rc_bad_input)
2298 printf("Failed. with return code = %d\n", rc);
2299 else
2300 printf("Success.\n");
2302 printf(
2303 "Test: Expecting ompd_rc_error or stale_handle for NULL addr_handle.\n");
2304 rc = ompd_enumerate_icvs(NULL, current, &next_id, &next_icv_name, &next_scope,
2305 &more);
2306 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
2307 printf("Failed. with return code = %d\n", rc);
2308 else
2309 printf("Success.\n");
2311 return Py_None;
2315 Test API: ompd_get_icv_from_scope
2317 Program:
2318 1 #include <stdio.h>
2319 2 #include <omp.h>
2320 3 int get_fib_num (int num)
2322 5 int t1, t2;
2323 6 if (num < 2)
2324 7 return num;
2325 8 else {
2326 9 #pragma omp task shared(t1)
2327 10 t1 = get_fib_num(num-1);
2328 11 #pragma omp task shared(t2)
2329 12 t2 = get_fib_num(num-2);
2330 13 #pragma omp taskwait
2331 14 return t1+t2;
2332 15 }
2333 16 }
2335 18 int main () {
2336 19 int ret = 0;
2337 20 omp_set_num_threads(2);
2338 21 #pragma omp parallel
2339 22 {
2340 23 ret = get_fib_num(10);
2341 24 }
2342 25 printf ("Fib of 10 is %d", ret);
2343 26 return 0;
2344 27 }
2346 GDB Commands:
2347 ompd init
2348 b 10
2350 ompdtestapi ompd_get_icv_from_scope
2352 PyObject *test_ompd_get_icv_from_scope_with_addr_handle(PyObject *self,
2353 PyObject *args) {
2354 printf("Testing \"ompd_get_icv_from_scope with addr_handle\"...\n");
2356 PyObject *addrSpaceTup = PyTuple_GetItem(args, 0);
2357 ompd_address_space_handle_t *addr_handle =
2358 (ompd_address_space_handle_t *)PyCapsule_GetPointer(addrSpaceTup,
2359 "AddressSpace");
2361 ompd_word_t icv_value;
2363 printf("Test: With Correct Arguments.\n");
2364 // cannot import enum ompd_icv from omp-icv.cpp, hardcoding as of now, if enum
2365 // changes it also requires modification
2366 ompd_rc_t rc = ompd_get_icv_from_scope(
2367 addr_handle, ompd_scope_address_space,
2368 19 /* ompd_icv_num_procs_var: check enum ompd_icv in omp-icv.cpp */,
2369 &icv_value);
2370 if (rc != ompd_rc_ok) {
2371 printf("Failed. with return code = %d\n", rc);
2372 return Py_None;
2373 } else
2374 printf("Success.\n");
2376 // ompd_rc_bad_input if an unknown value is provided in icv_id.
2377 printf("Test: bad_input for unknown icv_id.\n");
2378 rc = ompd_get_icv_from_scope(addr_handle, ompd_scope_address_space,
2379 99 /*wrong value*/, &icv_value);
2380 if (rc != ompd_rc_bad_input)
2381 printf("Failed. with return code = %d\n", rc);
2382 else
2383 printf("Success.\n");
2385 // ompd_rc_incompatible if the ICV cannot be represented as an integer;
2386 printf("Test: rc_incompatible for ICV that cant be represented as an "
2387 "integer.\n");
2388 rc = ompd_get_icv_from_scope(addr_handle, ompd_scope_address_space,
2389 12 /*ompd_icv_tool_libraries_var*/, &icv_value);
2390 if (rc != ompd_rc_incompatible)
2391 printf("Failed. with return code = %d\n", rc);
2392 else
2393 printf("Success.\n");
2395 // Random checks with null and invalid args.
2397 ompd_rc_stale_handle: is returned when the specified handle is no
2398 longer valid;
2399 ompd_rc_bad_input: is returned when the input parameters
2400 (other than handle) are invalid;
2401 ompd_rc_error: is returned when a fatal error occurred;
2404 printf("Test: Expecting ompd_rc_bad_input for NULL icv_value.\n");
2405 rc = ompd_get_icv_from_scope(addr_handle, ompd_scope_address_space,
2406 19 /*ompd_icv_num_procs_var*/, NULL);
2407 if (rc != ompd_rc_bad_input)
2408 printf("Failed. with return code = %d\n", rc);
2409 else
2410 printf("Success.\n");
2412 printf("Test: Expecting ompd_rc_error for NULL handle.\n");
2413 rc = ompd_get_icv_from_scope(NULL, ompd_scope_address_space,
2414 19 /*ompd_icv_num_procs_var*/, &icv_value);
2415 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
2416 printf("Failed. with return code = %d\n", rc);
2417 else
2418 printf("Success.\n");
2420 return Py_None;
2423 PyObject *test_ompd_get_icv_from_scope_with_thread_handle(PyObject *self,
2424 PyObject *args) {
2425 printf("Testing \"ompd_get_icv_from_scope with thread_handle\"...\n");
2427 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);
2428 ompd_thread_handle_t *thread_handle =
2429 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,
2430 "ThreadHandle"));
2432 ompd_word_t icv_value;
2434 printf("Test: With Correct Arguments.\n");
2435 ompd_rc_t rc = ompd_get_icv_from_scope(
2436 thread_handle, ompd_scope_thread,
2437 22 /* ompd_icv_thread_num_var check enum ompd_icv in omp-icv.cpp */,
2438 &icv_value);
2439 if (rc != ompd_rc_ok) {
2440 printf("Failed. with return code = %d\n", rc);
2441 return Py_None;
2442 } else
2443 printf("Success.\n");
2445 printf("Test: with nthreads_var for ompd_rc_incomplete.\n");
2446 rc = ompd_get_icv_from_scope(thread_handle, ompd_scope_thread,
2447 7 /*ompd_icv_nthreads_var*/, &icv_value);
2448 if (rc != ompd_rc_incomplete) {
2449 printf("Failed. with return code = %d\n", rc);
2450 return Py_None;
2451 } else
2452 printf("Success.\n");
2454 return Py_None;
2457 PyObject *test_ompd_get_icv_from_scope_with_parallel_handle(PyObject *self,
2458 PyObject *args) {
2459 printf("Testing \"ompd_get_icv_from_scope with parallel_handle\"...\n");
2461 PyObject *parallelHandlePy = PyTuple_GetItem(args, 0);
2462 ompd_parallel_handle_t *parallel_handle =
2463 (ompd_parallel_handle_t *)(PyCapsule_GetPointer(parallelHandlePy,
2464 "ParallelHandle"));
2466 ompd_word_t icv_value;
2468 printf("Test: With Correct Arguments.\n");
2469 ompd_rc_t rc = ompd_get_icv_from_scope(
2470 parallel_handle, ompd_scope_parallel,
2471 15 /*ompd_icv_active_levels_var:check enum ompd_icv in omp-icv.cpp */,
2472 &icv_value);
2473 if (rc != ompd_rc_ok) {
2474 printf("Failed. with return code = %d\n", rc);
2475 return Py_None;
2476 } else
2477 printf("Success.\n");
2479 return Py_None;
2482 PyObject *test_ompd_get_icv_from_scope_with_task_handle(PyObject *self,
2483 PyObject *args) {
2484 printf("Testing \"ompd_get_icv_from_scope with task_handle\"...\n");
2486 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);
2487 ompd_task_handle_t *task_handle =
2488 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy, "TaskHandle"));
2490 ompd_word_t icv_value;
2492 printf("Test: With Correct Arguments.\n");
2493 ompd_rc_t rc = ompd_get_icv_from_scope(
2494 task_handle, ompd_scope_task,
2495 16 /*ompd_icv_thread_limit_var: check enum ompd_icv in omp-icv.cpp */,
2496 &icv_value);
2497 if (rc != ompd_rc_ok) {
2498 printf("Failed. with return code = %d\n", rc);
2499 return Py_None;
2500 } else
2501 printf("Success.\n");
2503 return Py_None;
2506 Test API: ompd_get_icv_string_from_scope
2508 Program:
2509 1. #include <stdio.h>
2510 2. #include <omp.h>
2511 3. int main () {
2512 4. omp_set_num_threads(4);
2513 5. #pragma omp parallel
2514 6. {
2515 7. printf("Parallel level 1, thread num = %d",
2516 omp_get_thread_num());
2517 8. }
2518 9. return 0;
2519 10. }
2521 GDB Commands:
2522 ompd init
2525 ompdtestapi ompd_get_icv_string_from_scope
2527 PyObject *test_ompd_get_icv_string_from_scope(PyObject *self, PyObject *args) {
2528 printf("Testing \"ompd_get_icv_string_from_scope\"...\n");
2530 PyObject *addrSpaceTup = PyTuple_GetItem(args, 0);
2531 ompd_address_space_handle_t *addr_handle =
2532 (ompd_address_space_handle_t *)PyCapsule_GetPointer(addrSpaceTup,
2533 "AddressSpace");
2535 const char *icv_string;
2537 printf("Test: With Correct Arguments.\n");
2538 ompd_rc_t rc = ompd_get_icv_string_from_scope(
2539 addr_handle, ompd_scope_address_space,
2540 12 /*ompd_icv_tool_libraries_var: check enum ompd_icv in omp-icv.cpp */,
2541 &icv_string);
2542 if (rc != ompd_rc_ok) {
2543 printf("Failed. with return code = %d\n", rc);
2544 return Py_None;
2545 } else
2546 printf("Success.\n");
2548 // ompd_rc_bad_input if an unknown value is provided in icv_id.
2549 printf("Test: bad_input for unknown icv_id.\n");
2550 rc = ompd_get_icv_string_from_scope(addr_handle, ompd_scope_address_space,
2551 99 /*wrong value*/, &icv_string);
2552 if (rc != ompd_rc_bad_input)
2553 printf("Failed. with return code = %d\n", rc);
2554 else
2555 printf("Success.\n");
2557 // Random checks with null and invalid args.
2559 ompd_rc_stale_handle: is returned when the specified handle is no
2560 longer valid;
2561 ompd_rc_bad_input: is returned when the input parameters
2562 (other than handle) are invalid;
2563 ompd_rc_error: is returned when a fatal error occurred;
2566 printf("Test: Expecting ompd_rc_bad_input for NULL icv_string.\n");
2567 rc = ompd_get_icv_string_from_scope(addr_handle, ompd_scope_address_space,
2568 12 /*ompd_icv_tool_libraries_var*/, NULL);
2569 if (rc != ompd_rc_bad_input)
2570 printf("Failed. with return code = %d\n", rc);
2571 else
2572 printf("Success.\n");
2574 printf("Test: Expecting ompd_rc_error for NULL handle.\n");
2575 rc = ompd_get_icv_string_from_scope(NULL, ompd_scope_address_space,
2576 12 /*ompd_icv_tool_libraries_var*/,
2577 &icv_string);
2578 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)
2579 printf("Failed. with return code = %d\n", rc);
2580 else
2581 printf("Success.\n");
2583 return Py_None;
2586 PyObject *test_ompd_get_tool_data(PyObject *self, PyObject *args) {
2587 printf("Disabled: Testing Not enabled for \"ompd_get_tool_data\".\n");
2589 return Py_None;
2591 PyObject *test_ompd_enumerate_states(PyObject *self, PyObject *args) {
2592 printf("Disabled: Testing Not enabled for \"ompd_enumerate_states\".\n");
2594 return Py_None;