All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v1 0/9] Tests for sync infrastructure
@ 2016-03-09 15:28 Emilio López
  2016-03-09 15:28 ` [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework Emilio López
                   ` (9 more replies)
  0 siblings, 10 replies; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:28 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

Hello everyone,

This is a series of tests to exercise the sync kernel infrastructure. It is
meant to be a test suite for the work Gustavo has been doing to destage it,
see [0] for his latest series to date.

These tests were originally part of a battery of tests shipping with
Android's libsync that were rewritten to use the new userspace interfaces.

As usual, all comments are welcome.

Cheers!
Emilio

[0] https://lists.freedesktop.org/archives/dri-devel/2016-March/102204.html


Emilio López (9):
  selftest: sync: basic tests for sw_sync framework
  selftest: sync: fence tests for sw_sync framework
  selftest: sync: merge tests for sw_sync framework
  selftest: sync: wait tests for sw_sync framework
  selftest: sync: destruction tests for sw_sync framework
  selftest: sync: stress test for parallelism
  selftest: sync: stress consumer/producer test
  selftest: sync: stress test for merges
  selftest: sync: disable tests that rely on not yet defined behaviour

 tools/testing/selftests/Makefile                   |   1 +
 tools/testing/selftests/sync/.gitignore            |   1 +
 tools/testing/selftests/sync/Makefile              |  28 +++
 tools/testing/selftests/sync/sw_sync.h             |  46 +++++
 tools/testing/selftests/sync/sync.c                | 203 +++++++++++++++++++++
 tools/testing/selftests/sync/sync.h                | 119 ++++++++++++
 tools/testing/selftests/sync/sync_alloc.c          |  74 ++++++++
 tools/testing/selftests/sync/sync_destroyed.c      |  90 +++++++++
 tools/testing/selftests/sync/sync_fence.c          | 134 ++++++++++++++
 tools/testing/selftests/sync/sync_merge.c          |  60 ++++++
 .../testing/selftests/sync/sync_stress_consumer.c  | 185 +++++++++++++++++++
 tools/testing/selftests/sync/sync_stress_merge.c   | 115 ++++++++++++
 .../selftests/sync/sync_stress_parallelism.c       | 111 +++++++++++
 tools/testing/selftests/sync/sync_test.c           |  87 +++++++++
 tools/testing/selftests/sync/sync_wait.c           |  95 ++++++++++
 tools/testing/selftests/sync/synctest.h            |  69 +++++++
 16 files changed, 1418 insertions(+)
 create mode 100644 tools/testing/selftests/sync/.gitignore
 create mode 100644 tools/testing/selftests/sync/Makefile
 create mode 100644 tools/testing/selftests/sync/sw_sync.h
 create mode 100644 tools/testing/selftests/sync/sync.c
 create mode 100644 tools/testing/selftests/sync/sync.h
 create mode 100644 tools/testing/selftests/sync/sync_alloc.c
 create mode 100644 tools/testing/selftests/sync/sync_destroyed.c
 create mode 100644 tools/testing/selftests/sync/sync_fence.c
 create mode 100644 tools/testing/selftests/sync/sync_merge.c
 create mode 100644 tools/testing/selftests/sync/sync_stress_consumer.c
 create mode 100644 tools/testing/selftests/sync/sync_stress_merge.c
 create mode 100644 tools/testing/selftests/sync/sync_stress_parallelism.c
 create mode 100644 tools/testing/selftests/sync/sync_test.c
 create mode 100644 tools/testing/selftests/sync/sync_wait.c
 create mode 100644 tools/testing/selftests/sync/synctest.h

