| 1 | // The OpenMP standard defines 3 ways of providing ompt_start_tool: |
| 2 | |
| 3 | // 1. "statically-linking the tool’s definition of ompt_start_tool into an |
| 4 | // OpenMP application" |
| 5 | |
| 6 | // RUN: %libomp-compile -DCODE -DTOOL && \ |
| 7 | // RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ |
| 8 | // RUN: FileCheck %s --check-prefixes CHECK,ADDRSPACE |
| 9 | |
| 10 | // Note: We should compile the tool without -fopenmp as other tools developer |
| 11 | // would do. Otherwise this test may pass for the wrong reasons on Darwin. |
| 12 | |
| 13 | // RUN: %clang %flags -DTOOL -shared -fPIC %s -o %T/tool.so |
| 14 | |
| 15 | // 2. "introducing a dynamically-linked library that includes the tool’s |
| 16 | // definition of ompt_start_tool into the application’s address space" |
| 17 | |
| 18 | // 2.1 Link with tool during compilation |
| 19 | |
| 20 | // RUN: %libomp-compile -DCODE %no-as-needed-flag %T/tool.so && \ |
| 21 | // RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ |
| 22 | // RUN: FileCheck %s --check-prefixes CHECK,ADDRSPACE |
| 23 | |
| 24 | // 2.2 Link with tool during compilation, but AFTER the runtime |
| 25 | |
| 26 | // RUN: %libomp-compile -DCODE -lomp %no-as-needed-flag %T/tool.so && \ |
| 27 | // RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ |
| 28 | // RUN: FileCheck %s --check-prefixes CHECK,ADDRSPACE |
| 29 | |
| 30 | // 2.3 Inject tool via the dynamic loader |
| 31 | |
| 32 | // RUN: %libomp-compile -DCODE && \ |
| 33 | // RUN: env OMP_TOOL_VERBOSE_INIT=stdout %preload-tool %libomp-run | \ |
| 34 | // RUN: FileCheck %s --check-prefixes CHECK,ADDRSPACE |
| 35 | |
| 36 | // 3. "providing the name of a dynamically-linked library appropriate for the |
| 37 | // architecture and operating system used by the application in the |
| 38 | // tool-libraries-var ICV" |
| 39 | |
| 40 | // RUN: %libomp-compile -DCODE && env OMP_TOOL_LIBRARIES=%T/tool.so \ |
| 41 | // RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ |
| 42 | // RUN: FileCheck %s -DPARENTPATH=%T --check-prefixes CHECK,TOOLLIB |
| 43 | |
| 44 | // REQUIRES: ompt |
| 45 | |
| 46 | /* |
| 47 | * This file contains code for an OMPT shared library tool to be |
| 48 | * loaded and the code for the OpenMP executable. |
| 49 | * -DTOOL enables the code for the tool during compilation |
| 50 | * -DCODE enables the code for the executable during compilation |
| 51 | */ |
| 52 | |
| 53 | #ifdef CODE |
| 54 | #include "stdio.h" |
| 55 | #include "omp.h" |
| 56 | #include "omp-tools.h" |
| 57 | |
| 58 | int main() |
| 59 | { |
| 60 | #pragma omp parallel num_threads(2) |
| 61 | { |
| 62 | #pragma omp master |
| 63 | { |
| 64 | int result = omp_control_tool(omp_control_tool_start, 0, NULL); |
| 65 | printf("0: control_tool()=%d\n" , result); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
| 70 | // Check if libomp supports the callbacks for this test. |
| 71 | // CHECK-NOT: {{^}}0: Could not register callback |
| 72 | |
| 73 | // ADDRSPACE: ----- START LOGGING OF TOOL REGISTRATION ----- |
| 74 | // ADDRSPACE-NEXT: Search for OMP tool in current address space... |
| 75 | |
| 76 | // TOOLLIB: ----- START LOGGING OF TOOL REGISTRATION ----- |
| 77 | // TOOLLIB-NEXT: Search for OMP tool in current address space... Failed. |
| 78 | // TOOLLIB-NEXT: Searching tool libraries... |
| 79 | // TOOLLIB-NEXT: OMP_TOOL_LIBRARIES = [[PARENTPATH]]/tool.so |
| 80 | // TOOLLIB-NEXT: Opening [[PARENTPATH]]/tool.so... Success. |
| 81 | // TOOLLIB-NEXT: Searching for ompt_start_tool in |
| 82 | // TOOLLIB-SAME: [[PARENTPATH]]/tool.so... |
| 83 | |
| 84 | // CHECK: 0: Do not initialize tool |
| 85 | |
| 86 | // ADDRSPACE-NEXT: Failed. |
| 87 | // ADDRSPACE-NEXT: No OMP_TOOL_LIBRARIES defined. |
| 88 | // ADDRSPACE-NEXT: ...searching tool libraries failed. |
| 89 | // ADDRSPACE: No OMP tool loaded. |
| 90 | // ADDRSPACE-NEXT: ----- END LOGGING OF TOOL REGISTRATION ----- |
| 91 | |
| 92 | // TOOLLIB-NEXT: Found but not using the OMPT interface. |
| 93 | // TOOLLIB-NEXT: Continuing search... |
| 94 | // TOOLLIB-NEXT: ...searching tool libraries failed. |
| 95 | // TOOLLIB: No OMP tool loaded. |
| 96 | // TOOLLIB-NEXT: ----- END LOGGING OF TOOL REGISTRATION ----- |
| 97 | |
| 98 | // CHECK: {{^}}0: control_tool()=-2 |
| 99 | |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | #endif /* CODE */ |
| 105 | |
| 106 | #ifdef TOOL |
| 107 | |
| 108 | #include <omp-tools.h> |
| 109 | #include "stdio.h" |
| 110 | |
| 111 | ompt_start_tool_result_t* ompt_start_tool( |
| 112 | unsigned int omp_version, |
| 113 | const char *runtime_version) |
| 114 | { |
| 115 | printf("0: Do not initialize tool\n" ); |
| 116 | return NULL; |
| 117 | } |
| 118 | #endif /* TOOL */ |
| 119 | |