[Openmp-commits] [openmp] r271578 - Merging r270464:

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Thu Jun 2 13:19:12 PDT 2016


Author: jlpeyton
Date: Thu Jun  2 15:19:12 2016
New Revision: 271578

URL: http://llvm.org/viewvc/llvm-project?rev=271578&view=rev
Log:
Merging r270464:
------------------------------------------------------------------------
r270464 | jlpeyton | 2016-05-23 12:50:32 -0500 (Mon, 23 May 2016) | 12 lines

Allow unit testing on Windows

These changes allow testing on Windows using clang.exe.
There are two main changes:
1. Only link to -lm when it actually exists on the system
2. Create basic versions of pthread_create() and pthread_join() for windows.
   They are not POSIX compliant by any stretch but will allow any existing
   and future tests to use pthread_create() and pthread_join() for testing
   interactions of libomp with os threads.

Differential Revision: http://reviews.llvm.org/D20391

------------------------------------------------------------------------

Modified:
    openmp/branches/release_38/   (props changed)
    openmp/branches/release_38/runtime/src/CMakeLists.txt
    openmp/branches/release_38/runtime/test/CMakeLists.txt
    openmp/branches/release_38/runtime/test/lit.cfg
    openmp/branches/release_38/runtime/test/lit.site.cfg.in
    openmp/branches/release_38/runtime/test/omp_testsuite.h

Propchange: openmp/branches/release_38/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jun  2 15:19:12 2016
@@ -1 +1 @@
-/openmp/trunk:257833,258169,258528,258695,258990,263651,264166
+/openmp/trunk:257833,258169,258528,258695,258990,263651,264166,270464

Modified: openmp/branches/release_38/runtime/src/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/openmp/branches/release_38/runtime/src/CMakeLists.txt?rev=271578&r1=271577&r2=271578&view=diff
==============================================================================
--- openmp/branches/release_38/runtime/src/CMakeLists.txt (original)
+++ openmp/branches/release_38/runtime/src/CMakeLists.txt Thu Jun  2 15:19:12 2016
@@ -144,7 +144,11 @@ set_target_properties(omp PROPERTIES
 )
 
 # Get the library's location within the build tree for the unit tester
-get_target_property(LIBOMP_LIBRARY_DIR omp LIBRARY_OUTPUT_DIRECTORY)
+if(NOT WIN32)
+  get_target_property(LIBOMP_LIBRARY_DIR omp LIBRARY_OUTPUT_DIRECTORY)
+else()
+  get_target_property(LIBOMP_LIBRARY_DIR omp RUNTIME_OUTPUT_DIRECTORY)
+endif()
 if(NOT LIBOMP_LIBRARY_DIR)
   set(LIBOMP_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
   set(LIBOMP_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)

Modified: openmp/branches/release_38/runtime/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/openmp/branches/release_38/runtime/test/CMakeLists.txt?rev=271578&r1=271577&r2=271578&view=diff
==============================================================================
--- openmp/branches/release_38/runtime/test/CMakeLists.txt (original)
+++ openmp/branches/release_38/runtime/test/CMakeLists.txt Thu Jun  2 15:19:12 2016
@@ -1,6 +1,7 @@
 # CMakeLists.txt file for unit testing OpenMP Library
 include(FindPythonInterp)
 include(CheckTypeSize)
+include(CheckLibraryExists)
 
 if(NOT PYTHONINTERP_FOUND)
   libomp_warning_say("Could not find Python.")
@@ -8,6 +9,9 @@ if(NOT PYTHONINTERP_FOUND)
   return()
 endif()
 
+# Some tests use math functions
+check_library_exists(m sqrt "" LIBOMP_HAVE_LIBM)
+
 macro(pythonize_bool var)
   if (${var})
     set(${var} True)
@@ -17,6 +21,7 @@ macro(pythonize_bool var)
 endmacro()
 
 pythonize_bool(LIBOMP_USE_HWLOC)
+pythonize_bool(LIBOMP_HAVE_LIBM)
 
 set(LIBOMP_TEST_CFLAGS "" CACHE STRING
   "Extra compiler flags to send to the test compiler")

Modified: openmp/branches/release_38/runtime/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/openmp/branches/release_38/runtime/test/lit.cfg?rev=271578&r1=271577&r2=271578&view=diff
==============================================================================
--- openmp/branches/release_38/runtime/test/lit.cfg (original)
+++ openmp/branches/release_38/runtime/test/lit.cfg Thu Jun  2 15:19:12 2016
@@ -47,6 +47,11 @@ config.test_cflags = config.test_openmp_
     " -L " + config.library_dir + \
     " " + config.test_extra_cflags
 
+# extra libraries
+libs = ""
+if config.has_libm:
+    libs += " -lm"
+
 # Setup environment to find dynamic library at runtime
 append_dynamic_library_path(config.library_dir)
 if config.using_hwloc:
@@ -70,7 +75,10 @@ if config.operating_system == 'Darwin':
 
 # substitutions
 config.substitutions.append(("%libomp-compile-and-run", \
-    "%clang %cflags %s -o %t -lm && %t"))
+    "%libomp-compile && %libomp-run"))
+config.substitutions.append(("%libomp-compile", \
+    "%clang %cflags %s -o %t" + libs))
+config.substitutions.append(("%libomp-run", "%t"))
 config.substitutions.append(("%clang", config.test_compiler))
 config.substitutions.append(("%openmp_flag", config.test_openmp_flag))
 config.substitutions.append(("%cflags", config.test_cflags))