-- 
2.5.0

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
@ 2016-03-09 15:28 ` Emilio López
  2016-03-28 11:56     ` Emil Velikov
  2016-03-09 15:28 ` [RFC PATCH v1 2/9] selftest: sync: fence " Emilio López
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:28 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

These tests are based on the libsync test suite from Android.
This commit lays the ground for future tests, as well as includes
tests for a variety of basic allocation commands.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
---

 tools/testing/selftests/Makefile          |   1 +
 tools/testing/selftests/sync/.gitignore   |   1 +
 tools/testing/selftests/sync/Makefile     |  21 ++++
 tools/testing/selftests/sync/sw_sync.h    |  46 +++++++
 tools/testing/selftests/sync/sync.c       | 203 ++++++++++++++++++++++++++++++
 tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
 tools/testing/selftests/sync/sync_alloc.c |  74 +++++++++++
 tools/testing/selftests/sync/sync_test.c  |  71 +++++++++++
 tools/testing/selftests/sync/synctest.h   |  47 +++++++
 9 files changed, 583 insertions(+)
 create mode 100644 tools/testing/selftests/sync/.gitignore
 create mode 100644 tools/testing/selftests/sync/Makefile
 create mode 100644 tools/testing/selftests/sync/sw_sync.h
 create mode 100644 tools/testing/selftests/sync/sync.c
 create mode 100644 tools/testing/selftests/sync/sync.h
 create mode 100644 tools/testing/selftests/sync/sync_alloc.c
 create mode 100644 tools/testing/selftests/sync/sync_test.c
 create mode 100644 tools/testing/selftests/sync/synctest.h

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index b04afc3..35ed218 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -21,6 +21,7 @@ TARGETS += ptrace
 TARGETS += seccomp
 TARGETS += size
 TARGETS += static_keys
+TARGETS += sync
 TARGETS += sysctl
 ifneq (1, $(quicktest))
 TARGETS += timers
diff --git a/tools/testing/selftests/sync/.gitignore b/tools/testing/selftests/sync/.gitignore
new file mode 100644
index 0000000..f5091e7
--- /dev/null
+++ b/tools/testing/selftests/sync/.gitignore
@@ -0,0 +1 @@
+sync_test
diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
new file mode 100644
index 0000000..b21382d
--- /dev/null
+++ b/tools/testing/selftests/sync/Makefile
@@ -0,0 +1,21 @@
+CC = $(CROSS_COMPILE)gcc
+CFLAGS := -O2 -g -std=gnu89 -pthread -Wall
+CFLAGS += -I../../../../drivers/staging/android/
+LDFLAGS += -pthread
+
+TEST_PROGS = sync_test
+
+all: $(TEST_PROGS)
+
+include ../lib.mk
+
+SRC = sync_test.o sync.o
+
+TESTS += sync_alloc.o
+
+sync_test: $(SRC) $(TESTS)
+
+.PHONY: clean
+
+clean:
+	$(RM) sync_test $(SRC) $(TESTS)
diff --git a/tools/testing/selftests/sync/sw_sync.h b/tools/testing/selftests/sync/sw_sync.h
new file mode 100644
index 0000000..105961a
--- /dev/null
+++ b/tools/testing/selftests/sync/sw_sync.h
@@ -0,0 +1,46 @@
+/*
+ *  sw_sync abstraction
+ *
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2013 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.
+ */
+
+#ifndef _SELFTESTS_SW_SYNC_H
+#define _SELFTESTS_SW_SYNC_H
+
+/*
+ * sw_sync is mainly intended for testing and should not be compiled into
+ * production kernels
+ */
+
+int sw_sync_timeline_create(void);
+int sw_sync_timeline_is_valid(int fd);
+int sw_sync_timeline_inc(int fd, unsigned count);
+void sw_sync_timeline_destroy(int fd);
+
+int sw_sync_fence_create(int fd, const char *name, unsigned value);
+int sw_sync_fence_is_valid(int fd);
+void sw_sync_fence_destroy(int fd);
+
+#endif
diff --git a/tools/testing/selftests/sync/sync.c b/tools/testing/selftests/sync/sync.c
new file mode 100644
index 0000000..99570ab
--- /dev/null
+++ b/tools/testing/selftests/sync/sync.c
@@ -0,0 +1,203 @@
+/*
+ *  sync / sw_sync abstraction
+ *  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 <fcntl.h>
+#include <malloc.h>
+#include <string.h>
+#include <unistd.h>
+#include <poll.h>
+
+#include <uapi/sync.h>
+#include <uapi/sw_sync.h>
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+int sync_wait(int fd, int timeout)
+{
+	struct pollfd fds;
+
+	fds.fd = fd;
+	fds.events = POLLIN | POLLERR;
+	return poll(&fds, 1, timeout);
+}
+
+int sync_merge(const char *name, int fd1, int fd2)
+{
+	struct sync_merge_data data = {};
+	int err;
+
+	data.fd2 = fd2;
+	strncpy(data.name, name, sizeof(data.name) - 1);
+	data.name[sizeof(data.name) - 1] = '\0';
+
+	err = ioctl(fd1, SYNC_IOC_MERGE, &data);
+	if (err < 0)
+		return err;
+
+	return data.fence;
+}
+
+static struct sync_file_info *sync_file_info(int fd)
+{
+	struct sync_file_info *info;
+	int err, num_fences;
+
+	info = malloc(sizeof(*info));
+	if (info == NULL)
+		return NULL;
+
+	memset(info, 0, sizeof(*info));
+	err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
+	if (err < 0) {
+		free(info);
+		return NULL;
+	}
+
+	num_fences = info->num_fences;
+
+	if (num_fences) {
+		info->flags = 0;
+		info->num_fences = num_fences;
+		info->sync_fence_info = (uint64_t) calloc(num_fences,
+					sizeof(struct sync_fence_info));
+		if ((void *)info->sync_fence_info == NULL)
+			return NULL;
+
+		err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
+		if (err < 0) {
+			free((void *)info->sync_fence_info);
+			free(info);
+			return NULL;
+		}
+	}
+
+	return info;
+}
+
+static void sync_file_info_free(struct sync_file_info *info)
+{
+	free((void *)info->sync_fence_info);
+	free(info);
+}
+
+int sync_fence_size(int fd)
+{
+	int count;
+	struct sync_file_info *info = sync_file_info(fd);
+
+	if (!info)
+		return 0;
+
+	count = info->num_fences;
+
+	sync_file_info_free(info);
+
+	return count;
+}
+
+
+int sync_fence_count_with_status(int fd, int status)
+{
+	int i, count = 0;
+	struct sync_fence_info *fenceInfo = NULL;
+	struct sync_file_info *info = sync_file_info(fd);
+
+	if (!info)
+		return -1;
+
+	fenceInfo = (struct sync_fence_info *)info->sync_fence_info;
+	for (i = 0 ; i < info->num_fences ; i++) {
+		if (fenceInfo[i].status == status)
+			count++;
+	}
+
+	sync_file_info_free(info);
+
+	return count;
+}
+
+int sw_sync_timeline_create(void)
+{
+	return open("/sys/kernel/debug/sync/sw_sync", O_RDWR);
+}
+
+int sw_sync_timeline_inc(int fd, unsigned count)
+{
+	__u32 arg = count;
+
+	return ioctl(fd, SW_SYNC_IOC_INC, &arg);
+}
+
+int sw_sync_timeline_is_valid(int fd)
+{
+	int status;
+
+	if (fd == -1)
+		return 0;
+
+	status = fcntl(fd, F_GETFD, 0);
+	return (status >= 0);
+}
+
+void sw_sync_timeline_destroy(int fd)
+{
+	if (fd != -1)
+		close(fd);
+}
+
+int sw_sync_fence_create(int fd, const char *name, unsigned value)
+{
+	struct sw_sync_create_fence_data data = {};
+	int err;
+
+	data.value = value;
+	strncpy(data.name, name, sizeof(data.name) - 1);
+	data.name[sizeof(data.name) - 1] = '\0';
+
+	err = ioctl(fd, SW_SYNC_IOC_CREATE_FENCE, &data);
+	if (err < 0)
+		return err;
+
+	return data.fence;
+}
+
+int sw_sync_fence_is_valid(int fd)
+{
+	/* Same code! */
+	return sw_sync_timeline_is_valid(fd);
+}
+
+void sw_sync_fence_destroy(int fd)
+{
+	if (sw_sync_fence_is_valid(fd))
+		close(fd);
+}
diff --git a/tools/testing/selftests/sync/sync.h b/tools/testing/selftests/sync/sync.h
new file mode 100644
index 0000000..9370fa3
--- /dev/null
+++ b/tools/testing/selftests/sync/sync.h
@@ -0,0 +1,119 @@
+/*
+ *  sync abstraction
+ *  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.
+ */
+
+#ifndef _SELFTESTS_SYNC_H
+#define _SELFTESTS_SYNC_H
+
+#include <stdint.h>
+#include <sys/ioctl.h>
+
+#define FENCE_STATUS_ERROR	(-1)
+#define FENCE_STATUS_ACTIVE	(0)
+#define FENCE_STATUS_SIGNALED	(1)
+
+struct sync_merge_data {
+	char	name[32];
+	int32_t	fd2;
+	int32_t	fence;
+	uint32_t	flags;
+	uint32_t	pad;
+};
+
+/**
+ * struct sync_fence_info - detailed fence information
+ * @obj_name:		name of parent sync_timeline
+ * @driver_name:	name of driver implementing the parent
+ * @status:		status of the fence 0:active 1:signaled <0:error
+ * @flags:		fence_info flags
+ * @timestamp_ns:	timestamp of status change in nanoseconds
+ */
+struct sync_fence_info {
+	char	obj_name[32];
+	char	driver_name[32];
+	int32_t	status;
+	uint32_t	flags;
+	uint64_t	timestamp_ns;
+};
+
+/**
+ * struct sync_file_info - data returned from fence info ioctl
+ * @name:	name of fence
+ * @status:	status of fence. 1: signaled 0:active <0:error
+ * @flags:	sync_file_info flags
+ * @num_fences	number of fences in the sync_file
+ * @pad:	padding for 64-bit alignment, should always be zero
+ * @sync_fence_info: pointer to array of structs sync_fence_info with all
+ *		 fences in the sync_file
+ */
+struct sync_file_info {
+	char	name[32];
+	int32_t	status;
+	uint32_t	flags;
+	uint32_t	num_fences;
+	uint32_t	pad;
+
+	uint64_t	sync_fence_info;
+};
+
+#define SYNC_IOC_MAGIC		'>'
+
+/**
+ * Opcodes  0, 1 and 2 were burned during a API change to avoid users of the
+ * old API to get weird errors when trying to handling sync_files. The API
+ * change happened during the de-stage of the Sync Framework when there was
+ * no upstream users available.
+ */
+
+/**
+ * DOC: SYNC_IOC_MERGE - merge two fences
+ *
+ * Takes a struct sync_merge_data.  Creates a new fence containing copies of
+ * the sync_pts in both the calling fd and sync_merge_data.fd2.  Returns the
+ * new fence's fd in sync_merge_data.fence
+ */
+#define SYNC_IOC_MERGE		_IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data)
+
+/**
+ * DOC: SYNC_IOC_FENCE_INFO - get detailed information on a fence
+ *
+ * Takes a struct sync_file_info_data with extra space allocated for pt_info.
+ * Caller should write the size of the buffer into len.  On return, len is
+ * updated to reflect the total size of the sync_file_info_data including
+ * pt_info.
+ *
+ * pt_info is a buffer containing sync_pt_infos for every sync_pt in the fence.
+ * To iterate over the sync_pt_infos, use the sync_pt_info.len field.
+ */
+#define SYNC_IOC_FILE_INFO	_IOWR(SYNC_IOC_MAGIC, 4, struct sync_file_info)
+
+
+int sync_wait(int fd, int timeout);
+int sync_merge(const char *name, int fd1, int fd2);
+int sync_fence_size(int fd);
+int sync_fence_count_with_status(int fd, int status);
+
+#endif
diff --git a/tools/testing/selftests/sync/sync_alloc.c b/tools/testing/selftests/sync/sync_alloc.c
new file mode 100644
index 0000000..66a28af
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_alloc.c
@@ -0,0 +1,74 @@
+/*
+ *  sync allocation tests
+ *  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 "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+int test_alloc_timeline(void)
+{
+	int timeline, valid;
+
+	timeline = sw_sync_timeline_create();
+	valid = sw_sync_timeline_is_valid(timeline);
+	ASSERT(valid, "Failure allocating timeline\n");
+
+	sw_sync_timeline_destroy(timeline);
+	return 0;
+}
+
+int test_alloc_fence(void)
+{
+	int timeline, fence, valid;
+
+	timeline = sw_sync_timeline_create();
+	valid = sw_sync_timeline_is_valid(timeline);
+	ASSERT(valid, "Failure allocating timeline\n");
+
+	fence = sw_sync_fence_create(timeline, "allocFence", 1);
+	valid = sw_sync_fence_is_valid(fence);
+	ASSERT(valid, "Failure allocating fence\n");
+
+	sw_sync_fence_destroy(fence);
+	sw_sync_timeline_destroy(timeline);
+	return 0;
+}
+
+int test_alloc_fence_negative(void)
+{
+	int fence, timeline;
+
+	timeline = sw_sync_timeline_create();
+	ASSERT(timeline > 0, "Failure allocating timeline\n");
+
+	fence = sw_sync_fence_create(-1, "fence", 1);
+	ASSERT(fence < 0, "Success allocating negative fence\n");
+
+	sw_sync_fence_destroy(fence);
+	sw_sync_timeline_destroy(timeline);
+	return 0;
+}
diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
new file mode 100644
index 0000000..51efa71
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -0,0 +1,71 @@
+/*
+ *  sync test runner
+ *  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 <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "synctest.h"
+
+static int run_test(int (*test)(void), char *name)
+{
+	int result;
+	pid_t childpid;
+
+	fflush(stdout);
+	childpid = fork();
+
+	if (childpid) {
+		waitpid(childpid, &result, 0);
+		if (WIFEXITED(result))
+			return WEXITSTATUS(result);
+		return 1;
+	} else {
+		printf("[RUN]\tExecuting %s\n", name);
+		exit(test());
+	}
+}
+
+int main(void)
+{
+	int err = 0;
+
+	printf("[RUN]\tTesting sync framework\n");
+
+	err += RUN_TEST(test_alloc_timeline);
+	err += RUN_TEST(test_alloc_fence);
+	err += RUN_TEST(test_alloc_fence_negative);
+
+	if (err)
+		printf("[FAIL]\tsync errors: %d\n", err);
+	else
+		printf("[OK]\tsync\n");
+
+	return !!err;
+}
diff --git a/tools/testing/selftests/sync/synctest.h b/tools/testing/selftests/sync/synctest.h
new file mode 100644
index 0000000..edc5a8a
--- /dev/null
+++ b/tools/testing/selftests/sync/synctest.h
@@ -0,0 +1,47 @@
+/*
+ *  sync tests
+ *  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.
+ */
+
+#ifndef _SELFTESTS_SYNCTEST_H
+#define _SELFTESTS_SYNCTEST_H
+
+#include <stdio.h>
+
+#define ASSERT(cond, msg) do { \
+	if (!(cond)) { \
+		printf("[BAD]\t%s", (msg)); \
+		return 1; \
+	} \
+} while (0)
+
+#define RUN_TEST(x) run_test((x), #x)
+
+/* Allocation tests */
+int test_alloc_timeline(void);
+int test_alloc_fence(void);
+int test_alloc_fence_negative(void);
+
+#endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 2/9] selftest: sync: fence tests for sw_sync framework
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
  2016-03-09 15:28 ` [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework Emilio López
@ 2016-03-09 15:28 ` Emilio López
  2016-03-09 15:28 ` [RFC PATCH v1 3/9] selftest: sync: merge " Emilio López
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:28 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

These tests are based on the libsync test suite from Android.
This commit includes tests for basic fence creation.

Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
---

 tools/testing/selftests/sync/Makefile     |   1 +
 tools/testing/selftests/sync/sync_fence.c | 134 ++++++++++++++++++++++++++++++
 tools/testing/selftests/sync/sync_test.c  |   3 +
 tools/testing/selftests/sync/synctest.h   |   4 +
 4 files changed, 142 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_fence.c

diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index b21382d..a548e05 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -12,6 +12,7 @@ include ../lib.mk
 SRC = sync_test.o sync.o
 
 TESTS += sync_alloc.o
+TESTS += sync_fence.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_fence.c b/tools/testing/selftests/sync/sync_fence.c
new file mode 100644
index 0000000..6989112
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_fence.c
@@ -0,0 +1,134 @@
+/*
+ *  sync fence tests with one timeline
+ *  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 "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+int test_fence_one_timeline_wait(void)
+{
+	int fence, valid, ret;
+	int timeline = sw_sync_timeline_create();
+
+	valid = sw_sync_timeline_is_valid(timeline);
+	ASSERT(valid, "Failure allocating timeline\n");
+
+	fence = sw_sync_fence_create(timeline, "allocFence", 5);
+	valid = sw_sync_fence_is_valid(fence);
+	ASSERT(valid, "Failure allocating fence\n");
+
+	/* Wait on fence until timeout */
+	ret = sync_wait(fence, 0);
+	ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
+
+	/* Advance timeline from 0 -> 1 */
+	ret = sw_sync_timeline_inc(timeline, 1);
+	ASSERT(ret == 0, "Failure advancing timeline\n");
+
+	/* Wait on fence until timeout */
+	ret = sync_wait(fence, 0);
+	ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
+
+	/* Signal the fence */
+	ret = sw_sync_timeline_inc(timeline, 4);
+	ASSERT(ret == 0, "Failure signaling the fence\n");
+
+	/* Wait successfully */
+	ret = sync_wait(fence, 0);
+	ASSERT(ret > 0, "Failure waiting on fence\n");
+
+	/* Go even further, and confirm wait still succeeds */
+	ret = sw_sync_timeline_inc(timeline, 10);
+	ASSERT(ret == 0, "Failure going further\n");
+	ret = sync_wait(fence, 0);
+	ASSERT(ret > 0, "Failure waiting ahead\n");
+
+	sw_sync_fence_destroy(fence);
+	sw_sync_timeline_destroy(timeline);
+
+	return 0;
+}
+
+int test_fence_one_timeline_merge(void)
+{
+	int a, b, c, d, valid;
+	int timeline = sw_sync_timeline_create();
+
+	/* create fence a,b,c and then merge them all into fence d */
+	a = sw_sync_fence_create(timeline, "allocFence", 1);
+	b = sw_sync_fence_create(timeline, "allocFence", 2);
+	c = sw_sync_fence_create(timeline, "allocFence", 3);
+
+	valid = sw_sync_fence_is_valid(a) &&
+		sw_sync_fence_is_valid(b) &&
+		sw_sync_fence_is_valid(c);
+	ASSERT(valid, "Failure allocating fences\n");
+
+	d = sync_merge("mergeFence", b, a);
+	d = sync_merge("mergeFence", c, d);
+	valid = sw_sync_fence_is_valid(d);
+	ASSERT(valid, "Failure merging fences\n");
+
+	/* confirm all fences have one active point (even d) */
+	ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
+	       "a has too many active fences!\n");
+	ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
+	       "b has too many active fences!\n");
+	ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
+	       "c has too many active fences!\n");
+	ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
+	       "d has too many active fences!\n");
+
+	/* confirm that d is not signaled until the max of a,b,c */
+	sw_sync_timeline_inc(timeline, 1);
+	ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_SIGNALED) == 1,
+	       "a did not signal!\n");
+	ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 1,
+	       "d signaled too early!\n");
+
+	sw_sync_timeline_inc(timeline, 1);
+	ASSERT(sync_fence_count_with_status(b, FENCE_STATUS_SIGNALED) == 1,
+	       "b did not signal!\n");
+	ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 1,
+	       "d signaled too early!\n");
+
+	sw_sync_timeline_inc(timeline, 1);
+	ASSERT(sync_fence_count_with_status(c, FENCE_STATUS_SIGNALED) == 1,
+	       "c did not signal!\n");
+	ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 0 &&
+	       sync_fence_count_with_status(d, FENCE_STATUS_SIGNALED) == 1,
+	       "d did not signal!\n");
+
+	sw_sync_fence_destroy(d);
+	sw_sync_fence_destroy(c);
+	sw_sync_fence_destroy(b);
+	sw_sync_fence_destroy(a);
+	sw_sync_timeline_destroy(timeline);
+	return 0;
+}
diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index 51efa71..6cd6b4e 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -62,6 +62,9 @@ int main(void)
 	err += RUN_TEST(test_alloc_fence);
 	err += RUN_TEST(test_alloc_fence_negative);
 
