[Intel-gfx] [igt PATCH 5/5] tests: add kms_render

Rodrigo Vivi rodrigo.vivi at gmail.com
Wed Jun 5 20:28:29 CEST 2013


nice tests, only now I understood why Daniel "randomly" volunteered me
to review this series ;)
Reviewed-by: Rodrigo Vivi <rodrigo.vivi at gmail.com>

On Fri, May 31, 2013 at 6:23 AM, Imre Deak <imre.deak at intel.com> wrote:
> Add a test going through all connectors/crtcs/modes/formats painting to
> a front FB with CPU or painting to a back FB with CPU and blitting it
> to the front FB.
>
> Only formats understood by cairo are supported for now.
>
> Signed-off-by: Imre Deak <imre.deak at intel.com>
> ---
>  lib/drmtest.c      | 101 ++++++++++++++++++++--
>  lib/drmtest.h      |   7 ++
>  tests/.gitignore   |   1 +
>  tests/Makefile.am  |   1 +
>  tests/kms_render.c | 245 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 349 insertions(+), 6 deletions(-)
>  create mode 100644 tests/kms_render.c
>
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index a551e7c..d9d58e5 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -842,8 +842,8 @@ static int create_bo_for_fb(int fd, int width, int height, int bpp,
>         return 0;
>  }
>
> -static void
> -paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
> +void
> +kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
>                      int r, int g, int b)
>  {
>         cairo_pattern_t *pat;
> @@ -869,16 +869,16 @@ paint_test_patterns(cairo_t *cr, int width, int height)
>         gr_height = height * 0.08;
>         x = (width / 2) - (gr_width / 2);
>
> -       paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 0, 0);
> +       kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 0, 0);
>
>         y += gr_height;
> -       paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 1, 0);
> +       kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 1, 0);
>
>         y += gr_height;
> -       paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 0, 1);
> +       kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 0, 1);
>
>         y += gr_height;
> -       paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 1, 1);
> +       kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 1, 1);
>  }
>
>  int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align,
> @@ -1025,6 +1025,55 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
>         return fb->fb_id;
>  }
>
> +static uint32_t drm_format_to_bpp(uint32_t drm_format)
> +{
> +       struct format_desc_struct *f;
> +
> +       for_each_format(f)
> +               if (f->drm_id == drm_format)
> +                       return f->bpp;
> +
> +       abort();
> +}
> +
> +unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
> +                               bool tiled, struct kmstest_fb *fb)
> +{
> +       uint32_t handles[4];
> +       uint32_t pitches[4];
> +       uint32_t offsets[4];
> +       uint32_t fb_id;
> +       int bpp;
> +       int ret;
> +
> +       memset(fb, 0, sizeof(*fb));
> +
> +       bpp = drm_format_to_bpp(format);
> +       ret = create_bo_for_fb(fd, width, height, bpp, tiled, &fb->gem_handle,
> +                             &fb->size, &fb->stride);
> +       if (ret < 0)
> +               return ret;
> +
> +       memset(handles, 0, sizeof(handles));
> +       handles[0] = fb->gem_handle;
> +       memset(pitches, 0, sizeof(pitches));
> +       pitches[0] = fb->stride;
> +       memset(offsets, 0, sizeof(offsets));
> +       if (drmModeAddFB2(fd, width, height, format, handles, pitches,
> +                         offsets, &fb_id, 0) < 0) {
> +               gem_close(fd, fb->gem_handle);
> +
> +               return 0;
> +       }
> +
> +       fb->width = width;
> +       fb->height = height;
> +       fb->drm_format = format;
> +       fb->fb_id = fb_id;
> +
> +       return fb_id;
> +}
> +
>  static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
>  {
>         struct format_desc_struct *f;
> @@ -1075,6 +1124,46 @@ void kmstest_remove_fb(int fd, struct kmstest_fb *fb)
>         gem_close(fd, fb->gem_handle);
>  }
>
> +const char *kmstest_format_str(uint32_t drm_format)
> +{
> +       struct format_desc_struct *f;
> +
> +       for_each_format(f)
> +               if (f->drm_id == drm_format)
> +                       return f->name;
> +
> +       return "invalid";
> +}
> +
> +const char *kmstest_pipe_str(int pipe)
> +{
> +       const char *str[] = { "A", "B", "C" };
> +
> +       if (pipe > 2)
> +               return "invalid";
> +
> +       return str[pipe];
> +}
> +
> +void kmstest_get_all_formats(const uint32_t **formats, int *format_count)
> +{
> +       static uint32_t *drm_formats;
> +
> +       if (!drm_formats) {
> +               struct format_desc_struct *f;
> +               uint32_t *format;
> +
> +               drm_formats = calloc(ARRAY_SIZE(format_desc),
> +                                    sizeof(*drm_formats));
> +               format = &drm_formats[0];
> +               for_each_format(f)
> +                       *format++ = f->drm_id;
> +       }
> +
> +       *formats = drm_formats;
> +       *format_count = ARRAY_SIZE(format_desc);
> +}
> +
>  struct type_name {
>         int type;
>         const char *name;
> diff --git a/lib/drmtest.h b/lib/drmtest.h
> index 218914f..e3a9275 100644
> --- a/lib/drmtest.h
> +++ b/lib/drmtest.h
> @@ -144,11 +144,18 @@ int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align,
>  unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
>                                int depth, bool tiled,
>                                struct kmstest_fb *fb_info);
> +unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
> +                               bool tiled, struct kmstest_fb *fb);
>  void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
>  cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
> +void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
> +                                 int r, int g, int b);
>  void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
>  void kmstest_dump_mode(drmModeModeInfo *mode);
>  int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
> +const char *kmstest_format_str(uint32_t drm_format);
> +const char *kmstest_pipe_str(int pipe);
> +void kmstest_get_all_formats(const uint32_t **formats, int *format_count);
>  const char *kmstest_encoder_type_str(int type);
>  const char *kmstest_connector_status_str(int type);
>  const char *kmstest_connector_type_str(int type);
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 3cac813..1f7c691 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -85,6 +85,7 @@ getclient
>  getstats
>  getversion
>  kms_flip
> +kms_render
>  prime_nv_api
>  prime_nv_pcopy
>  prime_nv_test
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 7250968..3f301c9 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -33,6 +33,7 @@ TESTS_progs_M = \
>         gem_tiled_partial_pwrite_pread \
>         $(NOUVEAU_TESTS_M) \
>         kms_flip \
> +       kms_render \
>         prime_self_import \
>         $(NULL)
>
> diff --git a/tests/kms_render.c b/tests/kms_render.c
> new file mode 100644
> index 0000000..707ce27
> --- /dev/null
> +++ b/tests/kms_render.c
> @@ -0,0 +1,245 @@
> +/*
> + * 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.
> + *
> + * Authors:
> + *    Imre Deak <imre.deak at intel.com>
> + */
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <assert.h>
> +#include <cairo.h>
> +#include <errno.h>
> +#include <stdint.h>
> +#include <unistd.h>
> +#include <sys/time.h>
> +
> +#include "drmtest.h"
> +#include "testdisplay.h"
> +#include "intel_bufmgr.h"
> +#include "intel_batchbuffer.h"
> +#include "intel_gpu_tools.h"
> +
> +drmModeRes *resources;
> +int drm_fd;
> +static drm_intel_bufmgr *bufmgr;
> +struct intel_batchbuffer *batch;
> +uint32_t devid;
> +
> +enum test_flags {
> +       TEST_DIRECT_RENDER      = 0x01,
> +       TEST_GPU_BLIT           = 0x02,
> +};
> +
> +static int paint_fb(struct kmstest_fb *fb, const char *test_name,
> +                   const char *mode_format_str, const char *cconf_str)
> +{
> +       cairo_t *cr;
> +
> +       cr = kmstest_get_cairo_ctx(drm_fd, fb);
> +       if (!cr)
> +               return -1;
> +
> +       kmstest_paint_color_gradient(cr, 0, 0, fb->width, fb->height, 1, 1, 1);
> +       kmstest_paint_test_pattern(cr, fb->width, fb->height);
> +
> +       cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
> +                              CAIRO_FONT_WEIGHT_NORMAL);
> +       cairo_move_to(cr, fb->width / 2, fb->height / 2);
> +       cairo_set_font_size(cr, 36);
> +       kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", test_name);
> +       kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
> +       kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
> +
> +       return 0;
> +}
> +
> +static void gpu_blit(struct kmstest_fb *dst_fb, struct kmstest_fb *src_fb)
> +{
> +       drm_intel_bo *dst_bo;
> +       drm_intel_bo *src_bo;
> +
> +       dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "destination",
> +                                        dst_fb->gem_handle);
> +       assert(dst_bo);
> +       src_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "source",
> +                                        src_fb->gem_handle);
> +       assert(src_bo);
> +
> +       intel_copy_bo(batch, dst_bo, src_bo, src_fb->width, src_fb->height);
> +       intel_batchbuffer_flush(batch);
> +       gem_quiescent_gpu(drm_fd);
> +
> +       drm_intel_bo_unreference(src_bo);
> +       drm_intel_bo_unreference(dst_bo);
> +}
> +
> +static int test_format(const char *test_name,
> +                      struct kmstest_connector_config *cconf,
> +                      drmModeModeInfo *mode, uint32_t format,
> +                      enum test_flags flags)
> +{
> +       int width;
> +       int height;
> +       struct kmstest_fb fb[2];
> +       char *mode_format_str;
> +       char *cconf_str;
> +       int ret;
> +
> +       ret = asprintf(&mode_format_str, "%s @ %dHz / %s",
> +                mode->name, mode->vrefresh, kmstest_format_str(format));
> +       assert(ret > 0);
> +       ret = asprintf(&cconf_str, "pipe %s, encoder %s, connector %s",
> +                      kmstest_pipe_str(cconf->pipe),
> +                      kmstest_encoder_type_str(cconf->encoder->encoder_type),
> +                      kmstest_connector_type_str(cconf->connector->connector_type));
> +       assert(ret > 0);
> +
> +       printf("Beginning test %s with %s on %s\n",
> +               test_name, mode_format_str, cconf_str);
> +
> +       width = mode->hdisplay;
> +       height = mode->vdisplay;
> +
> +       if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[0]))
> +               goto err1;
> +
> +       if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[1]))
> +               goto err2;
> +
> +       do_or_die(drmModeSetCrtc(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
> +                                0, 0, &cconf->connector->connector_id, 1,
> +                                mode));
> +       do_or_die(drmModePageFlip(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
> +                                 0, NULL));
> +       sleep(2);
> +
> +       if (flags & TEST_DIRECT_RENDER) {
> +               paint_fb(&fb[0], test_name, mode_format_str, cconf_str);
> +       } else if (flags & TEST_GPU_BLIT) {
> +               paint_fb(&fb[1], test_name, mode_format_str, cconf_str);
> +               gpu_blit(&fb[0], &fb[1]);
> +       }
> +       sleep(5);
> +
> +       printf("Test %s with %s on %s: PASSED\n",
> +               test_name, mode_format_str, cconf_str);
> +       free(mode_format_str);
> +       free(cconf_str);
> +
> +       kmstest_remove_fb(drm_fd, &fb[1]);
> +       kmstest_remove_fb(drm_fd, &fb[0]);
> +
> +       return 0;
> +
> +err2:
> +       kmstest_remove_fb(drm_fd, &fb[0]);
> +err1:
> +       fprintf(stderr, "skip testing unsupported format %s\n",
> +               kmstest_format_str(format));
> +
> +       return -1;
> +}
> +
> +static void test_connector(const char *test_name,
> +                          struct kmstest_connector_config *cconf,
> +                          enum test_flags flags)
> +{
> +       const uint32_t *formats;
> +       int format_count;
> +       int i;
> +
> +       kmstest_get_all_formats(&formats, &format_count);
> +       for (i = 0; i < cconf->connector->count_modes; i++) {
> +               int j;
> +
> +               for (j = 0; j < format_count; j++)
> +                       test_format(test_name,
> +                                   cconf, &cconf->connector->modes[i],
> +                                   formats[j], flags);
> +       }
> +}
> +
> +static int run_test(const char *test_name, enum test_flags flags)
> +{
> +       int i;
> +
> +       resources = drmModeGetResources(drm_fd);
> +       assert(resources);
> +
> +       /* Find any connected displays */
> +       for (i = 0; i < resources->count_connectors; i++) {
> +               uint32_t connector_id;
> +               int j;
> +
> +               connector_id = resources->connectors[i];
> +               for (j = 0; j < resources->count_crtcs; j++) {
> +                       struct kmstest_connector_config cconf;
> +                       int ret;
> +
> +                       ret = kmstest_get_connector_config(drm_fd, connector_id,
> +                                                          1 << j, &cconf);
> +                       if (ret < 0)
> +                               continue;
> +
> +                       test_connector(test_name, &cconf, flags);
> +
> +                       kmstest_free_connector_config(&cconf);
> +               }
> +       }
> +
> +       drmModeFreeResources(resources);
> +
> +       return 1;
> +}
> +
> +int main(int argc, char **argv)
> +{
> +       struct {
> +               enum test_flags flags;
> +               const char *name;
> +       } tests[] = {
> +               { TEST_DIRECT_RENDER,   "direct-render" },
> +               { TEST_GPU_BLIT,        "gpu-blit" },
> +       };
> +       int i;
> +
> +       drmtest_subtest_init(argc, argv);
> +
> +       if (!drmtest_only_list_subtests()) {
> +               drm_fd = drm_open_any();
> +
> +               bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
> +               devid = intel_get_drm_devid(drm_fd);
> +               batch = intel_batchbuffer_alloc(bufmgr, devid);
> +
> +               do_or_die(drmtest_set_vt_graphics_mode());
> +       }
> +
> +       for (i = 0; i < ARRAY_SIZE(tests); i++) {
> +               if (drmtest_run_subtest(tests[i].name))
> +                       run_test(tests[i].name, tests[i].flags);
> +       }
> +
> +       if (!drmtest_only_list_subtests())
> +               close(drm_fd);
> +
> +       return 0;
> +}
> --
> 1.8.1.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Rodrigo Vivi
Blog: http://blog.vivi.eng.br



More information about the Intel-gfx mailing list