Skip to contentSkip to conversation

Implement sw_sync test

PATCH Superseded [email protected] 2 participants 28 messages Nov 17, 2016 Library code

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v6 cover Implement sw_sync test

From: Robert Foss <[email protected]>

This series implements the sw_sync test and the lib/sw_sync helper functions for said test.

The sw_sync subtests range from very basic tests of the sw_sync functionality, to stress testing and randomized tests.

Changes since v1:
Added "Reviewed-by: Eric Engestrom <[email protected]>" tag

lib/sw_sync:
- Fixed fd value checking
- Fixed fd validity check in sw_sync_fd_close()
- Moved sw_sync related paths to define
- Switched from malloc+memset to calloc in sync_file_info()
- Switched sizeof to dereferenced ptr

tests/sw_sync:
- Moved lib/sw_sync related code to lib/sw_sync commit
- Replaced memset with assignment in loop

Changes since v2:

lib/sw_sync:
- Replaced fd validity check in sw_sync_timeline_create()
- Replace sw_sync_XXX_destroy() functions with close()
- Simplified sw_sync_timeline_inc() comparison
- Changed sw_sync_merge() return value to -errno
- Changed name of sw_sync_fence_size() to sw_sync_fence_count()
- Reworked implementation of sw_sync_fence_count()
- Reworked implementation of sw_sync_fence_count_status()

tests/sw_sync:
- Replace sw_sync_XXX_destroy() functions with close()

Changes since v3:

lib/sw_sync:
- Changed sw_sync_fence_create() to take uint32_t seqno
- Added raw __sw_sync_fence_create() and failure check sw_sync_fence_create()

tests/sw_sync:
- Switch to using __sw_sync_fence_create() for failure cases

Changes since v4:

lib/sw_sync:
- Fixed whitespace in sw_sync_fence_count()
- Fixed whitespace and style of sw_sync_wait()
- Fixed whitespace in __sw_sync_fence_count_status()

Changes since v5:

lib/sw_sync:
- Added kernel_has_sw_sync()
- Added igt_require_sw_sync()
- Split out __sw_sync_merge() from sw_sync_merge()
- Added igt_debugfs.h include
- Change sw_sync_wait to reflect android implementation
- Renamed some functions:
- sw_sync_merge -> sync_merge
- sw_sync_wait -> sync_wait
- sw_sync_fence_count -> sync_fence_count
- sw_sync_fence_count_status -> sync_fence_count_status
- __sw_sync_fence_count_status -> __sync_fence_count_status

tests/sw_sync:
- Added subtest test_sync_expired_merge
- Added subtest test_timeline_closed
- Added subtest test_timeline_closed_signaled
- Added subtest test_sync_merge_invalid
- Added subtest test_sync_busy_fork
- Added subtest test_sync_busy_unixsockets
- Skip test on no sw_sync support
- Reworked comments of test_sync_wait
- Renamed test_sync_wait -> test_sync_busy
- Improved test_sync_wait igt_assert_f messages

Rafael Antognolli (1):
tests/sw_sync: Add subtest test_sync_expired_merge

Robert Foss (20):
lib/sw_sync: Add helper functions for managing synchronization
primitives
tests/sw_sync: Add sw_sync test
tests/sw_sync: Add subtest test_alloc_fence
tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline tests/sw_sync: Add subtest test_alloc_merge_fence tests/sw_sync: Add subtest test_sync_busy
tests/sw_sync: Add subtest test_sync_merge
tests/sw_sync: Add subtest test_sync_merge_same tests/sw_sync: Add subtest test_sync_multi_consumer tests/sw_sync: Add subtest test_sync_multi_consumer_producer tests/sw_sync: Add subtest test_sync_random_merge tests/sw_sync: Add subtest test_sync_multi_timeline_wait tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer tests/sw_sync: Add subtest test_timeline_closed tests/sw_sync: Add subtest test_timeline_closed_signaled lib/sw_sync: Add igt_require_sw_sync to enable skipping on no sw_sync
support
tests/sw_sync: Add igt_require check for sw_sync feature tests/sw_sync: Add subtest test_sync_merge_invalid tests/sw_sync: Add subtest test_sync_busy_fork tests/sw_sync: Add subtest test_sync_busy_unixsocket

 .settings/language.settings.xml |   25 +
 lib/Makefile.sources            |    2 +
 lib/sw_sync.c                   |  222 +++++
 lib/sw_sync.h                   |   49 ++
 tests/Makefile.sources          |    1 +
 tests/drm_fence                 |  Bin 0 -> 901032 bytes
 tests/kms_atomic.c.orig         | 1803 +++++++++++++++++++++++++++++++++++++++
 tests/kms_atomic.c.rej          |   15 +
 tests/kms_fence                 |  Bin 0 -> 1798632 bytes
 tests/sw_sync.c                 |  942 ++++++++++++++++++++
 tests/sw_sync.c.orig            |  694 +++++++++++++++
 11 files changed, 3753 insertions(+)
 create mode 100644 .settings/language.settings.xml
 create mode 100644 lib/sw_sync.c
 create mode 100644 lib/sw_sync.h
 create mode 100755 tests/drm_fence
 create mode 100644 tests/kms_atomic.c.orig
 create mode 100644 tests/kms_atomic.c.rej
 create mode 100755 tests/kms_fence
 create mode 100644 tests/sw_sync.c
 create mode 100644 tests/sw_sync.c.orig
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH v6 1/21 lib/sw_sync: Add helper functions for managing synchronization primitives

From: Robert Foss <[email protected]>

Base functions to help testing the Sync File Framework (explicit fencing mechanism ported from Android).
These functions allow you to create, use and destroy timelines and fences.

---
 lib/Makefile.sources |   2 +
 lib/sw_sync.c        | 199 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/sw_sync.h        |  48 +++++++++++++
 3 files changed, 249 insertions(+)
 create mode 100644 lib/sw_sync.c
 create mode 100644 lib/sw_sync.h
lib/Makefile.sources +2 -0
index e8e277b..7aaf42f 100644
@@ -63,6 +63,8 @@ lib_source_list =	 	\
 	rendercopy_gen8.c	\
 	rendercopy_gen9.c	\
 	rendercopy.h		\
+	sw_sync.c		\
+	sw_sync.h		\
 	intel_reg_map.c		\
 	intel_iosf.c		\
 	igt_kms.c		\
lib/sw_sync.c new file +199 -0

199 lines not on this page · raw message

lib/sw_sync.h new file +48 -0

48 lines not on this page · raw message

Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH v6 2/21 tests/sw_sync: Add sw_sync test

In reply to [email protected]

From: Robert Foss <[email protected]>

Add initial tests for sw_sync.

---
 .settings/language.settings.xml |   25 +
 lib/sw_sync.c                   |   12 +-
 lib/sw_sync.h                   |    8 +-
 tests/Makefile.sources          |    1 +
 tests/drm_fence                 |  Bin 0 -> 901032 bytes
 tests/kms_atomic.c.orig         | 1803 +++++++++++++++++++++++++++++++++++++++
 tests/kms_atomic.c.rej          |   15 +
 tests/kms_fence                 |  Bin 0 -> 1798632 bytes
 tests/sw_sync.c                 |   52 ++
 tests/sw_sync.c.orig            |  694 +++++++++++++++
 10 files changed, 2600 insertions(+), 10 deletions(-)
 create mode 100644 .settings/language.settings.xml
 create mode 100755 tests/drm_fence
 create mode 100644 tests/kms_atomic.c.orig
 create mode 100644 tests/kms_atomic.c.rej
 create mode 100755 tests/kms_fence
 create mode 100644 tests/sw_sync.c
 create mode 100644 tests/sw_sync.c.orig
.settings/language.settings.xml new file +25 -0
new file mode 100644
index 0000000..3f2f9a9
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project>
+	<configuration id="cdt.managedbuild.config.gnu.cross.exe.debug.2128817656" name="Debug">
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
+			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
+			<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-953487821198006981" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
+				<language-scope id="org.eclipse.cdt.core.g++"/>
+			</provider>
+		</extension>
+	</configuration>
+	<configuration id="cdt.managedbuild.config.gnu.cross.exe.release.884103109" name="Release">
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
+			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
+			<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-953487821198006981" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
+				<language-scope id="org.eclipse.cdt.core.g++"/>
+			</provider>
+		</extension>
+	</configuration>
+</project>
lib/sw_sync.c +6 -6
index 861119e..862f8c4 100644
@@ -110,7 +110,7 @@ void sw_sync_timeline_inc(int fd, uint32_t count)
 	do_ioctl(fd, SW_SYNC_IOC_INC, &arg);
 }
 
