| 1 | // RUN: %clang %flags -shared -fPIC %s -o %T/first_tool.so |
| 2 | // RUN: %clang %flags -DTOOL -DSECOND_TOOL -shared -fPIC %s -o %T/second_tool.so |
| 3 | // RUN: %clang %flags -DTOOL -DTHIRD_TOOL -shared -fPIC %s -o %T/third_tool.so |
| 4 | // RUN: %libomp-compile -DCODE |
| 5 | // RUN: env OMP_TOOL_LIBRARIES=%T/non_existing_file.so:%T/first_tool.so:%T/second_tool.so:%T/third_tool.so \ |
| 6 | // RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s -DPARENTPATH=%T |
| 7 | |
| 8 | // REQUIRES: ompt |
| 9 | // XFAIL: darwin |
| 10 | |
| 11 | /* |
| 12 | * This file contains code for three OMPT shared library tool to be |
| 13 | * loaded and the code for the OpenMP executable. |
| 14 | * No option enables code for the first shared library |
| 15 | * (without an implementation of ompt_start_tool) during compilation |
| 16 | * -DTOOL -DSECOND_TOOL enables the code for the second tool during compilation |
| 17 | * -DTOOL -DTHIRD_TOOL enables the code for the third tool during compilation |
| 18 | * -DCODE enables the code for the executable during compilation |
| 19 | */ |
| 20 | |
| 21 | // CHECK: ----- START LOGGING OF TOOL REGISTRATION ----- |
| 22 | // CHECK-NEXT: Search for OMP tool in current address space... Failed. |
| 23 | // CHECK-NEXT: Searching tool libraries... |
| 24 | // CHECK-NEXT: OMP_TOOL_LIBRARIES = [[PARENTPATH]]/non_existing_file.so |
| 25 | // CHECK-SAME: [[PARENTPATH]]/first_tool.so |
| 26 | // CHECK-SAME: [[PARENTPATH]]/second_tool.so |
| 27 | // CHECK-SAME: [[PARENTPATH]]/third_tool.so |
| 28 | // CHECK-NEXT: Opening [[PARENTPATH]]/non_existing_file.so... Failed: |
| 29 | // CHECK-SAME: [[PARENTPATH]]/non_existing_file.so: {{cannot open shared object file|open failed}}: |
| 30 | // CHECK-SAME: No such file or directory |
| 31 | // CHECK-NEXT: Opening [[PARENTPATH]]/first_tool.so... Success. |
| 32 | // CHECK-NEXT: Searching for ompt_start_tool in |
| 33 | // CHECK-SAME: [[PARENTPATH]]/first_tool.so... Failed: |
| 34 | // CHECK-SAME: {{.*/first_tool.so: undefined symbol: ompt_start_tool|ld.so.1: .*: ompt_start_tool: can't find symbol}} |
| 35 | // CHECK-NEXT: Opening [[PARENTPATH]]/second_tool.so... Success. |
| 36 | // CHECK-NEXT: Searching for ompt_start_tool in |
| 37 | // CHECK-SAME: [[PARENTPATH]]/second_tool.so... 0: Do not initialize tool |
| 38 | // CHECK-NEXT: Found but not using the OMPT interface. |
| 39 | // CHECK-NEXT: Continuing search... |
| 40 | // CHECK-NEXT: Opening [[PARENTPATH]]/third_tool.so... Success. |
| 41 | // CHECK-NEXT: Searching for ompt_start_tool in |
| 42 | // CHECK-SAME: [[PARENTPATH]]/third_tool.so... 0: Do initialize tool |
| 43 | // CHECK-NEXT: Success. |
| 44 | // CHECK-NEXT: Tool was started and is using the OMPT interface. |
| 45 | // CHECK-NEXT: ----- END LOGGING OF TOOL REGISTRATION ----- |
| 46 | |
| 47 | // Check if libomp supports the callbacks for this test. |
| 48 | |
| 49 | // CHECK-NOT: {{^}}0: Could not register callback |
| 50 | // CHECK: {{^}}0: Tool initialized |
| 51 | // CHECK: {{^}}0: ompt_event_thread_begin |
| 52 | // CHECK-DAG: {{^}}0: ompt_event_thread_begin |
| 53 | // CHECK-DAG: {{^}}0: control_tool()=-1 |
| 54 | // CHECK: {{^}}0: Tool finalized |
| 55 | |
| 56 | |
| 57 | #ifdef CODE |
| 58 | #include "stdio.h" |
| 59 | #include "omp.h" |
| 60 | #include "omp-tools.h" |
| 61 | |
| 62 | int main() |
| 63 | { |
| 64 | #pragma omp parallel num_threads(2) |
| 65 | { |
| 66 | #pragma omp master |
| 67 | { |
| 68 | int result = omp_control_tool(omp_control_tool_start, 0, NULL); |
| 69 | printf("0: control_tool()=%d\n" , result); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | #endif /* CODE */ |
| 78 | |
| 79 | #ifdef TOOL |
| 80 | |
| 81 | #include <omp-tools.h> |
| 82 | #include "stdio.h" |
| 83 | |
| 84 | #ifdef SECOND_TOOL |
| 85 | // The second tool has an implementation of ompt_start_tool that returns NULL |
| 86 | ompt_start_tool_result_t* ompt_start_tool( |
| 87 | unsigned int omp_version, |
| 88 | const char *runtime_version) |
| 89 | { |
| 90 | printf("0: Do not initialize tool\n" ); |
| 91 | return NULL; |
| 92 | } |
| 93 | #elif defined(THIRD_TOOL) |
| 94 | // The third tool has an implementation of ompt_start_tool that returns a |
| 95 | // pointer to a valid instance of ompt_start_tool_result_t |
| 96 | |
| 97 | static void |
| 98 | on_ompt_callback_thread_begin( |
| 99 | ompt_thread_t thread_type, |
| 100 | ompt_data_t *thread_data) |
| 101 | { |
| 102 | printf("0: ompt_event_thread_begin\n" ); |
| 103 | } |
| 104 | |
| 105 | int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num, |
| 106 | ompt_data_t *tool_data) { |
| 107 | ompt_set_callback_t ompt_set_callback = (ompt_set_callback_t) lookup("ompt_set_callback" ); |
| 108 | ompt_set_callback(ompt_callback_thread_begin, (ompt_callback_t)on_ompt_callback_thread_begin); |
| 109 | printf("0: Tool initialized\n" ); |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | void ompt_finalize(ompt_data_t *tool_data) |
| 114 | { |
| 115 | printf("0: Tool finalized\n" ); |
| 116 | } |
| 117 | |
| 118 | ompt_start_tool_result_t* ompt_start_tool( |
| 119 | unsigned int omp_version, |
| 120 | const char *runtime_version) |
| 121 | { |
| 122 | printf("0: Do initialize tool\n" ); |
| 123 | static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,&ompt_finalize, 0}; |
| 124 | return &ompt_start_tool_result; |
| 125 | } |
| 126 | #endif |
| 127 | |
| 128 | #endif /* TOOL */ |
| 129 | |