+	err += RUN_TEST(test_fence_one_timeline_wait);
+	err += RUN_TEST(test_fence_one_timeline_merge);
+
 	if (err)
 		printf("[FAIL]\tsync errors: %d\n", err);
 	else
diff --git a/tools/testing/selftests/sync/synctest.h b/tools/testing/selftests/sync/synctest.h
index edc5a8a..e9ceebe 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -44,4 +44,8 @@ int test_alloc_timeline(void);
 int test_alloc_fence(void);
 int test_alloc_fence_negative(void);
 
+/* Fence tests with one timeline */
+int test_fence_one_timeline_wait(void);
+int test_fence_one_timeline_merge(void);
+
 #endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 3/9] selftest: sync: merge tests for sw_sync framework
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
  2016-03-09 15:28 ` [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework Emilio López
  2016-03-09 15:28 ` [RFC PATCH v1 2/9] selftest: sync: fence " Emilio López
@ 2016-03-09 15:28 ` Emilio López
  2016-03-09 15:28 ` [RFC PATCH v1 4/9] selftest: sync: wait " Emilio López
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:28 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

These tests are based on the libsync test suite from Android.
This commit includes tests for basic merge operations.

Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
---

 tools/testing/selftests/sync/Makefile     |  1 +
 tools/testing/selftests/sync/sync_merge.c | 60 +++++++++++++++++++++++++++++++
 tools/testing/selftests/sync/sync_test.c  |  1 +
 tools/testing/selftests/sync/synctest.h   |  3 ++
 4 files changed, 65 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_merge.c

diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index a548e05..10f3197 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -13,6 +13,7 @@ SRC = sync_test.o sync.o
 
 TESTS += sync_alloc.o
 TESTS += sync_fence.o
+TESTS += sync_merge.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_merge.c b/tools/testing/selftests/sync/sync_merge.c
new file mode 100644
index 0000000..8914d43
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_merge.c
@@ -0,0 +1,60 @@
+/*
+ *  sync fence merge tests
+ *  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 "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+int test_fence_merge_same_fence(void)
+{
+	int fence, valid, merged;
+	int timeline = sw_sync_timeline_create();
+
+	valid = sw_sync_timeline_is_valid(timeline);
+	ASSERT(valid, "Failure allocating timeline\n");
+
+	fence = sw_sync_fence_create(timeline, "allocFence", 5);
+	valid = sw_sync_fence_is_valid(fence);
+	ASSERT(valid, "Failure allocating fence\n");
+
+	merged = sync_merge("mergeFence", fence, fence);
+	valid = sw_sync_fence_is_valid(fence);
+	ASSERT(valid, "Failure merging fence\n");
+
+	ASSERT(sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED) == 0,
+	       "fence signaled too early!\n");
+
+	sw_sync_timeline_inc(timeline, 5);
+	ASSERT(sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED) == 1,
+	       "fence did not signal!\n");
+
+	sw_sync_fence_destroy(merged);
+	sw_sync_fence_destroy(fence);
+	sw_sync_timeline_destroy(timeline);
+
+	return 0;
+}
diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index 6cd6b4e..48636d3 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -64,6 +64,7 @@ int main(void)
 
 	err += RUN_TEST(test_fence_one_timeline_wait);
 	err += RUN_TEST(test_fence_one_timeline_merge);
+	err += RUN_TEST(test_fence_merge_same_fence);
 
 	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 e9ceebe..750cf5a 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -48,4 +48,7 @@ int test_alloc_fence_negative(void);
 int test_fence_one_timeline_wait(void);
 int test_fence_one_timeline_merge(void);
 
+/* Fence merge tests */
+int test_fence_merge_same_fence(void);
+
 #endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 4/9] selftest: sync: wait tests for sw_sync framework
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
                   ` (2 preceding siblings ...)
  2016-03-09 15:28 ` [RFC PATCH v1 3/9] selftest: sync: merge " Emilio López
@ 2016-03-09 15:28 ` Emilio López
  2016-03-09 15:28 ` [RFC PATCH v1 5/9] selftest: sync: destruction " Emilio López
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:28 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

These tests are based on the libsync test suite from Android.
This commit includes tests for waiting on fences.

Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
---

 tools/testing/selftests/sync/Makefile    |  1 +
 tools/testing/selftests/sync/sync_test.c |  1 +
 tools/testing/selftests/sync/sync_wait.c | 95 ++++++++++++++++++++++++++++++++
 tools/testing/selftests/sync/synctest.h  |  3 +
 4 files changed, 100 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_wait.c

diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index 10f3197..9944957 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -14,6 +14,7 @@ SRC = sync_test.o sync.o
 TESTS += sync_alloc.o
 TESTS += sync_fence.o
 TESTS += sync_merge.o
+TESTS += sync_wait.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index 48636d3..344a2f6 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -65,6 +65,7 @@ int main(void)
 	err += RUN_TEST(test_fence_one_timeline_wait);
 	err += RUN_TEST(test_fence_one_timeline_merge);
 	err += RUN_TEST(test_fence_merge_same_fence);
+	err += RUN_TEST(test_fence_multi_timeline_wait);
 
 	if (err)
 		printf("[FAIL]\tsync errors: %d\n", err);
diff --git a/tools/testing/selftests/sync/sync_wait.c b/tools/testing/selftests/sync/sync_wait.c
new file mode 100644
index 0000000..224e66a
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_wait.c
@@ -0,0 +1,95 @@
+/*
+ *  sync fence wait tests
+ *  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 "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+int test_fence_multi_timeline_wait(void)
+{
+	int timelineA, timelineB, timelineC;
+	int fenceA, fenceB, fenceC, mergedFence;
+	int valid, active, signaled, ret;
+
+	timelineA = sw_sync_timeline_create();
+	timelineB = sw_sync_timeline_create();
+	timelineC = sw_sync_timeline_create();
+
+	fenceA = sw_sync_fence_create(timelineA, "allocFence", 5);
+	fenceB = sw_sync_fence_create(timelineB, "allocFence", 5);
+	fenceC = sw_sync_fence_create(timelineC, "allocFence", 5);
+
+	mergedFence = sync_merge("mergeFence", fenceB, fenceA);
+	mergedFence = sync_merge("mergeFence", fenceC, mergedFence);
+
+	valid = sw_sync_fence_is_valid(mergedFence);
+	ASSERT(valid, "Failure merging fence from various timelines\n");
+
+	/* Confirm fence isn't signaled */
+	active = sync_fence_count_with_status(mergedFence, FENCE_STATUS_ACTIVE);
+	ASSERT(active == 3, "Fence signaled too early!\n");
+
+	ret = sync_wait(mergedFence, 0);
+	ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
+
+	ret = sw_sync_timeline_inc(timelineA, 5);
+	active = sync_fence_count_with_status(mergedFence, FENCE_STATUS_ACTIVE);
+	signaled = sync_fence_count_with_status(mergedFence,
+						FENCE_STATUS_SIGNALED);
+	ASSERT(active == 2 && signaled == 1,
+	       "Fence did not signal properly!\n");
+
+	ret = sw_sync_timeline_inc(timelineB, 5);
+	active = sync_fence_count_with_status(mergedFence, FENCE_STATUS_ACTIVE);
+	signaled = sync_fence_count_with_status(mergedFence,
+						FENCE_STATUS_SIGNALED);
+	ASSERT(active == 1 && signaled == 2,
+	       "Fence did not signal properly!\n");
+
+	ret = sw_sync_timeline_inc(timelineC, 5);
+	active = sync_fence_count_with_status(mergedFence, FENCE_STATUS_ACTIVE);
+	signaled = sync_fence_count_with_status(mergedFence,
+						FENCE_STATUS_SIGNALED);
+	ASSERT(active == 0 && signaled == 3,
+	       "Fence did not signal properly!\n");
+
+	/* confirm you can successfully wait */
+	ret = sync_wait(mergedFence, 100);
+	ASSERT(ret > 0, "Failure waiting on signaled fence\n");
+
+	sw_sync_fence_destroy(mergedFence);
+	sw_sync_fence_destroy(fenceC);
+	sw_sync_fence_destroy(fenceB);
+	sw_sync_fence_destroy(fenceA);
+	sw_sync_timeline_destroy(timelineC);
+	sw_sync_timeline_destroy(timelineB);
+	sw_sync_timeline_destroy(timelineA);
+
+	return 0;
+}
diff --git a/tools/testing/selftests/sync/synctest.h b/tools/testing/selftests/sync/synctest.h
index 750cf5a..9287393 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -51,4 +51,7 @@ int test_fence_one_timeline_merge(void);
 /* Fence merge tests */
 int test_fence_merge_same_fence(void);
 
+/* Fence wait tests */
+int test_fence_multi_timeline_wait(void);
+
 #endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 5/9] selftest: sync: destruction tests for sw_sync framework
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
                   ` (3 preceding siblings ...)
  2016-03-09 15:28 ` [RFC PATCH v1 4/9] selftest: sync: wait " Emilio López
