diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/exynos/exynos_fimg2d_test.c | 1 | ||||
-rw-r--r-- | tests/exynos/meson.build | 21 | ||||
-rw-r--r-- | tests/kms/kms-steal-crtc.c | 161 | ||||
-rw-r--r-- | tests/kms/kms-universal-planes.c | 357 | ||||
-rw-r--r-- | tests/kms/libkms-test-crtc.c | 43 | ||||
-rw-r--r-- | tests/kms/libkms-test-device.c | 217 | ||||
-rw-r--r-- | tests/kms/libkms-test-framebuffer.c | 153 | ||||
-rw-r--r-- | tests/kms/libkms-test-plane.c | 137 | ||||
-rw-r--r-- | tests/kms/libkms-test-screen.c | 90 | ||||
-rw-r--r-- | tests/kms/libkms-test.h | 120 | ||||
-rw-r--r-- | tests/kms/meson.build | 49 | ||||
-rw-r--r-- | tests/kmstest/main.c | 109 | ||||
-rw-r--r-- | tests/kmstest/meson.build | 30 | ||||
-rw-r--r-- | tests/meson.build | 4 |
14 files changed, 9 insertions, 1483 deletions
diff --git a/tests/exynos/exynos_fimg2d_test.c b/tests/exynos/exynos_fimg2d_test.c index 99bb9233..d85e2f6b 100644 --- a/tests/exynos/exynos_fimg2d_test.c +++ b/tests/exynos/exynos_fimg2d_test.c @@ -35,7 +35,6 @@ #include <xf86drm.h> #include <xf86drmMode.h> -#include <libkms.h> #include <drm_fourcc.h> #include "exynos_drm.h" diff --git a/tests/exynos/meson.build b/tests/exynos/meson.build index 3a048e8a..12259c3c 100644 --- a/tests/exynos/meson.build +++ b/tests/exynos/meson.build @@ -20,18 +20,15 @@ inc_exynos = include_directories('../../exynos') -if with_libkms - exynos_fimg2d_test = executable( - 'exynos_fimg2d_test', - files('exynos_fimg2d_test.c'), - c_args : libdrm_c_args, - include_directories : [inc_root, inc_drm, inc_exynos, - include_directories('../../libkms')], - link_with : [libdrm, libkms, libdrm_exynos], - dependencies : dep_threads, - install : with_install_tests, - ) -endif +exynos_fimg2d_test = executable( + 'exynos_fimg2d_test', + files('exynos_fimg2d_test.c'), + c_args : libdrm_c_args, + include_directories : [inc_root, inc_drm, inc_exynos], + link_with : [libdrm, libdrm_exynos], + dependencies : dep_threads, + install : with_install_tests, +) exynos_fimg2d_perf = executable( 'exynos_fimg2d_perf', diff --git a/tests/kms/kms-steal-crtc.c b/tests/kms/kms-steal-crtc.c deleted file mode 100644 index 4d884c07..00000000 --- a/tests/kms/kms-steal-crtc.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright © 2014 NVIDIA Corporation - * - * 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 (including the next - * paragraph) 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 <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdint.h> -#include <string.h> -#include <unistd.h> -#if HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif - -#include <drm_fourcc.h> - -#include "util/pattern.h" -#include "libkms-test.h" - -static void signal_handler(int signum) -{ -} - -int main(int argc, char *argv[]) -{ - struct kms_framebuffer *fb; - struct kms_screen *screen; - struct kms_device *device; - unsigned int index = 0; - struct sigaction sa; - int fd, err; - void *ptr; - - if (argc < 2) { - fprintf(stderr, "usage: %s DEVICE\n", argv[0]); - return 1; - } - - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = signal_handler; - - err = sigaction(SIGINT, &sa, NULL); - if (err < 0) { - fprintf(stderr, "sigaction() failed: %m\n"); - return 1; - } - - fd = open(argv[1], O_RDWR); - if (fd < 0) { - fprintf(stderr, "open() failed: %m\n"); - return 1; - } - - device = kms_device_open(fd); - if (!device) { - fprintf(stderr, "kms_device_open() failed: %m\n"); - return 1; - } - - if (device->num_screens < 1) { - fprintf(stderr, "no screens found\n"); - kms_device_close(device); - close(fd); - return 1; - } - - /* TODO: allow command-line to override */ - screen = device->screens[0]; - - printf("Using screen %s, resolution %ux%u\n", screen->name, - screen->width, screen->height); - - fb = kms_framebuffer_create(device, screen->width, screen->height, - DRM_FORMAT_XRGB8888); - if (!fb) { - fprintf(stderr, "kms_framebuffer_create() failed\n"); - return 1; - } - - err = kms_framebuffer_map(fb, &ptr); - if (err < 0) { - fprintf(stderr, "kms_framebuffer_map() failed: %d\n", err); - return 1; - } - - util_fill_pattern(fb->format, UTIL_PATTERN_SMPTE, &ptr, fb->width, - fb->height, fb->pitch); - - kms_framebuffer_unmap(fb); - - err = kms_screen_set(screen, device->crtcs[index++], fb); - if (err < 0) { - fprintf(stderr, "kms_screen_set() failed: %d\n", err); - return 1; - } - - while (true) { - int nfds = STDIN_FILENO + 1; - struct timeval timeout; - fd_set fds; - - memset(&timeout, 0, sizeof(timeout)); - timeout.tv_sec = 5; - timeout.tv_usec = 0; - - FD_ZERO(&fds); - FD_SET(STDIN_FILENO, &fds); - - err = select(nfds, &fds, NULL, NULL, &timeout); - if (err < 0) { - if (errno == EINTR) - break; - - fprintf(stderr, "select() failed: %d\n", errno); - break; - } - - if (err > 0) { - if (FD_ISSET(STDIN_FILENO, &fds)) - break; - } - - /* switch CRTC */ - if (index >= device->num_crtcs) - index = 0; - - err = kms_screen_set(screen, device->crtcs[index], fb); - if (err < 0) { - fprintf(stderr, "kms_screen_set() failed: %d\n", err); - break; - } - - index++; - } - - kms_framebuffer_free(fb); - kms_device_close(device); - close(fd); - - return 0; -} diff --git a/tests/kms/kms-universal-planes.c b/tests/kms/kms-universal-planes.c deleted file mode 100644 index 1d793880..00000000 --- a/tests/kms/kms-universal-planes.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright © 2014 NVIDIA Corporation - * - * 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 (including the next - * paragraph) 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 <fcntl.h> -#include <getopt.h> -#include <stdbool.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#if HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif - -#include <drm_fourcc.h> -#include "xf86drm.h" - -#include "util/common.h" -#include "libkms-test.h" - -static const uint32_t formats[] = { - DRM_FORMAT_XRGB8888, - DRM_FORMAT_XBGR8888, - DRM_FORMAT_RGBA8888, -}; - -static uint32_t choose_format(struct kms_plane *plane) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(formats); i++) - if (kms_plane_supports_format(plane, formats[i])) - return formats[i]; - - return 0; -} - -static void prepare_framebuffer(struct kms_framebuffer *fb, bool invert) -{ - const unsigned int block_size = 16; - uint32_t colors[2]; - unsigned int i, j; - uint32_t *buf; - void *ptr; - int err; - - switch (fb->format) { - case DRM_FORMAT_XRGB8888: - printf("using XRGB8888 format\n"); - /* XXRRGGBB */ - colors[0] = 0xffff0000; - colors[1] = 0xff0000ff; - break; - - case DRM_FORMAT_XBGR8888: - printf("using XBGR8888 format\n"); - /* XXBBGGRR */ - colors[0] = 0xff0000ff; - colors[1] = 0xffff0000; - break; - - case DRM_FORMAT_RGBA8888: - printf("using RGBA8888 format\n"); - /* RRGGBBAA */ - colors[0] = 0xff0000ff; - colors[1] = 0x0000ffff; - break; - - default: - colors[0] = 0xffffffff; - colors[1] = 0xffffffff; - break; - } - - err = kms_framebuffer_map(fb, &ptr); - if (err < 0) { - fprintf(stderr, "kms_framebuffer_map() failed: %s\n", - strerror(-err)); - return; - } - - buf = ptr; - - for (j = 0; j < fb->height; j++) { - for (i = 0; i < fb->width; i++) { - unsigned int color = (j / block_size) ^ - (i / block_size); - - if (invert) - color ^= color; - - *buf++ = colors[color & 1]; - } - } - - kms_framebuffer_unmap(fb); -} - -int main(int argc, char *argv[]) -{ - static const char opts[] = "chopv"; - static struct option options[] = { - { "cursor", 0, 0, 'c' }, - { "help", 0, 0, 'h' }, - { "overlay", 0, 0, 'o' }, - { "primary", 0, 0, 'p' }, - { "verbose", 0, 0, 'v' }, - { 0, 0, 0, 0 }, - }; - struct kms_framebuffer *cursor = NULL; - struct kms_framebuffer *root = NULL; - struct kms_framebuffer *fb = NULL; - struct kms_device *device; - bool use_overlay = false; - bool use_primary = false; - struct kms_plane *plane; - bool use_cursor = false; - bool verbose = false; - unsigned int i; - int opt, idx; - int fd, err; - - while ((opt = getopt_long(argc, argv, opts, options, &idx)) != -1) { - switch (opt) { - case 'c': - use_cursor = true; - break; - - case 'h': - break; - - case 'o': - use_overlay = true; - break; - - case 'p': - use_primary = true; - break; - - case 'v': - verbose = true; - break; - - default: - printf("unknown option \"%c\"\n", opt); - return 1; - } - } - - if (optind >= argc) { - fprintf(stderr, "usage: %s [options] DEVICE\n", argv[0]); - return 1; - } - - fd = open(argv[optind], O_RDWR); - if (fd < 0) { - fprintf(stderr, "open() failed: %m\n"); - return 1; - } - - err = drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); - if (err < 0) { - fprintf(stderr, "drmSetClientCap() failed: %d\n", err); - return 1; - } - - device = kms_device_open(fd); - if (!device) - return 1; - - if (verbose) { - printf("Screens: %u\n", device->num_screens); - - for (i = 0; i < device->num_screens; i++) { - struct kms_screen *screen = device->screens[i]; - const char *status = "disconnected"; - - if (screen->connected) - status = "connected"; - - printf(" %u: %x\n", i, screen->id); - printf(" Status: %s\n", status); - printf(" Name: %s\n", screen->name); - printf(" Resolution: %ux%u\n", screen->width, - screen->height); - } - - printf("Planes: %u\n", device->num_planes); - - for (i = 0; i < device->num_planes; i++) { - const char *type = NULL; - - plane = device->planes[i]; - switch (plane->type) { - case DRM_PLANE_TYPE_OVERLAY: - type = "overlay"; - break; - - case DRM_PLANE_TYPE_PRIMARY: - type = "primary"; - break; - - case DRM_PLANE_TYPE_CURSOR: - type = "cursor"; - break; - } - - printf(" %u: %p\n", i, plane); - printf(" ID: %x\n", plane->id); - printf(" CRTC: %x\n", plane->crtc->id); - printf(" Type: %x (%s)\n", plane->type, type); - } - } - - if (use_cursor) { - unsigned int x, y; - uint32_t format; - - plane = kms_device_find_plane_by_type(device, - DRM_PLANE_TYPE_CURSOR, - 0); - if (!plane) { - fprintf(stderr, "no cursor plane found\n"); - return 1; - } - - format = choose_format(plane); - if (!format) { - fprintf(stderr, "no matching format found\n"); - return 1; - } - - cursor = kms_framebuffer_create(device, 32, 32, format); - if (!cursor) { - fprintf(stderr, "failed to create cursor buffer\n"); - return 1; - } - - prepare_framebuffer(cursor, false); - - x = (device->screens[0]->width - cursor->width) / 2; - y = (device->screens[0]->height - cursor->height) / 2; - - kms_plane_set(plane, cursor, x, y); - } - - if (use_overlay) { - uint32_t format; - - plane = kms_device_find_plane_by_type(device, - DRM_PLANE_TYPE_OVERLAY, - 0); - if (!plane) { - fprintf(stderr, "no overlay plane found\n"); - return 1; - } - - format = choose_format(plane); - if (!format) { - fprintf(stderr, "no matching format found\n"); - return 1; - } - - fb = kms_framebuffer_create(device, 320, 240, format); - if (!fb) - return 1; - - prepare_framebuffer(fb, false); - - kms_plane_set(plane, fb, 0, 0); - } - - if (use_primary) { - unsigned int x, y; - uint32_t format; - - plane = kms_device_find_plane_by_type(device, - DRM_PLANE_TYPE_PRIMARY, - 0); - if (!plane) { - fprintf(stderr, "no primary plane found\n"); - return 1; - } - - format = choose_format(plane); - if (!format) { - fprintf(stderr, "no matching format found\n"); - return 1; - } - - root = kms_framebuffer_create(device, 640, 480, format); - if (!root) - return 1; - - prepare_framebuffer(root, true); - - x = (device->screens[0]->width - root->width) / 2; - y = (device->screens[0]->height - root->height) / 2; - - kms_plane_set(plane, root, x, y); - } - - while (1) { - struct timeval timeout = { 1, 0 }; - fd_set fds; - - FD_ZERO(&fds); - FD_SET(STDIN_FILENO, &fds); - - err = select(STDIN_FILENO + 1, &fds, NULL, NULL, &timeout); - if (err < 0) { - fprintf(stderr, "select() failed: %m\n"); - break; - } - - /* timeout */ - if (err == 0) - continue; - - if (FD_ISSET(STDIN_FILENO, &fds)) - break; - } - - if (cursor) - kms_framebuffer_free(cursor); - - if (root) - kms_framebuffer_free(root); - - if (fb) - kms_framebuffer_free(fb); - - kms_device_close(device); - close(fd); - - return 0; -} diff --git a/tests/kms/libkms-test-crtc.c b/tests/kms/libkms-test-crtc.c deleted file mode 100644 index 2c28face..00000000 --- a/tests/kms/libkms-test-crtc.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright © 2014 NVIDIA Corporation - * - * 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 (including the next - * paragraph) 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 "libkms-test.h" - -struct kms_crtc *kms_crtc_create(struct kms_device *device, uint32_t id) -{ - struct kms_crtc *crtc; - - crtc = calloc(1, sizeof(*crtc)); - if (!crtc) - return NULL; - - crtc->device = device; - crtc->id = id; - - return crtc; -} - -void kms_crtc_free(struct kms_crtc *crtc) -{ - free(crtc); -} diff --git a/tests/kms/libkms-test-device.c b/tests/kms/libkms-test-device.c deleted file mode 100644 index d3bb11ce..00000000 --- a/tests/kms/libkms-test-device.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright © 2014 NVIDIA Corporation - * - * 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 (including the next - * paragraph) 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 <stdio.h> -#include <string.h> -#include <unistd.h> - -#include "util/common.h" -#include "libkms-test.h" - -static const char *const connector_names[] = { - "Unknown", - "VGA", - "DVI-I", - "DVI-D", - "DVI-A", - "Composite", - "SVIDEO", - "LVDS", - "Component", - "9PinDIN", - "DisplayPort", - "HDMI-A", - "HDMI-B", - "TV", - "eDP", - "Virtual", - "DSI", -}; - -static void kms_device_probe_screens(struct kms_device *device) -{ - unsigned int counts[ARRAY_SIZE(connector_names)]; - struct kms_screen *screen; - drmModeRes *res; - int i; - - memset(counts, 0, sizeof(counts)); - - res = drmModeGetResources(device->fd); - if (!res) - return; - - device->screens = calloc(res->count_connectors, sizeof(screen)); - if (!device->screens) - goto err_free_resources; - - for (i = 0; i < res->count_connectors; i++) { - unsigned int *count; - const char *type; - int len; - - screen = kms_screen_create(device, res->connectors[i]); - if (!screen) - continue; - - /* assign a unique name to this screen */ - type = connector_names[screen->type]; - count = &counts[screen->type]; - - len = snprintf(NULL, 0, "%s-%u", type, *count); - - screen->name = malloc(len + 1); - if (!screen->name) { - free(screen); - continue; - } - - snprintf(screen->name, len + 1, "%s-%u", type, *count); - (*count)++; - - device->screens[i] = screen; - device->num_screens++; - } - -err_free_resources: - drmModeFreeResources(res); -} - -static void kms_device_probe_crtcs(struct kms_device *device) -{ - struct kms_crtc *crtc; - drmModeRes *res; - int i; - - res = drmModeGetResources(device->fd); - if (!res) - return; - - device->crtcs = calloc(res->count_crtcs, sizeof(crtc)); - if (!device->crtcs) - goto err_free_resources; - - for (i = 0; i < res->count_crtcs; i++) { - crtc = kms_crtc_create(device, res->crtcs[i]); - if (!crtc) - continue; - - device->crtcs[i] = crtc; - device->num_crtcs++; - } - -err_free_resources: - drmModeFreeResources(res); -} - -static void kms_device_probe_planes(struct kms_device *device) -{ - struct kms_plane *plane; - drmModePlaneRes *res; - unsigned int i; - - res = drmModeGetPlaneResources(device->fd); - if (!res) - return; - - device->planes = calloc(res->count_planes, sizeof(plane)); - if (!device->planes) - goto err_free_resources; - - for (i = 0; i < res->count_planes; i++) { - plane = kms_plane_create(device, res->planes[i]); - if (!plane) - continue; - - device->planes[i] = plane; - device->num_planes++; - } - -err_free_resources: - drmModeFreePlaneResources(res); -} - -static void kms_device_probe(struct kms_device *device) -{ - kms_device_probe_screens(device); - kms_device_probe_crtcs(device); - kms_device_probe_planes(device); -} - -struct kms_device *kms_device_open(int fd) -{ - struct kms_device *device; - - device = calloc(1, sizeof(*device)); - if (!device) - return NULL; - - device->fd = fd; - - kms_device_probe(device); - - return device; -} - -void kms_device_close(struct kms_device *device) -{ - unsigned int i; - - for (i = 0; i < device->num_planes; i++) - kms_plane_free(device->planes[i]); - - free(device->planes); - - for (i = 0; i < device->num_crtcs; i++) - kms_crtc_free(device->crtcs[i]); - - free(device->crtcs); - - for (i = 0; i < device->num_screens; i++) - kms_screen_free(device->screens[i]); - - free(device->screens); - - if (device->fd >= 0) - close(device->fd); - - free(device); -} - -struct kms_plane *kms_device_find_plane_by_type(struct kms_device *device, - uint32_t type, - unsigned int index) -{ - unsigned int i; - - for (i = 0; i < device->num_planes; i++) { - if (device->planes[i]->type == type) { - if (index == 0) - return device->planes[i]; - - index--; - } - } - - return NULL; -} diff --git a/tests/kms/libkms-test-framebuffer.c b/tests/kms/libkms-test-framebuffer.c deleted file mode 100644 index 9bb2d95b..00000000 --- a/tests/kms/libkms-test-framebuffer.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright © 2014 NVIDIA Corporation - * - * 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 (including the next - * paragraph) 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 <errno.h> -#include <string.h> - -#include <sys/mman.h> - -#include <drm_fourcc.h> - -#include "xf86drm.h" - -#include "libkms-test.h" - -struct kms_framebuffer *kms_framebuffer_create(struct kms_device *device, - unsigned int width, - unsigned int height, - uint32_t format) -{ - uint32_t handles[4], pitches[4], offsets[4]; - struct drm_mode_create_dumb args; - struct kms_framebuffer *fb; - int err; - - fb = calloc(1, sizeof(*fb)); - if (!fb) - return NULL; - - fb->device = device; - fb->width = width; - fb->height = height; - fb->format = format; - - memset(&args, 0, sizeof(args)); - args.width = width; - args.height = height; - - switch (format) { - case DRM_FORMAT_XRGB8888: - case DRM_FORMAT_XBGR8888: - case DRM_FORMAT_RGBA8888: - args.bpp = 32; - break; - - default: - free(fb); - return NULL; - } - - err = drmIoctl(device->fd, DRM_IOCTL_MODE_CREATE_DUMB, &args); - if (err < 0) { - free(fb); - return NULL; - } - - fb->handle = args.handle; - fb->pitch = args.pitch; - fb->size = args.size; - - handles[0] = fb->handle; - pitches[0] = fb->pitch; - offsets[0] = 0; - - err = drmModeAddFB2(device->fd, width, height, format, handles, - pitches, offsets, &fb->id, 0); - if (err < 0) { - kms_framebuffer_free(fb); - return NULL; - } - - return fb; -} - -void kms_framebuffer_free(struct kms_framebuffer *fb) -{ - struct kms_device *device = fb->device; - struct drm_mode_destroy_dumb args; - int err; - - if (fb->id) { - err = drmModeRmFB(device->fd, fb->id); - if (err < 0) { - /* not much we can do now */ - } - } - - memset(&args, 0, sizeof(args)); - args.handle = fb->handle; - - err = drmIoctl(device->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &args); - if (err < 0) { - /* not much we can do now */ - } - - free(fb); -} - -int kms_framebuffer_map(struct kms_framebuffer *fb, void **ptrp) -{ - struct kms_device *device = fb->device; - struct drm_mode_map_dumb args; - void *ptr; - int err; - - if (fb->ptr) { - *ptrp = fb->ptr; - return 0; - } - - memset(&args, 0, sizeof(args)); - args.handle = fb->handle; - - err = drmIoctl(device->fd, DRM_IOCTL_MODE_MAP_DUMB, &args); - if (err < 0) - return -errno; - - ptr = mmap(0, fb->size, PROT_READ | PROT_WRITE, MAP_SHARED, - device->fd, args.offset); - if (ptr == MAP_FAILED) - return -errno; - - *ptrp = fb->ptr = ptr; - - return 0; -} - -void kms_framebuffer_unmap(struct kms_framebuffer *fb) -{ - if (fb->ptr) { - munmap(fb->ptr, fb->size); - fb->ptr = NULL; - } -} diff --git a/tests/kms/libkms-test-plane.c b/tests/kms/libkms-test-plane.c deleted file mode 100644 index 4cb27378..00000000 --- a/tests/kms/libkms-test-plane.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright © 2014 NVIDIA Corporation - * - * 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 (including the next - * paragraph) 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 <errno.h> -#include <string.h> - -#include "libkms-test.h" - -static int kms_plane_probe(struct kms_plane *plane) -{ - struct kms_device *device = plane->device; - drmModeObjectPropertiesPtr props; - drmModePlane *p; - unsigned int i; - - p = drmModeGetPlane(device->fd, plane->id); - if (!p) - return -ENODEV; - - /* TODO: allow dynamic assignment to CRTCs */ - if (p->crtc_id == 0) { - for (i = 0; i < device->num_crtcs; i++) { - if (p->possible_crtcs & (1 << i)) { - p->crtc_id = device->crtcs[i]->id; - break; - } - } - } - - for (i = 0; i < device->num_crtcs; i++) { - if (device->crtcs[i]->id == p->crtc_id) { - plane->crtc = device->crtcs[i]; - break; - } - } - - plane->formats = calloc(p->count_formats, sizeof(uint32_t)); - if (!plane->formats) { - drmModeFreePlane(p); - return -ENOMEM; - } - - for (i = 0; i < p->count_formats; i++) - plane->formats[i] = p->formats[i]; - - plane->num_formats = p->count_formats; - - drmModeFreePlane(p); - - props = drmModeObjectGetProperties(device->fd, plane->id, - DRM_MODE_OBJECT_PLANE); - if (!props) - return -ENODEV; - - for (i = 0; i < props->count_props; i++) { - drmModePropertyPtr prop; - - prop = drmModeGetProperty(device->fd, props->props[i]); - if (prop) { - if (strcmp(prop->name, "type") == 0) - plane->type = props->prop_values[i]; - - drmModeFreeProperty(prop); - } - } - - drmModeFreeObjectProperties(props); - - return 0; -} - -struct kms_plane *kms_plane_create(struct kms_device *device, uint32_t id) -{ - struct kms_plane *plane; - - plane = calloc(1, sizeof(*plane)); - if (!plane) - return NULL; - - plane->device = device; - plane->id = id; - - kms_plane_probe(plane); - - return plane; -} - -void kms_plane_free(struct kms_plane *plane) -{ - free(plane); -} - -int kms_plane_set(struct kms_plane *plane, struct kms_framebuffer *fb, - unsigned int x, unsigned int y) -{ - struct kms_device *device = plane->device; - int err; - - err = drmModeSetPlane(device->fd, plane->id, plane->crtc->id, fb->id, - 0, x, y, fb->width, fb->height, 0 << 16, - 0 << 16, fb->width << 16, fb->height << 16); - if (err < 0) - return -errno; - - return 0; -} - -bool kms_plane_supports_format(struct kms_plane *plane, uint32_t format) -{ - unsigned int i; - - for (i = 0; i < plane->num_formats; i++) - if (plane->formats[i] == format) - return true; - - return false; -} diff --git a/tests/kms/libkms-test-screen.c b/tests/kms/libkms-test-screen.c deleted file mode 100644 index d00ae547..00000000 --- a/tests/kms/libkms-test-screen.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright © 2014 NVIDIA Corporation - * - * 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 (including the next - * paragraph) 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 <errno.h> -#include <string.h> - -#include "libkms-test.h" - -static void kms_screen_probe(struct kms_screen *screen) -{ - struct kms_device *device = screen->device; - drmModeConnector *con; - - con = drmModeGetConnector(device->fd, screen->id); - if (!con) - return; - - screen->type = con->connector_type; - - if (con->connection == DRM_MODE_CONNECTED) - screen->connected = true; - else - screen->connected = false; - - if (con->modes) - memcpy(&screen->mode, &con->modes[0], sizeof(drmModeModeInfo)); - - screen->width = screen->mode.hdisplay; - screen->height = screen->mode.vdisplay; - - drmModeFreeConnector(con); -} - -struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id) -{ - struct kms_screen *screen; - - screen = calloc(1, sizeof(*screen)); - if (!screen) - return NULL; - - screen->device = device; - screen->id = id; - - kms_screen_probe(screen); - - return screen; -} - -void kms_screen_free(struct kms_screen *screen) -{ - if (screen) - free(screen->name); - - free(screen); -} - -int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc, - struct kms_framebuffer *fb) -{ - struct kms_device *device = screen->device; - int err; - - err = drmModeSetCrtc(device->fd, crtc->id, fb->id, 0, 0, &screen->id, - 1, &screen->mode); - if (err < 0) - return -errno; - - return 0; -} diff --git a/tests/kms/libkms-test.h b/tests/kms/libkms-test.h deleted file mode 100644 index 7b1d02e9..00000000 --- a/tests/kms/libkms-test.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright © 2014 NVIDIA Corporation - * - * 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 (including the next - * paragraph) 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 LIBKMS_TEST_H -#define LIBKMS_TEST_H - -#include <stdbool.h> -#include <stdint.h> -#include <stdlib.h> - -#include <xf86drmMode.h> - -struct kms_device { - int fd; - - struct kms_screen **screens; - unsigned int num_screens; - - struct kms_crtc **crtcs; - unsigned int num_crtcs; - - struct kms_plane **planes; - unsigned int num_planes; -}; - -struct kms_device *kms_device_open(int fd); -void kms_device_close(struct kms_device *device); - -struct kms_plane *kms_device_find_plane_by_type(struct kms_device *device, - uint32_t type, - unsigned int index); - -struct kms_crtc { - struct kms_device *device; - uint32_t id; -}; - -struct kms_crtc *kms_crtc_create(struct kms_device *device, uint32_t id); -void kms_crtc_free(struct kms_crtc *crtc); - -struct kms_framebuffer { - struct kms_device *device; - - unsigned int width; - unsigned int height; - unsigned int pitch; - uint32_t format; - size_t size; - - uint32_t handle; - uint32_t id; - - void *ptr; -}; - -struct kms_framebuffer *kms_framebuffer_create(struct kms_device *device, - unsigned int width, - unsigned int height, - uint32_t format); -void kms_framebuffer_free(struct kms_framebuffer *fb); -int kms_framebuffer_map(struct kms_framebuffer *fb, void **ptrp); -void kms_framebuffer_unmap(struct kms_framebuffer *fb); - -struct kms_screen { - struct kms_device *device; - bool connected; - uint32_t type; - uint32_t id; - - unsigned int width; - unsigned int height; - char *name; - - drmModeModeInfo mode; -}; - -struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id); -void kms_screen_free(struct kms_screen *screen); - -int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc, - struct kms_framebuffer *fb); - -struct kms_plane { - struct kms_device *device; - struct kms_crtc *crtc; - unsigned int type; - uint32_t id; - - uint32_t *formats; - unsigned int num_formats; -}; - -struct kms_plane *kms_plane_create(struct kms_device *device, uint32_t id); -void kms_plane_free(struct kms_plane *plane); - -int kms_plane_set(struct kms_plane *plane, struct kms_framebuffer *fb, - unsigned int x, unsigned int y); -bool kms_plane_supports_format(struct kms_plane *plane, uint32_t format); - -#endif diff --git a/tests/kms/meson.build b/tests/kms/meson.build deleted file mode 100644 index 91371aa0..00000000 --- a/tests/kms/meson.build +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright © 2017-2018 Intel Corporation - -# 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. - - -libkms_test = static_library( - 'kms-test', - files( - 'libkms-test-crtc.c', 'libkms-test-device.c', 'libkms-test-framebuffer.c', - 'libkms-test-plane.c', 'libkms-test-screen.c', - ), - include_directories : [inc_root, inc_tests, inc_drm], - link_with : libdrm, - c_args : libdrm_c_args, -) - -kms_steal_crtc = executable( - 'kms-steal-crtc', - files('kms-steal-crtc.c'), - dependencies : dep_cairo, - include_directories : [inc_root, inc_tests, inc_drm], - link_with : [libkms_test, libutil], - install : with_install_tests, -) - -kms_universal_planes = executable( - 'kms-universal-planes', - files('kms-universal-planes.c'), - dependencies : dep_cairo, - include_directories : [inc_root, inc_tests, inc_drm], - link_with : [libkms_test], - install : with_install_tests, -) diff --git a/tests/kmstest/main.c b/tests/kmstest/main.c deleted file mode 100644 index a0e4ebbd..00000000 --- a/tests/kmstest/main.c +++ /dev/null @@ -1,109 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * 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, sub license, 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 (including the - * next paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS 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 <getopt.h> -#include <stdio.h> -#include <string.h> -#include "xf86drm.h" -#include "libkms.h" - -#include "util/kms.h" - -#define CHECK_RET_RETURN(ret, str) \ - if (ret < 0) { \ - printf("%s: %s (%s)\n", __func__, str, strerror(-ret)); \ - return ret; \ - } - -static int test_bo(struct kms_driver *kms) -{ - struct kms_bo *bo; - int ret; - unsigned attrs[7] = { - KMS_WIDTH, 1024, - KMS_HEIGHT, 768, - KMS_BO_TYPE, KMS_BO_TYPE_SCANOUT_X8R8G8B8, - KMS_TERMINATE_PROP_LIST, - }; - - ret = kms_bo_create(kms, attrs, &bo); - CHECK_RET_RETURN(ret, "Could not create bo"); - - kms_bo_destroy(&bo); - - return 0; -} - -static void usage(const char *program) -{ - fprintf(stderr, "Usage: %s [options]\n", program); - fprintf(stderr, "\n"); - fprintf(stderr, " -D DEVICE open the given device\n"); - fprintf(stderr, " -M MODULE open the given module\n"); -} - -int main(int argc, char** argv) -{ - static const char optstr[] = "D:M:"; - struct kms_driver *kms; - int c, fd, ret; - char *device = NULL; - char *module = NULL; - - while ((c = getopt(argc, argv, optstr)) != -1) { - switch (c) { - case 'D': - device = optarg; - break; - case 'M': - module = optarg; - break; - default: - usage(argv[0]); - return 0; - } - } - - fd = util_open(device, module); - CHECK_RET_RETURN(fd, "Could not open device"); - - ret = kms_create(fd, &kms); - CHECK_RET_RETURN(ret, "Failed to create kms driver"); - - ret = test_bo(kms); - if (ret) - goto err; - - printf("%s: All ok!\n", __func__); - - kms_destroy(&kms); - return 0; - -err: - kms_destroy(&kms); - return ret; -} diff --git a/tests/kmstest/meson.build b/tests/kmstest/meson.build deleted file mode 100644 index 4fb870f9..00000000 --- a/tests/kmstest/meson.build +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright © 2017 Intel Corporation - -# 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. - -kmstest = executable( - 'kmstest', - files('main.c'), - c_args : libdrm_c_args, - include_directories : [ - inc_root, inc_tests, include_directories('../../libkms'), inc_drm, - ], - link_with : [libutil, libkms, libdrm], - install : with_install_tests, -) diff --git a/tests/meson.build b/tests/meson.build index 196edbfa..ac9e66b0 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -21,14 +21,10 @@ inc_tests = include_directories('.') subdir('util') -subdir('kms') subdir('modeprint') subdir('proptest') subdir('modetest') subdir('vbltest') -if with_libkms - subdir('kmstest') -endif if with_radeon subdir('radeon') endif |