[PATCH 06/10] check whether libpocl and the device libraries can be dlopen()ed
authorAndreas Beckmann <anbe@debian.org>
Fri, 5 Feb 2021 15:23:39 +0000 (16:23 +0100)
committerAndreas Beckmann <anbe@debian.org>
Tue, 16 Feb 2021 10:00:57 +0000 (10:00 +0000)
Gbp-Pq: Name 0006-check-whether-libpocl-and-the-device-libraries-can-b.patch

tests/CMakeLists.txt
tests/runtime/CMakeLists.txt
tests/runtime/test_dlopen.c [new file with mode: 0644]

index ed422d80cff906507acff85b35852f65f11f8adc..07648a00681bde940f291b38159960d4fd6cbf7f 100644 (file)
@@ -38,6 +38,41 @@ endif()
 
 #######################################################################
 
+add_test("pocl_test_dlopen_libpocl" "runtime/test_dlopen")
+set_property(TEST "pocl_version_check" APPEND PROPERTY DEPENDS "pocl_test_dlopen_libpocl")
+
+if(BUILD_BASIC)
+  add_test("pocl_test_dlopen_device_basic" "runtime/test_dlopen" "basic")
+  set_property(TEST "pocl_version_check" APPEND PROPERTY DEPENDS "pocl_test_dlopen_device_basic")
+endif()
+
+if(BUILD_PTHREAD)
+  add_test("pocl_test_dlopen_device_pthread" "runtime/test_dlopen" "pthread")
+  set_property(TEST "pocl_version_check" APPEND PROPERTY DEPENDS "pocl_test_dlopen_device_pthread")
+endif()
+
+if(BUILD_ACCEL)
+  add_test("pocl_test_dlopen_device_accel" "runtime/test_dlopen" "accel")
+  set_property(TEST "pocl_version_check" APPEND PROPERTY DEPENDS "pocl_test_dlopen_device_accel")
+endif()
+
+if(ENABLE_TCE)
+  add_test("pocl_test_dlopen_device_tce" "runtime/test_dlopen" "tce")
+  set_property(TEST "pocl_version_check" APPEND PROPERTY DEPENDS "pocl_test_dlopen_device_tce")
+endif()
+
+if(ENABLE_HSA)
+  add_test("pocl_test_dlopen_device_hsa" "runtime/test_dlopen" "hsa")
+  set_property(TEST "pocl_version_check" APPEND PROPERTY DEPENDS "pocl_test_dlopen_device_hsa")
+endif()
+
+if(ENABLE_CUDA)
+  add_test("pocl_test_dlopen_device_cuda" "runtime/test_dlopen" "cuda")
+  set_property(TEST "pocl_version_check" APPEND PROPERTY DEPENDS "pocl_test_dlopen_device_cuda")
+endif()
+
+#######################################################################
+
 add_subdirectory("kernel")
 add_subdirectory("regression")
 add_subdirectory("runtime")
index 4dc9d9ddc49f170f923207a4320774b001e37358..4a9436a28cbd90427eab0a2779fbf049dd33dcfd 100644 (file)
 #=============================================================================
 
 
+# do not link test_dlopen with -lOpenCL
+add_executable("test_dlopen" "test_dlopen.c")
+target_link_libraries("test_dlopen" ${DL_LIB})
+
 set(PROGRAMS_TO_BUILD test_clFinish test_clGetDeviceInfo test_clGetEventInfo
   test_clCreateProgramWithBinary test_clGetSupportedImageFormats
   test_clSetEventCallback test_clEnqueueNativeKernel test_clBuildProgram
diff --git a/tests/runtime/test_dlopen.c b/tests/runtime/test_dlopen.c
new file mode 100644 (file)
index 0000000..be4bf5e
--- /dev/null
@@ -0,0 +1,63 @@
+/* Test that pocl libraries can be dlopen()ed
+
+   Copyright (c) 2021 pocl developers
+
+   Permission is hereby granted, free of charge, to any person obtaining a copy
+   of this software and associated documentation files (the "Software"), to
+   deal in the Software without restriction, including without limitation the
+   rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+   sell copies of the Software, and to permit persons to whom the Software is
+   furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included in
+   all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+   IN THE SOFTWARE.
+*/
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+int
+main (int argc, char **argv)
+{
+  int ret = 0;
+  const char *libpocl = "$ORIGIN/../../lib/CL/libpocl.so";
+  char libdevice[4096] = "";
+  if (argc > 1)
+    snprintf (libdevice, sizeof (libdevice),
+              "$ORIGIN/../../lib/CL/devices/%s/libpocl-devices-%s.so", argv[1],
+              argv[1]);
+
+  void *handle_libpocl = dlopen (libpocl, RTLD_NOW | RTLD_GLOBAL);
+  if (!handle_libpocl)
+    {
+      fprintf (stderr, "dlopen(%s, RTLD_NOW | RTLD_GLOBAL) failed: %s\n",
+               libpocl, dlerror ());
+      ret = 1;
+    }
+
+  if (ret == 0 && argc > 1)
+    {
+      void *handle_device = dlopen (libdevice, RTLD_NOW);
+      if (!handle_device)
+        {
+          fprintf (stderr, "dlopen(%s, RTLD_NOW) failed: %s\n", libdevice,
+                   dlerror ());
+          ret = 1;
+        }
+      if (handle_device)
+        dlclose (handle_device);
+    }
+
+  if (handle_libpocl)
+    dlclose (handle_libpocl);
+
+  return ret;
+}