@ 2016-03-09 15:28 ` Emilio López
  2016-03-09 15:28 ` [RFC PATCH v1 6/9] selftest: sync: stress test for parallelism Emilio López
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:28 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

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@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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 6/9] selftest: sync: stress test for parallelism
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
                   ` (4 preceding siblings ...)
  2016-03-09 15:28 ` [RFC PATCH v1 5/9] selftest: sync: destruction " Emilio López
@ 2016-03-09 15:28 ` Emilio López
  2016-03-09 15:29 ` [RFC PATCH v1 7/9] selftest: sync: stress consumer/producer test Emilio López
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:28 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

This test is based on the libsync test suite from Android.
This commit includes a stress test that invokes operations
in parallel.

Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
---

 tools/testing/selftests/sync/Makefile              |   1 +
 .../selftests/sync/sync_stress_parallelism.c       | 111 +++++++++++++++++++++
 tools/testing/selftests/sync/sync_test.c           |   1 +
 tools/testing/selftests/sync/synctest.h            |   3 +
 4 files changed, 116 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_stress_parallelism.c

diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index 4104d22..55739a4 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -16,6 +16,7 @@ TESTS += sync_fence.o
 TESTS += sync_merge.o
 TESTS += sync_wait.o
 TESTS += sync_destroyed.o
+TESTS += sync_stress_parallelism.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_stress_parallelism.c b/tools/testing/selftests/sync/sync_stress_parallelism.c
new file mode 100644
index 0000000..293794b
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_stress_parallelism.c
@@ -0,0 +1,111 @@
+/*
+ *  sync stress test: parallelism
+ *  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 <pthread.h>
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+static struct {
+	int iterations;
+	int timeline;
+	int counter;
+} test_data_two_threads;
+
+static int test_stress_two_threads_shared_timeline_thread(void *d)
+{
+	int threadId = (long)d;
+	int timeline = test_data_two_threads.timeline;
+	int iterations = test_data_two_threads.iterations;
+	int fence, valid, ret, i;
+
+	for (i = 0; i < iterations; i++) {
+		fence = sw_sync_fence_create(timeline, "fence",
+					     i * 2 + threadId);
+		valid = sw_sync_fence_is_valid(fence);
+		ASSERT(valid, "Failure allocating fence\n");
+
+		/* Wait on the prior thread to complete */
+		ret = sync_wait(fence, -1);
+		ASSERT(ret > 0, "Problem occurred on prior thread\n");
+
+		/*
+		 * Confirm the previous thread's writes are visible
+		 * and then increment
+		 */
+		ASSERT(test_data_two_threads.counter == i * 2 + threadId,
+		       "Counter got damaged!\n");
+		test_data_two_threads.counter++;
+
+		/* Kick off the other thread */
+		ret = sw_sync_timeline_inc(timeline, 1);
+		ASSERT(ret == 0, "Advancing timeline failed\n");
+
+		sw_sync_fence_destroy(fence);
+	}
+
+	return 0;
+}
+
+int test_stress_two_threads_shared_timeline(void)
+{
+	pthread_t a, b;
+	int valid;
+	int timeline = sw_sync_timeline_create();
+
+	valid = sw_sync_timeline_is_valid(timeline);
+	ASSERT(valid, "Failure allocating timeline\n");
+
+	test_data_two_threads.iterations = 1 << 16;
+	test_data_two_threads.counter = 0;
+	test_data_two_threads.timeline = timeline;
+
+	/*
+	 * Use a single timeline to synchronize two threads
+	 * hammmering on the same counter.
+	 */
+
+	pthread_create(&a, NULL, (void *(*)(void *))
+		       test_stress_two_threads_shared_timeline_thread,
+		       (void *)0);
+	pthread_create(&b, NULL, (void *(*)(void *))
+		       test_stress_two_threads_shared_timeline_thread,
+		       (void *)1);
+
+	pthread_join(a, NULL);
+	pthread_join(b, NULL);
+
+	/* make sure the threads did not trample on one another */
+	ASSERT(test_data_two_threads.counter ==
+	       test_data_two_threads.iterations * 2,
+	       "Counter has unexpected value\n");
+
+	sw_sync_timeline_destroy(timeline);
+
+	return 0;
+}
diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index 91f6b51..d4306ae 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -67,6 +67,7 @@ int main(void)
 	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);
 
 	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 bc8faae0..8c64504 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -57,4 +57,7 @@ int test_fence_multi_timeline_wait(void);
 /* Fence test on destroyed timelines */
 int test_fence_wait_on_destroyed_timeline(void);
 
+/* Stress test - parallelism */
+int test_stress_two_threads_shared_timeline(void);
+
 #endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 7/9] selftest: sync: stress consumer/producer test
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
                   ` (5 preceding siblings ...)
  2016-03-09 15:28 ` [RFC PATCH v1 6/9] selftest: sync: stress test for parallelism Emilio López
@ 2016-03-09 15:29 ` Emilio López
  2016-03-09 15:29 ` [RFC PATCH v1 8/9] selftest: sync: stress test for merges Emilio López
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:29 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

This test is based on the libsync test suite from Android.
This commit includes a stress test that replicates a
consumer/producer pattern.

Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
---

 tools/testing/selftests/sync/Makefile              |   1 +
 .../testing/selftests/sync/sync_stress_consumer.c  | 185 +++++++++++++++++++++
 tools/testing/selftests/sync/sync_test.c           |   1 +
 tools/testing/selftests/sync/synctest.h            |   3 +
 4 files changed, 190 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_stress_consumer.c

diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index 55739a4..eb14e8c 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -17,6 +17,7 @@ TESTS += sync_merge.o
 TESTS += sync_wait.o
 TESTS += sync_destroyed.o
 TESTS += sync_stress_parallelism.o
+TESTS += sync_stress_consumer.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_stress_consumer.c b/tools/testing/selftests/sync/sync_stress_consumer.c
new file mode 100644
index 0000000..d023f0e
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_stress_consumer.c
@@ -0,0 +1,185 @@
+/*
+ *  sync stress test: producer/consumer
+ *  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 <pthread.h>
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+/* 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.
+ */
+
+/* Returns 1 on error, 0 on success */
+static int busy_wait_on_fence(int fence)
+{
+	int error, active;
+
+	do {
+		error = sync_fence_count_with_status(fence, FENCE_STATUS_ERROR);
+		ASSERT(error == 0, "Error occurred on fence\n");
+		active = sync_fence_count_with_status(fence,
+						      FENCE_STATUS_ACTIVE);
+	} while (active);
+
+	return 0;
+}
+
+static struct {
+	int iterations;
+	int threads;
+	int counter;
+	int consumerTimeline;
+	int *producerTimelines;
+	pthread_mutex_t lock;
+} test_data_mpsc;
+
+static int mpsc_producer_thread(void *d)
+{
+	int id = (long)d;
+	int fence, valid, i;
+	int *producerTimelines = test_data_mpsc.producerTimelines;
+	int consumerTimeline = test_data_mpsc.consumerTimeline;
+	int iterations = test_data_mpsc.iterations;
+
+	for (i = 0; i < iterations; i++) {
+		fence = sw_sync_fence_create(consumerTimeline, "fence", i);
+		valid = sw_sync_fence_is_valid(fence);
+		ASSERT(valid, "Failure creating fence\n");
+
+		/*
+		 * Wait for the consumer to finish. Use alternate
+		 * means of waiting on the fence
+		 */
+
+		if ((iterations + id) % 8 != 0) {
+			ASSERT(sync_wait(fence, -1) > 0,
+			       "Failure waiting on fence\n");
+		} else {
+			ASSERT(busy_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_data_mpsc.lock);
+		test_data_mpsc.counter++;
+		pthread_mutex_unlock(&test_data_mpsc.lock);
+
+		ASSERT(sw_sync_timeline_inc(producerTimelines[id], 1) == 0,
+		       "Error advancing producer timeline\n");
+
+		sw_sync_fence_destroy(fence);
+	}
+
+	return 0;
+}
+
+static int mpcs_consumer_thread(void)
+{
+	int fence, merged, tmp, valid, it, i;
+	int *producerTimelines = test_data_mpsc.producerTimelines;
+	int consumerTimeline = test_data_mpsc.consumerTimeline;
+	int iterations = test_data_mpsc.iterations;
+	int n = test_data_mpsc.threads;
+
+	for (it = 1; it <= iterations; it++) {
+		fence = sw_sync_fence_create(producerTimelines[0], "name", it);
+		for (i = 1; i < n; i++) {
+			tmp = sw_sync_fence_create(producerTimelines[i],
+						   "name", it);
+			merged = sync_merge("name", tmp, fence);
+			sw_sync_fence_destroy(tmp);
+			sw_sync_fence_destroy(fence);
+			fence = merged;
+		}
+
+		valid = sw_sync_fence_is_valid(fence);
+		ASSERT(valid, "Failure merging fences\n");
+
+		/*
+		 * Make sure we see an increment from every producer thread.
+		 * Vary the means by which we wait.
+		 */
+		if (iterations % 8 != 0) {
+			ASSERT(sync_wait(fence, -1) == 0,
+			       "Producers did not increment as expected\n");
+		} else {
+			ASSERT(busy_wait_on_fence(fence) == 0,
+			       "Failure waiting on fence\n");
+		}
+
+		ASSERT(test_data_mpsc.counter == n * it,
+		       "Counter value mismatch!\n");
+
+		/* Release the producer threads */
+		ASSERT(sw_sync_timeline_inc(consumerTimeline, 1) == 0,
+		       "Failure releasing producer threads\n");
+
+		sw_sync_fence_destroy(fence);
+	}
+
+	return 0;
+}
+
+int test_consumer_stress_multi_producer_single_consumer(void)
+{
+	int iterations = 1 << 12;
+	int n = 5;
+	long i, ret;
+	int producerTimelines[n];
+	int consumerTimeline;
+	pthread_t threads[n];
+
+	consumerTimeline = sw_sync_timeline_create();
+	for (i = 0; i < n; i++)
+		producerTimelines[i] = sw_sync_timeline_create();
+
+	test_data_mpsc.producerTimelines = producerTimelines;
+	test_data_mpsc.consumerTimeline = consumerTimeline;
+	test_data_mpsc.iterations = iterations;
+	test_data_mpsc.threads = n;
+	test_data_mpsc.counter = 0;
+	pthread_mutex_init(&test_data_mpsc.lock, NULL);
+
+	for (i = 0; i < n; i++) {
+		pthread_create(&threads[i], NULL, (void * (*)(void *))
+			       mpsc_producer_thread, (void *)i);
+	}
+
+	/* Consumer thread runs here */
+	ret = mpcs_consumer_thread();
+
+	for (i = 0; i < n; i++)
+		pthread_join(threads[i], NULL);
+
+	return ret;
+}
diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index d4306ae..b27f492 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -68,6 +68,7 @@ int main(void)
 	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);
 
 	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 8c64504..94c4594 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -60,4 +60,7 @@ int test_fence_wait_on_destroyed_timeline(void);
 /* Stress test - parallelism */
 int test_stress_two_threads_shared_timeline(void);
 
+/* Stress test - consumer */
+int test_consumer_stress_multi_producer_single_consumer(void);
+
 #endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 8/9] selftest: sync: stress test for merges
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
                   ` (6 preceding siblings ...)
  2016-03-09 15:29 ` [RFC PATCH v1 7/9] selftest: sync: stress consumer/producer test Emilio López
