diff mbox

[11/12] tests/kms_atomic_transition: add in_fences tests

Message ID 1479117566-17709-14-git-send-email-gustavo@padovan.org (mailing list archive)
State New, archived
Headers show

Commit Message

Gustavo Padovan Nov. 14, 2016, 9:59 a.m. UTC
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 tests/kms_atomic_transition.c | 92 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 82 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/tests/kms_atomic_transition.c b/tests/kms_atomic_transition.c
index 507f526..54fc9da 100644
--- a/tests/kms_atomic_transition.c
+++ b/tests/kms_atomic_transition.c
@@ -23,7 +23,9 @@ 
 
 #include "igt.h"
 #include "drmtest.h"
+#include "sw_sync.h"
 #include <errno.h>
+#include <pthread.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
@@ -111,6 +113,78 @@  enum transition_type {
 	TRANSITION_MODESET_DISABLE,
 };
 
+int timeline[IGT_MAX_PLANES];
+pthread_t thread[IGT_MAX_PLANES];
+int seqno[IGT_MAX_PLANES];
+
+static void prepare_fencing(igt_display_t *display, enum pipe pipe)
+{
+	igt_plane_t *plane;
+
+	for_each_plane_on_pipe(display, pipe, plane)
+		timeline[plane->index] = sw_sync_timeline_create();
+}
+
+static void unprepare_fencing(igt_display_t *display, enum pipe pipe)
+{
+	igt_plane_t *plane;
+
+	for_each_plane_on_pipe(display, pipe, plane)
+		close(timeline[plane->index]);
+}
+
+static void *fence_inc_thread(void *arg)
+{
+	int t = *((int *) arg);
+
+	pthread_detach(pthread_self());
+
+	usleep(5000);
+	sw_sync_timeline_inc(t, 1);
+	return NULL;
+}
+
+static void configure_fencing(igt_display_t *display, enum pipe pipe)
+{
+	igt_plane_t *plane;
+	int i, fd, ret;
+
+	for_each_plane_on_pipe(display, pipe, plane) {
+
+		if (!plane->fb)
+			continue;
+
+		i = plane->index;
+
+		seqno[i]++;
+		fd = sw_sync_fence_create(timeline[i], seqno[i]);
+		igt_plane_set_fence_fd(plane, fd);
+		ret = pthread_create(&thread[i], NULL, fence_inc_thread, &timeline[i]);
+		igt_assert_eq(ret, 0);
+	}
+}
+
+static void clear_fencing(igt_display_t *display, enum pipe pipe)
+{
+	igt_plane_t *plane;
+
+	for_each_plane_on_pipe(display, pipe, plane)
+		igt_plane_set_fence_fd(plane, -1);
+}
+
+static void atomic_commit(igt_display_t *display, enum pipe pipe, unsigned int flags, void *data, bool fencing, int *out_fence)
+{
+	if (fencing) {
+		configure_fencing(display, pipe);
+		igt_pipe_set_out_fence_ptr(&display->pipes[pipe], out_fence);
+	}
+
+	igt_display_commit_atomic(display, flags, data);
+
+	if (fencing)
+		clear_fencing(display, pipe);
+}
+
 /*
  * 1. Set primary plane to a known fb.
  * 2. Make sure getcrtc returns the correct fb id.
@@ -134,6 +208,9 @@  run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
 	unsigned flags = DRM_MODE_PAGE_FLIP_EVENT;
 	int out_fence, ret;
 
+	if (fencing)
+		prepare_fencing(display, pipe);
+
 	if (nonblocking)
 		flags |= DRM_MODE_ATOMIC_NONBLOCK;
 
@@ -233,10 +310,8 @@  run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
 
 		wm_setup_plane(display, pipe, i, parms);
 
-		if (fencing)
-			igt_pipe_set_out_fence_ptr(&display->pipes[pipe], &out_fence);
+		atomic_commit(display, pipe, flags, (void *)(unsigned long)i, fencing, &out_fence);
 
-		igt_display_commit_atomic(display, flags, (void *)(unsigned long)i);
 		drmHandleEvent(display->drm_fd, &drm_events);
 
 		if (type == TRANSITION_MODESET_DISABLE) {
@@ -260,19 +335,14 @@  run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
 				if (type == TRANSITION_MODESET)
 					igt_output_override_mode(output, &override_mode);
 
-				if (fencing)
-					igt_pipe_set_out_fence_ptr(&display->pipes[pipe], &out_fence);
-
-				igt_display_commit_atomic(display, flags, (void *)(unsigned long)j);
+				atomic_commit(display, pipe, flags, (void *)(unsigned long)i, fencing, &out_fence);
 				drmHandleEvent(display->drm_fd, &drm_events);
 
 				wm_setup_plane(display, pipe, i, parms);
 				if (type == TRANSITION_MODESET)
 					igt_output_override_mode(output, NULL);
 
-				if (fencing)
-					igt_pipe_set_out_fence_ptr(&display->pipes[pipe], &out_fence);
-
+				atomic_commit(display, pipe, flags, (void *)(unsigned long)i, fencing, &out_fence);
 				igt_display_commit_atomic(display, flags, (void *)(unsigned long)i);
 				drmHandleEvent(display->drm_fd, &drm_events);
 			}
@@ -280,6 +350,8 @@  run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
 	}
 
 cleanup:
+	unprepare_fencing(display, pipe);
+
 	igt_output_set_pipe(output, PIPE_NONE);
 
 	for_each_plane_on_pipe(display, pipe, plane)