tests: Split out common code
diff --git a/tests/common.c b/tests/common.c
new file mode 100644
index 0000000..158a23d
--- /dev/null
+++ b/tests/common.c
@@ -0,0 +1,191 @@
+/*
+ * XGL
+ *
+ * Copyright (C) 2014 LunarG, Inc.
+ *
+ * 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 "common.h"
+
+void app_dev_init_formats(struct app_dev *dev)
+{
+    XGL_CHANNEL_FORMAT ch;
+    XGL_NUM_FORMAT num;
+
+    for (ch = 0; ch < XGL_MAX_CH_FMT; ch++) {
+        for (num = 0; num < XGL_MAX_NUM_FMT; num++) {
+            const XGL_FORMAT fmt = {
+                .channelFormat = ch,
+                .numericFormat = num,
+            };
+            XGL_RESULT err;
+            XGL_SIZE size;
+
+            err = xglGetFormatInfo(dev->obj, fmt,
+                                   XGL_INFO_TYPE_FORMAT_PROPERTIES,
+                                   &size, &dev->format_props[ch][num]);
+            if (err) {
+                memset(&dev->format_props[ch][num], 0,
+                       sizeof(dev->format_props[ch][num]));
+            }
+            else if (size != sizeof(dev->format_props[ch][num])) {
+                ERR_EXIT(XGL_ERROR_UNKNOWN);
+            }
+        }
+    }
+}
+
+void app_dev_init(struct app_dev *dev, struct app_gpu *gpu)
+{
+    XGL_DEVICE_CREATE_INFO info = {
+        .sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+        .pNext = NULL,
+        .queueRecordCount = 0,
+        .pRequestedQueues = NULL,
+        .extensionCount = 0,
+        .ppEnabledExtensionNames = NULL,
+        .maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE,
+        .flags = XGL_DEVICE_CREATE_VALIDATION_BIT,
+    };
+    XGL_RESULT err;
+    XGL_SIZE size;
+    XGL_UINT i;
+
+    /* XXX how to request queues? */
+
+    /* enable all extensions */
+    info.extensionCount = gpu->extension_count;
+    info.ppEnabledExtensionNames = gpu->extensions;
+
+    dev->gpu = gpu;
+    err = xglCreateDevice(gpu->obj, &info, &dev->obj);
+    if (err)
+        ERR_EXIT(err);
+
+    err = xglGetMemoryHeapCount(dev->obj, &dev->heap_count);
+    if (err)
+        ERR_EXIT(err);
+
+    dev->heap_props =
+            malloc(sizeof(dev->heap_props[0]) * dev->heap_count);
+    if (!dev->heap_props)
+        ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
+
+    for (i = 0; i < dev->heap_count; i++) {
+        err = xglGetMemoryHeapInfo(dev->obj, i,
+                                   XGL_INFO_TYPE_MEMORY_HEAP_PROPERTIES,
+                                   &size, &dev->heap_props[i]);
+        if (err || size != sizeof(dev->heap_props[0]))
+            ERR_EXIT(err);
+    }
+}
+
+void app_dev_destroy(struct app_dev *dev)
+{
+    free(dev->heap_props);
+    xglDestroyDevice(dev->obj);
+}
+
+void app_gpu_init_extensions(struct app_gpu *gpu)
+{
+    XGL_RESULT err;
+    XGL_UINT i;
+
+    static const XGL_CHAR *known_extensions[] = {
+        (const XGL_CHAR *) "some_extension",
+    };
+
+    for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
+        err = xglGetExtensionSupport(gpu->obj, known_extensions[i]);
+        if (!err)
+            gpu->extension_count++;
+    }
+
+    gpu->extensions =
+            malloc(sizeof(gpu->extensions[0]) * gpu->extension_count);
+    if (!gpu->extensions)
+        ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
+
+    gpu->extension_count = 0;
+    for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
+        err = xglGetExtensionSupport(gpu->obj, known_extensions[i]);
+        if (!err)
+            gpu->extensions[gpu->extension_count++] = known_extensions[i];
+    }
+}
+
+void app_gpu_init(struct app_gpu *gpu, XGL_UINT id, XGL_PHYSICAL_GPU obj)
+{
+    XGL_SIZE size;
+    XGL_RESULT err;
+    int i;
+
+    memset(gpu, 0, sizeof(*gpu));
+
+    gpu->id = id;
+    gpu->obj = obj;
+
+    err = xglGetGpuInfo(gpu->obj,
+                        XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES,
+                        &size, &gpu->props);
+    if (err || size != sizeof(gpu->props))
+        ERR_EXIT(err);
+
+    err = xglGetGpuInfo(gpu->obj,
+                        XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE,
+                        &size, &gpu->perf);
+    if (err || size != sizeof(gpu->perf))
+        ERR_EXIT(err);
+
+    /* get queue count */
+    err = xglGetGpuInfo(gpu->obj,
+                        XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
+                        &size, NULL);
+    if (err || size % sizeof(gpu->queue_props[0]))
+        ERR_EXIT(err);
+    gpu->queue_count = size / sizeof(gpu->queue_props[0]);
+
+    gpu->queue_props =
+            malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count);
+    if (!gpu->queue_props)
+        ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
+    err = xglGetGpuInfo(gpu->obj,
+                        XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
+                        &size, gpu->queue_props);
+    if (err || size != sizeof(gpu->queue_props[0]) * gpu->queue_count)
+        ERR_EXIT(err);
+
+    err = xglGetGpuInfo(gpu->obj,
+                        XGL_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES,
+                        &size, &gpu->memory_props);
+    if (err || size != sizeof(gpu->memory_props))
+        ERR_EXIT(err);
+
+    app_gpu_init_extensions(gpu);
+    app_dev_init(&gpu->dev, gpu);
+    app_dev_init_formats(&gpu->dev);
+}
+
+void app_gpu_destroy(struct app_gpu *gpu)
+{
+    app_dev_destroy(&gpu->dev);
+    free(gpu->extensions);
+}
+
diff --git a/tests/common.h b/tests/common.h
new file mode 100644
index 0000000..97db273
--- /dev/null
+++ b/tests/common.h
@@ -0,0 +1,134 @@
+/*
+ * XGL
+ *
+ * Copyright (C) 2014 LunarG, Inc.
+ *
+ * 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.
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <xgl.h>
+
+#define ERR(err) printf("%s:%d: failed with %s\n", \
+    __FILE__, __LINE__, xgl_result_string(err));
+
+#define ERR_EXIT(err) do { ERR(err); exit(-1); } while (0)
+
+#define ERR_MSG(msg) printf("%s:%d: failed with %s\n", \
+    __FILE__, __LINE__, msg);
+
+#define ERR_MSG_EXIT(err) do { ERR_MSG(err); exit(-1); } while (0)
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+#define MAX_GPUS 8
+
+struct app_dev {
+    struct app_gpu *gpu; /* point back to the GPU */
+
+    XGL_DEVICE obj;
+
+    XGL_UINT heap_count;
+    XGL_MEMORY_HEAP_PROPERTIES *heap_props;
+
+    XGL_FORMAT_PROPERTIES format_props[XGL_MAX_CH_FMT][XGL_MAX_NUM_FMT];
+};
+
+struct app_gpu {
+    XGL_UINT id;
+    XGL_PHYSICAL_GPU obj;
+
+    XGL_PHYSICAL_GPU_PROPERTIES props;
+    XGL_PHYSICAL_GPU_PERFORMANCE perf;
+
+    XGL_UINT queue_count;
+    XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *queue_props;
+
+    XGL_PHYSICAL_GPU_MEMORY_PROPERTIES memory_props;
+
+    XGL_UINT extension_count;
+    const XGL_CHAR **extensions;
+
+    struct app_dev dev;
+};
+
+static const char *xgl_result_string(XGL_RESULT err)
+{
+    switch (err) {
+#define STR(r) case r: return #r
+    STR(XGL_SUCCESS);
+    STR(XGL_UNSUPPORTED);
+    STR(XGL_NOT_READY);
+    STR(XGL_TIMEOUT);
+    STR(XGL_EVENT_SET);
+    STR(XGL_EVENT_RESET);
+    STR(XGL_ERROR_UNKNOWN);
+    STR(XGL_ERROR_UNAVAILABLE);
+    STR(XGL_ERROR_INITIALIZATION_FAILED);
+    STR(XGL_ERROR_OUT_OF_MEMORY);
+    STR(XGL_ERROR_OUT_OF_GPU_MEMORY);
+    STR(XGL_ERROR_DEVICE_ALREADY_CREATED);
+    STR(XGL_ERROR_DEVICE_LOST);
+    STR(XGL_ERROR_INVALID_POINTER);
+    STR(XGL_ERROR_INVALID_VALUE);
+    STR(XGL_ERROR_INVALID_HANDLE);
+    STR(XGL_ERROR_INVALID_ORDINAL);
+    STR(XGL_ERROR_INVALID_MEMORY_SIZE);
+    STR(XGL_ERROR_INVALID_EXTENSION);
+    STR(XGL_ERROR_INVALID_FLAGS);
+    STR(XGL_ERROR_INVALID_ALIGNMENT);
+    STR(XGL_ERROR_INVALID_FORMAT);
+    STR(XGL_ERROR_INVALID_IMAGE);
+    STR(XGL_ERROR_INVALID_DESCRIPTOR_SET_DATA);
+    STR(XGL_ERROR_INVALID_QUEUE_TYPE);
+    STR(XGL_ERROR_INVALID_OBJECT_TYPE);
+    STR(XGL_ERROR_UNSUPPORTED_SHADER_IL_VERSION);
+    STR(XGL_ERROR_BAD_SHADER_CODE);
+    STR(XGL_ERROR_BAD_PIPELINE_DATA);
+    STR(XGL_ERROR_TOO_MANY_MEMORY_REFERENCES);
+    STR(XGL_ERROR_NOT_MAPPABLE);
+    STR(XGL_ERROR_MEMORY_MAP_FAILED);
+    STR(XGL_ERROR_MEMORY_UNMAP_FAILED);
+    STR(XGL_ERROR_INCOMPATIBLE_DEVICE);
+    STR(XGL_ERROR_INCOMPATIBLE_DRIVER);
+    STR(XGL_ERROR_INCOMPLETE_COMMAND_BUFFER);
+    STR(XGL_ERROR_BUILDING_COMMAND_BUFFER);
+    STR(XGL_ERROR_MEMORY_NOT_BOUND);
+    STR(XGL_ERROR_INCOMPATIBLE_QUEUE);
+    STR(XGL_ERROR_NOT_SHAREABLE);
+#undef STR
+    default: return "UNKNOWN_RESULT";
+    }
+}
+
+void app_dev_init_formats(struct app_dev *dev);
+void app_dev_init(struct app_dev *dev, struct app_gpu *gpu);
+void app_dev_destroy(struct app_dev *dev);
+void app_gpu_init_extensions(struct app_gpu *gpu);
+void app_gpu_init(struct app_gpu *gpu, XGL_UINT id, XGL_PHYSICAL_GPU obj);
+void app_gpu_destroy(struct app_gpu *gpu);
+
+#endif // COMMON_H
diff --git a/tests/debug.h b/tests/debug.h
new file mode 100644
index 0000000..141a7e3
--- /dev/null
+++ b/tests/debug.h
@@ -0,0 +1,90 @@
+/*
+ * XGL
+ *
+ * Copyright (C) 2014 LunarG, Inc.
+ *
+ * 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.
+ *
+ * Many function below borrowed from Mesa u_debug.h
+ */
+
+#ifndef DEBUG_H
+#define DEBUG_H
+
+static inline void
+debug_printf(const char *format, ...)
+{
+#ifdef DEBUG
+   va_list ap;
+   va_start(ap, format);
+   _debug_vprintf(format, ap);
+   va_end(ap);
+#else
+   (void) format; /* silence warning */
+#endif
+}
+
+/**
+ * Assert macro
+ *
+ * Do not expect that the assert call terminates -- errors must be handled
+ * regardless of assert behavior.
+ *
+ * For non debug builds the assert macro will expand to a no-op, so do not
+ * call functions with side effects in the assert expression.
+ */
+#ifdef DEBUG
+#define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
+#else
+#define debug_assert(expr) do { } while (0 && (expr))
+#endif
+
+
+/** Override standard assert macro */
+#ifdef assert
+#undef assert
+#endif
+#define assert(expr) debug_assert(expr)
+
+
+/**
+ * Output the current function name.
+ */
+#ifdef DEBUG
+#define debug_checkpoint() \
+   _debug_printf("%s\n", __FUNCTION__)
+#else
+#define debug_checkpoint() \
+   ((void)0)
+#endif
+
+
+/**
+ * Output the full source code position.
+ */
+#ifdef DEBUG
+#define debug_checkpoint_full() \
+   _debug_printf("%s:%u:%s\n", __FILE__, __LINE__, __FUNCTION__)
+#else
+#define debug_checkpoint_full() \
+   ((void)0)
+#endif
+
+
+#endif // DEBUG_H
diff --git a/tests/xglAllocMemory.c b/tests/xglAllocMemory.c
new file mode 100644
index 0000000..313090d
--- /dev/null
+++ b/tests/xglAllocMemory.c
@@ -0,0 +1,119 @@
+/*
+ * XGL
+ *
+ * Copyright (C) 2014 LunarG, Inc.
+ *
+ * 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 "common.h"
+#include "debug.h"
+
+int main(int argc, char **argv)
+{
+    static const XGL_APPLICATION_INFO app_info = {
+        .sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO,
+        .pNext = NULL,
+        .pAppName = (const XGL_CHAR *) "xglCreateDevice",
+        .appVersion = 1,
+        .pEngineName = (const XGL_CHAR *) "xglCreateDevice",
+        .engineVersion = 1,
+        .apiVersion = XGL_MAKE_VERSION(0, 22, 0),
+    };
+    struct app_gpu gpus[MAX_GPUS];
+    XGL_PHYSICAL_GPU objs[MAX_GPUS];
+    XGL_UINT gpu_count, i, gpu_idx;
+    XGL_RESULT err;
+    XGL_MEMORY_ALLOC_INFO alloc_info;
+    XGL_GPU_MEMORY gpu_mem;
+
+    err = xglInitAndEnumerateGpus(&app_info, NULL,
+                                  MAX_GPUS, &gpu_count, objs);
+    if (err)
+        ERR_EXIT(err);
+
+    if (gpu_count <= 0) {
+        ERR_MSG_EXIT("No GPU avialable");
+    }
+
+    for (i = 0; i < gpu_count; i++) {
+        app_gpu_init(&gpus[i], i, objs[i]);
+    }
+
+    for (gpu_idx = 0; gpu_idx < gpu_count; gpu_idx++) {
+        if (gpus[gpu_idx].dev.heap_count > 0) {
+            memset(&alloc_info, 0, sizeof(alloc_info));
+
+//                XGL_STRUCTURE_TYPE                      sType;                      // Must be XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO
+            alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
+
+//                XGL_VOID*                               pNext;                      // Pointer to next structure
+//                XGL_GPU_SIZE                            allocationSize;             // Size of memory allocation
+//                XGL_GPU_SIZE                            alignment;
+//                XGL_FLAGS                               flags;                      // XGL_MEMORY_ALLOC_FLAGS
+//                XGL_UINT                                heapCount;
+//                XGL_UINT                                heaps[XGL_MAX_MEMORY_HEAPS];
+
+            alloc_info.allocationSize = 1024 * 1024; // 1MB
+            alloc_info.alignment = 0;
+            alloc_info.heapCount = 1;
+            alloc_info.heaps[0] = 0; // TODO: Reference other heaps
+
+// XGL_MEMORY_ALLOC_FLAGS
+//                XGL_MEMORY_HEAP_CPU_VISIBLE_BIT                         = 0x00000001,
+//                XGL_MEMORY_HEAP_CPU_GPU_COHERENT_BIT                    = 0x00000002,
+//                XGL_MEMORY_HEAP_CPU_UNCACHED_BIT                        = 0x00000004,
+//                XGL_MEMORY_HEAP_CPU_WRITE_COMBINED_BIT                  = 0x00000008,
+//                XGL_MEMORY_HEAP_HOLDS_PINNED_BIT                        = 0x00000010,
+//                XGL_MEMORY_HEAP_SHAREABLE_BIT                           = 0x00000020,
+            // TODO: Pick heap properties indicated by heap info
+            alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT;
+
+//   XGL_MEMORY_PRIORITY
+//                XGL_MEMORY_PRIORITY_UNUSED                              = 0x0,
+//                XGL_MEMORY_PRIORITY_VERY_LOW                            = 0x1,
+//                XGL_MEMORY_PRIORITY_LOW                                 = 0x2,
+//                XGL_MEMORY_PRIORITY_NORMAL                              = 0x3,
+//                XGL_MEMORY_PRIORITY_HIGH                                = 0x4,
+//                XGL_MEMORY_PRIORITY_VERY_HIGH                           = 0x5,
+
+//                XGL_MEMORY_PRIORITY_BEGIN_RANGE                         = XGL_MEMORY_PRIORITY_UNUSED,
+//                XGL_MEMORY_PRIORITY_END_RANGE                           = XGL_MEMORY_PRIORITY_VERY_HIGH,
+//                XGL_NUM_MEMORY_PRIORITY                                 = (XGL_MEMORY_PRIORITY_END_RANGE - XGL_MEMORY_PRIORITY_BEGIN_RANGE + 1),
+            // TODO: Try variety of memory priorities
+            alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
+
+            err = xglAllocMemory(gpus[gpu_idx].dev.obj, &alloc_info, &gpu_mem);
+            if (err)
+                ERR_EXIT(err);
+
+            err = xglFreeMemory(gpu_mem);
+            if (err)
+                ERR_EXIT(err);
+
+        } else {
+            debug_printf("No heaps available for GPU #%d: %s", gpu_idx, gpus[gpu_idx].props.gpuName);
+        }
+    }
+
+    for (i = 0; i < gpu_count; i++)
+        app_gpu_destroy(&gpus[i]);
+
+    return 0;
+}