@ 2016-03-09 15:29 ` Emilio López
  2016-03-09 15:29 ` [RFC PATCH v1 9/9] selftest: sync: disable tests that rely on not yet defined behaviour Emilio López
  2016-03-09 16:13   ` Shuah Khan
  9 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:29 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

This test is based on the libsync test suite from Android.
This commit includes a test to stress merge operations.

Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
---

 tools/testing/selftests/sync/Makefile            |   1 +
 tools/testing/selftests/sync/sync_stress_merge.c | 115 +++++++++++++++++++++++
 tools/testing/selftests/sync/sync_test.c         |   1 +
 tools/testing/selftests/sync/synctest.h          |   3 +
 4 files changed, 120 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_stress_merge.c

diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index eb14e8c..7237a6c 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -18,6 +18,7 @@ TESTS += sync_wait.o
 TESTS += sync_destroyed.o
 TESTS += sync_stress_parallelism.o
 TESTS += sync_stress_consumer.o
+TESTS += sync_stress_merge.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_stress_merge.c b/tools/testing/selftests/sync/sync_stress_merge.c
new file mode 100644
index 0000000..7eb2cdf
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_stress_merge.c
@@ -0,0 +1,115 @@
+/*
+ *  sync stress test: merging
+ *  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 <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+static int fence_map[1024 * 32];
+
+int test_merge_stress_random_merge(void)
+{
+	int i, size, ret;
+	int timelineCount = 32;
+	int mergeCount = 1024 * 32;
+	int timelines[timelineCount];
+	int fence, tmpfence, merged, valid;
+	int timeline, timelineOffset, syncPoint;
+
+	srand(time(NULL));
+
+	for (i = 0; i < timelineCount; i++)
+		timelines[i] = sw_sync_timeline_create();
+
+	fence = sw_sync_fence_create(timelines[0], "fence", 0);
+	valid = sw_sync_fence_is_valid(fence);
+	ASSERT(valid, "Failure creating fence\n");
+
+	memset(fence_map, -1, sizeof(fence_map));
+	fence_map[0] = 0;
+
+	/*
+	 * Randomly create syncpoints out of a fixed set of timelines,
+	 * and merge them together
+	 */
+	for (i = 0; i < mergeCount; i++) {
+		/* Generate syncpoint. */
+		timelineOffset = rand() % timelineCount;
+		timeline = timelines[timelineOffset];
+		syncPoint = rand();
+
+		/* Keep track of the latest syncpoint in each timeline. */
+		if (fence_map[timelineOffset] == -1)
+			fence_map[timelineOffset] = syncPoint;
+		else if (fence_map[timelineOffset] < syncPoint)
+			fence_map[timelineOffset] = syncPoint;
+
+		/* Merge */
+		tmpfence = sw_sync_fence_create(timeline, "fence", syncPoint);
+		merged = sync_merge("merge", tmpfence, fence);
+		sw_sync_fence_destroy(tmpfence);
+		sw_sync_fence_destroy(fence);
+		fence = merged;
+
+		valid = sw_sync_fence_is_valid(merged);
+		ASSERT(valid, "Failure creating fence i\n");
+	}
+
+	size = 0;
+	for (i = 0; i < mergeCount; i++)
+		if (fence_map[i] != -1)
+			size++;
+
+	/* Confirm our map matches the fence. */
+	ASSERT(sync_fence_size(fence) == size,
+	       "Quantity of elements not matching\n");
+
+	/* Trigger the merged fence */
+	for (i = 0; i < mergeCount; i++) {
+		if (fence_map[i] != -1) {
+			ret = sync_wait(fence, 0);
+			ASSERT(ret == 0,
+			       "Failure waiting on fence until timeout\n");
+			/* Increment the timeline to the last syncpoint */
+			sw_sync_timeline_inc(timelines[i], fence_map[i]);
+		}
+	}
+
+	/* Check that the fence is triggered. */
+	ret = sync_wait(fence, 0);
+	ASSERT(ret > 0, "Failure triggering fence\n");
+
+	for (i = 0; i < timelineCount; i++)
+		sw_sync_timeline_destroy(timelines[i]);
+
+	return 0;
+}
diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index b27f492..c3e4c01 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -69,6 +69,7 @@ int main(void)
 	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);
 
 	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 94c4594..f74459e 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -63,4 +63,7 @@ int test_stress_two_threads_shared_timeline(void);
 /* Stress test - consumer */
 int test_consumer_stress_multi_producer_single_consumer(void);
 
+/* Stress test - merging */
+int test_merge_stress_random_merge(void);
+
 #endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH v1 9/9] selftest: sync: disable tests that rely on not yet defined behaviour
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
                   ` (7 preceding siblings ...)
  2016-03-09 15:29 ` [RFC PATCH v1 8/9] selftest: sync: stress test for merges Emilio López
@ 2016-03-09 15:29 ` Emilio López
  2016-03-09 16:14     ` Shuah Khan
  2016-03-09 16:13   ` Shuah Khan
  9 siblings, 1 reply; 27+ messages in thread
From: Emilio López @ 2016-03-09 15:29 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Emilio López

One of the tests rely on a behaviour only observed on the driver currently
in use in Android. Disable it here until the behaviour is implemented
or it is decided it should not be implemented on the driver in mainline.

Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>

---

 tools/testing/selftests/sync/sync_test.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
index c3e4c01..3f484318 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -66,7 +66,14 @@ 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);
+#if 0
+	/* The following test has been disabled due to differences
+	 * between the upstream and Android kernel drivers. The behaviour
+	 * that should occur when destroying a timeline with active fences
+	 * has not been defined yet.
+	 */
 	err += RUN_TEST(test_fence_wait_on_destroyed_timeline);
+#endif
 	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);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 0/9] Tests for sync infrastructure
  2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
@ 2016-03-09 16:13   ` Shuah Khan
  2016-03-09 15:28 ` [RFC PATCH v1 2/9] selftest: sync: fence " Emilio López
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 27+ messages in thread
From: Shuah Khan @ 2016-03-09 16:13 UTC (permalink / raw)
  To: Emilio López
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Shuah Khan

On 03/09/2016 08:28 AM, Emilio López wrote:
> Hello everyone,
> 
> This is a series of tests to exercise the sync kernel infrastructure. It is
> meant to be a test suite for the work Gustavo has been doing to destage it,
> see [0] for his latest series to date.
> 
> These tests were originally part of a battery of tests shipping with
> Android's libsync that were rewritten to use the new userspace interfaces.
> 
> As usual, all comments are welcome.
> 
> Cheers!
> Emilio
> 
> [0] https://lists.freedesktop.org/archives/dri-devel/2016-March/102204.html

Good to see this suite added to Kselftest. Thanks for
being thorough and including .gitignore.

Are there any destructive and/or longer time tests
in this suite. If so could you please make them
optional to run. Please see selftests/timers as an
example for excluding.

More comments on individual patches to follow.

thanks,
-- Shuah

> 
> 
> Emilio López (9):
>   selftest: sync: basic tests for sw_sync framework
>   selftest: sync: fence tests for sw_sync framework
>   selftest: sync: merge tests for sw_sync framework
>   selftest: sync: wait tests for sw_sync framework
>   selftest: sync: destruction tests for sw_sync framework
>   selftest: sync: stress test for parallelism
>   selftest: sync: stress consumer/producer test
>   selftest: sync: stress test for merges
>   selftest: sync: disable tests that rely on not yet defined behaviour
> 
>  tools/testing/selftests/Makefile                   |   1 +
>  tools/testing/selftests/sync/.gitignore            |   1 +
>  tools/testing/selftests/sync/Makefile              |  28 +++
>  tools/testing/selftests/sync/sw_sync.h             |  46 +++++
>  tools/testing/selftests/sync/sync.c                | 203 +++++++++++++++++++++
>  tools/testing/selftests/sync/sync.h                | 119 ++++++++++++
>  tools/testing/selftests/sync/sync_alloc.c          |  74 ++++++++
>  tools/testing/selftests/sync/sync_destroyed.c      |  90 +++++++++
>  tools/testing/selftests/sync/sync_fence.c          | 134 ++++++++++++++
>  tools/testing/selftests/sync/sync_merge.c          |  60 ++++++
>  .../testing/selftests/sync/sync_stress_consumer.c  | 185 +++++++++++++++++++
>  tools/testing/selftests/sync/sync_stress_merge.c   | 115 ++++++++++++
>  .../selftests/sync/sync_stress_parallelism.c       | 111 +++++++++++
>  tools/testing/selftests/sync/sync_test.c           |  87 +++++++++
>  tools/testing/selftests/sync/sync_wait.c           |  95 ++++++++++
>  tools/testing/selftests/sync/synctest.h            |  69 +++++++
>  16 files changed, 1418 insertions(+)
>  create mode 100644 tools/testing/selftests/sync/.gitignore
>  create mode 100644 tools/testing/selftests/sync/Makefile
>  create mode 100644 tools/testing/selftests/sync/sw_sync.h
>  create mode 100644 tools/testing/selftests/sync/sync.c
>  create mode 100644 tools/testing/selftests/sync/sync.h
>  create mode 100644 tools/testing/selftests/sync/sync_alloc.c
>  create mode 100644 tools/testing/selftests/sync/sync_destroyed.c
>  create mode 100644 tools/testing/selftests/sync/sync_fence.c
>  create mode 100644 tools/testing/selftests/sync/sync_merge.c
>  create mode 100644 tools/testing/selftests/sync/sync_stress_consumer.c
>  create mode 100644 tools/testing/selftests/sync/sync_stress_merge.c
>  create mode 100644 tools/testing/selftests/sync/sync_stress_parallelism.c
>  create mode 100644 tools/testing/selftests/sync/sync_test.c
>  create mode 100644 tools/testing/selftests/sync/sync_wait.c
>  create mode 100644 tools/testing/selftests/sync/synctest.h
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 0/9] Tests for sync infrastructure
@ 2016-03-09 16:13   ` Shuah Khan
  0 siblings, 0 replies; 27+ messages in thread
From: Shuah Khan @ 2016-03-09 16:13 UTC (permalink / raw)
  To: Emilio López
  Cc: devel, Rob Clark, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Maarten Lankhorst, linux-kernel,
	dri-devel, Shuah Khan, Riley Andrews, Greg Hackmann,
	linux-kselftest, Gustavo Padovan, John Harrison

On 03/09/2016 08:28 AM, Emilio López wrote:
> Hello everyone,
> 
> This is a series of tests to exercise the sync kernel infrastructure. It is
> meant to be a test suite for the work Gustavo has been doing to destage it,
> see [0] for his latest series to date.
> 
> These tests were originally part of a battery of tests shipping with
> Android's libsync that were rewritten to use the new userspace interfaces.
> 
> As usual, all comments are welcome.
> 
> Cheers!
> Emilio
> 
> [0] https://lists.freedesktop.org/archives/dri-devel/2016-March/102204.html

Good to see this suite added to Kselftest. Thanks for
being thorough and including .gitignore.

Are there any destructive and/or longer time tests
in this suite. If so could you please make them
optional to run. Please see selftests/timers as an
example for excluding.

More comments on individual patches to follow.

thanks,
-- Shuah

> 
> 
> Emilio López (9):
>   selftest: sync: basic tests for sw_sync framework
>   selftest: sync: fence tests for sw_sync framework
>   selftest: sync: merge tests for sw_sync framework
>   selftest: sync: wait tests for sw_sync framework
>   selftest: sync: destruction tests for sw_sync framework
>   selftest: sync: stress test for parallelism
>   selftest: sync: stress consumer/producer test
>   selftest: sync: stress test for merges
>   selftest: sync: disable tests that rely on not yet defined behaviour
> 
>  tools/testing/selftests/Makefile                   |   1 +
>  tools/testing/selftests/sync/.gitignore            |   1 +
>  tools/testing/selftests/sync/Makefile              |  28 +++
>  tools/testing/selftests/sync/sw_sync.h             |  46 +++++
>  tools/testing/selftests/sync/sync.c                | 203 +++++++++++++++++++++
>  tools/testing/selftests/sync/sync.h                | 119 ++++++++++++
>  tools/testing/selftests/sync/sync_alloc.c          |  74 ++++++++
>  tools/testing/selftests/sync/sync_destroyed.c      |  90 +++++++++
>  tools/testing/selftests/sync/sync_fence.c          | 134 ++++++++++++++
>  tools/testing/selftests/sync/sync_merge.c          |  60 ++++++
>  .../testing/selftests/sync/sync_stress_consumer.c  | 185 +++++++++++++++++++
>  tools/testing/selftests/sync/sync_stress_merge.c   | 115 ++++++++++++
>  .../selftests/sync/sync_stress_parallelism.c       | 111 +++++++++++
>  tools/testing/selftests/sync/sync_test.c           |  87 +++++++++
>  tools/testing/selftests/sync/sync_wait.c           |  95 ++++++++++
>  tools/testing/selftests/sync/synctest.h            |  69 +++++++
>  16 files changed, 1418 insertions(+)
>  create mode 100644 tools/testing/selftests/sync/.gitignore
>  create mode 100644 tools/testing/selftests/sync/Makefile
>  create mode 100644 tools/testing/selftests/sync/sw_sync.h
>  create mode 100644 tools/testing/selftests/sync/sync.c
>  create mode 100644 tools/testing/selftests/sync/sync.h
>  create mode 100644 tools/testing/selftests/sync/sync_alloc.c
>  create mode 100644 tools/testing/selftests/sync/sync_destroyed.c
>  create mode 100644 tools/testing/selftests/sync/sync_fence.c
>  create mode 100644 tools/testing/selftests/sync/sync_merge.c
>  create mode 100644 tools/testing/selftests/sync/sync_stress_consumer.c
>  create mode 100644 tools/testing/selftests/sync/sync_stress_merge.c
>  create mode 100644 tools/testing/selftests/sync/sync_stress_parallelism.c
>  create mode 100644 tools/testing/selftests/sync/sync_test.c
>  create mode 100644 tools/testing/selftests/sync/sync_wait.c
>  create mode 100644 tools/testing/selftests/sync/synctest.h
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 9/9] selftest: sync: disable tests that rely on not yet defined behaviour
  2016-03-09 15:29 ` [RFC PATCH v1 9/9] selftest: sync: disable tests that rely on not yet defined behaviour Emilio López
