All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gustavo Padovan <gustavo@padovan.org>
To: dri-devel@lists.freedesktop.org
Cc: "Emilio López" <emilio.lopez@collabora.co.uk>,
	"Shuah Khan" <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org
Subject: [PATCH 1/2] selftests: sync: add test that waits on a destroyed timeline
Date: Mon,  4 Sep 2017 20:06:03 -0300	[thread overview]
Message-ID: <20170904230604.12757-1-gustavo@padovan.org> (raw)

From: Emilio López <emilio.lopez@collabora.co.uk>

If a sw_sync_timeline is destroyed the fences associated to it need
to be signalled. This test checks that.

Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
---
 tools/testing/selftests/sync/sync_test.c |  1 +
 tools/testing/selftests/sync/sync_wait.c | 58 ++++++++++++++++++++++++++++++++
 tools/testing/selftests/sync/synctest.h  |  1 +
 3 files changed, 60 insertions(+)

diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index 62fa666e501a..5d93c9dcc290 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -79,6 +79,7 @@ int main(void)
 	err += RUN_TEST(test_fence_one_timeline_merge);
 	err += RUN_TEST(test_fence_merge_same_fence);
 	err += RUN_TEST(test_fence_multi_timeline_wait);
+	err += RUN_TEST(test_fence_wait_on_destroyed_timeline);
 	err += RUN_TEST(test_stress_two_threads_shared_timeline);
 	err += RUN_TEST(test_consumer_stress_multi_producer_single_consumer);
 	err += RUN_TEST(test_merge_stress_random_merge);
diff --git a/tools/testing/selftests/sync/sync_wait.c b/tools/testing/selftests/sync/sync_wait.c
index d69b752f6550..82ad9f519959 100644
--- a/tools/testing/selftests/sync/sync_wait.c
+++ b/tools/testing/selftests/sync/sync_wait.c
@@ -25,6 +25,7 @@
  *  OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <pthread.h>
 #include "sync.h"
 #include "sw_sync.h"
 #include "synctest.h"
@@ -89,3 +90,60 @@ int test_fence_multi_timeline_wait(void)
 
 	return 0;
 }
+
+struct fds_test {
+       int timeline;
+       int fencesig, fencekill;
+       int result;
+};
+
+static int test_fence_wait_on_destroyed_timeline_thread(void *d)
+{
+       struct fds_test *data = d;
+       int ret;
+
+       /* in case of errors */
+       data->result = 1;
+
+       ret = sw_sync_timeline_inc(data->timeline, 100);
+       ASSERT(ret == 0, "Failure advancing timeline\n");
+
+       ret = sync_wait(data->fencekill, -1);
+       ASSERT(ret == 1, "Failure waiting on fence\n");
+
+       /* no errors occurred */
+       data->result = 0;
+       return 0;
+}
+
+int test_fence_wait_on_destroyed_timeline(void)
+{
+       struct fds_test data;
+       pthread_t thread;
+       int valid;
+
+       data.timeline = sw_sync_timeline_create();
+       valid = sw_sync_timeline_is_valid(data.timeline);
+       ASSERT(valid, "Failure allocating timeline\n");
+
+       data.fencesig = sw_sync_fence_create(data.timeline, "allocFence", 100);
+       data.fencekill = sw_sync_fence_create(data.timeline, "allocFence", 200);
+
+       /* Spawn a thread to wait on a fence when the timeline is killed */
+       pthread_create(&thread, NULL, (void *(*)(void *))
+                      test_fence_wait_on_destroyed_timeline_thread, &data);
+
+       /* Wait for the thread to spool up */
+       sync_wait(data.fencesig, -1);
+
+       /* Kill the timeline */
+       sw_sync_timeline_destroy(data.timeline);
+
+       /* wait for the thread to clean up */
+       pthread_join(thread, NULL);
+
+       sw_sync_fence_destroy(data.fencesig);
+       sw_sync_fence_destroy(data.fencekill);
+
+       return data.result;
+}
diff --git a/tools/testing/selftests/sync/synctest.h b/tools/testing/selftests/sync/synctest.h
index e7d1d57dba7a..1cbe1e3658b3 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -53,6 +53,7 @@ int test_fence_merge_same_fence(void);
 
 /* Fence wait tests */
 int test_fence_multi_timeline_wait(void);
+int test_fence_wait_on_destroyed_timeline(void);
 
 /* Stress test - parallelism */
 int test_stress_two_threads_shared_timeline(void);
-- 
2.13.5

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

             reply	other threads:[~2017-09-04 23:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04 23:06 Gustavo Padovan [this message]
2017-09-04 23:06 ` [PATCH 2/2] dma-buf/sw_sync: force signal all unsignaled fences on dying timeline Gustavo Padovan
2017-09-04 23:53   ` Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170904230604.12757-1-gustavo@padovan.org \
    --to=gustavo@padovan.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emilio.lopez@collabora.co.uk \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.