From: Andreas Beckmann Date: Fri, 5 Feb 2021 15:23:39 +0000 (+0100) Subject: [PATCH 06/10] check whether libpocl and the device libraries can be dlopen()ed X-Git-Tag: archive/raspbian/1.6-5+rpi1^2~20 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b8ee7e47dd0c18f1cbf208bde00c39b94557bfeb;p=pocl.git [PATCH 06/10] check whether libpocl and the device libraries can be dlopen()ed Gbp-Pq: Name 0006-check-whether-libpocl-and-the-device-libraries-can-b.patch --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ed422d8..07648a0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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") diff --git a/tests/runtime/CMakeLists.txt b/tests/runtime/CMakeLists.txt index 4dc9d9d..4a9436a 100644 --- a/tests/runtime/CMakeLists.txt +++ b/tests/runtime/CMakeLists.txt @@ -24,6 +24,10 @@ #============================================================================= +# 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 index 0000000..be4bf5e --- /dev/null +++ b/tests/runtime/test_dlopen.c @@ -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 +#include + +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; +}