| 1 |
// clang-format off |
| 2 |
// The OpenMP standard defines 3 ways of providing ompt_start_tool: |
| 3 |
|
| 4 |
// RUN: mkdir -p %t.tool_dir |
| 5 |
|
| 6 |
// 1. "statically-linking the tool’s definition of ompt_start_tool into an |
| 7 |
// OpenMP application" |
| 8 |
|
| 9 |
// RUN: %libomp-compile -DCODE -DTOOL && env OMP_TOOL_VERBOSE_INIT=stdout \ |
| 10 |
// RUN: %libomp-run | FileCheck %s --check-prefixes CHECK,ADDRSPACE |
| 11 |
|
| 12 |
// Note: We should compile the tool without -fopenmp as other tools developer |
| 13 |
// would do. Otherwise this test may pass for the wrong reasons on Darwin. |
| 14 |
|
| 15 |
// RUN: %clang %flags -DTOOL -shared -fPIC %s -o %t.tool_dir/tool.so |
| 16 |
|
| 17 |
// 2. "introducing a dynamically-linked library that includes the tool’s |
| 18 |
// definition of ompt_start_tool into the application’s address space" |
| 19 |
|
| 20 |
// 2.1 Link with tool during compilation |
| 21 |
|
| 22 |
// RUN: %libomp-compile -DCODE %no-as-needed-flag %t.tool_dir/tool.so && \ |
| 23 |
// RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s \ |
| 24 |
// RUN: --check-prefixes CHECK,ADDRSPACE |
| 25 |
|
| 26 |
// 2.2 Link with tool during compilation, but AFTER the runtime |
| 27 |
|
| 28 |
// RUN: %libomp-compile -DCODE -lomp %no-as-needed-flag %t.tool_dir/tool.so && \ |
| 29 |
// RUN: env OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s \ |
| 30 |
// RUN: --check-prefixes CHECK,ADDRSPACE |
| 31 |
|
| 32 |
// 2.3 Inject tool via the dynamic loader |
| 33 |
|
| 34 |
// RUN: %libomp-compile -DCODE && env OMP_TOOL_VERBOSE_INIT=stdout \ |
| 35 |
// RUN: %preload-tool %libomp-run | FileCheck %s \ |
| 36 |
// RUN: --check-prefixes CHECK,ADDRSPACE |
| 37 |
|
| 38 |
// 3. "providing the name of a dynamically-linked library appropriate for the |
| 39 |
// architecture and operating system used by the application in the |
| 40 |
// tool-libraries-var ICV" |
| 41 |
|
| 42 |
// 3.1 OMP_TOOL_VERBOSE_INIT not set |
| 43 |
|
| 44 |
// RUN: %libomp-compile -DCODE && \ |
| 45 |
// RUN: env OMP_TOOL_LIBRARIES=%t.tool_dir/tool.so %libomp-run | FileCheck %s |
| 46 |
|
| 47 |
// 3.2 OMP_TOOL_VERBOSE_INIT disabled |
| 48 |
|
| 49 |
// RUN: env OMP_TOOL_LIBRARIES=%t.tool_dir/tool.so OMP_TOOL_VERBOSE_INIT=disabled \ |
| 50 |
// RUN: %libomp-run | FileCheck %s |
| 51 |
|
| 52 |
// 3.3 OMP_TOOL_VERBOSE_INIT to stdout |
| 53 |
|
| 54 |
// RUN: %libomp-compile -DCODE && env OMP_TOOL_LIBRARIES=%t.tool_dir/tool.so \ |
| 55 |
// RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | \ |
| 56 |
// RUN: FileCheck %s -DPARENTPATH=%t.tool_dir --check-prefixes CHECK,TOOLLIB |
| 57 |
|
| 58 |
// 3.4 OMP_TOOL_VERBOSE_INIT to stderr, check merged stdout and stderr |
| 59 |
|
| 60 |
// RUN: env OMP_TOOL_LIBRARIES=%t.tool_dir/tool.so OMP_TOOL_VERBOSE_INIT=stderr \ |
| 61 |
// RUN: %libomp-run 2>&1 | \ |
| 62 |
// RUN: FileCheck %s -DPARENTPATH=%t.tool_dir --check-prefixes CHECK,TOOLLIB |
| 63 |
|
| 64 |
// 3.5 OMP_TOOL_VERBOSE_INIT to stderr, check just stderr |
| 65 |
|
| 66 |
// RUN: env OMP_TOOL_LIBRARIES=%t.tool_dir/tool.so OMP_TOOL_VERBOSE_INIT=stderr \ |
| 67 |
// RUN: %libomp-run 2>&1 >/dev/null | \ |
| 68 |
// RUN: FileCheck %s -DPARENTPATH=%t.tool_dir --check-prefixes TOOLLIB |
| 69 |
|
| 70 |
// 3.6 OMP_TOOL_VERBOSE_INIT to file "init.log" |
| 71 |
|
| 72 |
// RUN: env OMP_TOOL_LIBRARIES=%t.tool_dir/tool.so OMP_TOOL_VERBOSE_INIT=%t.tool_dir/init.log \ |
| 73 |
// RUN: %libomp-run | FileCheck %s && cat %t.tool_dir/init.log | \ |
| 74 |
// RUN: FileCheck %s -DPARENTPATH=%t.tool_dir --check-prefixes TOOLLIB |
| 75 |
|
| 76 |
|
| 77 |
// REQUIRES: ompt |
| 78 |
// clang-format on |
| 79 |
|
| 80 |
/* |
| 81 |
* This file contains code for an OMPT shared library tool to be |
| 82 |
* loaded and the code for the OpenMP executable. |
| 83 |
* -DTOOL enables the code for the tool during compilation |
| 84 |
* -DCODE enables the code for the executable during compilation |
| 85 |
*/ |
| 86 |
|
| 87 |
// clang-format off |
| 88 |
// Check if libomp supports the callbacks for this test. |
| 89 |
// CHECK-NOT: {{^}}0: Could not register callback |
| 90 |
|
| 91 |
// ADDRSPACE: ----- START LOGGING OF TOOL REGISTRATION ----- |
| 92 |
// ADDRSPACE-NEXT: Search for OMP tool in current address space... Success. |
| 93 |
// ADDRSPACE-NEXT: Tool was started and is using the OMPT interface. |
| 94 |
// ADDRSPACE-NEXT: ----- END LOGGING OF TOOL REGISTRATION ----- |
| 95 |
|
| 96 |
// TOOLLIB: ----- START LOGGING OF TOOL REGISTRATION ----- |
| 97 |
// TOOLLIB-NEXT: Search for OMP tool in current address space... Failed. |
| 98 |
// TOOLLIB-NEXT: Searching tool libraries... |
| 99 |
// TOOLLIB-NEXT: OMP_TOOL_LIBRARIES = [[PARENTPATH]]/tool.so |
| 100 |
// TOOLLIB-NEXT: Opening [[PARENTPATH]]/tool.so... Success. |
| 101 |
// TOOLLIB-NEXT: Searching for ompt_start_tool in |
| 102 |
// TOOLLIB-SAME: [[PARENTPATH]]/tool.so... Success. |
| 103 |
// TOOLLIB-NEXT: Tool was started and is using the OMPT interface. |
| 104 |
// TOOLLIB-NEXT: ----- END LOGGING OF TOOL REGISTRATION ----- |
| 105 |
// clang-format on |
| 106 |
|
| 107 |
#ifdef CODE |
| 108 |
#include "omp.h" |
| 109 |
|
| 110 |
int main() { |
| 111 |
#pragma omp parallel num_threads(2) |
| 112 |
{ |
| 113 |
} |
| 114 |
|
| 115 |
// clang-format off |
| 116 |
// CHECK-NOT: ----- START LOGGING OF TOOL REGISTRATION ----- |
| 117 |
// CHECK-NOT: ----- END LOGGING OF TOOL REGISTRATION ----- |
| 118 |
|
| 119 |
// CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] |
| 120 |
// CHECK: {{^}}0: ompt_event_runtime_shutdown |
| 121 |
// clang-format on |
| 122 |
|
| 123 |
return 0; |
| 124 |
} |
| 125 |
|
| 126 |
#endif /* CODE */ |
| 127 |
|
| 128 |
#ifdef TOOL |
| 129 |
|
| 130 |
#include <stdio.h> |
| 131 |
#include <omp-tools.h> |
| 132 |
|
| 133 |
int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num, |
| 134 |
ompt_data_t *tool_data) { |
| 135 |
printf("0: NULL_POINTER=%p\n", (void *)NULL); |
| 136 |
return 1; // success |
| 137 |
} |
| 138 |
|
| 139 |
void ompt_finalize(ompt_data_t *tool_data) { |
| 140 |
printf("0: ompt_event_runtime_shutdown\n"); |
| 141 |
} |
| 142 |
|
| 143 |
ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version, |
| 144 |
const char *runtime_version) { |
| 145 |
static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize, |
| 146 |
&ompt_finalize, 0}; |
| 147 |
return &ompt_start_tool_result; |
| 148 |
} |
| 149 |
#endif /* TOOL */ |