@ 2016-03-09 16:14     ` Shuah Khan
  0 siblings, 0 replies; 27+ messages in thread
From: Shuah Khan @ 2016-03-09 16:14 UTC (permalink / raw)
  To: Emilio López
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg, Shuah Khan

On 03/09/2016 08:29 AM, Emilio López wrote:
> One of the tests rely on a behaviour only observed on the driver currently
> in use in Android. Disable it here until the behaviour is implemented
> or it is decided it should not be implemented on the driver in mainline.
> 
> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
> 
> ---
> 
>  tools/testing/selftests/sync/sync_test.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
> index c3e4c01..3f484318 100644
> --- a/tools/testing/selftests/sync/sync_test.c
> +++ b/tools/testing/selftests/sync/sync_test.c
> @@ -66,7 +66,14 @@ 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);
> +#if 0
> +	/* The following test has been disabled due to differences
> +	 * between the upstream and Android kernel drivers. The behaviour
> +	 * that should occur when destroying a timeline with active fences
> +	 * has not been defined yet.
> +	 */
>  	err += RUN_TEST(test_fence_wait_on_destroyed_timeline);
> +#endif

It would be useful to have a real define here that can be
enabled later easily instead of if 0.

thanks,
-- Shuah

>  	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);
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 9/9] selftest: sync: disable tests that rely on not yet defined behaviour
@ 2016-03-09 16:14     ` Shuah Khan
  0 siblings, 0 replies; 27+ messages in thread
From: Shuah Khan @ 2016-03-09 16:14 UTC (permalink / raw)
  To: Emilio López
  Cc: devel, Rob Clark, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Maarten Lankhorst, linux-kernel,
	dri-devel, Shuah Khan, Riley Andrews, Greg Hackmann,
	linux-kselftest, Gustavo Padovan, John Harrison

On 03/09/2016 08:29 AM, Emilio López wrote:
> One of the tests rely on a behaviour only observed on the driver currently
> in use in Android. Disable it here until the behaviour is implemented
> or it is decided it should not be implemented on the driver in mainline.
> 
> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
> 
> ---
> 
>  tools/testing/selftests/sync/sync_test.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
> index c3e4c01..3f484318 100644
> --- a/tools/testing/selftests/sync/sync_test.c
> +++ b/tools/testing/selftests/sync/sync_test.c
> @@ -66,7 +66,14 @@ 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);
> +#if 0
> +	/* The following test has been disabled due to differences
> +	 * between the upstream and Android kernel drivers. The behaviour
> +	 * that should occur when destroying a timeline with active fences
> +	 * has not been defined yet.
> +	 */
>  	err += RUN_TEST(test_fence_wait_on_destroyed_timeline);
> +#endif

It would be useful to have a real define here that can be
enabled later easily instead of if 0.

thanks,
-- Shuah

>  	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);
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
  2016-03-09 15:28 ` [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework Emilio López
@ 2016-03-28 11:56     ` Emil Velikov
  0 siblings, 0 replies; 27+ messages in thread
From: Emil Velikov @ 2016-03-28 11:56 UTC (permalink / raw)
  To: Emilio López
  Cc: Shuah Khan, devel, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Linux-Kernel@Vger. Kernel. Org,
	ML dri-devel, Riley Andrews, linux-kselftest, Gustavo Padovan,
	John Harrison

Hi Emilio,

On 9 March 2016 at 15:28, Emilio López <emilio.lopez@collabora.co.uk> wrote:
> These tests are based on the libsync test suite from Android.
> This commit lays the ground for future tests, as well as includes
> tests for a variety of basic allocation commands.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
> ---
>

>  tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
Admittedly I know nothing about the kernel selftests although copying
the UAPI header, seems to defeat the purpose of this exercise.
Shouldn't one reuse the existing header ? It would even cause issues
as the interface gets updated (iirc Gustavo changed the ioctl numbers
and/or header name with latter series).

Regards,
Emil

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
@ 2016-03-28 11:56     ` Emil Velikov
  0 siblings, 0 replies; 27+ messages in thread
From: Emil Velikov @ 2016-03-28 11:56 UTC (permalink / raw)
  To: Emilio López
  Cc: devel, Daniel Stone, Daniel Vetter, Shuah Khan, ML dri-devel,
	Linux-Kernel@Vger. Kernel. Org, Arve Hjønnevåg,
	linux-kselftest, Riley Andrews, Gustavo Padovan, John Harrison

Hi Emilio,

On 9 March 2016 at 15:28, Emilio López <emilio.lopez@collabora.co.uk> wrote:
> These tests are based on the libsync test suite from Android.
> This commit lays the ground for future tests, as well as includes
> tests for a variety of basic allocation commands.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
> ---
>

>  tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
Admittedly I know nothing about the kernel selftests although copying
the UAPI header, seems to defeat the purpose of this exercise.
Shouldn't one reuse the existing header ? It would even cause issues
as the interface gets updated (iirc Gustavo changed the ioctl numbers
and/or header name with latter series).

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
  2016-03-28 11:56     ` Emil Velikov
@ 2016-03-28 12:20       ` Emilio López
  -1 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-28 12:20 UTC (permalink / raw)
  To: Emil Velikov
  Cc: Shuah Khan, devel, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Linux-Kernel@Vger. Kernel. Org,
	ML dri-devel, Riley Andrews, linux-kselftest, Gustavo Padovan,
	John Harrison

Hi,

El 28/03/16 a las 08:56, Emil Velikov escribió:
> Hi Emilio,
>
> On 9 March 2016 at 15:28, Emilio López <emilio.lopez@collabora.co.uk> wrote:
>> These tests are based on the libsync test suite from Android.
>> This commit lays the ground for future tests, as well as includes
>> tests for a variety of basic allocation commands.
>>
>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>> ---
>>
>
>>   tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
> Admittedly I know nothing about the kernel selftests although copying
> the UAPI header, seems to defeat the purpose of this exercise.
> Shouldn't one reuse the existing header ? It would even cause issues
> as the interface gets updated (iirc Gustavo changed the ioctl numbers
> and/or header name with latter series).

The problem is that one cannot use the system header without having 
built and installed the kernel first, which is rather problematic for 
eg. crosscompiling or virtualization. I discussed this with Gustavo and 
we agreed that the best way forward would be to copy the interfaces, as 
suggested by kernelnewbies' wiki[0]:

"""
The correct way to address this problem is to isolate the specific 
interfaces that you need, e.g. a single header file that is patched in a 
new kernel providing the ioctl numbers for a character device used by 
your program. In your own program, add a copy of that source file, with 
a notice that it should be kept in sync with new kernel versions.
"""

Cheers,
Emilio

[0] http://kernelnewbies.org/KernelHeaders

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
@ 2016-03-28 12:20       ` Emilio López
  0 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-28 12:20 UTC (permalink / raw)
  To: Emil Velikov
  Cc: devel, Daniel Stone, Daniel Vetter, Shuah Khan, ML dri-devel,
	Linux-Kernel@Vger. Kernel. Org, Arve Hjønnevåg,
	linux-kselftest, Riley Andrews, Gustavo Padovan, John Harrison

Hi,

El 28/03/16 a las 08:56, Emil Velikov escribió:
> Hi Emilio,
>
> On 9 March 2016 at 15:28, Emilio López <emilio.lopez@collabora.co.uk> wrote:
>> These tests are based on the libsync test suite from Android.
>> This commit lays the ground for future tests, as well as includes
>> tests for a variety of basic allocation commands.
>>
>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>> ---
>>
>
>>   tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
> Admittedly I know nothing about the kernel selftests although copying
> the UAPI header, seems to defeat the purpose of this exercise.
> Shouldn't one reuse the existing header ? It would even cause issues
> as the interface gets updated (iirc Gustavo changed the ioctl numbers
> and/or header name with latter series).

