[Openmp-commits] [openmp] r324588 - [OMPT] Add tool_available_search testcase

Joachim Protze via Openmp-commits openmp-commits at lists.llvm.org
Thu Feb 8 02:04:33 PST 2018


Author: jprotze
Date: Thu Feb  8 02:04:33 2018
New Revision: 324588

URL: http://llvm.org/viewvc/llvm-project?rev=324588&view=rev
Log:
[OMPT] Add tool_available_search testcase

Tests the search for tools as defined in the spec. The OMP_TOOL_LIBRARIES
environment variable contains paths to the following files(in that order)

-to a nonexisting file
-to a shared library that does not have a ompt_start_tool function
-to a shared library that has an ompt_start_tool implementation returning NULL
-to a shared library that has an ompt_start_tool implementation returning a
    pointer to a valid instance of ompt_start_tool_result_t

The expected result is that the last tool gets active and can print in the
thread-begin callback.

Differential Revision: https://reviews.llvm.org/D42166

Added:
    openmp/trunk/runtime/test/ompt/loadtool/tool_available_search/
    openmp/trunk/runtime/test/ompt/loadtool/tool_available_search/tool_available_search.c

Added: openmp/trunk/runtime/test/ompt/loadtool/tool_available_search/tool_available_search.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/test/ompt/loadtool/tool_available_search/tool_available_search.c?rev=324588&view=auto
==============================================================================
--- openmp/trunk/runtime/test/ompt/loadtool/tool_available_search/tool_available_search.c (added)
+++ openmp/trunk/runtime/test/ompt/loadtool/tool_available_search/tool_available_search.c Thu Feb  8 02:04:33 2018
@@ -0,0 +1,104 @@
+// RUN: %clang %flags -shared -fPIC %s -o %T/first_tool.so
+// RUN: %clang %flags -DTOOL -DSECOND_TOOL -shared -fPIC %s -o %T/second_tool.so
+// RUN: %clang %flags -DTOOL -DTHIRD_TOOL -shared -fPIC %s -o %T/third_tool.so
+// RUN: %libomp-compile -DCODE && env OMP_TOOL_LIBRARIES=%T/non_existing_file.so:%T/first_tool.so:%T/second_tool.so:%T/third_tool.so %libomp-run | FileCheck %s
+
+// REQUIRES: ompt
+
+/*
+ *  This file contains code for three OMPT shared library tool to be 
+ *  loaded and the code for the OpenMP executable. 
+ *  No option enables code for the first shared library 
+ *  (without an implementation of ompt_start_tool) during compilation
+ *  -DTOOL -DSECOND_TOOL enables the code for the second tool during compilation
+ *  -DTOOL -DTHIRD_TOOL enables the code for the third tool during compilation
+ *  -DCODE enables the code for the executable during compilation
+ */
+
+#ifdef CODE
+#include "stdio.h"
+#include "omp.h"
+#include "ompt.h"
+
+int main()
+{
+  #pragma omp parallel num_threads(2)
+  {
+    #pragma omp master
+    {
+      int result = omp_control_tool(omp_control_tool_start, 0, NULL);
+      printf("0: control_tool()=%d\n", result);
+    }
+  }
+
+
+  // Check if libomp supports the callbacks for this test.
+  // CHECK-NOT: {{^}}0: Could not register callback 
+  
+  // CHECK: {{^}}0: Do not initialize tool
+
+  // CHECK: {{^}}0: Do initialize tool
+  // CHECK: {{^}}0: Tool initialized
+  // CHECK: {{^}}0: ompt_event_thread_begin
+  // CHECK-DAG: {{^}}0: ompt_event_thread_begin
+  // CHECK-DAG: {{^}}0: control_tool()=-1
+  // CHECK: {{^}}0: Tool finalized
+  
+
+  return 0;
+}
+
+#endif /* CODE */
+
+#ifdef TOOL
+
+#include <ompt.h>
+#include "stdio.h"
+
+#ifdef SECOND_TOOL
+// The second tool has an implementation of ompt_start_tool that returns NULL
+ompt_start_tool_result_t* ompt_start_tool(
+  unsigned int omp_version,
+  const char *runtime_version)
+{
+  printf("0: Do not initialize tool\n");
+  return NULL;
+}
+#elif defined(THIRD_TOOL)
+// The third tool has an implementation of ompt_start_tool that returns a 
+// pointer to a valid instance of ompt_start_tool_result_t
+
+static void
+on_ompt_callback_thread_begin(
+  ompt_thread_type_t thread_type,
+  ompt_data_t *thread_data)
+{
+  printf("0: ompt_event_thread_begin\n");
+}
+
+int ompt_initialize(
+  ompt_function_lookup_t lookup,
+  ompt_data_t *tool_data)
+{
+  ompt_set_callback_t ompt_set_callback = (ompt_set_callback_t) lookup("ompt_set_callback");
+  ompt_set_callback(ompt_callback_thread_begin, (ompt_callback_t)on_ompt_callback_thread_begin);
+  printf("0: Tool initialized\n");
+  return 1;
+}
+
+void ompt_finalize(ompt_data_t *tool_data)
+{
+  printf("0: Tool finalized\n");
+}
+
+ompt_start_tool_result_t* ompt_start_tool(
+  unsigned int omp_version,
+  const char *runtime_version)
+{
+  printf("0: Do initialize tool\n");
+  static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,&ompt_finalize, 0};
+  return &ompt_start_tool_result;
+}
+#endif
+
+#endif /* TOOL */




More information about the Openmp-commits mailing list