void ShaderAPITest::test_uniform_size_type1(const char *glslType, GLenum glType, const char *el) { char buffer[1024]; GLuint program; GLint active, i; //printf(" Running subtest %s\n", glslType); //fflush(stdout); sprintf(buffer, "#version 120\nuniform %s m[60];\nvoid main() { gl_Position[0] = m[59]%s; }\n", glslType, el); program = make_program(buffer, NULL); glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &active); assert_no_error(); for (i = 0; i < active; i++) { GLint size = -1; GLenum type = 0; glGetActiveUniform(program, i, sizeof(buffer), NULL, &size, &type, buffer); assert_no_error(); assert(type == glType); assert(size == 60); if (strncmp(buffer, "m", 1) == 0) break; } }
void ShaderAPITest::test_attrib_size_type1(const char *glslType, GLenum glType, const char *el) { char buffer[1024]; GLuint program; GLint active, i; //printf(" Running subtest %s\n", glslType); //fflush(stdout); sprintf(buffer, "#version 120\nattribute %s m;\nvoid main() { gl_Position[0] = m%s; }\n", glslType, el); program = make_program(buffer, NULL); glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active); assert_no_error(); for (i = 0; i < active; i++) { GLint size = -1; GLenum type = 0; glGetActiveAttrib(program, i, sizeof(buffer), NULL, &size, &type, buffer); assert_no_error(); assert(type == glType); assert(size == 1); if (strncmp(buffer, "m", 1) == 0) break; } assert(i < active); /* Otherwise the compiler optimised it out */ }
GLuint ShaderAPITest::make_shader(GLenum type, const char *src) { GLuint id; assert_no_error(); id = glCreateShader(type); glShaderSource(id, 1, &src, NULL); glCompileShader(id); check_compile_status(id); assert_no_error(); return id; }
void ShaderAPITest::test_uniform_array_overflow(void) { GLuint program; GLint location; GLfloat data[128]; program = make_program("#version 120\nuniform vec2 x[10];\nvoid main() { gl_Position.xy = x[9]; }\n", NULL); location = glGetUniformLocation(program, "x"); assert_no_error(); glUniform2fv(location, 64, data); assert_no_error(); }
void ShaderAPITest::test_uniform_multiple_samplers(void) { GLuint program; GLint location; GLint values[2] = {0, 1}; assert_no_error(); program = make_program(NULL, "uniform sampler2D s[2];\nvoid main() { gl_FragColor = texture2D(s[1], vec2(0.0, 0.0)); }\n"); location = glGetUniformLocation_func(program, "s[0]"); assert(location != -1); assert_no_error(); glUniform1iv_func(location, 2, values); assert_no_error(); }
void hblas_dgemv(const enum HBLAS_ORDER Order, const enum HBLAS_TRANSPOSE trans, const int M, const int N, const double a, const double *A, const int lda, const double *x, const int incx, const double b, double *y, const int incy) { bool t = false; switch (trans) { case HblasNoTrans: t = false; break; case HblasConjTrans: case HblasTrans: t = true; break; }; buffer_t buff_A, buff_x, buff_y; init_matrix_buffer(M, N, A, lda, &buff_A); if (t) { init_vector_buffer(M, x, incx, &buff_x); init_vector_buffer(N, y, incy, &buff_y); } else { init_vector_buffer(N, x, incx, &buff_x); init_vector_buffer(M, y, incy, &buff_y); } assert_no_error(halide_dgemv(t, a, &buff_A, &buff_x, b, &buff_y)); }
static void setup (Fixture *f, gconstpointer data) { if (!dbus_threads_init_default ()) g_error ("OOM"); f->loop = _dbus_loop_new (); g_assert (f->loop != NULL); dbus_error_init (&f->e); f->server = dbus_server_listen ("tcp:host=127.0.0.1", &f->e); assert_no_error (&f->e); g_assert (f->server != NULL); if (!dbus_connection_allocate_data_slot (&connection_slot)) g_error ("OOM"); if (!dbus_server_allocate_data_slot (&server_slot)) g_error ("OOM"); if (!dbus_message_allocate_data_slot (&message_slot)) g_error ("OOM"); if (!dbus_pending_call_allocate_data_slot (&pending_call_slot)) g_error ("OOM"); }
void hblas_scopy(const int N, const float *x, const int incx, float *y, const int incy) { buffer_t buff_x, buff_y; init_vector_buffer(N, x, incx, &buff_x); init_vector_buffer(N, y, incy, &buff_y); assert_no_error(halide_scopy(&buff_x, &buff_y)); }
void hblas_dcopy(const int N, const double *x, const int incx, double *y, const int incy) { buffer_t buff_x, buff_y; init_vector_buffer(N, x, incx, &buff_x); init_vector_buffer(N, y, incy, &buff_y); assert_no_error(halide_dcopy(&buff_x, &buff_y)); }
static void setup_connection (Fixture *f, gconstpointer data) { char *address; setup (f, data); dbus_server_set_new_connection_function (f->server, new_conn_cb, f, NULL); if (!test_server_setup (f->loop, f->server)) g_error ("failed to set up server"); address = dbus_server_get_address (f->server); g_assert (address != NULL); f->connection = dbus_connection_open_private (address, &f->e); assert_no_error (&f->e); g_assert (f->connection != NULL); dbus_free (address); if (!test_connection_setup (f->loop, f->connection)) g_error ("failed to set up connection"); while (f->server_connection == NULL) _dbus_loop_iterate (f->loop, TRUE); test_connection_shutdown (f->loop, f->connection); test_server_shutdown (f->loop, f->server); }
int pflash_cfi01_fdt_init(char *node_path, FDTMachineInfo *fdti, void *opaque) { hwaddr flash_base = 0; int flash_size = 0; Error *errp = NULL; int be = *((int *)opaque); DriveInfo *dinfo; int bank_width; flash_base = qemu_devtree_getprop_cell(fdti->fdt, node_path, "reg", 0, false, &errp); flash_base += fdt_get_parent_base(node_path, fdti); flash_size = qemu_devtree_getprop_cell(fdti->fdt, node_path, "reg", 1, false, &errp); bank_width = qemu_devtree_getprop_cell(fdti->fdt, node_path, "bank-width", 0, false, &errp); assert_no_error(errp); printf("FDT: FLASH: baseaddr: 0x%"HWADDR_PRIX", size: 0x%x\n", flash_base, flash_size); dinfo = drive_get_next(IF_PFLASH); pflash_cfi01_register(flash_base, NULL, node_path, flash_size, dinfo ? dinfo->bdrv : NULL, FLASH_SECTOR_SIZE, flash_size/FLASH_SECTOR_SIZE, bank_width, 0x89, 0x18, 0x0000, 0x0, be); return 0; }
static int uart16550_fdt_init(char *node_path, FDTMachineInfo *fdti, void *priv) { /* FIXME: Pass in dynamically */ MemoryRegion *address_space_mem = get_system_memory(); hwaddr base; int baudrate; qemu_irq irqline; char irq_info[1024]; Error *errp = NULL; base = qemu_devtree_getprop_cell(fdti->fdt, node_path, "reg", 0, false, &errp); base += qemu_devtree_getprop_cell(fdti->fdt, node_path, "reg-offset", 0, false, &errp); assert_no_error(errp); base &= ~3ULL; /* qemu uart16550 model starts with 3* 8bit offset */ baudrate = qemu_devtree_getprop_cell(fdti->fdt, node_path, "current-speed", 0, false, &errp); if (errp) { baudrate = 115200; } irqline = fdt_get_irq_info(fdti, node_path, 0 , NULL, irq_info); printf("FDT: UART16550a: baseaddr: 0x" TARGET_FMT_plx ", irq: %s, baud %d\n", base, irq_info, baudrate); /* it_shift = 2, reg-shift in DTS - for Xilnx IP is hardcoded */ (void) serial_mm_init(address_space_mem, base, 2, irqline, baudrate, qemu_char_get_next_serial(), DEVICE_LITTLE_ENDIAN); return 0; }
double hblas_dnrm2(const int N, const double *x, const int incx) { double result; buffer_t buff_x, buff_nrm; init_vector_buffer(N, x, incx, &buff_x); init_scalar_buffer(&result, &buff_nrm); assert_no_error(halide_ddot(&buff_x, &buff_x, &buff_nrm)); return std::sqrt(result); }
float hblas_sasum(const int N, const float *x, const int incx) { float result; buffer_t buff_x, buff_sum; init_vector_buffer(N, x, incx, &buff_x); init_scalar_buffer(&result, &buff_sum); assert_no_error(halide_sasum(&buff_x, &buff_sum)); return result; }
void ShaderAPITest::test_uniform_neg_location(void) { GLuint program; GLfloat data[4]; program = make_program("#version 110\nvoid main() { gl_Position = vec4(1.0, 1.0, 1.0, 1.0); }\n", NULL); assert_no_error(); glUniform1i_func(-1, 1); assert_no_error(); glUniform1i_func(-200, 1); assert_error(GL_INVALID_OPERATION); glUniformMatrix2fv_func(-1, 1, GL_FALSE, data); assert_no_error(); glUniformMatrix2fv_func(-200, 1, GL_FALSE, data); assert_error(GL_INVALID_OPERATION); }
float hblas_snrm2(const int N, const float *x, const int incx) { float result; buffer_t buff_x, buff_nrm; init_vector_buffer(N, x, incx, &buff_x); init_scalar_buffer(&result, &buff_nrm); assert_no_error(halide_sdot(&buff_x, &buff_x, &buff_nrm)); return std::sqrt(result); }
double hblas_dasum(const int N, const double *x, const int incx) { double result; buffer_t buff_x, buff_sum; init_vector_buffer(N, x, incx, &buff_x); init_scalar_buffer(&result, &buff_sum); assert_no_error(halide_dasum(&buff_x, &buff_sum)); return result; }
void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value) { Error *errp = NULL; assert(!value || value->name); object_property_set_str(OBJECT(dev), value ? value->name : "", name, &errp); assert_no_error(errp); }
void ShaderAPITest::test_uniform_bool_conversion(void) { GLuint program; GLint location; GLint value[16]; /* in case glGetUniformiv goes nuts on the stack */ assert_no_error(); program = make_program("uniform bool b;\nvoid main() { gl_Position.x = b ? 1.5 : 0.5; }\n", NULL); location = glGetUniformLocation(program, "b"); assert(location != -1); assert_no_error(); glUniform1i(location, 5); assert_no_error(); glGetUniformiv(program, location, &value[0]); assert_no_error(); assert(value[0] == 1); }
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value) { Error *errp = NULL; assert(!value || value->label); object_property_set_str(OBJECT(dev), value ? value->label : "", name, &errp); assert_no_error(errp); }
float hblas_sdot(const int N, const float *x, const int incx, const float *y, const int incy) { float result; buffer_t buff_x, buff_y, buff_dot; init_vector_buffer(N, x, incx, &buff_x); init_vector_buffer(N, y, incy, &buff_y); init_scalar_buffer(&result, &buff_dot); assert_no_error(halide_sdot(&buff_x, &buff_y, &buff_dot)); return result; }
static DBusConnection * connect_to_bus (const gchar *address) { DBusConnection *conn; DBusError error = DBUS_ERROR_INIT; dbus_bool_t ok; conn = dbus_connection_open_private (address, &error); assert_no_error (&error); g_assert (conn != NULL); ok = dbus_bus_register (conn, &error); assert_no_error (&error); g_assert (ok); g_assert (dbus_bus_get_unique_name (conn) != NULL); dbus_connection_setup_with_g_main (conn, NULL); return conn; }
double hblas_ddot(const int N, const double *x, const int incx, const double *y, const int incy) { double result; buffer_t buff_x, buff_y, buff_dot; init_vector_buffer(N, x, incx, &buff_x); init_vector_buffer(N, y, incy, &buff_y); init_scalar_buffer(&result, &buff_dot); assert_no_error(halide_ddot(&buff_x, &buff_y, &buff_dot)); return result; }
void ShaderAPITest::test_uniform_scalar_count(void) { GLuint program; GLint location; GLfloat data[128]; program = make_program("#version 110\nuniform vec2 x;\nvoid main() { gl_Position.xy = x; }\n", NULL); location = glGetUniformLocation(program, "x"); assert_no_error(); glUniform2fv(location, 64, data); assert_error(GL_INVALID_OPERATION); }
GLuint ShaderAPITest::make_program(const char *vs_src, const char *fs_src) { GLuint id, vs, fs; assert_no_error(); id = glCreateProgram(); if (vs_src) { vs = make_shader(GL_VERTEX_SHADER, vs_src); glAttachShader(id, vs); glDeleteShader(vs); } if (fs_src) { fs = make_shader(GL_FRAGMENT_SHADER, fs_src); glAttachShader(id, fs); glDeleteShader(fs); } glLinkProgram(id); check_link_status(id); glUseProgram(id); glDeleteProgram(id); assert_no_error(); return id; }
static void setup (Fixture *f, gconstpointer data) { if (!dbus_threads_init_default ()) g_error ("OOM"); f->n_threads = N_THREADS; f->n_refs = N_REFS; // wine sets WINESERVERSOCKET for its child processes automatically if (g_getenv ("WINESERVERSOCKET") != NULL) { /* Our reference-counting is really slow under Wine (it involves * IPC to wineserver). Do fewer iterations: enough to demonstrate * that it works, rather than a performance test. */ f->n_threads = 10; f->n_refs = 10; } f->loop = _dbus_loop_new (); g_assert (f->loop != NULL); dbus_error_init (&f->e); f->server = dbus_server_listen ("tcp:host=127.0.0.1", &f->e); assert_no_error (&f->e); g_assert (f->server != NULL); if (!dbus_connection_allocate_data_slot (&connection_slot)) g_error ("OOM"); if (!dbus_server_allocate_data_slot (&server_slot)) g_error ("OOM"); if (!dbus_message_allocate_data_slot (&message_slot)) g_error ("OOM"); if (!dbus_pending_call_allocate_data_slot (&pending_call_slot)) g_error ("OOM"); }
void hblas_dgemm(const enum HBLAS_ORDER Order, const enum HBLAS_TRANSPOSE TransA, const enum HBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const double alpha, const double *A, const int lda, const double *B, const int ldb, const double beta, double *C, const int ldc) { bool tA = false, tB = false; switch (TransA) { case HblasNoTrans: tA = false; break; case HblasConjTrans: case HblasTrans: tA = true; break; }; switch (TransB) { case HblasNoTrans: tB = false; break; case HblasConjTrans: case HblasTrans: tB = true; break; }; buffer_t buff_A, buff_B, buff_C; if (!tA) { init_matrix_buffer(M, K, A, lda, &buff_A); } else { init_matrix_buffer(K, M, A, lda, &buff_A); } if (!tB) { init_matrix_buffer(K, N, B, ldb, &buff_B); } else { init_matrix_buffer(N, K, B, ldb, &buff_B); } init_matrix_buffer(M, N, C, ldc, &buff_C); assert_no_error(halide_dgemm(tA, tB, alpha, &buff_A, &buff_B, beta, &buff_C)); }
void hblas_dscal(const int N, const double a, double *x, const int incx) { buffer_t buff_x; init_vector_buffer(N, x, incx, &buff_x); assert_no_error(halide_dscal(a, &buff_x)); }
void hblas_sscal(const int N, const float a, float *x, const int incx) { buffer_t buff_x; init_vector_buffer(N, x, incx, &buff_x); assert_no_error(halide_sscal(a, &buff_x)); }
static int fdt_init_qdev(char *node_path, FDTMachineInfo *fdti, char *compat) { int err; qemu_irq irq; hwaddr base; int offset; DeviceState *dev; char *dev_type = NULL; int is_intc; Error *errp = NULL; int i; dev = fdt_create_qdev_from_compat(compat, &dev_type); if (!dev) { DB_PRINT("no match found for %s\n", compat); return 1; } /* FIXME: attach to the sysbus instead */ object_property_add_child(container_get(qdev_get_machine(), "/unattached"), qemu_devtree_get_node_name(fdti->fdt, node_path), OBJECT(dev), NULL); fdt_init_set_opaque(fdti, node_path, dev); /* connect nic if appropriate */ static int nics; if (object_property_find(OBJECT(dev), "mac", NULL)) { qdev_set_nic_properties(dev, &nd_table[nics]); if (nd_table[nics].instantiated) { DB_PRINT("NIC instantiated: %s\n", dev_type); nics++; } } offset = fdt_path_offset(fdti->fdt, node_path); for (offset = fdt_first_property_offset(fdti->fdt, offset); offset != -FDT_ERR_NOTFOUND; offset = fdt_next_property_offset(fdti->fdt, offset)) { const char *propname; int len; const void *val = fdt_getprop_by_offset(fdti->fdt, offset, &propname, &len); propname = trim_vendor(propname); ObjectProperty *p = object_property_find(OBJECT(dev), propname, NULL); if (p) { DB_PRINT("matched property: %s of type %s, len %d\n", propname, p->type, len); } if (!p) { continue; } /* FIXME: handle generically using accessors and stuff */ if (!strcmp(p->type, "uint8") || !strcmp(p->type, "uint16") || !strcmp(p->type, "uint32") || !strcmp(p->type, "uint64")) { uint64_t offset = (!strcmp(propname, "reg")) ? fdt_get_parent_base(node_path, fdti) : 0; object_property_set_int(OBJECT(dev), get_int_be(val, len) + offset, propname, &errp); assert_no_error(errp); DB_PRINT("set property %s to %#llx\n", propname, (long long unsigned int)get_int_be(val, len)); } else if (!strcmp(p->type, "bool")) { object_property_set_bool(OBJECT(dev), !!get_int_be(val, len), propname, &errp); assert_no_error(errp); DB_PRINT("set property %s to %#llx\n", propname, (long long unsigned int)get_int_be(val, len)); } else if (!strncmp(p->type, "link", 4)) { char target_node_path[DT_PATH_LENGTH]; DeviceState *linked_dev; if (qemu_devtree_get_node_by_phandle(fdti->fdt, target_node_path, get_int_be(val, len))) { abort(); } while (!fdt_init_has_opaque(fdti, target_node_path)) { fdt_init_yield(fdti); } linked_dev = fdt_init_get_opaque(fdti, target_node_path); object_property_set_link(OBJECT(dev), OBJECT(linked_dev), propname, &errp); assert_no_error(errp); } else if (!strcmp(p->type, "string")) { object_property_set_str(OBJECT(dev), strndup(val, len), propname, &errp); } } qdev_init_nofail(dev); /* map slave attachment */ base = qemu_devtree_getprop_cell(fdti->fdt, node_path, "reg", 0, false, &errp); assert_no_error(errp); base += fdt_get_parent_base(node_path, fdti); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); { int len; fdt_get_property(fdti->fdt, fdt_path_offset(fdti->fdt, node_path), "interrupt-controller", &len); is_intc = len >= 0; DB_PRINT("is interrupt controller: %c\n", is_intc ? 'y' : 'n'); } /* connect irq */ for (i = 0; ; ++i) { char irq_info[1024]; irq = fdt_get_irq_info(fdti, node_path, i, &err, irq_info); /* INTCs inferr their top level, if no IRQ connection specified */ if (err && is_intc) { irq = fdti->irq_base[0]; sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq); fprintf(stderr, "FDT: (%s) connected top level irq %s\n", dev_type, irq_info); break; } if (!err) { sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); fprintf(stderr, "FDT: (%s) connected irq %s\n", dev_type, irq_info); } else { break; } } if (dev_type) { g_free(dev_type); } return 0; }