124 lines · c
1// clang-format off2// RUN: mkdir -p %t.tool_dir3// RUN: %clang %flags -shared -fPIC %s -o %t.tool_dir/first_tool.so4// RUN: %clang %flags -DTOOL -DSECOND_TOOL -shared -fPIC %s -o %t.tool_dir/second_tool.so5// RUN: %clang %flags -DTOOL -DTHIRD_TOOL -shared -fPIC %s -o %t.tool_dir/third_tool.so6// RUN: %libomp-compile -DCODE7// RUN: env OMP_TOOL_LIBRARIES=%t.tool_dir/non_existing_file.so:%t.tool_dir/first_tool.so:%t.tool_dir/second_tool.so:%t.tool_dir/third_tool.so \8// RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s -DPARENTPATH=%t.tool_dir9 10// REQUIRES: ompt11// XFAIL: darwin12// clang-format on13 14/*15 * This file contains code for three OMPT shared library tool to be16 * loaded and the code for the OpenMP executable.17 * No option enables code for the first shared library18 * (without an implementation of ompt_start_tool) during compilation19 * -DTOOL -DSECOND_TOOL enables the code for the second tool during compilation20 * -DTOOL -DTHIRD_TOOL enables the code for the third tool during compilation21 * -DCODE enables the code for the executable during compilation22 */23 24// clang-format off25// CHECK: ----- START LOGGING OF TOOL REGISTRATION -----26// CHECK-NEXT: Search for OMP tool in current address space... Failed.27// CHECK-NEXT: Searching tool libraries...28// CHECK-NEXT: OMP_TOOL_LIBRARIES = [[PARENTPATH]]/non_existing_file.so29// CHECK-SAME: [[PARENTPATH]]/first_tool.so30// CHECK-SAME: [[PARENTPATH]]/second_tool.so31// CHECK-SAME: [[PARENTPATH]]/third_tool.so32// CHECK-NEXT: Opening [[PARENTPATH]]/non_existing_file.so... Failed:33// CHECK-SAME: [[PARENTPATH]]/non_existing_file.so: {{cannot open shared object file|open failed}}:34// CHECK-SAME: No such file or directory35// CHECK-NEXT: Opening [[PARENTPATH]]/first_tool.so... Success.36// CHECK-NEXT: Searching for ompt_start_tool in37// CHECK-SAME: [[PARENTPATH]]/first_tool.so... Failed:38// CHECK-SAME: {{.*/first_tool.so: undefined symbol: ompt_start_tool|ld.so.1: .*: ompt_start_tool: can't find symbol}}39// CHECK-NEXT: Opening [[PARENTPATH]]/second_tool.so... Success.40// CHECK-NEXT: Searching for ompt_start_tool in41// CHECK-SAME: [[PARENTPATH]]/second_tool.so... 0: Do not initialize tool42// CHECK-NEXT: Found but not using the OMPT interface.43// CHECK-NEXT: Continuing search...44// CHECK-NEXT: Opening [[PARENTPATH]]/third_tool.so... Success.45// CHECK-NEXT: Searching for ompt_start_tool in46// CHECK-SAME: [[PARENTPATH]]/third_tool.so... 0: Do initialize tool47// CHECK-NEXT: Success.48// CHECK-NEXT: Tool was started and is using the OMPT interface.49// CHECK-NEXT: ----- END LOGGING OF TOOL REGISTRATION -----50 51// Check if libomp supports the callbacks for this test.52 53// CHECK-NOT: {{^}}0: Could not register callback54// CHECK: {{^}}0: Tool initialized55// CHECK: {{^}}0: ompt_event_thread_begin56// CHECK-DAG: {{^}}0: ompt_event_thread_begin57// CHECK-DAG: {{^}}0: control_tool()=-158// CHECK: {{^}}0: Tool finalized59// clang-format on60 61#ifdef CODE62#include "stdio.h"63#include "omp.h"64#include "omp-tools.h"65 66int main() {67#pragma omp parallel num_threads(2)68 {69#pragma omp master70 {71 int result = omp_control_tool(omp_control_tool_start, 0, NULL);72 printf("0: control_tool()=%d\n", result);73 }74 }75 76 return 0;77}78 79#endif /* CODE */80 81#ifdef TOOL82 83#include <omp-tools.h>84#include "stdio.h"85 86#ifdef SECOND_TOOL87// The second tool has an implementation of ompt_start_tool that returns NULL88ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,89 const char *runtime_version) {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 a95// pointer to a valid instance of ompt_start_tool_result_t96 97static void on_ompt_callback_thread_begin(ompt_thread_t thread_type,98 ompt_data_t *thread_data) {99 printf("0: ompt_event_thread_begin\n");100}101 102int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,103 ompt_data_t *tool_data) {104 ompt_set_callback_t ompt_set_callback =105 (ompt_set_callback_t)lookup("ompt_set_callback");106 ompt_set_callback(ompt_callback_thread_begin,107 (ompt_callback_t)on_ompt_callback_thread_begin);108 printf("0: Tool initialized\n");109 return 1;110}111 112void ompt_finalize(ompt_data_t *tool_data) { printf("0: Tool finalized\n"); }113 114ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,115 const char *runtime_version) {116 printf("0: Do initialize tool\n");117 static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,118 &ompt_finalize, 0};119 return &ompt_start_tool_result;120}121#endif122 123#endif /* TOOL */124