2596 lines · c
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>9 10extern void *ompd_library;11 12struct _ompd_aspace_cont {13 int id;14};15struct _ompd_thread_cont {16 int id;17};18ompd_address_space_context_t context = {42};19ompd_address_space_context_t invalidcontext = {99};20 21// call back functions for ompd_initialize22ompd_rc_t _alloc(ompd_size_t bytes, void **ptr);23ompd_rc_t _free(void *ptr);24ompd_rc_t _sizes(ompd_address_space_context_t *_acontext,25 ompd_device_type_sizes_t *sizes);26ompd_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);29ompd_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);32ompd_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);36ompd_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);39ompd_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);43ompd_rc_t _print(const char *str, int category);44 45/*46 Test API: ompd_get_thread_handle47 48 ompdtestapi threadandparallel49 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 parallel56 6. {57 7. printf("Parallel level 1, thread num = %d",58 omp_get_thread_num());59 8. }60 9. return 0;61 10. }62 63 GDB Commands:64 ompd init65 b 766 c67 ompdtestapi ompd_get_thread_handle68 69 for ompd_rc_unavailable:70 ompd init71 ompdtestapi ompd_get_thread_handle72*/73 74PyObject *test_ompd_get_thread_handle(PyObject *self, PyObject *args) {75 printf("Testing \"ompd_get_thread_handle\"...\n");76 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");81 82 PyObject *threadIdTup = PyTuple_GetItem(args, 1);83 uint64_t threadID = (uint64_t)PyLong_AsLong(threadIdTup);84 85 ompd_size_t sizeof_thread_id = sizeof(threadID);86 ompd_thread_handle_t *thread_handle;87 88 // should be successful89 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);92 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 else101 printf("Success.\n");102 103 // as in ompd-types.h, only 0-3 are valid for thread kind104 // 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 else111 printf("Success.\n");112 113 // ompd_rc_bad_input: if a different value in sizeof_thread_id is expected for114 // a thread kind.115 // sizeof_thread_id is validated at thread_context which is call back function116 // "_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 else123 printf("Success.\n");124 125 // Random checks with null and invalid args.126 /*127 ompd_rc_stale_handle: is returned when the specified handle is no128 longer valid;129 ompd_rc_bad_input: is returned when the input parameters130 (other than handle) are invalid;131 ompd_rc_error: is returned when a fatal error occurred;132 */133 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 else140 printf("Success.\n");141 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 else149 printf("Success.\n");150 151 return Py_None;152}153 154/*155 Test API: ompd_get_curr_parallel_handle.156 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 parallel163 6. {164 7. printf("Parallel level 1, thread num = %d",165 omp_get_thread_num());166 8. }167 9. return 0;168 10. }169 170 GDB Commands:171 ompd init172 b 7173 omptestapi ompd_get_curr_parallel_handle174 175 for ompd_rc_unavailable176 ompd init177 omptestapi ompd_get_curr_parallel_handle (or break at line 4178 before this)179*/180 181PyObject *test_ompd_get_curr_parallel_handle(PyObject *self, PyObject *args) {182 printf("Testing \"ompd_get_curr_parallel_handle\"...\n");183 184 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);185 ompd_thread_handle_t *thread_handle =186 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,187 "ThreadHandle"));188 189 ompd_parallel_handle_t *parallel_handle;190 191 printf("Test: With Correct Arguments.\n");192 ompd_rc_t rc = ompd_get_curr_parallel_handle(thread_handle, ¶llel_handle);193 if (rc == ompd_rc_unavailable) {194 // ompd_rc_unavailable if the thread is not currently part of a team195 196 // ToCheck: Even in non parallel region, error code is stale_handle197 // 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 else208 printf("Success.\n");209 210 // Random checks with null and invalid args.211 /*212 ompd_rc_stale_handle: is returned when the specified handle is no213 longer valid;214 ompd_rc_bad_input: is returned when the input parameters215 (other than handle) are invalid;216 ompd_rc_error: is returned when a fatal error occurred;217 */218 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 else224 printf("Success.\n");225 226 printf("Test: Expecting ompd_rc_error or stale_handle for NULL "227 "thread_handle.\n");228 rc = ompd_get_curr_parallel_handle(NULL, ¶llel_handle);229 if (rc != ompd_rc_error && rc != ompd_rc_stale_handle)230 printf("Failed, with return code = %d\n", rc);231 else232 printf("Success.\n");233 234 return Py_None;235}236 237/*238 Test API: ompd_get_thread_in_parallel.239 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 parallel246 6. {247 7. printf("Parallel level 1, thread num = %d",248 omp_get_thread_num());249 8. }250 9. return 0;251 10. }252 253 GDB Commands:254 ompd init255 b 7256 omptestapi ompd_get_thread_in_parallel257*/258PyObject *test_ompd_get_thread_in_parallel(PyObject *self, PyObject *args) {259 printf("Testing \"ompd_get_thread_in_parallel\"...\n");260 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;266 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 } else274 printf("Success.\n");275 276 // ompd_rc_bad_input: if the thread_num argument is greater than or equal to277 // the team-size-var ICV or negative278 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 else283 printf("Success.\n");284 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 else290 printf("Success.\n");291 292 // Random checks with null and invalid args.293 /*294 ompd_rc_stale_handle: is returned when the specified handle is no295 longer valid;296 ompd_rc_bad_input: is returned when the input parameters297 (other than handle) are invalid;298 ompd_rc_error: is returned when a fatal error occurred;299 */300 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 else306 printf("Success.\n");307 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 else314 printf("Success.\n");315 316 return Py_None;317}318 319/*320 Test API: ompd_thread_handle_compare.321 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 parallel328 6. {329 7. printf("Parallel level 1, thread num = %d",330 omp_get_thread_num());331 8. }332 9. return 0;333 10. }334 335 GDB Commands:336 ompd init337 b 7338 omptestapi ompd_thread_handle_compare339*/340 341PyObject *test_ompd_thread_handle_compare(PyObject *self, PyObject *args) {342 printf("Testing \"ompd_thread_handle_compare\"...\n");343 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"));352 353 int cmp_value;354 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 } else362 printf("Success.\n");363 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 thread368 // 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;378 }379 if (cmp_value >= 0)380 printf("Success now cmp_value is greater, %d.\n", cmp_value);381 else382 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;391 }392 if (cmp_value <= 0)393 printf("Success now cmp_value is lesser, %d.\n", cmp_value);394 else395 printf("Failed.\n");396 }397 398 // Random checks with null and invalid args.399 /*400 ompd_rc_stale_handle: is returned when the specified handle is no401 longer valid;402 ompd_rc_bad_input: is returned when the input parameters403 (other than handle) are invalid;404 ompd_rc_error: is returned when a fatal error occurred;405 */406 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 else412 printf("Success.\n");413 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 else420 printf("Success.\n");421 }422 423 return Py_None;424}425 426/*427 Test API: ompd_get_thread_id.428 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 parallel435 6. {436 7. printf("Parallel level 1, thread num = %d",437 omp_get_thread_num());438 8. }439 9. return 0;440 10. }441 442 GDB Commands:443 ompd init444 b 7445 omptestapi ompd_get_thread_id446*/447 448PyObject *test_ompd_get_thread_id(PyObject *self, PyObject *args) {449 printf("Testing \"ompd_get_thread_id\"...\n");450 451 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);452 ompd_thread_handle_t *thread_handle =453 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,454 "ThreadHandle"));455 456 uint64_t threadID;457 ompd_size_t sizeof_thread_id = sizeof(threadID);458 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 } else466 printf("Success. Thread id = %ld\n", threadID);467 468 // ompd_rc_bad_input: if a different value in sizeof_thread_id is expected for469 // a thread kind of kind470 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 else476 printf("Success.\n");477 478 // ompd_rc_unsupported: if the kind of thread is not supported479 printf("Test: Unsupported thread kind.\n");480 // thread kind currently support from 0-3, refer in ompd-types.h481 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 else485 printf("Success.\n");486 487 // Random checks with null and invalid args.488 /*489 ompd_rc_stale_handle: is returned when the specified handle is no490 longer valid;491 ompd_rc_bad_input: is returned when the input parameters492 (other than handle) are invalid;493 ompd_rc_error: is returned when a fatal error occurred;494 */495 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 else502 printf("Success.\n");503 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 else510 printf("Success.\n");511 512 return Py_None;513}514 515/*516 Test API: ompd_rel_thread_handle517 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 parallel524 6. {525 7. printf("Parallel level 1, thread num = %d",526 omp_get_thread_num());527 8. }528 9. return 0;529 10. }530 531 GDB Commands:532 ompd init533 b 7534 omptestapi ompd_rel_thread_handle535*/536 537// TODO: This might not be the right way to do,as this handle comes from538// python not generated by ompd API539 540PyObject *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;544}545 546/*547 Test API: ompd_get_enclosing_parallel_handle.548 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 parallel555 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 parallel560 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. }567 568 GDB Commands:569 ompd init570 b 11571 ompdtestapi ompd_get_enclosing_parallel_handle572 573 for "ompd_rc_unavailable":574 ompd init575 omptestapi ompd_get_enclosing_parallel_handle576 (or break at line 4 before this)577*/578 579PyObject *test_ompd_get_enclosing_parallel_handle(PyObject *self,580 PyObject *args) {581 printf("Testing \"ompd_get_enclosing_parallel_handle\"...\n");582 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;588 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 } else602 printf("Success.\n");603 604 // Random checks with null and invalid args.605 /*606 ompd_rc_stale_handle: is returned when the specified handle is no607 longer valid;608 ompd_rc_bad_input: is returned when the input parameters609 (other than handle) are invalid;610 ompd_rc_error: is returned when a fatal error occurred;611 */612 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 else619 printf("Success.\n");620 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 else627 printf("Success.\n");628 629 return Py_None;630}631 632/*633 Test API: ompd_parallel_handle_compare.634 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 parallel641 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 parallel646 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. }653 654 GDB Commands:655 ompd init656 b 11657 ompdtestapi ompd_parallel_handle_compare658*/659 660PyObject *test_ompd_parallel_handle_compare(PyObject *self, PyObject *args) {661 printf("Testing \"ompd_parallel_handle_compare\"...\n");662 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"));671 672 int cmp_value;673 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 } else681 printf("Success.\n");682 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 region687 // corresponding to parallel_handle_1 is, respectively, less than, equal to,688 // or greater than that corresponding to parallel_handle_2689 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;698 }699 if (cmp_value >= 0)700 printf("Success now cmp_value is greater, %d.\n", cmp_value);701 else702 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;711 }712 if (cmp_value <= 0)713 printf("Success now cmp_value is lesser, %d.\n", cmp_value);714 else715 printf("Failed.\n");716 }717 718 // Random checks with null and invalid args.719 /*720 ompd_rc_stale_handle: is returned when the specified handle is no721 longer valid;722 ompd_rc_bad_input: is returned when the input parameters723 (other than handle) are invalid;724 ompd_rc_error: is returned when a fatal error occurred;725 */726 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 else732 printf("Success.\n");733 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 else740 printf("Success.\n");741 }742 743 return Py_None;744}745 746/*747 Test API: ompd_rel_parallel_handle748 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 parallel755 6. {756 7. printf("Parallel level 1, thread num = %d",757 omp_get_thread_num());758 8. }759 9. return 0;760 10. }761 762 GDB Commands:763 ompd init764 b 7765 omptestapi ompd_rel_parallel_handle766*/767 768// TODO: Same as thread_rel_handle, might not be a right way to test769// What released should be provided by ompd API, this address is actually from770// python771PyObject *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;775}776 777/*778 Test API: ompd_initialize779 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 parallel786 6. {787 7. printf("Parallel level 1, thread num = %d",788 omp_get_thread_num());789 8. }790 9. return 0;791 10. }792 793 GDB Commands:794 b 4795 ompdtestapi ompd_initialize\796*/797PyObject *test_ompd_initialize(PyObject *self, PyObject *noargs) {798 printf("Testing \"test_ompd_initialize\"...\n");799 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;805 }806 807 static ompd_callbacks_t table = {808 _alloc, _free, _print, _sizes, _sym_addr, _read,809 NULL, _read_string, _endianess, _endianess, _thread_context};810 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 } else819 printf("Success.\n");820 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 */832 };833 834 // ompd_rc_bad_input: if invalid callbacks are provided835 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 else840 printf("Success.\n");841 842 // ompd_rc_unsupported: if the requested API version cannot be provided843 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 else848 printf("Success.\n");849 850 // Random checks with null and invalid args.851 /*852 ompd_rc_stale_handle: is returned when the specified handle is no853 longer valid;854 ompd_rc_bad_input: is returned when the input parameters855 (other than handle) are invalid;856 ompd_rc_error: is returned when a fatal error occurred;857 */858 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 else864 printf("Success.\n");865 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 else871 printf("Success.\n");872 873 return Py_None;874}875 876/*877 Test API: ompd_get_api_version878 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 parallel885 6. {886 7. printf("Parallel level 1, thread num = %d",887 omp_get_thread_num());888 8. }889 9. return 0;890 10. }891 892 GDB Commands:893 ompd init894 b 7895 ompdtestapi ompd_get_version896 897*/898 899PyObject *test_ompd_get_api_version(PyObject *self, PyObject *noargs) {900 printf("Testing \"ompd_get_api_version\"...\n");901 902 ompd_word_t version;903 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 } else910 printf("Success. API version is %ld\n", version);911 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 else918 printf("Success.\n");919 920 return Py_None;921}922 923/*924 Test API: ompd_get_version_string925 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 parallel932 6. {933 7. printf("Parallel level 1, thread num = %d",934 omp_get_thread_num());935 8. }936 9. return 0;937 10. }938 939 GDB Commands:940 ompd init941 b 7942 omptestapi ompd_get_version_string943 944*/945 946PyObject *test_ompd_get_version_string(PyObject *self, PyObject *noargs) {947 printf("Testing \"ompd_get_version_string\"...\n");948 949 const char *string;950 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 } else957 printf("Success. API version is %s\n", string);958 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 else965 printf("Success.\n");966 967 return Py_None;968}969 970/*971 Test API: ompd_finalize972 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 parallel979 6. {980 7. printf("Parallel level 1, thread num = %d",981 omp_get_thread_num());982 8. }983 9. return 0;984 10. }985 986 GDB Commands:987 ompd init988 b 7989 ompdtestapi ompd_finalize990 991 992 b 4993 r994 ompdtestapi ompd_finalize995*/996 997PyObject *test_ompd_finalize(PyObject *self, PyObject *noargs) {998 printf("Testing \"ompd_finalize\"...\n");999 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 else1009 printf("Failed: Return code is %d.\n", rc);1010 1011 return Py_None;1012}1013 1014/*1015 Test API: ompd_process_initialize1016 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 parallel1023 6. {1024 7. printf("Parallel level 1, thread num = %d",1025 omp_get_thread_num());1026 8. }1027 9. return 0;1028 10. }1029 1030 GDB Commands:1031 1032*/1033 1034PyObject *test_ompd_process_initialize(PyObject *self, PyObject *noargs) {1035 1036 printf("Testing \"ompd_process_initialize\"....\n");1037 1038 ompd_address_space_handle_t *addr_handle;1039 1040 // ompd_address_space_context_t context = {42};1041 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 } else1048 printf("Success.\n");1049 1050 printf("Test: With Unsupported library.\n");1051 printf("Warning: Have to test manually with 32 and 64 bit combination.\n");1052 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 else1060 printf("Success.\n");1061 1062 // Random checks with null and invalid args.1063 /*1064 ompd_rc_stale_handle: is returned when the specified handle is no1065 longer valid;1066 ompd_rc_bad_input: is returned when the input parameters1067 (other than handle) are invalid;1068 ompd_rc_error: is returned when a fatal error occurred;1069 */1070 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 else1076 printf("Success.\n");1077 1078 return Py_None;1079}1080 1081/*1082 Test API: ompd_device_initialize1083 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 parallel1090 6. {1091 7. printf("Parallel level 1, thread num = %d",1092 omp_get_thread_num());1093 8. }1094 9. return 0;1095 10. }1096 1097 GDB Commands:1098 1099*/1100 1101PyObject *test_ompd_device_initialize(PyObject *self, PyObject *noargs) {1102 printf("Testing Not enabled for \"ompd_device_initialize\".\n");1103 printf("Disabled.\n");1104 1105 return Py_None;1106}1107 1108/*1109 Test API: ompd_rel_address_space_handle1110 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 parallel1117 6. {1118 7. printf("Parallel level 1, thread num = %d",1119 omp_get_thread_num());1120 8. }1121 9. return 0;1122 10. }1123 1124 GDB Commands:1125 1126*/1127PyObject *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");1130 1131 return Py_None;1132}1133 1134/*1135 Test API: ompd_get_omp_version1136 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 parallel1143 6. {1144 7. printf("Parallel level 1, thread num = %d",1145 omp_get_thread_num());1146 8. }1147 9. return 0;1148 10. }1149 1150 GDB Commands:1151 ompd init1152 b 101153 c1154 ompdtestapi ompd_get_omp_version1155*/1156PyObject *test_ompd_get_omp_version(PyObject *self, PyObject *args) {1157 printf("Testing \"ompd_get_omp_version\" ...\n");1158 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");1163 1164 ompd_word_t omp_version;1165 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 } else1172 printf("Success. API version is %ld\n", omp_version);1173 1174 // Random checks with null and invalid args.1175 /*1176 ompd_rc_stale_handle: is returned when the specified handle is no1177 longer valid;1178 ompd_rc_bad_input: is returned when the input parameters1179 (other than handle) are invalid;1180 ompd_rc_error: is returned when a fatal error occurred;1181 */1182 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 else1188 printf("Success.\n");1189 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 else1195 printf("Success.\n");1196 1197 return Py_None;1198}1199 1200/*1201 Test API: ompd_get_omp_version_string1202 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 parallel1209 6. {1210 7. printf("Parallel level 1, thread num = %d",1211 omp_get_thread_num());1212 8. }1213 9. return 0;1214 10. }1215 1216 GDB Commands:1217 ompd init1218 b 71219 ompdtestapi ompd_get_omp_version_string1220*/1221PyObject *test_ompd_get_omp_version_string(PyObject *self, PyObject *args) {1222 printf("Testing \"ompd_get_omp_version_string\" ...\n");1223 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");1228 1229 const char *string;1230 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 } else1237 printf("Success. API version is %s\n", string);1238 1239 // Random checks with null and invalid args.1240 /*1241 ompd_rc_stale_handle: is returned when the specified handle is no1242 longer valid;1243 ompd_rc_bad_input: is returned when the input parameters1244 (other than handle) are invalid;1245 ompd_rc_error: is returned when a fatal error occurred;1246 */1247 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 else1253 printf("Success.\n");1254 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 else1260 printf("Success.\n");1261 1262 return Py_None;1263}1264 1265/*1266 Test API: ompd_get_curr_task_handle1267 1268 Program:1269 1 #include <stdio.h>1270 2 #include <omp.h>1271 3 int get_fib_num (int num)1272 4 {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 taskwait1282 14 return t1+t2;1283 15 }1284 16 }1285 171286 18 int main () {1287 19 int ret = 0;1288 20 omp_set_num_threads(2);1289 21 #pragma omp parallel1290 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 }1296 1297 GDB Commands:1298 ompd init1299 b 101300 c1301 ompdtestapi ompd_get_curr_task_handle1302*/1303 1304PyObject *test_ompd_get_curr_task_handle(PyObject *self, PyObject *args) {1305 printf("Testing \"ompd_get_curr_task_handle\"...\n");1306 1307 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);1308 ompd_thread_handle_t *thread_handle =1309 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,1310 "ThreadHandle"));1311 1312 ompd_task_handle_t *task_handle;1313 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 task1318 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 else1330 printf("Success.\n");1331 1332 // Random checks with null and invalid args.1333 /*1334 ompd_rc_stale_handle: is returned when the specified handle is no1335 longer valid;1336 ompd_rc_bad_input: is returned when the input parameters1337 (other than handle) are invalid;1338 ompd_rc_error: is returned when a fatal error occurred;1339 */1340 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 else1346 printf("Success.\n");1347 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 else1354 printf("Success.\n");1355 1356 return Py_None;1357}1358 1359/*1360 Test API: ompd_get_task_parallel_handle1361 1362 Program:1363 1 #include <stdio.h>1364 2 #include <omp.h>1365 3 int get_fib_num (int num)1366 4 {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 taskwait1376 14 return t1+t2;1377 15 }1378 16 }1379 171380 18 int main () {1381 19 int ret = 0;1382 20 omp_set_num_threads(2);1383 21 #pragma omp parallel1384 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 }1390 1391 GDB Commands:1392 ompd init1393 b 101394 c1395 ompdtestapi ompd_get_task_parallel_handle1396*/1397PyObject *test_ompd_get_task_parallel_handle(PyObject *self, PyObject *args) {1398 1399 printf("Testing \"ompd_get_task_parallel_handle\"...\n");1400 1401 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);1402 ompd_task_handle_t *task_handle =1403 PyCapsule_GetPointer(taskHandlePy, "TaskHandle");1404 1405 ompd_parallel_handle_t *task_parallel_handle;1406 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 } else1414 printf("Success.\n");1415 1416 // Random checks with null and invalid args.1417 /*1418 ompd_rc_stale_handle: is returned when the specified handle is no1419 longer valid;1420 ompd_rc_bad_input: is returned when the input parameters1421 (other than handle) are invalid;1422 ompd_rc_error: is returned when a fatal error occurred;1423 */1424 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 else1430 printf("Success.\n");1431 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 else1438 printf("Success.\n");1439 1440 return Py_None;1441}1442 1443/*1444 Test API: ompd_get_generating_task_handle1445 1446 Program:1447 1 #include <stdio.h>1448 2 #include <omp.h>1449 3 int get_fib_num (int num)1450 4 {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 taskwait1460 14 return t1+t2;1461 15 }1462 16 }1463 171464 18 int main () {1465 19 int ret = 0;1466 20 omp_set_num_threads(2);1467 21 #pragma omp parallel1468 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 }1474 1475 GDB Commands:1476 ompd init1477 b 101478 c1479 c // may or may not be needed1480 ompdtestapi ompd_get_generating_task_handle1481*/1482PyObject *test_ompd_get_generating_task_handle(PyObject *self, PyObject *args) {1483 printf("Testing \"ompd_get_generating_task_handle\"...\n");1484 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;1489 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 } else1502 printf("Success.\n");1503 1504 // Random checks with null and invalid args.1505 /*1506 ompd_rc_stale_handle: is returned when the specified handle is no1507 longer valid;1508 ompd_rc_bad_input: is returned when the input parameters1509 (other than handle) are invalid;1510 ompd_rc_error: is returned when a fatal error occurred;1511 */1512 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 else1519 printf("Success.\n");1520 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 else1527 printf("Success.\n");1528 1529 return Py_None;1530}1531 1532/*1533 Test API: ompd_get_scheduling_task_handle1534 1535 Program:1536 1 #include <stdio.h>1537 2 #include <omp.h>1538 3 int get_fib_num (int num)1539 4 {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 taskwait1549 14 return t1+t2;1550 15 }1551 16 }1552 171553 18 int main () {1554 19 int ret = 0;1555 20 omp_set_num_threads(2);1556 21 #pragma omp parallel1557 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 }1563 1564 GDB Commands:1565 ompd init1566 b 101567 c1568 ompdtestapi ompd_get_scheduling_task_handle1569*/1570PyObject *test_ompd_get_scheduling_task_handle(PyObject *self, PyObject *args) {1571 printf("Testing \"ompd_get_scheduling_task_handle\"...\n");1572 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;1577 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 } else1591 printf("Success.\n");1592 1593 // Random checks with null and invalid args.1594 /*1595 ompd_rc_stale_handle: is returned when the specified handle is no1596 longer valid;1597 ompd_rc_bad_input: is returned when the input parameters1598 (other than handle) are invalid;1599 ompd_rc_error: is returned when a fatal error occurred;1600 */1601 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 else1608 printf("Success.\n");1609 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 else1616 printf("Success.\n");1617 1618 return Py_None;1619}1620 1621/*1622 Test API: ompd_get_task_in_parallel1623 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 parallel1631 6. {1632 7. printf("Parallel level 1, thread num = %d",1633 omp_get_thread_num());1634 8. }1635 9. return 0;1636 10. }1637 1638 GDB Commands:1639 ompd init1640 b 71641 c1642 ompdtestapi ompd_get_task_in_parallel1643*/1644PyObject *test_ompd_get_task_in_parallel(PyObject *self, PyObject *args) {1645 printf("Testing \"ompd_get_task_in_parallel\"...\n");1646 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;1652 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 } else1660 printf("Success.\n");1661 1662 // ompd_rc_bad_input if the thread_num argument is greater than or equal to1663 // the team-size-var ICV or negative1664 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 else1669 printf("Success.\n");1670 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 else1676 printf("Success.\n");1677 1678 // Random checks with null and invalid args.1679 /*1680 ompd_rc_stale_handle: is returned when the specified handle is no1681 longer valid;1682 ompd_rc_bad_input: is returned when the input parameters1683 (other than handle) are invalid;1684 ompd_rc_error: is returned when a fatal error occurred;1685 */1686 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 else1692 printf("Success.\n");1693 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 else1700 printf("Success.\n");1701 1702 return Py_None;1703}1704 1705/*1706 Test API: ompd_rel_task_handle1707 1708 Program:1709 1 #include <stdio.h>1710 2 #include <omp.h>1711 3 int get_fib_num (int num)1712 4 {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 taskwait1722 14 return t1+t2;1723 15 }1724 16 }1725 171726 18 int main () {1727 19 int ret = 0;1728 20 omp_set_num_threads(2);1729 21 #pragma omp parallel1730 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 }1736 1737 GDB Commands:1738 ompd init1739 b 101740 c1741 ompdtestapi ompd_rel_task_handle1742*/1743PyObject *test_ompd_rel_task_handle(PyObject *self, PyObject *noargs) {1744 printf("Testing Not enabled for \"ompd_rel_task_handle\".\n");1745 printf("Disabled.\n");1746 1747 return Py_None;1748}1749 1750/*1751 Test API: ompd_task_handle_compare1752 1753 Program:1754 1 #include <stdio.h>1755 2 #include <omp.h>1756 3 int get_fib_num (int num)1757 4 {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 taskwait1767 14 return t1+t2;1768 15 }1769 16 }1770 171771 18 int main () {1772 19 int ret = 0;1773 20 omp_set_num_threads(2);1774 21 #pragma omp parallel1775 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 }1781 1782 GDB Commands:1783 ompd init1784 b 101785 c1786 c1787 ompdtestapi ompd_task_handle_compare1788*/1789PyObject *test_ompd_task_handle_compare(PyObject *self, PyObject *args) {1790 printf("Testing \"ompd_task_handle_compare\"...\n");1791 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"));1798 1799 int cmp_value;1800 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 } else1808 printf("Success.\n");1809 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 task1814 // 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;1824 }1825 if (cmp_value >= 0)1826 printf("Success now cmp_value is greater, %d.\n", cmp_value);1827 else1828 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;1836 }1837 if (cmp_value <= 0)1838 printf("Success now cmp_value is lesser, %d.\n", cmp_value);1839 else1840 printf("Failed.\n");1841 }1842 1843 // Random checks with null and invalid args.1844 /*1845 ompd_rc_stale_handle: is returned when the specified handle is no1846 longer valid;1847 ompd_rc_bad_input: is returned when the input parameters1848 (other than handle) are invalid;1849 ompd_rc_error: is returned when a fatal error occurred;1850 */1851 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 else1857 printf("Success.\n");1858 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 else1865 printf("Success.\n");1866 }1867 1868 return Py_None;1869}1870 1871/*1872 Test API: ompd_get_task_function1873 1874 Program:1875 1 #include <stdio.h>1876 2 #include <omp.h>1877 3 int get_fib_num (int num)1878 4 {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 taskwait1888 14 return t1+t2;1889 15 }1890 16 }1891 171892 18 int main () {1893 19 int ret = 0;1894 20 omp_set_num_threads(2);1895 21 #pragma omp parallel1896 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 }1902 1903 GDB Commands:1904 ompd init1905 b 101906 c1907 ompdtestapi ompd_get_task_function1908*/1909PyObject *test_ompd_get_task_function(PyObject *self, PyObject *args) {1910 printf("Testing \"ompd_get_task_function\"...\n");1911 1912 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);1913 ompd_task_handle_t *task_handle =1914 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy, "TaskHandle"));1915 1916 ompd_address_t entry_point;1917 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 } else1924 printf("Success. Entry point is %lx.\n", entry_point.address);1925 1926 // Random checks with null and invalid args.1927 /*1928 ompd_rc_stale_handle: is returned when the specified handle is no1929 longer valid;1930 ompd_rc_bad_input: is returned when the input parameters1931 (other than handle) are invalid;1932 ompd_rc_error: is returned when a fatal error occurred;1933 */1934 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 else1940 printf("Success.\n");1941 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 else1948 printf("Success.\n");1949 1950 return Py_None;1951}1952 1953/*1954 Test API: ompd_get_task_frame1955 1956 Program:1957 1 #include <stdio.h>1958 2 #include <omp.h>1959 3 int get_fib_num (int num)1960 4 {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 taskwait1970 14 return t1+t2;1971 15 }1972 16 }1973 171974 18 int main () {1975 19 int ret = 0;1976 20 omp_set_num_threads(2);1977 21 #pragma omp parallel1978 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 }1984 1985 GDB Commands:1986 ompd init1987 b 101988 c1989 ompdtestapi ompd_get_task_frame1990*/1991PyObject *test_ompd_get_task_frame(PyObject *self, PyObject *args) {1992 printf("Testing \"ompd_get_task_frame\"...\n");1993 1994 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);1995 ompd_task_handle_t *task_handle =1996 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy, "TaskHandle"));1997 1998 ompd_frame_info_t exit_frame;1999 ompd_frame_info_t enter_frame;2000 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 } else2007 printf("Success.\n");2008 2009 // Random checks with null and invalid args.2010 /*2011 ompd_rc_stale_handle: is returned when the specified handle is no2012 longer valid;2013 ompd_rc_bad_input: is returned when the input parameters2014 (other than handle) are invalid;2015 ompd_rc_error: is returned when a fatal error occurred;2016 */2017 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 else2023 printf("Success.\n");2024 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 else2031 printf("Success.\n");2032 2033 return Py_None;2034}2035 2036/*2037 Test API: ompd_get_state2038 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 parallel2046 6. {2047 7. printf("Parallel level 1, thread num = %d",2048 omp_get_thread_num());2049 8. }2050 9. return 0;2051 10. }2052 2053 GDB Commands:2054 ompd init2055 b 72056 c2057 ompdtestapi ompd_get_state2058*/2059PyObject *test_ompd_get_state(PyObject *self, PyObject *args) {2060 printf("Testing \"ompd_get_state\"...\n");2061 2062 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);2063 ompd_thread_handle_t *thread_handle =2064 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,2065 "ThreadHandle"));2066 2067 ompd_word_t state;2068 ompt_wait_id_t wait_id;2069 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 } else2076 printf("Success.\n");2077 2078 // Random checks with null and invalid args.2079 /*2080 ompd_rc_stale_handle: is returned when the specified handle is no2081 longer valid;2082 ompd_rc_bad_input: is returned when the input parameters2083 (other than handle) are invalid;2084 ompd_rc_error: is returned when a fatal error occurred;2085 */2086 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 else2093 printf("Success.\n");2094 2095 return Py_None;2096}2097 2098/*2099 Test API: ompd_get_display_control_vars2100 2101 Program:2102 1 #include <stdio.h>2103 2 #include <omp.h>2104 3 int get_fib_num (int num)2105 4 {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 taskwait2115 14 return t1+t2;2116 15 }2117 16 }2118 172119 18 int main () {2120 19 int ret = 0;2121 20 omp_set_num_threads(2);2122 21 #pragma omp parallel2123 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 }2129 2130 GDB Commands:2131 ompd init2132 b 102133 c2134 ompdtestapi ompd_get_display_control_vars2135*/2136PyObject *test_ompd_get_display_control_vars(PyObject *self, PyObject *args) {2137 printf("Testing \"ompd_get_display_control_vars\" ...\n");2138 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");2143 2144 const char *const *control_vars;2145 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 } else2152 printf("Success.\n");2153 2154 // Random checks with null and invalid args.2155 /*2156 ompd_rc_stale_handle: is returned when the specified handle is no2157 longer valid;2158 ompd_rc_bad_input: is returned when the input parameters2159 (other than handle) are invalid;2160 ompd_rc_error: is returned when a fatal error occurred;2161 */2162 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 else2168 printf("Success.\n");2169 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 else2175 printf("Success.\n");2176 2177 return Py_None;2178}2179 2180/*2181 Test API: ompd_rel_display_control_vars2182 2183 Program:2184 1 #include <stdio.h>2185 2 #include <omp.h>2186 3 int get_fib_num (int num)2187 4 {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 taskwait2197 14 return t1+t2;2198 15 }2199 16 }2200 172201 18 int main () {2202 19 int ret = 0;2203 20 omp_set_num_threads(2);2204 21 #pragma omp parallel2205 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 }2211 2212 GDB Commands:2213 ompd init2214 b 102215 c2216 ompdtestapi ompd_rel_display_control_vars2217*/2218PyObject *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");2221 2222 return Py_None;2223}2224 2225/*2226 Test API: ompd_enumerate_icvs2227 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 parallel2235 6. {2236 7. printf("Parallel level 1, thread num = %d",2237 omp_get_thread_num());2238 8. }2239 9. return 0;2240 10. }2241 2242 GDB Commands:2243 ompd init2244 b 72245 c2246 ompdtestapi ompd_enumerate_icvs2247*/2248 2249PyObject *test_ompd_enumerate_icvs(PyObject *self, PyObject *args) {2250 printf("Testing \"ompd_enumerate_icvs\"...\n");2251 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");2256 2257 ompd_icv_id_t current = 0; // To begin enumerating the ICVs, a tool should2258 // pass ompd_icv_undefined as the value of current2259 ompd_icv_id_t next_id;2260 const char *next_icv_name;2261 ompd_scope_t next_scope;2262 int more;2263 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 } else2271 printf("Success.\n");2272 2273 // ompd_rc_bad_input if an unknown value is provided in current2274 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 else2282 printf("Success.\n");2283 2284 // Random checks with null and invalid args.2285 /*2286 ompd_rc_stale_handle: is returned when the specified handle is no2287 longer valid;2288 ompd_rc_bad_input: is returned when the input parameters2289 (other than handle) are invalid;2290 ompd_rc_error: is returned when a fatal error occurred;2291 */2292 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 else2300 printf("Success.\n");2301 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 else2309 printf("Success.\n");2310 2311 return Py_None;2312}2313 2314/*2315 Test API: ompd_get_icv_from_scope2316 2317 Program:2318 1 #include <stdio.h>2319 2 #include <omp.h>2320 3 int get_fib_num (int num)2321 4 {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 taskwait2331 14 return t1+t2;2332 15 }2333 16 }2334 172335 18 int main () {2336 19 int ret = 0;2337 20 omp_set_num_threads(2);2338 21 #pragma omp parallel2339 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 }2345 2346 GDB Commands:2347 ompd init2348 b 102349 c2350 ompdtestapi ompd_get_icv_from_scope2351*/2352PyObject *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");2355 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");2360 2361 ompd_word_t icv_value;2362 2363 printf("Test: With Correct Arguments.\n");2364 // cannot import enum ompd_icv from omp-icv.cpp, hardcoding as of now, if enum2365 // changes it also requires modification2366 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 } else2374 printf("Success.\n");2375 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 else2383 printf("Success.\n");2384 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 else2393 printf("Success.\n");2394 2395 // Random checks with null and invalid args.2396 /*2397 ompd_rc_stale_handle: is returned when the specified handle is no2398 longer valid;2399 ompd_rc_bad_input: is returned when the input parameters2400 (other than handle) are invalid;2401 ompd_rc_error: is returned when a fatal error occurred;2402 */2403 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 else2410 printf("Success.\n");2411 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 else2418 printf("Success.\n");2419 2420 return Py_None;2421}2422 2423PyObject *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");2426 2427 PyObject *threadHandlePy = PyTuple_GetItem(args, 0);2428 ompd_thread_handle_t *thread_handle =2429 (ompd_thread_handle_t *)(PyCapsule_GetPointer(threadHandlePy,2430 "ThreadHandle"));2431 2432 ompd_word_t icv_value;2433 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 } else2443 printf("Success.\n");2444 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 } else2452 printf("Success.\n");2453 2454 return Py_None;2455}2456 2457PyObject *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");2460 2461 PyObject *parallelHandlePy = PyTuple_GetItem(args, 0);2462 ompd_parallel_handle_t *parallel_handle =2463 (ompd_parallel_handle_t *)(PyCapsule_GetPointer(parallelHandlePy,2464 "ParallelHandle"));2465 2466 ompd_word_t icv_value;2467 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 } else2477 printf("Success.\n");2478 2479 return Py_None;2480}2481 2482PyObject *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");2485 2486 PyObject *taskHandlePy = PyTuple_GetItem(args, 0);2487 ompd_task_handle_t *task_handle =2488 (ompd_task_handle_t *)(PyCapsule_GetPointer(taskHandlePy, "TaskHandle"));2489 2490 ompd_word_t icv_value;2491 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 } else2501 printf("Success.\n");2502 2503 return Py_None;2504}2505/*2506 Test API: ompd_get_icv_string_from_scope2507 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 parallel2514 6. {2515 7. printf("Parallel level 1, thread num = %d",2516 omp_get_thread_num());2517 8. }2518 9. return 0;2519 10. }2520 2521 GDB Commands:2522 ompd init2523 b 72524 c2525 ompdtestapi ompd_get_icv_string_from_scope2526*/2527PyObject *test_ompd_get_icv_string_from_scope(PyObject *self, PyObject *args) {2528 printf("Testing \"ompd_get_icv_string_from_scope\"...\n");2529 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");2534 2535 const char *icv_string;2536 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 } else2546 printf("Success.\n");2547 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 else2555 printf("Success.\n");2556 2557 // Random checks with null and invalid args.2558 /*2559 ompd_rc_stale_handle: is returned when the specified handle is no2560 longer valid;2561 ompd_rc_bad_input: is returned when the input parameters2562 (other than handle) are invalid;2563 ompd_rc_error: is returned when a fatal error occurred;2564 */2565 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 else2572 printf("Success.\n");2573 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 else2581 printf("Success.\n");2582 2583 return Py_None;2584}2585 2586PyObject *test_ompd_get_tool_data(PyObject *self, PyObject *args) {2587 printf("Disabled: Testing Not enabled for \"ompd_get_tool_data\".\n");2588 2589 return Py_None;2590}2591PyObject *test_ompd_enumerate_states(PyObject *self, PyObject *args) {2592 printf("Disabled: Testing Not enabled for \"ompd_enumerate_states\".\n");2593 2594 return Py_None;2595}2596