Modified: openmp/branches/release_38/runtime/test/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/openmp/branches/release_38/runtime/test/lit.site.cfg.in?rev=271578&r1=271577&r2=271578&view=diff
==============================================================================
--- openmp/branches/release_38/runtime/test/lit.site.cfg.in (original)
+++ openmp/branches/release_38/runtime/test/lit.site.cfg.in Thu Jun  2 15:19:12 2016
@@ -9,6 +9,7 @@ config.omp_header_directory = "@LIBOMP_B
 config.operating_system = "@CMAKE_SYSTEM_NAME@"
 config.hwloc_library_dir = "@LIBOMP_HWLOC_LIBRARY_DIR@"
 config.using_hwloc = @LIBOMP_USE_HWLOC@
+config.has_libm = @LIBOMP_HAVE_LIBM@
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBOMP_BASE_DIR@/test/lit.cfg")

Modified: openmp/branches/release_38/runtime/test/omp_testsuite.h
URL: http://llvm.org/viewvc/llvm-project/openmp/branches/release_38/runtime/test/omp_testsuite.h?rev=271578&r1=271577&r2=271578&view=diff
==============================================================================
--- openmp/branches/release_38/runtime/test/omp_testsuite.h (original)
+++ openmp/branches/release_38/runtime/test/omp_testsuite.h Thu Jun  2 15:19:12 2016
@@ -4,6 +4,7 @@
 #define OMP_TESTSUITE_H
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <omp.h>
 
 /* General                                                */
@@ -19,4 +20,60 @@
 #define NUM_TASKS 25
 #define MAX_TASKS_PER_THREAD 5
 
+#ifdef  _WIN32
+// Windows versions of pthread_create() and pthread_join()
+# include <windows.h>
+typedef HANDLE pthread_t;
+
+// encapsulates the information about a pthread-callable function
+struct thread_func_info_t {
+  void* (*start_routine)(void*);
+  void* arg;
+};
+
+// call the void* start_routine(void*);
+static DWORD __thread_func_wrapper(LPVOID lpParameter) {
+  struct thread_func_info_t* function_information;
+  function_information = (struct thread_func_info_t*)lpParameter;
+  function_information->start_routine(function_information->arg);
+  free(function_information);
+  return 0;
+}
+
+// attr is ignored
+static int pthread_create(pthread_t *thread, void *attr,
+                          void *(*start_routine) (void *), void *arg) {
+  pthread_t pthread;
+  struct thread_func_info_t* info;
+  info = (struct thread_func_info_t*)malloc(sizeof(struct thread_func_info_t));
+  info->start_routine = start_routine;
+  info->arg = arg;
+  pthread = CreateThread(NULL, 0, __thread_func_wrapper, info, 0, NULL);
+  if (pthread == NULL) {
+    fprintf(stderr, "CreateThread() failed: Error #%u.\n", GetLastError());
+    exit(1);
+  }
+  *thread = pthread;
+  return 0;
+}
+// retval is ignored for now
+static int pthread_join(pthread_t thread, void **retval) {
+  int rc;
+  rc = WaitForSingleObject(thread, INFINITE);
+  if (rc == WAIT_FAILED) {
+    fprintf(stderr, "WaitForSingleObject() failed: Error #%u.\n",
+            GetLastError());
+    exit(1);
+  }
+  rc = CloseHandle(thread);
+  if (rc == 0) {
+    fprintf(stderr, "CloseHandle() failed: Error #%u.\n", GetLastError());
+    exit(1);
+  }
+  return 0;
+}
+#else
+# include <pthread.h>
+#endif
+
 #endif




More information about the Openmp-commits mailing list