[RFC PATCH v1 5/9] selftest: sync: destruction tests for sw_sync framework
Emilio López
emilio.lopez at collabora.co.uk
Wed Mar 9 15:28:58 UTC 2016
These tests are based on the libsync test suite from Android.
This commit includes tests for operations on destructed objects.
Signed-off-by: Emilio López <emilio.lopez at collabora.co.uk>
---
tools/testing/selftests/sync/Makefile | 1 +
tools/testing/selftests/sync/sync_destroyed.c | 90 +++++++++++++++++++++++++++
tools/testing/selftests/sync/sync_test.c | 1 +
tools/testing/selftests/sync/synctest.h | 3 +
4 files changed, 95 insertions(+)
create mode 100644 tools/testing/selftests/sync/sync_destroyed.c
diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index 9944957..4104d22 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -15,6 +15,7 @@ TESTS += sync_alloc.o
TESTS += sync_fence.o
TESTS += sync_merge.o
TESTS += sync_wait.o
+TESTS += sync_destroyed.o
sync_test: $(SRC) $(TESTS)
diff --git a/tools/testing/selftests/sync/sync_destroyed.c b/tools/testing/selftests/sync/sync_destroyed.c
new file mode 100644
index 0000000..4d42f0e
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_destroyed.c
@@ -0,0 +1,90 @@
+/*
+ * sync fence tests on destroyed timelines
+ * Copyright 2015-2016 Collabora Ltd.
+ *
+ * Based on the implementation from the Android Open Source Project,
+ *
+ * Copyright 2012 Google, Inc
+ *
+ * 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.
+ */
+
+#include <errno.h>
+#include <pthread.h>
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+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/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index 344a2f6..91f6b51 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -66,6 +66,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);
if (err)
printf("[FAIL]\tsync errors: %d\n", err);
diff --git a/tools/testing/selftests/sync/synctest.h b/tools/testing/selftests/sync/synctest.h
index 9287393..bc8faae0 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -54,4 +54,7 @@ int test_fence_merge_same_fence(void);
/* Fence wait tests */
int test_fence_multi_timeline_wait(void);
+/* Fence test on destroyed timelines */
+int test_fence_wait_on_destroyed_timeline(void);
+
#endif
--
2.5.0
More information about the dri-devel
mailing list