From 39dc3ff40b6ab52d776af4a1e0f8faee31d4ea00 Mon Sep 17 00:00:00 2001 From: Vincent Danjean Date: Mon, 8 Jun 2015 01:03:22 +0200 Subject: [PATCH] Fix and improve testsuite Run through our ICD loader (or the system ICD Loader when updating the database) is now using the whole prototypes of OpenCL functions. And, when testing our ICD Loader, the result is matched against what is expected. --- Makefile.am | 8 +++++++ icd_generator.rb | 48 +++++++++++++++++++++++++++---------- libdummy_icd.c | 16 ++++++++++--- ocl_icd_loader.c | 2 +- tests/testsuite-standard.at | 6 ++++- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/Makefile.am b/Makefile.am index e497438..845e89d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -114,6 +114,8 @@ nodist_run_dummy_icd_through_our_ICDL_SOURCES = \ run_dummy_icd_through_our_ICDL_CFLAGS= $(NO_DEPRECATED_DECLARATIONS_FLAGS) $(AM_CFLAGS) # we want to link to our implementation here run_dummy_icd_through_our_ICDL_LDADD = libOpenCL.la +# +run_dummy_icd_through_our_ICDL_CPPFLAGS = $(AM_CPPFLAGS) -DOCL_ICD_PRINT_EXPECTED ################################################################## # rules to update the database from an already installed ICD Loader @@ -133,6 +135,12 @@ run_dummy_icd_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o # run the test program and update the database run_dummy_icd_output.yaml: run_dummy_icd install_test_lib libdummycl.la "$$(dirname $<)/$$(basename $<)" > $@ + @if grep -v -E '^(---|([0-9]* *: .*))$$' $@ ; then \ + echo "Invalid $@ file, trying to fix it" ; \ + grep -E '^(---|([0-9]* *: .*))$$' $@ > $@.fix ;\ + mv $@.fix $@ ;\ + fi + CLEANFILES += run_dummy_output.yaml .PHONY: update-database update-database: icd_generator.rb run_dummy_icd_output.yaml diff --git a/icd_generator.rb b/icd_generator.rb index 3c3f0a8..28faceb 100644 --- a/icd_generator.rb +++ b/icd_generator.rb @@ -28,14 +28,17 @@ require 'yaml' module IcdGenerator $api_entries = {} + $key_entries = {} $api_entries_array = [] $cl_objects = ["platform_id", "device_id", "context", "command_queue", "mem", "program", "kernel", "event", "sampler"] $know_entries = { 1 => "clGetPlatformInfo", 0 => "clGetPlatformIDs", 2 => "clGetDeviceIDs" } $use_name_in_test = { 1 => "clGetPlatformInfo", 0 => "clGetPlatformIDs", 2 => "clGetDeviceIDs" } # do not call these functions when trying to discover the mapping - $forbidden_funcs = ["clGetExtensionFunctionAddress", "clGetPlatformIDs", - "clGetPlatformInfo", "clGetGLContextInfoKHR", "clUnloadCompiler", - "clSetCommandQueueProperty", "clGetDeviceIDs"] + $forbidden_funcs = [ + "clUnloadCompiler", # No parameters so no way to forward to an ICD, OpenCL 1.0 + "clGetPlatformIDs", # Implemented directly within the ICD Loader, not forwarded to ICD + ] + # windows function to ignore when loading the database $windows_funcs = ["clGetDeviceIDsFromD3D10KHR", "clCreateFromD3D10BufferKHR", "clCreateFromD3D10Texture2DKHR", "clCreateFromD3D10Texture3DKHR", "clEnqueueAcquireD3D10ObjectsKHR", "clEnqueueReleaseD3D10ObjectsKHR", @@ -141,6 +144,7 @@ EOF version = value.match(/SUFFIX__VERSION_(\d_\d)/m)[1] $versions_entries[version].push(entry_name) $known_entries[key] = entry_name + $key_entries[entry_name] = key $api_entries[entry_name] = value } $api_entries_array = [] @@ -228,9 +232,12 @@ EOF run_dummy_icd += self.include_headers run_dummy_icd += "#pragma GCC diagnostic pop\n" run_dummy_icd += "\n\n" - run_dummy_icd += "typedef CL_API_ENTRY cl_int (CL_API_CALL* oclFuncPtr_fn)(cl_platform_id platform);\n\n" + $api_entries.each_key { |func_name| + next if $forbidden_funcs.include?(func_name) + run_dummy_icd += $api_entries[func_name]+";\n" + } + run_dummy_icd += "\n\n" run_dummy_icd += "void call_all_OpenCL_functions(cl_platform_id chosen_platform) {\n" - run_dummy_icd += " oclFuncPtr_fn oclFuncPtr;\n" run_dummy_icd += " cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)chosen_platform, 0 };\n" $api_entries.each_key { |func_name| next if $forbidden_funcs.include?(func_name) @@ -242,15 +249,32 @@ EOF run_dummy_icd += " #{func_name}(properties,CL_DEVICE_TYPE_CPU,NULL,NULL,NULL);\n" elsif func_name == "clWaitForEvents" then run_dummy_icd += " #{func_name}(1,(cl_event*)&chosen_platform);\n" - elsif func_name == "clGetExtensionFunctionAddressForPlatform" then - run_dummy_icd += " #{func_name}((cl_platform_id)chosen_platform, \"clIcdGetPlatformIDsKHR\");\n" - elsif func_name == "clGetDeviceIDs" then - run_dummy_icd += " #{func_name}((cl_platform_id)chosen_platform,0,0,NULL,NULL);\n" + elsif func_name == "clGetExtensionFunctionAddress" then + run_dummy_icd += " #{func_name}(\"extLIG\");\n" + elsif func_name == "clUnloadCompiler" then + run_dummy_icd += " #{func_name}();\n" else - run_dummy_icd += " oclFuncPtr = (oclFuncPtr_fn)" + func_name + ";\n" - run_dummy_icd += " oclFuncPtr(chosen_platform);\n" + params = $api_entries[func_name].gsub(/[[:space:]]+/, ' ') + params.gsub!(/[\/][*](([^*]*)[*][^\/])*[^*]*[*][\/]/,'') + params.gsub!(/^[^(]*[(] *(.*[^ ]) *[)][^)]*$/, '\1') + params = params.gsub(/[^,(]+([(][^)]*[)])*[^,]*/) { |p| + p.gsub!("[]", "*") + p.gsub!("user_func", "") + if false && p.match(/[*]/) then + "NULL" + else + "(#{p})0" + end + } + if func_name != "clGetPlatformIDs" then + params.gsub!(/^([^0]*)0/, '\1chosen_platform') + end + run_dummy_icd += " #{func_name}(#{params});\n" end - run_dummy_icd += " printf(\"%s\\n\", \"#{func_name}\");" + run_dummy_icd += " printf(\"%s\\n\", \"#{func_name}\");\n" + run_dummy_icd += "#ifdef OCL_ICD_PRINT_EXPECTED\n" + run_dummy_icd += " printf(\"#{$key_entries[func_name]} : %s (expected)\\n\", \"#{func_name}\");\n" + run_dummy_icd += "#endif\n" run_dummy_icd += " fflush(NULL);\n" } run_dummy_icd += " return;\n}\n" diff --git a/libdummy_icd.c b/libdummy_icd.c index 1ee3a91..b470f1b 100644 --- a/libdummy_icd.c +++ b/libdummy_icd.c @@ -97,6 +97,9 @@ CL_API_ENTRY void * CL_API_CALL INTclGetExtensionFunctionAddress( debug(D_LOG, "request address for %s", func_name); if( func_name != NULL && strcmp("clIcdGetPlatformIDsKHR", func_name) == 0 ) return (void *)_GetPlatformIDs; + if (func_name != NULL && strcmp("extLIG", func_name) == 0) { + printf("65 : "); + } return NULL; } SYMB(clGetExtensionFunctionAddress); @@ -115,6 +118,10 @@ CL_API_ENTRY cl_int CL_API_CALL INTclGetPlatformInfo( debug_trace(); debug(D_LOG, "request info for 0x%x", param_name); + if (param_name==0 && param_value_size==0 + && param_value==NULL && param_value_size_ret==NULL) { + printf("1 : "); + } char cl_platform_profile[] = "FULL_PROFILE"; char cl_platform_version[] = "OpenCL 1.2"; char cl_platform_name[] = "DummyCL" ICD_SUFFIX; @@ -195,17 +202,20 @@ INTclGetDeviceIDs(cl_platform_id pid /* platform */, cl_device_id * devid /* devices */, cl_uint * res /* num_devices */) CL_API_SUFFIX__VERSION_1_0 { + if (ctype==0 && num==0 && devid==NULL && res==NULL) { + printf("2 : "); + } char* ENVNAME=NULL; if (res == NULL) { return CL_SUCCESS; } switch (ctype) { case CL_DEVICE_TYPE_GPU: - ENVNAME="NB_GPU"; + ENVNAME="NB_GPU" ICD_SUFFIX; break; case CL_DEVICE_TYPE_CPU: - ENVNAME="NB_CPU"; + ENVNAME="NB_CPU" ICD_SUFFIX; break; case CL_DEVICE_TYPE_ALL: - ENVNAME="NB_ALL"; + ENVNAME="NB_ALL" ICD_SUFFIX; break; } if (ENVNAME==NULL) { diff --git a/ocl_icd_loader.c b/ocl_icd_loader.c index 9628ace..88ba703 100644 --- a/ocl_icd_loader.c +++ b/ocl_icd_loader.c @@ -270,7 +270,7 @@ static void* _get_function_addr(void* dlh, clGetExtensionFunctionAddress_fn fn, } #ifdef DEBUG_OCL_ICD if (addr1 && addr2 && addr1!=addr2) { - debug(D_WARN, "Function and symbol '%s' have different addresses!", name); + debug(D_WARN, "Function and symbol '%s' have different addresses (%p != %p)!", name, addr2, addr1); } #endif } diff --git a/tests/testsuite-standard.at b/tests/testsuite-standard.at index cf515ad..930bc1a 100644 --- a/tests/testsuite-standard.at +++ b/tests/testsuite-standard.at @@ -35,10 +35,14 @@ ocl-icd ICD test AT_CLEANUP AT_SETUP([Our dummy ICD through our ICD loader]) -AT_EXPORT([OCL_ICD_DEBUG],[15], +AT_EXPORT([OCL_ICD_DEBUG],[7], [OCL_ICD_VENDORS],[$abs_top_builddir/vendors]) AT_CHECK([run_dummy_icd_through_our_ICDL], 0, [stdout], [stderr]) AT_CHECK([grep "^-1" stdout | sort], 0, []) +AT_CHECK([grep -v '^[[0-9]]* *:' stdout ], 0, [--- +]) +AT_CHECK([sed -e "s/ *(expected)//" stdout | uniq -c | grep -v '^ *2 ' ], 0, [ 1 --- +]) AT_CLEANUP AT_SETUP([ICD Loader extension]) -- 2.32.0.93.g670b81a890