aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Jakobi2015-03-11 14:38:40 -0500
committerEmil Velikov2015-03-16 17:18:05 -0500
commit6f950de953ead6391ffa82b6c517fd4ea3ce3e29 (patch)
tree31d027b0f23c9f064523cd62b3848a778f2cf6e6 /tests/exynos/exynos_fimg2d_test.c
parent763ff19a2ff751cf3821769681d2e25ec175abc2 (diff)
downloadexternal-libgbm-6f950de953ead6391ffa82b6c517fd4ea3ce3e29.tar.gz
external-libgbm-6f950de953ead6391ffa82b6c517fd4ea3ce3e29.tar.xz
external-libgbm-6f950de953ead6391ffa82b6c517fd4ea3ce3e29.zip
tests/exynos: fimg2d: add a checkerboard test
This makes it easier to spot memory corruptions which don't become visible when using a plain buffer filled with a solid color (so corruptions that are just a permutation of the bytes in the buffer). Signed-off-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de> Reviewed-by: Inki Dae <inki.dae@samsung.com> Tested-by: Joonyoung Shim <jy0922.shim@samsung.com>
Diffstat (limited to 'tests/exynos/exynos_fimg2d_test.c')
-rw-r--r--tests/exynos/exynos_fimg2d_test.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/exynos/exynos_fimg2d_test.c b/tests/exynos/exynos_fimg2d_test.c
index 8e20e27b..52d5543f 100644
--- a/tests/exynos/exynos_fimg2d_test.c
+++ b/tests/exynos/exynos_fimg2d_test.c
@@ -57,6 +57,9 @@ struct fimg2d_test_case {
57 int (*blend)(struct exynos_device *dev, 57 int (*blend)(struct exynos_device *dev,
58 struct exynos_bo *src, struct exynos_bo *dst, 58 struct exynos_bo *src, struct exynos_bo *dst,
59 enum e_g2d_buf_type); 59 enum e_g2d_buf_type);
60 int (*checkerboard)(struct exynos_device *dev,
61 struct exynos_bo *src, struct exynos_bo *dst,
62 enum e_g2d_buf_type);
60}; 63};
61 64
62struct connector { 65struct connector {
@@ -209,6 +212,33 @@ static struct exynos_bo *exynos_create_buffer(struct exynos_device *dev,
209 return bo; 212 return bo;
210} 213}
211 214
215/* Allocate buffer and fill it with checkerboard pattern, where the tiles *
216 * have a random color. The caller has to free the buffer. */
217void *create_checkerboard_pattern(unsigned int num_tiles_x,
218 unsigned int num_tiles_y, unsigned int tile_size)
219{
220 unsigned int *buf;
221 unsigned int x, y, i, j;
222 const unsigned int stride = num_tiles_x * tile_size;
223
224 if (posix_memalign((void*)&buf, 64, num_tiles_y * tile_size * stride * 4) != 0)
225 return NULL;
226
227 for (x = 0; x < num_tiles_x; ++x) {
228 for (y = 0; y < num_tiles_y; ++y) {
229 const unsigned int color = 0xff000000 + (random() & 0xffffff);
230
231 for (i = 0; i < tile_size; ++i) {
232 for (j = 0; j < tile_size; ++j) {
233 buf[x * tile_size + y * stride * tile_size + i + j * stride] = color;
234 }
235 }
236 }
237 }
238
239 return buf;
240}
241
212static void exynos_destroy_buffer(struct exynos_bo *bo) 242static void exynos_destroy_buffer(struct exynos_bo *bo)
213{ 243{
214 exynos_bo_destroy(bo); 244 exynos_bo_destroy(bo);
@@ -538,11 +568,90 @@ err_free_userptr:
538 return 0; 568 return 0;
539} 569}
540 570
571static int g2d_checkerboard_test(struct exynos_device *dev,
572 struct exynos_bo *src,
573 struct exynos_bo *dst,
574 enum e_g2d_buf_type type)
575{
576 struct g2d_context *ctx;
577 struct g2d_image src_img = {0}, dst_img = {0};
578 unsigned int src_x, src_y, dst_x, dst_y, img_w, img_h;
579 void *checkerboard = NULL;
580 int ret;
581
582 ctx = g2d_init(dev->fd);
583 if (!ctx)
584 return -EFAULT;
585
586 dst_img.bo[0] = dst->handle;
587
588 src_x = 0;
589 src_y = 0;
590 dst_x = 0;
591 dst_y = 0;
592
593 checkerboard = create_checkerboard_pattern(screen_width / 32, screen_height / 32, 32);
594 if (checkerboard == NULL) {
595 ret = -1;
596 goto fail;
597 }
598
599 img_w = screen_width - (screen_width % 32);
600 img_h = screen_height - (screen_height % 32);
601
602 switch (type) {
603 case G2D_IMGBUF_GEM:
604 memcpy(src->vaddr, checkerboard, img_w * img_h * 4);
605 src_img.bo[0] = src->handle;
606 break;
607 case G2D_IMGBUF_USERPTR:
608 src_img.user_ptr[0].userptr = (unsigned long)checkerboard;
609 src_img.user_ptr[0].size = img_w * img_h * 4;
610 break;
611 default:
612 ret = -EFAULT;
613 goto fail;
614 }
615
616 printf("checkerboard test with %s.\n",
617 type == G2D_IMGBUF_GEM ? "gem" : "userptr");
618
619 src_img.width = img_w;
620 src_img.height = img_h;
621 src_img.stride = src_img.width * 4;
622 src_img.buf_type = type;
623 src_img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;
624
625 dst_img.width = screen_width;
626 dst_img.height = screen_height;
627 dst_img.stride = dst_img.width * 4;
628 dst_img.buf_type = G2D_IMGBUF_GEM;
629 dst_img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;
630 src_img.color = 0xff000000;
631 ret = g2d_solid_fill(ctx, &dst_img, src_x, src_y, screen_width, screen_height);
632 if (ret < 0)
633 goto fail;
634
635 ret = g2d_copy(ctx, &src_img, &dst_img, src_x, src_y, dst_x, dst_y,
636 img_w, img_h);
637 if (ret < 0)
638 goto fail;
639
640 g2d_exec(ctx);
641
642fail:
643 free(checkerboard);
644 g2d_fini(ctx);
645
646 return ret;
647}
648
541static struct fimg2d_test_case test_case = { 649static struct fimg2d_test_case test_case = {
542 .solid_fill = &g2d_solid_fill_test, 650 .solid_fill = &g2d_solid_fill_test,
543 .copy = &g2d_copy_test, 651 .copy = &g2d_copy_test,
544 .copy_with_scale = &g2d_copy_with_scale_test, 652 .copy_with_scale = &g2d_copy_with_scale_test,
545 .blend = &g2d_blend_test, 653 .blend = &g2d_blend_test,
654 .checkerboard = &g2d_checkerboard_test,
546}; 655};
547 656
548static void usage(char *name) 657static void usage(char *name)
@@ -684,6 +793,14 @@ int main(int argc, char **argv)
684 goto err_free_src; 793 goto err_free_src;
685 } 794 }
686 795
796 wait_for_user_input(0);
797
798 ret = test_case.checkerboard(dev, src, bo, G2D_IMGBUF_GEM);
799 if (ret < 0) {
800 fprintf(stderr, "failed to issue checkerboard test.\n");
801 goto err_free_src;
802 }
803
687 wait_for_user_input(1); 804 wait_for_user_input(1);
688 805
689 /* 806 /*