Add exceptions as errors in is_extension_available (#732)

is_extension_available is modified to handle errors by throwing
exceptions.

Contributes to #627

Change-Id: Ie9423df588892a0f8effa03d1cb48bf12400b983
Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>
diff --git a/test_common/harness/deviceInfo.cpp b/test_common/harness/deviceInfo.cpp
index aeb5607..7eb13bd 100644
--- a/test_common/harness/deviceInfo.cpp
+++ b/test_common/harness/deviceInfo.cpp
@@ -13,6 +13,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 //
+#include <stdexcept>
 #include "deviceInfo.h"
 #include "errorHelpers.h"
 #include "typeWrappers.h"
@@ -20,35 +21,23 @@
 /* Helper to allocate and return a buffer containing device information for the specified device info parameter. */
 static void *alloc_and_get_device_info( cl_device_id device, cl_device_info param_name, const char *param_description )
 {
-    void *buffer;
     size_t size = 0;
     int err;
 
     if ((err = clGetDeviceInfo(device, param_name, 0, NULL, &size)) != CL_SUCCESS)
     {
-        log_error("Error: failed to determine size of device %s at %s:%d (err = %d)\n",
-                  param_description, __FILE__, __LINE__, err);
-        return NULL;
+        throw std::runtime_error("clGetDeviceInfo failed\n");
     }
 
     if (0 == size)
         return NULL;
 
-    buffer = malloc(size);
-
-    if (NULL == buffer)
-    {
-        log_error("Error: unable to allocate %zu byte buffer for device %s at %s:%d (err = %d)\n",
-                  size, param_description, __FILE__, __LINE__,  err);
-        return NULL;
-    }
+    auto buffer = new uint8_t[size];
 
     if ((err = clGetDeviceInfo(device, param_name, size, buffer, NULL)) != CL_SUCCESS)
     {
-        free(buffer);
-        log_error( "Error: failed to obtain device %s at %s:%d (err = %d)\n",
-                   param_description, __FILE__, __LINE__, err );
-        return NULL;
+        delete [] buffer;
+        throw std::runtime_error("clGetDeviceInfo failed\n");
     }
 
     return buffer;
@@ -59,13 +48,6 @@
 {
     char *extString = alloc_and_get_device_extensions_string(device);
 
-    if (NULL == extString)
-    {
-        /* An error message will have already been printed by alloc_and_get_device_info(),
-         * so we can just return, here. */
-        return 0;
-    }
-
     BufferOwningPtr<char> extStringBuf(extString);
 
     return strstr(extString, extensionName) != NULL;
diff --git a/test_common/harness/kernelHelpers.cpp b/test_common/harness/kernelHelpers.cpp
index 34da3d2..cc2817d 100644
--- a/test_common/harness/kernelHelpers.cpp
+++ b/test_common/harness/kernelHelpers.cpp
@@ -359,8 +359,6 @@
     char *extensionsString = alloc_and_get_device_extensions_string(device);
     if ( NULL == extensionsString )
     {
-        /* An error message will have already been printed by alloc_and_get_device_info(),
-         * so we can just return, here. */
         return -1;
     }
 
@@ -369,8 +367,6 @@
     char *versionString = alloc_and_get_device_version_string(device);
     if ( NULL == versionString )
     {
-        /* An error message will have already been printed by alloc_and_get_device_info(),
-         * so we can just return, here. */
         return -1;
     }
 
@@ -379,17 +375,15 @@
     std::ostringstream clDeviceInfoStream;
     std::string file_type = get_offline_compilation_file_type_str(compilationMode);
     clDeviceInfoStream << "# OpenCL device info affecting " << file_type << " offline compilation:" << std::endl
-                       << "CL_DEVICE_ADDRESS_BITS=" << device_address_space_size << std::endl
-                       << "CL_DEVICE_EXTENSIONS=\"" << extensionsString << "\"" << std::endl;
+                    << "CL_DEVICE_ADDRESS_BITS=" << device_address_space_size << std::endl
+                    << "CL_DEVICE_EXTENSIONS=\"" << extensionsString << "\"" << std::endl;
     /* We only need the device's supported IL version(s) when compiling IL
-     * that will be loaded with clCreateProgramWithIL() */
+    * that will be loaded with clCreateProgramWithIL() */
     if (compilationMode == kSpir_v)
     {
         char *ilVersionString = alloc_and_get_device_il_version_string(device);
         if ( NULL == ilVersionString )
         {
-            /* An error message will have already been printed by alloc_and_get_device_info(),
-             * so we can just return, here. */
             return -1;
         }
 
@@ -400,6 +394,7 @@
     clDeviceInfoStream << "CL_DEVICE_VERSION=\"" << versionString << "\"" << std::endl;
 
     clDeviceInfo = clDeviceInfoStream.str();
+
     return CL_SUCCESS;
 }