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