The problem is that one cannot use the system header without having 
built and installed the kernel first, which is rather problematic for 
eg. crosscompiling or virtualization. I discussed this with Gustavo and 
we agreed that the best way forward would be to copy the interfaces, as 
suggested by kernelnewbies' wiki[0]:

"""
The correct way to address this problem is to isolate the specific 
interfaces that you need, e.g. a single header file that is patched in a 
new kernel providing the ioctl numbers for a character device used by 
your program. In your own program, add a copy of that source file, with 
a notice that it should be kept in sync with new kernel versions.
"""

Cheers,
Emilio

[0] http://kernelnewbies.org/KernelHeaders
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 0/9] Tests for sync infrastructure
  2016-03-09 16:13   ` Shuah Khan
@ 2016-03-28 12:32     ` Emilio López
  -1 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-28 12:32 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg

Hi,

I somehow missed these emails back in the day, sorry for the delay in 
replying.

El 09/03/16 a las 13:13, Shuah Khan escribió:
> On 03/09/2016 08:28 AM, Emilio López wrote:
>> Hello everyone,
>>
>> This is a series of tests to exercise the sync kernel infrastructure. It is
>> meant to be a test suite for the work Gustavo has been doing to destage it,
>> see [0] for his latest series to date.
>>
>> These tests were originally part of a battery of tests shipping with
>> Android's libsync that were rewritten to use the new userspace interfaces.
>>
>> As usual, all comments are welcome.
>>
>> Cheers!
>> Emilio
>>
>> [0] https://lists.freedesktop.org/archives/dri-devel/2016-March/102204.html
>
> Good to see this suite added to Kselftest. Thanks for
> being thorough and including .gitignore.
>
> Are there any destructive and/or longer time tests
> in this suite. If so could you please make them
> optional to run. Please see selftests/timers as an
> example for excluding.

As far as I know they shouldn't destroy anything. The full sync suite 
runs in under 5 seconds on my virtualized setup; we can make the stress 
tests optional if that's too long a time, what do you think?.

Cheers,
Emilio

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 0/9] Tests for sync infrastructure
@ 2016-03-28 12:32     ` Emilio López
  0 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-28 12:32 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Rob Clark, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Maarten Lankhorst, linux-kernel,
	dri-devel, Riley Andrews, Greg Hackmann, linux-kselftest,
	Gustavo Padovan, John Harrison

Hi,

I somehow missed these emails back in the day, sorry for the delay in 
replying.

El 09/03/16 a las 13:13, Shuah Khan escribió:
> On 03/09/2016 08:28 AM, Emilio López wrote:
>> Hello everyone,
>>
>> This is a series of tests to exercise the sync kernel infrastructure. It is
>> meant to be a test suite for the work Gustavo has been doing to destage it,
>> see [0] for his latest series to date.
>>
>> These tests were originally part of a battery of tests shipping with
>> Android's libsync that were rewritten to use the new userspace interfaces.
>>
>> As usual, all comments are welcome.
>>
>> Cheers!
>> Emilio
>>
>> [0] https://lists.freedesktop.org/archives/dri-devel/2016-March/102204.html
>
> Good to see this suite added to Kselftest. Thanks for
> being thorough and including .gitignore.
>
> Are there any destructive and/or longer time tests
> in this suite. If so could you please make them
> optional to run. Please see selftests/timers as an
> example for excluding.

As far as I know they shouldn't destroy anything. The full sync suite 
runs in under 5 seconds on my virtualized setup; we can make the stress 
tests optional if that's too long a time, what do you think?.

Cheers,
Emilio
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 9/9] selftest: sync: disable tests that rely on not yet defined behaviour
  2016-03-09 16:14     ` Shuah Khan
@ 2016-03-28 12:33       ` Emilio López
  -1 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-28 12:33 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Gustavo Padovan, Riley Andrews, Daniel Vetter,
	John Harrison, linux-kernel, dri-devel, Greg Hackmann, Rob Clark,
	linux-kselftest, Maarten Lankhorst, Daniel Stone,
	Arve Hjønnevåg

El 09/03/16 a las 13:14, Shuah Khan escribió:
> On 03/09/2016 08:29 AM, Emilio López wrote:
>> One of the tests rely on a behaviour only observed on the driver currently
>> in use in Android. Disable it here until the behaviour is implemented
>> or it is decided it should not be implemented on the driver in mainline.
>>
>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>>
>> ---
>>
>>   tools/testing/selftests/sync/sync_test.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
>> index c3e4c01..3f484318 100644
>> --- a/tools/testing/selftests/sync/sync_test.c
>> +++ b/tools/testing/selftests/sync/sync_test.c
>> @@ -66,7 +66,14 @@ 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);
>> +#if 0
>> +	/* The following test has been disabled due to differences
>> +	 * between the upstream and Android kernel drivers. The behaviour
>> +	 * that should occur when destroying a timeline with active fences
>> +	 * has not been defined yet.
>> +	 */
>>   	err += RUN_TEST(test_fence_wait_on_destroyed_timeline);
>> +#endif
>
> It would be useful to have a real define here that can be
> enabled later easily instead of if 0.

Ok, sounds good.

Thanks!
Emilio

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 9/9] selftest: sync: disable tests that rely on not yet defined behaviour
@ 2016-03-28 12:33       ` Emilio López
  0 siblings, 0 replies; 27+ messages in thread
From: Emilio López @ 2016-03-28 12:33 UTC (permalink / raw)
  To: Shuah Khan
  Cc: devel, Rob Clark, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Maarten Lankhorst, linux-kernel,
	dri-devel, Riley Andrews, Greg Hackmann, linux-kselftest,
	Gustavo Padovan, John Harrison

El 09/03/16 a las 13:14, Shuah Khan escribió:
> On 03/09/2016 08:29 AM, Emilio López wrote:
>> One of the tests rely on a behaviour only observed on the driver currently
>> in use in Android. Disable it here until the behaviour is implemented
>> or it is decided it should not be implemented on the driver in mainline.
>>
>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>>
>> ---
>>
>>   tools/testing/selftests/sync/sync_test.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
>> index c3e4c01..3f484318 100644
>> --- a/tools/testing/selftests/sync/sync_test.c
>> +++ b/tools/testing/selftests/sync/sync_test.c
>> @@ -66,7 +66,14 @@ 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);
>> +#if 0
>> +	/* The following test has been disabled due to differences
>> +	 * between the upstream and Android kernel drivers. The behaviour
>> +	 * that should occur when destroying a timeline with active fences
>> +	 * has not been defined yet.
>> +	 */
>>   	err += RUN_TEST(test_fence_wait_on_destroyed_timeline);
>> +#endif
>
> It would be useful to have a real define here that can be
> enabled later easily instead of if 0.

Ok, sounds good.

Thanks!
Emilio
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
  2016-03-28 12:20       ` Emilio López
@ 2016-03-28 13:48         ` Emil Velikov
  -1 siblings, 0 replies; 27+ messages in thread
From: Emil Velikov @ 2016-03-28 13:48 UTC (permalink / raw)
  To: Emilio López
  Cc: Shuah Khan, devel, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Linux-Kernel@Vger. Kernel. Org,
	ML dri-devel, Riley Andrews, linux-kselftest, Gustavo Padovan,
	John Harrison

On 28 March 2016 at 13:20, Emilio López <emilio.lopez@collabora.co.uk> wrote:
> Hi,
>
> El 28/03/16 a las 08:56, Emil Velikov escribió:
>>
>> Hi Emilio,
>>
>> On 9 March 2016 at 15:28, Emilio López <emilio.lopez@collabora.co.uk>
>> wrote:
>>>
>>> These tests are based on the libsync test suite from Android.
>>> This commit lays the ground for future tests, as well as includes
>>> tests for a variety of basic allocation commands.
>>>
>>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>>> ---
>>>
>>
>>>   tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
>>
>> Admittedly I know nothing about the kernel selftests although copying
>> the UAPI header, seems to defeat the purpose of this exercise.
>> Shouldn't one reuse the existing header ? It would even cause issues
>> as the interface gets updated (iirc Gustavo changed the ioctl numbers
>> and/or header name with latter series).
>
>
> The problem is that one cannot use the system header without having built
> and installed the kernel first, which is rather problematic for eg.
> crosscompiling or virtualization. I discussed this with Gustavo and we
> agreed that the best way forward would be to copy the interfaces, as
> suggested by kernelnewbies' wiki[0]:
>
In the case of using a system header one can just `make
headers_install' without building the kernel, as mentioned in the very
same page ;-) Although I wasn't thinking that one should be using the
header already available in tree. After all this series is not
supposed to land before Gustavo's work, is it ?

>From a quick skim though the selftests, I cannot see cases where UAPI
headers are copied/duplicated.

> """
> The correct way to address this problem is to isolate the specific
> interfaces that you need, e.g. a single header file that is patched in a new
> kernel providing the ioctl numbers for a character device used by your
> program. In your own program, add a copy of that source file, with a notice
> that it should be kept in sync with new kernel versions.
> """
My understanding of the article is that it refers to building user
space programs that do _not_ live in the same tree as the kernel. Am I
missing something ?

Regards,
Emil

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
@ 2016-03-28 13:48         ` Emil Velikov
  0 siblings, 0 replies; 27+ messages in thread
From: Emil Velikov @ 2016-03-28 13:48 UTC (permalink / raw)
  To: Emilio López
  Cc: devel, Daniel Stone, Daniel Vetter, Shuah Khan, ML dri-devel,
	Linux-Kernel@Vger. Kernel. Org, Arve Hjønnevåg,
	linux-kselftest, Riley Andrews, Gustavo Padovan, John Harrison

On 28 March 2016 at 13:20, Emilio López <emilio.lopez@collabora.co.uk> wrote:
> Hi,
>
> El 28/03/16 a las 08:56, Emil Velikov escribió:
>>
>> Hi Emilio,
>>
>> On 9 March 2016 at 15:28, Emilio López <emilio.lopez@collabora.co.uk>
>> wrote:
>>>
>>> These tests are based on the libsync test suite from Android.
>>> This commit lays the ground for future tests, as well as includes
>>> tests for a variety of basic allocation commands.
>>>
>>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>>> ---
>>>
>>
>>>   tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
>>
>> Admittedly I know nothing about the kernel selftests although copying
>> the UAPI header, seems to defeat the purpose of this exercise.
>> Shouldn't one reuse the existing header ? It would even cause issues
>> as the interface gets updated (iirc Gustavo changed the ioctl numbers
>> and/or header name with latter series).
>
>
> The problem is that one cannot use the system header without having built
> and installed the kernel first, which is rather problematic for eg.
> crosscompiling or virtualization. I discussed this with Gustavo and we
> agreed that the best way forward would be to copy the interfaces, as
> suggested by kernelnewbies' wiki[0]:
>
In the case of using a system header one can just `make
headers_install' without building the kernel, as mentioned in the very
same page ;-) Although I wasn't thinking that one should be using the
header already available in tree. After all this series is not
supposed to land before Gustavo's work, is it ?

From a quick skim though the selftests, I cannot see cases where UAPI
headers are copied/duplicated.

> """
> The correct way to address this problem is to isolate the specific
> interfaces that you need, e.g. a single header file that is patched in a new
> kernel providing the ioctl numbers for a character device used by your
> program. In your own program, add a copy of that source file, with a notice
> that it should be kept in sync with new kernel versions.
> """
My understanding of the article is that it refers to building user
space programs that do _not_ live in the same tree as the kernel. Am I
missing something ?

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
  2016-03-28 13:48         ` Emil Velikov
  (?)