-int sw_sync_merge(int fd1, int fd2)
+int sync_merge(int fd1, int fd2)
 {
 	struct sync_merge_data data = {};
 	int err;
@@ -126,7 +126,7 @@ int sw_sync_merge(int fd1, int fd2)
 	return data.fence;
 }
 
-int sw_sync_wait(int fd, int timeout)
+int sync_wait(int fd, int timeout)
 {
 	struct pollfd fds = {0};
 	int ret;
@@ -151,7 +151,7 @@ int sw_sync_wait(int fd, int timeout)
 	return ret;
 }
 
-int sw_sync_fence_count(int fd)
+int sync_fence_count(int fd)
 {
 	struct sync_file_info info;
 
@@ -162,7 +162,7 @@ int sw_sync_fence_count(int fd)
 	return info.num_fences;
 }
 
-static int __sw_sync_fence_count_status(int fd, int status)
+static int __sync_fence_count_status(int fd, int status)
 {
 	struct sync_file_info info;
 	struct sync_fence_info *fence_info;
@@ -191,9 +191,9 @@ static int __sw_sync_fence_count_status(int fd, int status)
 	return count;
 }
 
-int sw_sync_fence_count_status(int fd, int status)
+int sync_fence_count_status(int fd, int status)
 {
-	int count = __sw_sync_fence_count_status(fd, status);
+	int count = __sync_fence_count_status(fd, status);
 	igt_assert(count >= 0);
 	return count;
 }
lib/sw_sync.h +4 -4
index fee9249..1f47b29 100644
@@ -39,10 +39,10 @@ int sw_sync_timeline_create(void);
 int __sw_sync_fence_create(int fd, uint32_t seqno);
 int sw_sync_fence_create(int fd, uint32_t seqno);
 void sw_sync_timeline_inc(int fd, uint32_t count);
-int sw_sync_merge(int fd1, int fd2);
-int sw_sync_wait(int fence, int timeout);
-int sw_sync_fence_count(int fd);
-int sw_sync_fence_count_status(int fd, int status);
+int sync_merge(int fd1, int fd2);
+int sync_wait(int fence, int timeout);
+int sync_fence_count(int fd);
+int sync_fence_count_status(int fd, int status);
 
 #endif
 
tests/Makefile.sources +1 -0
index 65e0792..8848094 100644
@@ -131,6 +131,7 @@ TESTS_progs_M = \
 	prime_mmap_kms \
 	prime_self_import \
 	prime_vgem \
+	sw_sync \
 	template \
 	vgem_basic \
 	vgem_slow \
tests/drm_fence new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..e6dd304879891827c182f517db4c6f972e082554
GIT binary patch
tests/kms_atomic.c.orig new file +1803 -0

1,803 lines not on this page · raw message

tests/kms_atomic.c.rej new file +15 -0
new file mode 100644
index 0000000..3ab73c8
@@ -0,0 +1,15 @@
+--- tests/kms_atomic.c
++++ tests/kms_atomic.c
+@@ -1627,10 +1625,10 @@ static void fence_out_commit_n(struct kms_atomic_crtc_state *crtc,
+ 		  memset(&ioc, 0, sizeof(ioc));
+ 		  memset(&out_fences_raw, 0, count_out_fences * sizeof(*out_fences_raw));
+ 
+-		  for (j = 0; j < count_out_fences; j++)
++		  for (i = 0; i < count_out_fences; i++)
+ 		  {
+ 			  out_fences_raw[0].fd = -1;
+-			  out_fences_raw[0].crtc_id = crtc->state->crtcs[j].obj;
++			  out_fences_raw[0].crtc_id = crtc->state->crtcs[i].obj;
+ 		  }
+ 
+ 		  req = drmModeAtomicAlloc();
tests/kms_fence new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..1cd691fb0d7d75bb398db780ede63ab361b01943
GIT binary patch
tests/sw_sync.c new file +52 -0

52 lines not on this page · raw message

tests/sw_sync.c.orig new file +694 -0

694 lines not on this page · raw message

Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

Re: [PATCH i-g-t v6 02/21] tests/sw_sync: Add sw_sync test

Quoted 7 lines · On Thu, Nov 17, 2016 at 10:01:50AM -0500, [email protected] wrote:

From: Robert Foss <[email protected]>

Add initial tests for sw_sync.

Quoted 11 lines
---
 .settings/language.settings.xml |   25 +
 lib/sw_sync.c                   |   12 +-
 lib/sw_sync.h                   |    8 +-
 tests/Makefile.sources          |    1 +
 tests/drm_fence                 |  Bin 0 -> 901032 bytes
 tests/kms_atomic.c.orig         | 1803 +++++++++++++++++++++++++++++++++++++++
 tests/kms_atomic.c.rej          |   15 +
 tests/kms_fence                 |  Bin 0 -> 1798632 bytes
 tests/sw_sync.c                 |   52 ++
 tests/sw_sync.c.orig            |  694 +++++++++++++++

Awooga.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH v6 3/21 tests/sw_sync: Add subtest test_alloc_fence

In reply to [email protected]

From: Robert Foss <[email protected]>

Add subtest alloc_fence that verifies that it's possible to allocate a fence on a timeline.

---
 tests/sw_sync.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tests/sw_sync.c +16 -0
index 47e2dfa..8f6208b 100644
@@ -44,9 +44,25 @@ static void test_alloc_timeline(void)
 	close(timeline);
 }
 
+static void test_alloc_fence(void)
+{
+	int in_fence;
+	int timeline;
+
+	timeline = sw_sync_timeline_create();
+	in_fence = sw_sync_fence_create(timeline, 0);
+
+	close(in_fence);
+	close(timeline);
+}
+
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
 		test_alloc_timeline();
+
+	igt_subtest("alloc_fence")
+		test_alloc_fence();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

PATCH v6 4/21 tests/sw_sync: Add subtest test_alloc_fence_invalid_timeline

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtests tests that creating fences on negative timelines fail.

---
 tests/sw_sync.c | 7 +++++++
 1 file changed, 7 insertions(+)
tests/sw_sync.c +7 -0
index 8f6208b..75bd471 100644
@@ -56,6 +56,10 @@ static void test_alloc_fence(void)
 	close(timeline);
 }
 
+static void test_alloc_fence_invalid_timeline(void)
+{
+	igt_assert(__sw_sync_fence_create(-1, 0) < 0);
+}
 
 igt_main
 {
@@ -64,5 +68,8 @@ igt_main
 
 	igt_subtest("alloc_fence")
 		test_alloc_fence();
+
+	igt_subtest("alloc_fence_invalid_timeline")
+		test_alloc_fence_invalid_timeline();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

PATCH v6 5/21 tests/sw_sync: Add subtest test_alloc_merge_fence

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtest verifies that merging two fences works in the simples possible case.

---
 tests/sw_sync.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
tests/sw_sync.c +23 -0
index 75bd471..ecc75ca 100644
@@ -61,6 +61,26 @@ static void test_alloc_fence_invalid_timeline(void)
 	igt_assert(__sw_sync_fence_create(-1, 0) < 0);
 }
 
+static void test_alloc_merge_fence(void)
+{
+	int in_fence[2];
+	int fence_merge;
+	int timeline[2];
+
+	timeline[0] = sw_sync_timeline_create();
+	timeline[1] = sw_sync_timeline_create();
+
+	in_fence[0] = sw_sync_fence_create(timeline[0], 1);
+	in_fence[1] = sw_sync_fence_create(timeline[1], 1);
+	fence_merge = sync_merge(in_fence[1], in_fence[0]);
+
+	close(in_fence[0]);
+	close(in_fence[1]);
+	close(fence_merge);
+	close(timeline[0]);
+	close(timeline[1]);
+}
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
@@ -71,5 +91,8 @@ igt_main
 
 	igt_subtest("alloc_fence_invalid_timeline")
 		test_alloc_fence_invalid_timeline();
+
+	igt_subtest("alloc_merge_fence")
+		test_alloc_merge_fence();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

PATCH v6 6/21 tests/sw_sync: Add subtest test_sync_busy

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtest verifies that waiting on fences works properly.

---
 tests/sw_sync.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
tests/sw_sync.c +37 -0
index ecc75ca..9667b93 100644
@@ -81,6 +81,40 @@ static void test_alloc_merge_fence(void)
 	close(timeline[1]);
 }
 
