1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <check.h>
#include "gpuarray/buffer.h"
#include "gpuarray/error.h"
char* dev_name = NULL;
int get_env_dev(const char **name, gpucontext_props *p) {
char *dev = NULL;
char *end;
long no;
int pl;
dev = dev_name;
if (dev == NULL) {
if ((dev = getenv("GPUARRAY_TEST_DEVICE")) == NULL) {
if ((dev = getenv("DEVICE")) == NULL) {
fprintf(stderr, "No device specified for testing, specify a device with DEVICE or GPUARRAY_TEST_DEVICE");
return -1;
}
}
}
if (strncmp(dev, "cuda", 4) == 0) {
*name = "cuda";
no = strtol(dev + 4, &end, 10);
if (end == dev || *end != '\0')
return -1;
if (no < 0 || no > INT_MAX)
return -1;
gpucontext_props_cuda_dev(p, (int)no);
return 0;
}
if (strncmp(dev, "opencl", 6) == 0) {
*name = "opencl";
no = strtol(dev + 6, &end, 10);
if (end == dev || *end != ':')
return -1;
if (no < 0 || no > 32768)
return -1;
pl = (int)no;
dev = end;
no = strtol(dev + 1, &end, 10);
if (end == dev || *end != '\0')
return -1;
if (no < 0 || no > 32768)
return -1;
gpucontext_props_opencl_dev(p, pl, (int)no);
return 0;
}
return -1;
}
gpucontext *ctx;
void setup(void) {
const char *name = NULL;
gpucontext_props *p;
ck_assert_int_eq(gpucontext_props_new(&p), GA_NO_ERROR);
ck_assert_int_eq(get_env_dev(&name, p), 0);
ck_assert_int_eq(gpucontext_init(&ctx, name, p), GA_NO_ERROR);
ck_assert_ptr_ne(ctx, NULL);
}
void teardown(void) {
gpucontext_deref(ctx);
ctx = NULL;
}
|