vtest: start adding vtest framework

The idea is to have a unix socket and possible shmem protocol
between a renderering server and local gallium sw driver.

This could be used to validate virgl without qemu with piglit.
macos/master
Marc-André Lureau 10 years ago committed by Dave Airlie
parent e9ca2d4ad3
commit 0b27e44304
  1. 2
      Makefile.am
  2. 1
      configure.ac
  3. 19
      vtest/Makefile.am
  4. 8
      vtest/vtest.h
  5. 40
      vtest/vtest_renderer.c
  6. 104
      vtest/vtest_server.c

@ -19,7 +19,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
SUBDIRS = src tests
SUBDIRS = src vtest tests
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = virglrenderer.pc

@ -96,6 +96,7 @@ AC_CONFIG_FILES([
Makefile
src/Makefile
src/gallium/auxiliary/Makefile
vtest/Makefile
tests/Makefile
])
AC_OUTPUT

@ -0,0 +1,19 @@
AM_CFLAGS = \
-I$(top_srcdir)/src/gallium/drivers/virgl \
-I$(top_srcdir)/src/gallium/include \
-I$(top_srcdir)/src/gallium/auxiliary \
-I$(top_srcdir)/src/gallium/drivers \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
$(DEFINES) \
$(PIC_FLAGS) \
$(LIBDRM_CFLAGS) \
$(EPOXY_CFLAGS) \
$(VISIBILITY_CFLAGS) \
$(CODE_COVERAGE_CFLAGS)
noinst_PROGRAMS = vtest_server
vtest_server_SOURCES = vtest_server.c vtest_renderer.c
vtest_server_LDADD = $(top_builddir)/src/libvirglrenderer.la

@ -0,0 +1,8 @@
#ifndef VTEST_H
#define VTEST_H
int vtest_create_renderer(int fd);
int vtest_send_caps(void);
#endif

@ -0,0 +1,40 @@
#include <stdlib.h>
#include <unistd.h>
#include "virglrenderer.h"
struct virgl_renderer_callbacks vtest_cbs = {
.version = 1,
// .write_fence = vtest_write_fence,
};
struct vtest_renderer {
int remote_fd;
};
struct vtest_renderer renderer;
int vtest_create_renderer(int fd)
{
renderer.remote_fd = fd;
virgl_renderer_init(&renderer, VIRGL_RENDERER_USE_EGL, &vtest_cbs);
}
int vtest_send_caps(void)
{
uint32_t max_ver, max_size;
void *caps_buf;
uint32_t hdr_buf[2];
virgl_renderer_get_cap_set(1, &max_ver, &max_size);
caps_buf = malloc(max_size);
if (!caps_buf)
return -1;
virgl_renderer_fill_caps(1, 1, caps_buf);
hdr_buf[0] = max_size + 1;
hdr_buf[1] = 1;
write(renderer.remote_fd, hdr_buf, 8);
write(renderer.remote_fd, caps_buf, max_size);
return 0;
}

@ -0,0 +1,104 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include "vtest.h"
static int vtest_open_socket(const char *path)
{
struct sockaddr_un un;
int sock;
sock = socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
return -1;
}
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
unlink(un.sun_path);
if (bind(sock, (struct sockaddr *)&un, sizeof(un)) < 0) {
goto err;
}
if (listen(sock, 1) < 0){
goto err;
}
return sock;
err:
close(sock);
return -1;
}
int wait_for_socket_accept(int sock)
{
fd_set read_fds;
int new_fd;
int ret;
FD_ZERO(&read_fds);
FD_SET(sock, &read_fds);
ret = select(sock + 1, &read_fds, NULL, NULL, NULL);
if (ret < 0)
return ret;
if (FD_ISSET(sock, &read_fds)) {
new_fd = accept(sock, NULL, NULL);
return new_fd;
}
return -1;
}
int wait_for_socket_read(int sock)
{
fd_set read_fds;
int ret;
FD_ZERO(&read_fds);
FD_SET(sock, &read_fds);
ret = select(sock + 1, &read_fds, NULL, NULL, NULL);
if (ret < 0)
return ret;
if (FD_ISSET(sock, &read_fds)) {
return 0;
}
return -1;
}
int main(void)
{
int sock, new_fd, ret;
uint32_t header[2];
sock = vtest_open_socket("/tmp/.virgl_test");
new_fd = wait_for_socket_accept(sock);
again:
ret = wait_for_socket_read(new_fd);
if (ret < 0)
goto err;
vtest_create_renderer(new_fd);
ret = read(new_fd, &header, 2 * sizeof(uint32_t));
if (ret == 8) {
fprintf(stderr, "got %d %d\n", header[0], header[1]);
if (header[1] == 1) {
vtest_send_caps();
}
goto again;
}
err:
close(new_fd);
close(sock);
}
Loading…
Cancel
Save