+static void test_sync_busy(void)
+{
+	int fence, ret;
+	int timeline;
+
+	timeline = sw_sync_timeline_create();
+	fence = sw_sync_fence_create(timeline, 5);
+
+	/* Make sure that fence has not been signaled yet */
+	ret = sync_wait(fence, 0);
+	igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled early (timeline value 0, fence seqno 5)\n");
+
+	/* Advance timeline from 0 -> 1 */
+	sw_sync_timeline_inc(timeline, 1);
+
+	/* Make sure that fence has not been signaled yet */
+	ret = sync_wait(fence, 0);
+	igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled early (timeline value 1, fence seqno 5)\n");
+
+	/* Advance timeline from 1 -> 5: signaling the fence (seqno 5)*/
+	sw_sync_timeline_inc(timeline, 4);
+
+	ret = sync_wait(fence, 0);
+	igt_assert_f(ret == 0, "Fence not signaled (timeline value 5, fence seqno 5)\n");
+
+	/* Go even further, and confirm wait still succeeds */
+	sw_sync_timeline_inc(timeline, 10);
+	ret = sync_wait(fence, 0);
+	igt_assert_f(ret == 0, "Fence not signaled! (timeline value 10, fence seqno 5)\n");
+
+	close(fence);
+	close(timeline);
+}
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
@@ -94,5 +128,8 @@ igt_main
 
 	igt_subtest("alloc_merge_fence")
 		test_alloc_merge_fence();
+
+	igt_subtest("sync_busy")
+		test_sync_busy();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

PATCH v6 7/21 tests/sw_sync: Add subtest test_sync_merge

In reply to [email protected]

From: Robert Foss <[email protected]>

Add subtest test_sync_merge that tests merging fences and the validity of the resulting merged fence.

---
 tests/sw_sync.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
tests/sw_sync.c +67 -0
index 9667b93..528be4d 100644
@@ -115,6 +115,70 @@ static void test_sync_busy(void)
 	close(timeline);
 }
 