@ 2016-04-04  4:12         ` Emilio López
  2016-04-07 14:47             ` Emil Velikov
  -1 siblings, 1 reply; 27+ messages in thread
From: Emilio López @ 2016-04-04  4:12 UTC (permalink / raw)
  To: Emil Velikov
  Cc: Shuah Khan, devel, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Linux-Kernel@Vger. Kernel. Org,
	ML dri-devel, Riley Andrews, linux-kselftest, Gustavo Padovan,
	John Harrison

Hi,

El 28/03/16 a las 10:48, Emil Velikov escribió:
>>>> These tests are based on the libsync test suite from Android.
>>>> This commit lays the ground for future tests, as well as includes
>>>> tests for a variety of basic allocation commands.
>>>>
>>>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>>>> ---
>>>>
>>>
>>>>    tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
>>>
>>> Admittedly I know nothing about the kernel selftests although copying
>>> the UAPI header, seems to defeat the purpose of this exercise.
>>> Shouldn't one reuse the existing header ? It would even cause issues
>>> as the interface gets updated (iirc Gustavo changed the ioctl numbers
>>> and/or header name with latter series).
>>
>>
>> The problem is that one cannot use the system header without having built
>> and installed the kernel first, which is rather problematic for eg.
>> crosscompiling or virtualization. I discussed this with Gustavo and we
>> agreed that the best way forward would be to copy the interfaces, as
>> suggested by kernelnewbies' wiki[0]:
>>
> In the case of using a system header one can just `make
> headers_install' without building the kernel, as mentioned in the very
> same page ;-) Although I wasn't thinking that one should be using the
> header already available in tree. After all this series is not
> supposed to land before Gustavo's work, is it ?
>
>  From a quick skim though the selftests, I cannot see cases where UAPI
> headers are copied/duplicated.
>
>> """
>> The correct way to address this problem is to isolate the specific
>> interfaces that you need, e.g. a single header file that is patched in a new
>> kernel providing the ioctl numbers for a character device used by your
>> program. In your own program, add a copy of that source file, with a notice
>> that it should be kept in sync with new kernel versions.
>> """
> My understanding of the article is that it refers to building user
> space programs that do _not_ live in the same tree as the kernel. Am I
> missing something ?

When I tried using the header directly from the kernel tree, the 
compiler told me not to do that and pointed me to that kernelnewbies 
page; I could try overriding the check like I see memfd does[0] but I 
don't know if that's the way to go. Shuah, what's your thoughts on this?

Thanks,
Emilio

[0] 
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/memfd/memfd_test.c#n2

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
  2016-04-04  4:12         ` Emilio López
@ 2016-04-07 14:47             ` Emil Velikov
  0 siblings, 0 replies; 27+ messages in thread
From: Emil Velikov @ 2016-04-07 14:47 UTC (permalink / raw)
  To: Emilio López
  Cc: Shuah Khan, devel, Daniel Stone, Daniel Vetter,
	Arve Hjønnevåg, Linux-Kernel@Vger. Kernel. Org,
	ML dri-devel, Riley Andrews, linux-kselftest, Gustavo Padovan,
	John Harrison

On 4 April 2016 at 05:12, Emilio López <emilio.lopez@collabora.co.uk> wrote:
> Hi,
>
> El 28/03/16 a las 10:48, Emil Velikov escribió:
>
>>>>> These tests are based on the libsync test suite from Android.
>>>>> This commit lays the ground for future tests, as well as includes
>>>>> tests for a variety of basic allocation commands.
>>>>>
>>>>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>>>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>>>>> ---
>>>>>
>>>>
>>>>>    tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
>>>>
>>>>
>>>> Admittedly I know nothing about the kernel selftests although copying
>>>> the UAPI header, seems to defeat the purpose of this exercise.
>>>> Shouldn't one reuse the existing header ? It would even cause issues
>>>> as the interface gets updated (iirc Gustavo changed the ioctl numbers
>>>> and/or header name with latter series).
>>>
>>>
>>>
>>> The problem is that one cannot use the system header without having built
>>> and installed the kernel first, which is rather problematic for eg.
>>> crosscompiling or virtualization. I discussed this with Gustavo and we
>>> agreed that the best way forward would be to copy the interfaces, as
>>> suggested by kernelnewbies' wiki[0]:
>>>
>> In the case of using a system header one can just `make
>> headers_install' without building the kernel, as mentioned in the very
>> same page ;-) Although I wasn't thinking that one should be using the
>> header already available in tree. After all this series is not
>> supposed to land before Gustavo's work, is it ?
>>
>>  From a quick skim though the selftests, I cannot see cases where UAPI
>> headers are copied/duplicated.
>>
>>> """
>>> The correct way to address this problem is to isolate the specific
>>> interfaces that you need, e.g. a single header file that is patched in a
>>> new
>>> kernel providing the ioctl numbers for a character device used by your
>>> program. In your own program, add a copy of that source file, with a
>>> notice
>>> that it should be kept in sync with new kernel versions.
>>> """
>>
>> My understanding of the article is that it refers to building user
>> space programs that do _not_ live in the same tree as the kernel. Am I
>> missing something ?
>
>
> When I tried using the header directly from the kernel tree, the compiler
> told me not to do that and pointed me to that kernelnewbies page; I could
> try overriding the check like I see memfd does[0] but I don't know if that's
> the way to go. Shuah, what's your thoughts on this?
>
Afaics the warning comes up, as the uapi header gets picked up prior
to the normal one (in include/).

Thus by reordering the includes things should work. One could even do
a similar thing for memfd and drop the hack(?). Then again, not sure
what's the policy on any of this is. I'm thinking that it should be
documented somewhere, but I could not find anything :-\

Regards,
Emil

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework
@ 2016-04-07 14:47             ` Emil Velikov
  0 siblings, 0 replies; 27+ messages in thread
From: Emil Velikov @ 2016-04-07 14:47 UTC (permalink / raw)
  To: Emilio López
  Cc: devel, Daniel Stone, Daniel Vetter, Shuah Khan, ML dri-devel,
	Linux-Kernel@Vger. Kernel. Org, Arve Hjønnevåg,
	linux-kselftest, Riley Andrews, Gustavo Padovan, John Harrison

On 4 April 2016 at 05:12, Emilio López <emilio.lopez@collabora.co.uk> wrote:
> Hi,
>
> El 28/03/16 a las 10:48, Emil Velikov escribió:
>
>>>>> These tests are based on the libsync test suite from Android.
>>>>> This commit lays the ground for future tests, as well as includes
>>>>> tests for a variety of basic allocation commands.
>>>>>
>>>>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>>>> Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
>>>>> ---
>>>>>
>>>>
>>>>>    tools/testing/selftests/sync/sync.h       | 119 ++++++++++++++++++
>>>>
>>>>
>>>> Admittedly I know nothing about the kernel selftests although copying
>>>> the UAPI header, seems to defeat the purpose of this exercise.
>>>> Shouldn't one reuse the existing header ? It would even cause issues
>>>> as the interface gets updated (iirc Gustavo changed the ioctl numbers
>>>> and/or header name with latter series).
>>>
>>>
>>>
>>> The problem is that one cannot use the system header without having built
>>> and installed the kernel first, which is rather problematic for eg.
>>> crosscompiling or virtualization. I discussed this with Gustavo and we
>>> agreed that the best way forward would be to copy the interfaces, as
>>> suggested by kernelnewbies' wiki[0]:
>>>
>> In the case of using a system header one can just `make
>> headers_install' without building the kernel, as mentioned in the very
>> same page ;-) Although I wasn't thinking that one should be using the
>> header already available in tree. After all this series is not
>> supposed to land before Gustavo's work, is it ?
>>
>>  From a quick skim though the selftests, I cannot see cases where UAPI
>> headers are copied/duplicated.
>>
>>> """
>>> The correct way to address this problem is to isolate the specific
>>> interfaces that you need, e.g. a single header file that is patched in a
>>> new
>>> kernel providing the ioctl numbers for a character device used by your
>>> program. In your own program, add a copy of that source file, with a
>>> notice
>>> that it should be kept in sync with new kernel versions.
>>> """
>>
>> My understanding of the article is that it refers to building user
>> space programs that do _not_ live in the same tree as the kernel. Am I
>> missing something ?
>
>
> When I tried using the header directly from the kernel tree, the compiler
> told me not to do that and pointed me to that kernelnewbies page; I could
> try overriding the check like I see memfd does[0] but I don't know if that's
> the way to go. Shuah, what's your thoughts on this?
>
Afaics the warning comes up, as the uapi header gets picked up prior
to the normal one (in include/).

Thus by reordering the includes things should work. One could even do
a similar thing for memfd and drop the hack(?). Then again, not sure
what's the policy on any of this is. I'm thinking that it should be
documented somewhere, but I could not find anything :-\

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2016-04-07 14:47 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-09 15:28 [RFC PATCH v1 0/9] Tests for sync infrastructure Emilio López
2016-03-09 15:28 ` [RFC PATCH v1 1/9] selftest: sync: basic tests for sw_sync framework Emilio López
2016-03-28 11:56   ` Emil Velikov
2016-03-28 11:56     ` Emil Velikov
2016-03-28 12:20     ` Emilio López
2016-03-28 12:20       ` Emilio López
2016-03-28 13:48       ` Emil Velikov
2016-03-28 13:48         ` Emil Velikov
2016-04-04  4:12         ` Emilio López
2016-04-07 14:47           ` Emil Velikov
2016-04-07 14:47             ` Emil Velikov
2016-03-09 15:28 ` [RFC PATCH v1 2/9] selftest: sync: fence " Emilio López
2016-03-09 15:28 ` [RFC PATCH v1 3/9] selftest: sync: merge " Emilio López
2016-03-09 15:28 ` [RFC PATCH v1 4/9] selftest: sync: wait " Emilio López
2016-03-09 15:28 ` [RFC PATCH v1 5/9] selftest: sync: destruction " Emilio López
2016-03-09 15:28 ` [RFC PATCH v1 6/9] selftest: sync: stress test for parallelism Emilio López
2016-03-09 15:29 ` [RFC PATCH v1 7/9] selftest: sync: stress consumer/producer test Emilio López
2016-03-09 15:29 ` [RFC PATCH v1 8/9] selftest: sync: stress test for merges Emilio López
2016-03-09 15:29 ` [RFC PATCH v1 9/9] selftest: sync: disable tests that rely on not yet defined behaviour Emilio López
2016-03-09 16:14   ` Shuah Khan
2016-03-09 16:14     ` Shuah Khan
2016-03-28 12:33     ` Emilio López
2016-03-28 12:33       ` Emilio López
2016-03-09 16:13 ` [RFC PATCH v1 0/9] Tests for sync infrastructure Shuah Khan
2016-03-09 16:13   ` Shuah Khan
2016-03-28 12:32   ` Emilio López
2016-03-28 12:32     ` Emilio López

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.