+static void test_sync_merge(void)
+{
+	int in_fence[3];
+	int fence_merge;
+	int timeline;
+	int active, signaled;
+
+	timeline = sw_sync_timeline_create();
+	in_fence[0] = sw_sync_fence_create(timeline, 1);
+	in_fence[1] = sw_sync_fence_create(timeline, 2);
+	in_fence[2] = sw_sync_fence_create(timeline, 3);
+
+	fence_merge = sync_merge(in_fence[0], in_fence[1]);
+	fence_merge = sync_merge(in_fence[2], fence_merge);
+
+	/* confirm all fences have one active point (even d) */
+	active = sync_fence_count_status(in_fence[0],
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	igt_assert_f(active == 1, "in_fence[0] has too many active fences\n");
+	active = sync_fence_count_status(in_fence[1],
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	igt_assert_f(active == 1, "in_fence[1] has too many active fences\n");
+	active = sync_fence_count_status(in_fence[2],
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	igt_assert_f(active == 1, "in_fence[2] has too many active fences\n");
+	active = sync_fence_count_status(fence_merge,
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	igt_assert_f(active == 1, "fence_merge has too many active fences\n");
+
+	/* confirm that fence_merge is not signaled until the max of fence 0,1,2 */
+	sw_sync_timeline_inc(timeline, 1);
+	signaled = sync_fence_count_status(in_fence[0],
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	active = sync_fence_count_status(fence_merge,
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	igt_assert_f(signaled == 1, "in_fence[0] did not signal\n");
+	igt_assert_f(active == 1, "fence_merge signaled too early\n");
+
+	sw_sync_timeline_inc(timeline, 1);
+	signaled = sync_fence_count_status(in_fence[1],
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	active = sync_fence_count_status(fence_merge,
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	igt_assert_f(signaled == 1, "in_fence[1] did not signal\n");
+	igt_assert_f(active == 1, "fence_merge signaled too early\n");
+
+	sw_sync_timeline_inc(timeline, 1);
+	signaled = sync_fence_count_status(in_fence[2],
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	igt_assert_f(signaled == 1, "in_fence[2] did not signal\n");
+	signaled = sync_fence_count_status(fence_merge,
+					       SW_SYNC_FENCE_STATUS_SIGNALED);
+	active = sync_fence_count_status(fence_merge,
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	igt_assert_f(active == 0 && signaled == 1,
+		     "fence_merge did not signal\n");
+
+	close(in_fence[0]);
+	close(in_fence[1]);
+	close(in_fence[2]);
+	close(fence_merge);
+	close(timeline);
+}
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
@@ -131,5 +195,8 @@ igt_main
 
 	igt_subtest("sync_busy")
 		test_sync_busy();
+
+	igt_subtest("sync_merge")
+		test_sync_merge();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

Re: [PATCH i-g-t v6 07/21] tests/sw_sync: Add subtest test_sync_merge

Quoted 23 lines · On Thu, Nov 17, 2016 at 10:01:55AM -0500, [email protected] wrote:

From: Robert Foss <[email protected]>

Add subtest test_sync_merge that tests merging fences and the validity of the resulting merged fence.

---
 tests/sw_sync.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
tests/sw_sync.c +4 -0
index 9667b93..528be4d 100644
@@ -115,6 +115,70 @@ static void test_sync_busy(void)
 	close(timeline);
 }
 
+static void test_sync_merge(void)
+{
+	int in_fence[3];
+	int fence_merge;

tests/sw_sync.c static void test_sync_busy(void) · line 131

Quoted 10 lines
tests/sw_sync.c +10 -0
+	int timeline;
+	int active, signaled;
+
+	timeline = sw_sync_timeline_create();
+	in_fence[0] = sw_sync_fence_create(timeline, 1);
+	in_fence[1] = sw_sync_fence_create(timeline, 2);
+	in_fence[2] = sw_sync_fence_create(timeline, 3);
+
+	fence_merge = sync_merge(in_fence[0], in_fence[1]);
+	fence_merge = sync_merge(in_fence[2], fence_merge);

Can I suggest the pattern:

fence_merge = -1;

for (i = 0; i < ARRAY_SIZE(in_fence); i++) {
	in_fence[i] = sw_sync_fence_create(timeline, i + 1);
	fence_merge = sync_merge(fence_merge, in_fence[i]);

	active = sync_fence_count_status(in_fence[i],
					 SW_SYNC_FENCE_STATUS_ACTIVE);
	igt_assert_f(active == 1, "in_fence[%d] has too many active fences\n", i);

	igt_assert(!sync_fence_count_status(in_fence[i],
					    SW_SYNC_FENCE_STATUS_SIGNALED));
	igt_assert(!sync_fence_count_status(fence_merge,
					    SW_SYNC_FENCE_STATUS_SIGNALED));
}

tests/sw_sync.c static void test_sync_busy(void) · line 147

Quoted 1 line
tests/sw_sync.c +1 -0
+	/* confirm that fence_merge is not signaled until the max of fence 0,1,2 */
for (i = 0; i < ARRAY_SIZE(in_fence); i++) {
	sw_sync_timeline_inc(timeline, 1);

	signaled = sync_fence_count_status(in_fence[i],
					   SW_SYNC_FENCE_STATUS_SIGNALED);
	igt_assert_f(signaled == 1, "in_fence[%d] did not signal\n", i);

	signaled = sync_fence_count_status(fence_merge,
					   SW_SYNC_FENCE_STATUS_SIGNALED);
	active = sync_fence_count_status(fence_merge,
					 SW_SYNC_FENCE_STATUS_ACTIVE);
	if (i + 1 == ARRAY_SIZE(in_fence)) { /* all signaled -> merge complete */
		igt_assert_f(active == 0 && signaled == 1,
			     "fence_merge did not signal\n");
	} else {
		igt_assert_f(active == 1 && signaled == 0,
			     "fence_merge signaled too early\n");
	}

	close(in_fence[1]);
}
Quoted 19 lines
tests/sw_sync.c +7 -0
+	close(fence_merge);
+	close(timeline);
+}
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
@@ -131,5 +195,8 @@ igt_main
 
 	igt_subtest("sync_busy")
 		test_sync_busy();
+
+	igt_subtest("sync_merge")
+		test_sync_merge();
 }
 
Signature · 1 line
2.10.2
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw

PATCH v6 8/21 tests/sw_sync: Add subtest test_sync_merge_same

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtest verifies merging a fence with itself does not fail.

---
 tests/sw_sync.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
tests/sw_sync.c +27 -0
index 528be4d..51aa025 100644
@@ -179,6 +179,30 @@ static void test_sync_merge(void)
 	close(timeline);
 }
 
+static void test_sync_merge_same(void)
+{
+	int in_fence[2];
+	int timeline;
+	int signaled;
+
+	timeline = sw_sync_timeline_create();
+	in_fence[0] = sw_sync_fence_create(timeline, 1);
+	in_fence[1] = sync_merge(in_fence[0], in_fence[0]);
+
+	signaled = sync_fence_count_status(in_fence[0],
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	igt_assert_f(signaled == 0, "fence signaled too early\n");
+
+	sw_sync_timeline_inc(timeline, 1);
+	signaled = sync_fence_count_status(in_fence[0],
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	igt_assert_f(signaled == 1, "fence did not signal\n");
+
+	close(in_fence[0]);
+	close(in_fence[1]);
+	close(timeline);
+}
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
@@ -198,5 +222,8 @@ igt_main
 
 	igt_subtest("sync_merge")
 		test_sync_merge();
+
+	igt_subtest("sync_merge_same")
+		test_sync_merge_same();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw

Re: [PATCH i-g-t v6 08/21] tests/sw_sync: Add subtest test_sync_merge_same

Quoted 26 lines · On Thu, Nov 17, 2016 at 10:01:56AM -0500, [email protected] wrote:

From: Robert Foss <[email protected]>

This subtest verifies merging a fence with itself does not fail.

---
 tests/sw_sync.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
tests/sw_sync.c +8 -0
index 528be4d..51aa025 100644
@@ -179,6 +179,30 @@ static void test_sync_merge(void)
 	close(timeline);
 }
 
+static void test_sync_merge_same(void)
+{
+	int in_fence[2];
+	int timeline;
+	int signaled;
+
+	timeline = sw_sync_timeline_create();
+	in_fence[0] = sw_sync_fence_create(timeline, 1);

tests/sw_sync.c static void test_sync_merge(void) · line 199

Quoted 10 lines
tests/sw_sync.c +10 -0
+	in_fence[1] = sync_merge(in_fence[0], in_fence[0]);
+
+	signaled = sync_fence_count_status(in_fence[0],
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	igt_assert_f(signaled == 0, "fence signaled too early\n");
+
+	sw_sync_timeline_inc(timeline, 1);
+	signaled = sync_fence_count_status(in_fence[0],
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	igt_assert_f(signaled == 1, "fence did not signal\n");

But what in_fence[1]? How does the lifetime of in_fence[1] relate to in_fence[0]?
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw

PATCH v6 9/21 tests/sw_sync: Add subtest test_sync_multi_consumer

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtest verifies the access ordering of multiple consumer threads.

---
 tests/sw_sync.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)
tests/sw_sync.c +103 -0
index 51aa025..833ee07 100644
@@ -27,6 +27,8 @@
  *    Robert Foss <[email protected]>
  */
 
+#include <pthread.h>
+#include <semaphore.h>
 #include <stdint.h>
 #include <unistd.h>
 
@@ -36,6 +38,15 @@
 
 IGT_TEST_DESCRIPTION("Test SW Sync Framework");
 
+typedef struct {
+	int timeline;
+	uint32_t thread_id;
+	uint32_t nbr_threads;
+	uint32_t nbr_iterations;
+	volatile uint32_t * volatile counter;
+	sem_t *sem;
+} data_t;
+
 static void test_alloc_timeline(void)
 {
 	int timeline;
@@ -203,6 +214,95 @@ static void test_sync_merge_same(void)
 	close(timeline);
 }
 
+static void * test_sync_multi_consumer_thread(void *arg)
+{
+	data_t *data = arg;
+	int thread_id = data->thread_id;
+	int nbr_threads = data->nbr_threads;
+	int timeline = data->timeline;
+	int iterations = data->nbr_iterations;
+	int ret, i;
+
+	for (i = 0; i < iterations; i++) {
+		int next_point = i * nbr_threads + thread_id;
+		int fence = sw_sync_fence_create(timeline, next_point);
+
+		ret = sync_wait(fence, 1000);
+		if (ret == -1)
+		{
+			return (void *) 1;
+		}
+
+		if (*(data->counter) != next_point)
+		{
+			return (void *) 1;
+		}
+
+		sem_post(data->sem);
+		close(fence);
+	}
+	return NULL;
+}
+
+static void test_sync_multi_consumer(void)
+{
+	const uint32_t nbr_threads = 8;
+	const uint32_t nbr_iterations = 1 << 14;
+	data_t data_arr[nbr_threads];
+	pthread_t thread_arr[nbr_threads];
+	sem_t sem;
+	int timeline;
+	volatile uint32_t counter = 0;
+	uintptr_t thread_ret = 0;
+	data_t data;
+	int i, ret;
+
+	sem_init(&sem, 0, 0);
+	timeline = sw_sync_timeline_create();
+
+	data.nbr_iterations = nbr_iterations;
+	data.nbr_threads = nbr_threads;
+	data.counter = &counter;
+	data.timeline = timeline;
+	data.sem = &sem;
+
+	/* Start sync threads. */
+	for (i = 0; i < nbr_threads; i++)
+	{
+		data_arr[i] = data;
+		data_arr[i].thread_id = i;
+		ret = pthread_create(&thread_arr[i], NULL,
+				     test_sync_multi_consumer_thread,
+				     (void *) &(data_arr[i]));
+		igt_assert_eq(ret, 0);
+	}
+
+	/* Produce 'content'. */
+	for (i = 0; i < nbr_threads * nbr_iterations; i++)
+	{
+		sem_wait(&sem);
+
+		counter++;
+		sw_sync_timeline_inc(timeline, 1);
+	}
+
+	/* Wait for threads to complete. */
+	for (i = 0; i < nbr_threads; i++)
+	{
+		uintptr_t local_thread_ret;
+		pthread_join(thread_arr[i], (void **)&local_thread_ret);
+		thread_ret |= local_thread_ret;
+	}
+
+	close(timeline);
+	sem_destroy(&sem);
+
+	igt_assert_f(counter == nbr_threads * nbr_iterations,
+		     "Counter has unexpected value.\n");
+
+	igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
+}
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
@@ -225,5 +325,8 @@ igt_main
 
 	igt_subtest("sync_merge_same")
 		test_sync_merge_same();
+
+	igt_subtest("sync_multi_consumer")
+		test_sync_multi_consumer();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw

PATCH v6 10/21 tests/sw_sync: Add subtest test_sync_multi_consumer_producer

In reply to [email protected]

From: Robert Foss <[email protected]>

This test verifies that stressing the kernel by creating multiple consumer/producer threads that wait on a single timeline to be incremented by another conumer/producer thread does not fail.
And that the order amongst the threads is maintained.

---
 tests/sw_sync.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
tests/sw_sync.c +83 -0
index 833ee07..db182eb 100644
@@ -303,6 +303,86 @@ static void test_sync_multi_consumer(void)
 	igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
 }
 
+static void * test_sync_multi_consumer_producer_thread(void *arg)
+{
+	data_t *data = arg;
+	int thread_id = data->thread_id;
+	int nbr_threads = data->nbr_threads;
+	int timeline = data->timeline;
+	int iterations = data->nbr_iterations;
+	int ret, i;
+
+	for (i = 0; i < iterations; i++) {
+		int next_point = i * nbr_threads + thread_id;
+		int fence = sw_sync_fence_create(timeline, next_point);
+
+		ret = sync_wait(fence, 1000);
+		if (ret == -1)
+		{
+			return (void *) 1;
+		}
+
+		if (*(data->counter) != next_point)
+		{
+			return (void *) 1;
+		}
+
+		(*data->counter)++;
+
+		/* Kick off the next thread. */
+		sw_sync_timeline_inc(timeline, 1);
+
+		close(fence);
+	}
+	return NULL;
+}
+
+static void test_sync_multi_consumer_producer(void)
+{
+	const uint32_t nbr_threads = 8;
+	const uint32_t nbr_iterations = 1 << 14;
+	data_t data_arr[nbr_threads];
+	pthread_t thread_arr[nbr_threads];
+	int timeline;
+	volatile uint32_t counter = 0;
+	uintptr_t thread_ret = 0;
+	data_t data;
+	int i, ret;
+
+	timeline = sw_sync_timeline_create();
+
+	data.nbr_iterations = nbr_iterations;
+	data.nbr_threads = nbr_threads;
+	data.counter = &counter;
+	data.timeline = timeline;
+
+	/* Start consumer threads. */
+	for (i = 0; i < nbr_threads; i++)
+	{
+		data_arr[i] = data;
+		data_arr[i].thread_id = i;
+		ret = pthread_create(&thread_arr[i], NULL,
+				     test_sync_multi_consumer_producer_thread,
+				     (void *) &(data_arr[i]));
+		igt_assert_eq(ret, 0);
+	}
+
+	/* Wait for threads to complete. */
+	for (i = 0; i < nbr_threads; i++)
+	{
+		uintptr_t local_thread_ret;
+		pthread_join(thread_arr[i], (void **)&local_thread_ret);
+		thread_ret |= local_thread_ret;
+	}
+
+	close(timeline);
+
+	igt_assert_f(counter == nbr_threads * nbr_iterations,
+		     "Counter has unexpected value.\n");
+
+	igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
+}
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
@@ -328,5 +408,8 @@ igt_main
 
 	igt_subtest("sync_multi_consumer")
 		test_sync_multi_consumer();
+
+	igt_subtest("sync_multi_consumer_producer")
+		test_sync_multi_consumer_producer();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#14 lore raw

PATCH v6 11/21 tests/sw_sync: Add subtest test_sync_random_merge

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtest verifies that creating many timelines and merging random fences from each timeline with eachother results in merged fences that are fully functional.

---
 tests/sw_sync.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
tests/sw_sync.c +73 -0
index db182eb..d59adb4 100644
@@ -383,6 +383,76 @@ static void test_sync_multi_consumer_producer(void)
 	igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
 }
 
+static void test_sync_random_merge(void)
+{
+	int i, size, ret;
+	const int nbr_timeline = 32;
+	const int nbr_merge = 1024;
+	int fence_map[nbr_timeline];
+	int timeline_arr[nbr_timeline];
+	int fence, tmpfence, merged;
+	int timeline, timeline_offset, sync_pt;
+
+	srand(time(NULL));
+
+	for (i = 0; i < nbr_timeline; i++) {
+		timeline_arr[i] = sw_sync_timeline_create();
+		fence_map[i] = -1;
+	}
+
+	sync_pt = rand();
+	fence = sw_sync_fence_create(timeline_arr[0], sync_pt);
+
+	fence_map[0] = sync_pt;
+
+	/* Randomly create syncpoints out of a fixed set of timelines,
+	 * and merge them together.
+	 */
+	for (i = 0; i < nbr_merge; i++) {
+		/* Generate syncpoint. */
+		timeline_offset = rand() % nbr_timeline;
+		timeline = timeline_arr[timeline_offset];
+		sync_pt = rand();
+
+		/* Keep track of the latest sync_pt in each timeline. */
+		if (fence_map[timeline_offset] == -1)
+			fence_map[timeline_offset] = sync_pt;
+		else if (fence_map[timeline_offset] < sync_pt)
+			fence_map[timeline_offset] = sync_pt;
+
+		/* Merge. */
+		tmpfence = sw_sync_fence_create(timeline, sync_pt);
+		merged = sync_merge(tmpfence, fence);
+		close(tmpfence);
+		close(fence);
+		fence = merged;
+	}
+
+	size = 0;
+	for (i = 0; i < nbr_timeline; i++)
+		if (fence_map[i] != -1)
+			size++;
+
+	/* Trigger the merged fence. */
+	for (i = 0; i < nbr_timeline; i++) {
+		if (fence_map[i] != -1) {
+			ret = sync_wait(fence, 0);
+			igt_assert_f(ret == -1 && errno == ETIME,
+				    "Failure waiting on fence until timeout\n");
+			/* Increment the timeline to the last sync_pt */
+			sw_sync_timeline_inc(timeline_arr[i], fence_map[i]);
+		}
+	}
+
+	/* Check that the fence is triggered. */
+	ret = sync_wait(fence, 0);
+	igt_assert_f(ret == 0, "Failure triggering fence\n");
+
+	close(fence);
+	for (i = 0; i < nbr_timeline; i++)
+		close(timeline_arr[i]);
+}
+
 igt_main
 {
 	igt_subtest("alloc_timeline")
@@ -411,5 +481,8 @@ igt_main
 
 	igt_subtest("sync_multi_consumer_producer")
 		test_sync_multi_consumer_producer();
+
+	igt_subtest("sync_random_merge")
+		test_sync_random_merge();
 }
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#15 lore raw

PATCH v6 12/21 tests/sw_sync: Add subtest test_sync_multi_timeline_wait

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtest verifies that waiting, timing out on a wait and that counting fences in various states works.

---
 tests/sw_sync.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
tests/sw_sync.c +66 -0
index d59adb4..99bd3d9 100644
@@ -214,6 +214,69 @@ static void test_sync_merge_same(void)
 	close(timeline);
 }
 
+static void test_sync_multi_timeline_wait(void)
+{
+	int timeline[3];
+	int in_fence[3];
+	int fence_merge;
+	int active, signaled, ret;
+
+	timeline[0] = sw_sync_timeline_create();
+	timeline[1] = sw_sync_timeline_create();
+	timeline[2] = sw_sync_timeline_create();
+
+	in_fence[0] = sw_sync_fence_create(timeline[0], 5);
+	in_fence[1] = sw_sync_fence_create(timeline[1], 5);
+	in_fence[2] = sw_sync_fence_create(timeline[2], 5);
+
+	fence_merge = sync_merge(in_fence[0], in_fence[1]);
+	fence_merge = sync_merge(in_fence[2], fence_merge);
+
+	/* Confirm fence isn't signaled */
+	active = sync_fence_count_status(fence_merge,
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	igt_assert_f(active == 3, "Fence signaled too early\n");
+
+	ret = sync_wait(fence_merge, 0);
+	igt_assert_f(ret == -1 && errno == ETIME, "Failure waiting on fence until timeout\n");
+
+	sw_sync_timeline_inc(timeline[0], 5);
+	active = sync_fence_count_status(fence_merge,
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	signaled = sync_fence_count_status(fence_merge,
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	igt_assert_f(active == 2 && signaled == 1,
+		    "Fence did not signal properly\n");
+
+	sw_sync_timeline_inc(timeline[1], 5);
+	active = sync_fence_count_status(fence_merge,
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	signaled = sync_fence_count_status(fence_merge,
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	igt_assert_f(active == 1 && signaled == 2,
+		    "Fence did not signal properly\n");
+
+	sw_sync_timeline_inc(timeline[2], 5);
+	active = sync_fence_count_status(fence_merge,
+					    SW_SYNC_FENCE_STATUS_ACTIVE);
+	signaled = sync_fence_count_status(fence_merge,
+					      SW_SYNC_FENCE_STATUS_SIGNALED);
+	igt_assert_f(active == 0 && signaled == 3,
+		     "Fence did not signal properly\n");
+
+	/* confirm you can successfully wait */
+	ret = sync_wait(fence_merge, 100);
+	igt_assert_f(ret == 0, "Failure waiting on signaled fence\n");
+
+	close(in_fence[0]);
+	close(in_fence[1]);
+	close(in_fence[2]);
+	close(fence_merge);
+	close(timeline[0]);
+	close(timeline[1]);
+	close(timeline[2]);
+}
+
 static void * test_sync_multi_consumer_thread(void *arg)
 {
 	data_t *data = arg;
@@ -476,6 +539,9 @@ igt_main
 	igt_subtest("sync_merge_same")
 		test_sync_merge_same();
 
+	igt_subtest("sync_multi_timeline_wait")
+		test_sync_multi_timeline_wait();
+
 	igt_subtest("sync_multi_consumer")
 		test_sync_multi_consumer();
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#16 lore raw

PATCH v6 13/21 tests/sw_sync: Add subtest test_sync_multi_producer_single_consumer

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtest runs a single consumer thread and multiple producer thread that are synchronized using multiple timelines.

---
 tests/sw_sync.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 139 insertions(+)
tests/sw_sync.c +139 -0
index 99bd3d9..4e52f48 100644
@@ -446,6 +446,142 @@ static void test_sync_multi_consumer_producer(void)
 	igt_assert_f(thread_ret == 0, "A sync thread reported failure.\n");
 }
 
+static int test_mspc_wait_on_fence(int fence)
+{
+	int error, active;
+
+	do {
+		error = sync_fence_count_status(fence,
+						   SW_SYNC_FENCE_STATUS_ERROR);
+		igt_assert_f(error == 0, "Error occurred on fence\n");
+		active = sync_fence_count_status(fence,
+						    SW_SYNC_FENCE_STATUS_ACTIVE);
+	} while (active);
+
+	return 0;
+}
+
+static struct {
+	int iterations;
+	int threads;
+	int counter;
+	int cons_timeline;
+	int *prod_timeline;
+	pthread_mutex_t lock;
+} test_mpsc_data;
+
+static int mpsc_producer_thread(void *d)
+{
+	int id = (long)d;
+	int fence, i;
+	int *prod_timeline = test_mpsc_data.prod_timeline;
+	int cons_timeline = test_mpsc_data.cons_timeline;
+	int iterations = test_mpsc_data.iterations;
+
+	for (i = 0; i < iterations; i++) {
+		fence = sw_sync_fence_create(cons_timeline, i);
+
+		/* Wait for the consumer to finish. Use alternate
+		 * means of waiting on the fence
+		 */
+		if ((iterations + id) % 8 != 0) {
+			igt_assert_f(sync_wait(fence, -1) == 0,
+				     "Failure waiting on fence\n");
+		} else {
+			igt_assert_f(test_mspc_wait_on_fence(fence) == 0,
+				     "Failure waiting on fence\n");
+		}
+
+		/* Every producer increments the counter, the consumer
+		 * checks and erases it
+		 */
+		pthread_mutex_lock(&test_mpsc_data.lock);
+		test_mpsc_data.counter++;
+		pthread_mutex_unlock(&test_mpsc_data.lock);
+
+		sw_sync_timeline_inc(prod_timeline[id], 1);
+		close(fence);
+	}
+
+	return 0;
+}
+
+static int mpsc_consumer_thread(void)
+{
+	int fence, merged, tmp, it, i;
+	int *prod_timeline = test_mpsc_data.prod_timeline;
+	int cons_timeline = test_mpsc_data.cons_timeline;
+	int iterations = test_mpsc_data.iterations;
+	int n = test_mpsc_data.threads;
+
+	for (it = 1; it <= iterations; it++) {
+		fence = sw_sync_fence_create(prod_timeline[0], it);
+		for (i = 1; i < n; i++) {
+			tmp = sw_sync_fence_create(prod_timeline[i], it);
+			merged = sync_merge(tmp, fence);
+			close(tmp);
+			close(fence);
+			fence = merged;
+		}
+
+		/* Make sure we see an increment from every producer thread.
+		 * Vary the means by which we wait.
+		 */
+		if (iterations % 8 != 0) {
+			igt_assert_f(sync_wait(fence, -1) == 0,
+				    "Producers did not increment as expected\n");
+		} else {
+			igt_assert_f(test_mspc_wait_on_fence(fence) == 0,
+				     "Failure waiting on fence\n");
+		}
+
+		igt_assert_f(test_mpsc_data.counter == n * it,
+			     "Counter value mismatch\n");
+
+		/* Release the producer threads */
+		sw_sync_timeline_inc(cons_timeline, 1);
+		close(fence);
+	}
+
+	return 0;
+}
+
+/* IMPORTANT NOTE: if you see this test failing on your system, it may be
+ * due to a shortage of file descriptors. Please ensure your system has
+ * a sensible limit for this test to finish correctly.
+ */
+static void test_sync_multi_producer_single_consumer(void)
+{
+	int iterations = 1 << 12;
+	int n = 5;
+	int prod_timeline[n];
+	int cons_timeline;
+	pthread_t threads[n];
+	long i;
+
+	cons_timeline = sw_sync_timeline_create();
+	for (i = 0; i < n; i++)
+		prod_timeline[i] = sw_sync_timeline_create();
+
+	test_mpsc_data.prod_timeline = prod_timeline;
+	test_mpsc_data.cons_timeline = cons_timeline;
+	test_mpsc_data.iterations = iterations;
+	test_mpsc_data.threads = n;
+	test_mpsc_data.counter = 0;
+	pthread_mutex_init(&test_mpsc_data.lock, NULL);
+
+	for (i = 0; i < n; i++) {
+		pthread_create(&threads[i], NULL, (void * (*)(void *))
+			       mpsc_producer_thread,
+			       (void *)i);
+	}
+
+	mpsc_consumer_thread();
+
+	for (i = 0; i < n; i++)
+		pthread_join(threads[i], NULL);
+}
+
 static void test_sync_random_merge(void)
 {
 	int i, size, ret;
@@ -548,6 +684,9 @@ igt_main
 	igt_subtest("sync_multi_consumer_producer")
 		test_sync_multi_consumer_producer();
 
+	igt_subtest("sync_multi_producer_single_consumer")
+		test_sync_multi_producer_single_consumer();
+
 	igt_subtest("sync_random_merge")
 		test_sync_random_merge();
 }
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw

PATCH v6 14/21 tests/sw_sync: Add subtest test_sync_expired_merge

In reply to [email protected]

From: Rafael Antognolli <[email protected]>

This test creates an already expired fence, then creates a merged fence out of that expired one (passed twice to the merge operation), and finally closes the merged fence. It shows that if the refcounts are wrong on the original expired fence, it might get freed while still in use. Usually a kernel panick will follow.

---
 tests/sw_sync.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
tests/sw_sync.c +28 -0
index 4e52f48..65416ad 100644
@@ -582,6 +582,31 @@ static void test_sync_multi_producer_single_consumer(void)
 		pthread_join(threads[i], NULL);
 }
 
+static void test_sync_expired_merge(void)
+{
+	int iterations = 1 << 20;
+	int timeline;
+	int i;
+	int fence_expired, fence_merged;
+
+	timeline = sw_sync_timeline_create();
+
+	sw_sync_timeline_inc(timeline, 100);
+	fence_expired = sw_sync_fence_create(timeline, 1);
+	fence_merged = sync_merge(fence_expired, fence_expired);
+	close(fence_merged);
+
+	for (i = 0; i < iterations; i++) {
+		int fence = sync_merge(fence_expired, fence_expired);
+
+		igt_assert_f(sync_wait(fence, -1) == 0,
+				     "Failure waiting on fence\n");
+		close(fence);
+	}
+
+	close(fence_expired);
+}
+
 static void test_sync_random_merge(void)
 {
 	int i, size, ret;
@@ -687,6 +712,9 @@ igt_main
 	igt_subtest("sync_multi_producer_single_consumer")
 		test_sync_multi_producer_single_consumer();
 
+	igt_subtest("sync_expired_merge")
+		test_sync_expired_merge();
+
 	igt_subtest("sync_random_merge")
 		test_sync_random_merge();
 }
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#18 lore raw

Re: [PATCH i-g-t v6 14/21] tests/sw_sync: Add subtest test_sync_expired_merge

Quoted 23 lines · On Thu, Nov 17, 2016 at 10:02:02AM -0500, [email protected] wrote:

From: Rafael Antognolli <[email protected]>

This test creates an already expired fence, then creates a merged fence out of that expired one (passed twice to the merge operation), and finally closes the merged fence. It shows that if the refcounts are wrong on the original expired fence, it might get freed while still in use. Usually a kernel panick will follow.

---
 tests/sw_sync.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
tests/sw_sync.c +1 -0
index 4e52f48..65416ad 100644
@@ -582,6 +582,31 @@ static void test_sync_multi_producer_single_consumer(void)
 		pthread_join(threads[i], NULL);
 }
 
+static void test_sync_expired_merge(void)

tests/sw_sync.c static void test_sync_multi_producer_single_consumer(void) · line 595

Quoted 10 lines
tests/sw_sync.c +10 -0
+{
+	int iterations = 1 << 20;
+	int timeline;
+	int i;
+	int fence_expired, fence_merged;
+
+	timeline = sw_sync_timeline_create();
+
+	sw_sync_timeline_inc(timeline, 100);
+	fence_expired = sw_sync_fence_create(timeline, 1);

igt_assert(sync_wait(fence_expired, 0) == 1);
or
igt_assert(fence_signaled(fence_expired));

Both illustrative of the setup, and tests them.

tests/sw_sync.c static void test_sync_multi_producer_single_consumer(void) · line 604

Quoted 9 lines
tests/sw_sync.c +9 -0
+	fence_merged = sync_merge(fence_expired, fence_expired);
+	close(fence_merged);
+
+	for (i = 0; i < iterations; i++) {
+		int fence = sync_merge(fence_expired, fence_expired);
+
+		igt_assert_f(sync_wait(fence, -1) == 0,
+				     "Failure waiting on fence\n");
+		close(fence);

Is the millionth iteration more likely to fail than iteration 0?

There's no change in code coverage, so is it worth the extra iterations? -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#19 lore raw

Re: [PATCH i-g-t v6 14/21] tests/sw_sync: Add subtest test_sync_expired_merge

Quoted 43 lines · Chris Wilson
Quoted 27 lines · On Thu, Nov 17, 2016 at 10:02:02AM -0500, [email protected] wrote:

From: Rafael Antognolli <[email protected]>

This test creates an already expired fence, then creates a merged fence
out of that expired one (passed twice to the merge operation), and finally closes the merged fence. It shows that if the refcounts are wrong on the original expired fence, it might get freed while still in
use. Usually a kernel panick will follow.

---
 tests/sw_sync.c | 28 ++++++++++++++++++++++++++++

 1 file changed, 28 insertions(+)
tests/sw_sync.c +0 -0
index 4e52f48..65416ad 100644
@@ -582,6 +582,31 @@ static void
 test_sync_multi_producer_single_consumer(void)
  		pthread_join(threads[i], NULL);
  }

tests/sw_sync.c +1 -0
+static void test_sync_expired_merge(void)

tests/sw_sync.c static void test_sync_multi_producer_single_consumer(void) · line 595

Quoted 10 lines
tests/sw_sync.c +10 -0
+{
+	int iterations = 1 << 20;
+	int timeline;
+	int i;
+	int fence_expired, fence_merged;
+
+	timeline = sw_sync_timeline_create();
+
+	sw_sync_timeline_inc(timeline, 100);
+	fence_expired = sw_sync_fence_create(timeline, 1);

igt_assert(sync_wait(fence_expired, 0) == 1);
or
igt_assert(fence_signaled(fence_expired));

Quoted 1 line

Both illustrative of the setup, and tests them.

Agreed, I'll add it for v7.

Quoted 15 lines

tests/sw_sync.c static void test_sync_multi_producer_single_consumer(void) · line 604

Quoted 13 lines
tests/sw_sync.c +5 -0
+	fence_merged = sync_merge(fence_expired, fence_expired);
+	close(fence_merged);
+
+	for (i = 0; i < iterations; i++) {
+		int fence = sync_merge(fence_expired,

fence_expired);

tests/sw_sync.c +3 -0
+
+		igt_assert_f(sync_wait(fence, -1) == 0,
+				     "Failure waiting on

fence\n");

tests/sw_sync.c +1 -0
+		close(fence);

Is the millionth iteration more likely to fail than iteration 0?

Quoted 2 lines

There's no change in code coverage, so is it worth the extra iterations?

I don't know if it is more likely to fail or not, which is why multiple iterations are tested.

If you can tell me with certainty that multiple iterations always will behave the same way I would be happy to remove the multiple iterations.

Granted, there are a few other tests that also do stress testing as a part of what they test. So maybe this is redundant either way?
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#20 lore raw

PATCH v6 15/21 tests/sw_sync: Add subtest test_timeline_closed

In reply to [email protected]

From: Robert Foss <[email protected]>

This subtest verifies that the fences of a timeline are not signalled when a timelne is closed.

---
 tests/sw_sync.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
tests/sw_sync.c +17 -0
index 65416ad..f19eaa8 100644
@@ -72,6 +72,20 @@ static void test_alloc_fence_invalid_timeline(void)
 	igt_assert(__sw_sync_fence_create(-1, 0) < 0);
 }
 
+static void test_timeline_closed(void)
+{
+	int fence, ret;
+	int timeline;
+
+	timeline = sw_sync_timeline_create();
+	fence = sw_sync_fence_create(timeline, 1);
+
+	close(timeline);
+	ret = sync_wait(fence, 0);
+	igt_assert_f(ret == -1 && errno == ETIME,
+	             "Failure waiting on unsignaled fence on closed timeline\n");
+}
+
 static void test_alloc_merge_fence(void)
 {
 	int in_fence[2];
@@ -688,6 +702,9 @@ igt_main
 	igt_subtest("alloc_fence_invalid_timeline")
 		test_alloc_fence_invalid_timeline();
 
+	igt_subtest("timeline_closed")
+		test_timeline_closed();
+
 	igt_subtest("alloc_merge_fence")
 		test_alloc_merge_fence();
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#21 lore raw

PATCH v6 16/21 tests/sw_sync: Add subtest test_timeline_closed_signaled

In reply to [email protected]

From: Robert Foss <[email protected]>

Add subtest test_timeline_closed_signaled that verifies that a signaled fence stays signaled after its timeline has been closed.

---
 tests/sw_sync.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
tests/sw_sync.c +18 -0
index f19eaa8..c885199 100644
@@ -86,6 +86,21 @@ static void test_timeline_closed(void)
 	             "Failure waiting on unsignaled fence on closed timeline\n");
 }
 
+static void test_timeline_closed_signaled(void)
+{
+	int fence, ret;
+	int timeline;
+
+	timeline = sw_sync_timeline_create();
+	fence = sw_sync_fence_create(timeline, 1);
+
+	sw_sync_timeline_inc(timeline, 1);
+	close(timeline);
+	ret = sync_wait(fence, 0);
+	igt_assert_f(ret == 0,
+	             "Failure waiting on signaled fence for closed timeline\n");
+}
+
 static void test_alloc_merge_fence(void)
 {
 	int in_fence[2];
@@ -705,6 +720,9 @@ igt_main
 	igt_subtest("timeline_closed")
 		test_timeline_closed();
 
+	igt_subtest("timeline_closed_signaled")
+		test_timeline_closed_signaled();
+
 	igt_subtest("alloc_merge_fence")
 		test_alloc_merge_fence();
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#22 lore raw

PATCH v6 17/21 lib/sw_sync: Add igt_require_sw_sync to enable skipping on no sw_sync support

In reply to [email protected]

From: Robert Foss <[email protected]>

Add igt_require_sw_sync to provide tests to skip if sw_sync support isn't available on the host machine.

---
 lib/sw_sync.c | 22 ++++++++++++++++++++++
 lib/sw_sync.h |  1 +
 2 files changed, 23 insertions(+)
lib/sw_sync.c +22 -0
index 862f8c4..38fe670 100644
@@ -197,3 +197,25 @@ int sync_fence_count_status(int fd, int status)
 	igt_assert(count >= 0);
 	return count;
 }
+
+static bool kernel_has_sw_sync(void)
+{
+	bool err;
+
+	igt_ignore_warn(system("/sbin/modprobe -s r sw_sync"));
+
+	err = false;
+	if (access(DEVFS_SW_SYNC, R_OK | W_OK) < 0) {
+		char buf[128];
+
+		snprintf(buf, sizeof(buf), "%s/sw_sync", igt_debugfs_mount());
+		err = access(DEBUGFS_SW_SYNC, R_OK | W_OK) < 0;
+	}
+
+	return !err;
+}
+
+void igt_require_sw_sync(void)
+{
+	igt_require(kernel_has_sw_sync());
+}
lib/sw_sync.h +1 -0
index 1f47b29..0bbe73c 100644
@@ -43,6 +43,7 @@ int sync_merge(int fd1, int fd2);
 int sync_wait(int fence, int timeout);
 int sync_fence_count(int fd);
 int sync_fence_count_status(int fd, int status);
+void igt_require_sw_sync(void);
 
 #endif
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#23 lore raw

PATCH v6 18/21 tests/sw_sync: Add igt_require check for sw_sync feature

In reply to [email protected]

From: Robert Foss <[email protected]>

Make sure that this test is skipped if the sw_sync feature is missing from the host system.

---
 lib/sw_sync.c   | 1 +
 tests/sw_sync.c | 3 +++
 2 files changed, 4 insertions(+)
lib/sw_sync.c +1 -0
index 38fe670..ac793ad 100644
@@ -38,6 +38,7 @@
 #include <linux/sync_file.h>
 #include <sys/ioctl.h>
 
+#include "igt_debugfs.h"
 #include "sw_sync.h"
 #include "drmtest.h"
 #include "ioctl_wrappers.h"
tests/sw_sync.c +3 -0
index c885199..0aae4dc 100644
@@ -708,6 +708,9 @@ static void test_sync_random_merge(void)
 
 igt_main
 {
+	igt_fixture
+		igt_require_sw_sync();
+
 	igt_subtest("alloc_timeline")
 		test_alloc_timeline();
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#24 lore raw

PATCH v6 19/21 tests/sw_sync: Add subtest test_sync_merge_invalid

In reply to [email protected]

From: Robert Foss <[email protected]>

Add subtest test_sync_merge_invalid that tests merging invalid fences.

---
 tests/sw_sync.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tests/sw_sync.c +41 -0
index 0aae4dc..d60fb32 100644
@@ -155,6 +155,44 @@ static void test_sync_busy(void)
 	close(timeline);
 }
 
+static void test_sync_merge_invalid(void)
+{
+	int in_fence;
+	int fence_invalid;
+	int fence_merge;
+	int timeline;
+	char tmppath[] = "/tmp/igt-XXXXXX";
+	int skip = 0;
+
+	timeline = sw_sync_timeline_create();
+	in_fence = sw_sync_fence_create(timeline, 1);
+
+	fence_invalid = -1;
+	fence_merge = sync_merge(in_fence, fence_invalid);
+	igt_assert_f(fence_merge < 0, "Verify invalid fd (-1) handling");
+
+	fence_invalid = drm_open_driver(DRIVER_ANY);
+	fence_merge = sync_merge(in_fence, fence_invalid);
+	igt_assert_f(fence_merge < 0, "Verify invalid fd (device fd) handling");
+
+	fence_invalid = mkstemp(tmppath);
+	if (fence_invalid == -1) {
+		skip = 1;
+		goto out;
+	}
+	unlink(tmppath);
+	fence_invalid = drm_open_driver(DRIVER_ANY);
+	fence_merge = sync_merge(in_fence, fence_invalid);
+	close(fence_invalid);
+	igt_assert_f(fence_merge < 0, "Verify invalid fd (file fd) handling");
+
+out:
+	close(in_fence);
+	close(fence_merge);
+	close(timeline);
+	igt_require(skip == 0);
+}
+
 static void test_sync_merge(void)
 {
 	int in_fence[3];
@@ -732,6 +770,9 @@ igt_main
 	igt_subtest("sync_busy")
 		test_sync_busy();
 
+	igt_subtest("sync_merge_invalid")
+		test_sync_merge_invalid();
+
 	igt_subtest("sync_merge")
 		test_sync_merge();
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#25 lore raw

Re: [PATCH i-g-t v6 19/21] tests/sw_sync: Add subtest test_sync_merge_invalid

Quoted 22 lines · On Thu, Nov 17, 2016 at 10:02:07AM -0500, [email protected] wrote:

From: Robert Foss <[email protected]>

Add subtest test_sync_merge_invalid that tests merging invalid fences.

---
 tests/sw_sync.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tests/sw_sync.c +5 -0
index 0aae4dc..d60fb32 100644
@@ -155,6 +155,44 @@ static void test_sync_busy(void)
 	close(timeline);
 }
 
+static void test_sync_merge_invalid(void)
+{
+	int in_fence;
+	int fence_invalid;
+	int fence_merge;

tests/sw_sync.c static void test_sync_busy(void) · line 172

Quoted 10 lines
tests/sw_sync.c +10 -0
+	int timeline;
+	char tmppath[] = "/tmp/igt-XXXXXX";
+	int skip = 0;
+
+	timeline = sw_sync_timeline_create();
+	in_fence = sw_sync_fence_create(timeline, 1);
+
+	fence_invalid = -1;
+	fence_merge = sync_merge(in_fence, fence_invalid);
+	igt_assert_f(fence_merge < 0, "Verify invalid fd (-1) handling");

For these you probably want:

int __sync_merge(int acc, int fd)

{
	int out;

	out = sync_merge(acc, fd);
	if (out < 0)
		out = -errno;
	return out;
}

then igt_assert_eq(__sync_merge(in_fence, -1), -EINVAL);

Or at least assert the errno is EINVAL.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#26 lore raw

PATCH v6 20/21 tests/sw_sync: Add subtest test_sync_busy_fork

In reply to [email protected]

From: Robert Foss <[email protected]>

Add subtest test_sync_busy_fork which increments the timeline in a forked child process.

---
 tests/sw_sync.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
tests/sw_sync.c +39 -0
index d60fb32..440c1bf 100644
@@ -155,6 +155,42 @@ static void test_sync_busy(void)
 	close(timeline);
 }
 
+static void test_sync_busy_fork(void)
+{
+	int fence, ret;
+	int timeline;
+	int skip = 0;
+
+	timeline = sw_sync_timeline_create();
+	fence = sw_sync_fence_create(timeline, 1);
+
+	switch (fork()) {
+	case 0:
+		/* Child process */
+		usleep(1*1000*1000);
+		/* Advance timeline from 0 -> 1 */
+		sw_sync_timeline_inc(timeline, 1);
+		_Exit(0);
+		break;
+	case -1:
+		/* Failed fork */
+		skip = 1;
+		break;
+	default:
+		/* Parent process */
+		ret = sync_wait(fence, 0);
+		igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled (it should not have been signalled yet)\n");
+
+		ret = sync_wait(fence, 2*1000);
+		igt_assert_f(ret == 0, "Fence not signaled (timeline value 1 fence seqno 1)\n");
+		break;
+	}
+
+	close(fence);
+	close(timeline);
+	igt_require(!skip);
+}
+
 static void test_sync_merge_invalid(void)
 {
 	int in_fence;
@@ -770,6 +806,9 @@ igt_main
 	igt_subtest("sync_busy")
 		test_sync_busy();
 
+	igt_subtest("sync_busy_fork")
+		test_sync_busy_fork();
+
 	igt_subtest("sync_merge_invalid")
 		test_sync_merge_invalid();
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#27 lore raw

PATCH v6 21/21 tests/sw_sync: Add subtest test_sync_busy_unixsocket

In reply to [email protected]

From: Robert Foss <[email protected]>

Add subtest test_sync_busy_fork which increments the timeline in a forked child process, where the timeline fd has been sent through a UNIX socket.

---
 tests/sw_sync.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)
tests/sw_sync.c +103 -0
index 440c1bf..f7c51c4 100644
@@ -30,6 +30,8 @@
 #include <pthread.h>
 #include <semaphore.h>
 #include <stdint.h>
+#include <sys/socket.h>
+#include <sys/types.h>
 #include <unistd.h>
 
 #include "sw_sync.h"
@@ -155,6 +157,104 @@ static void test_sync_busy(void)
 	close(timeline);
 }
 
+static void test_sync_busy_fork_unixsocket(void)
+{
+	int fence, ret;
+	int timeline;
+	int skip = 0;
+	int sv[2];
+
+
+	timeline = sw_sync_timeline_create();
+	fence = sw_sync_fence_create(timeline, 1);
+
+	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv) != 0) {
+		skip = 1;
+		goto out;
+	}
+
+	switch (fork()) {
+	case 0:
+	{
+		/* Child process */
+		int socket = sv[1];
+		int socket_timeline;
+		struct msghdr msg = {0};
+		struct cmsghdr *cmsg;
+		unsigned char *data;
+		char m_buffer[256];
+		char c_buffer[256];
+		struct iovec io = { .iov_base = m_buffer, .iov_len = sizeof(m_buffer) };
+		close(sv[0]);
+
+		msg.msg_iov = &io;
+		msg.msg_iovlen = 1;
+		msg.msg_control = c_buffer;
+		msg.msg_controllen = sizeof(c_buffer);
+
+		if (recvmsg(socket, &msg, 0) < 0)
+		    _Exit(1);
+
+		cmsg = CMSG_FIRSTHDR(&msg);
+		data = CMSG_DATA(cmsg);
+		socket_timeline = *((int *) data);
+
+		/* Advance timeline from 0 -> 1 */
+		sw_sync_timeline_inc(socket_timeline, 1);
+
+		_Exit(0);
+		break;
+	}
+	case -1:
+	{
+		/* Failed fork */
+		skip = 1;
+		break;
+	}
+	default:
+	{
+		/* Parent process */
+		int socket = sv[0];
+		struct cmsghdr *cmsg;
+		struct iovec io = { .iov_base = (char *)"ABC", .iov_len = 3 };
+		struct msghdr msg = { 0 };
+		char buf[CMSG_SPACE(sizeof(timeline))];
+		memset(buf, '\0', sizeof(buf));
+		close(sv[1]);
+
+		msg.msg_iov = &io;
+		msg.msg_iovlen = 1;
+		msg.msg_control = buf;
+		msg.msg_controllen = sizeof(buf);
+
+		cmsg = CMSG_FIRSTHDR(&msg);
+		cmsg->cmsg_level = SOL_SOCKET;
+		cmsg->cmsg_type = SCM_RIGHTS;
+		cmsg->cmsg_len = CMSG_LEN(sizeof(timeline));
+
+		*((int *) CMSG_DATA(cmsg)) = timeline;
+		msg.msg_controllen = cmsg->cmsg_len;
+
+		ret = sync_wait(fence, 0);
+		igt_assert_f(ret == -1 && errno == ETIME, "Fence signaled (it should not have been signalled yet)\n");
+
+		if (sendmsg(socket, &msg, 0) < 0) {
+		    skip = 1;
+		    goto out;
+		}
+
+		ret = sync_wait(fence, 2*1000);
+		igt_assert_f(ret == 0, "Fence not signaled (timeline value 1 fence seqno 1)\n");
+		break;
+	}
+	}
+
+out:
+	close(fence);
+	close(timeline);
+	igt_require(!skip);
+}
+
 static void test_sync_busy_fork(void)
 {
 	int fence, ret;
@@ -809,6 +909,9 @@ igt_main
 	igt_subtest("sync_busy_fork")
 		test_sync_busy_fork();
 
+	igt_subtest("sync_busy_fork_unixsocket")
+		test_sync_busy_fork_unixsocket();
+
 	igt_subtest("sync_merge_invalid")
 		test_sync_merge_invalid();
 
Signature · 6 lines
2.10.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx