intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH igt v6 0/8] Blob property and atomic modesetting tests
@ 2015-10-01 16:34 Daniel Stone
  2015-10-01 16:34 ` [PATCH igt 1/8] lib/igt_core: Add igt_assert_neq_*() variants Daniel Stone
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Daniel Stone @ 2015-10-01 16:34 UTC (permalink / raw)
  To: intel-gfx; +Cc: daniel.vetter, thomas.wood

Hi all,
Another respin of the blob/atomic tests.

Pretty minor changes compared to the last round this time; this introduces
the new drm_ioctl_err macro, and moves some of the asserts into macros
rather than helper functions, so we can pin the failures at the exact
callsite, rather than just in a helper.

6/8 is just an igt.cocci run across all of tests/, and can be dropped in
favour of manually running it, to make life easier. Unfortunately, I can't
figure out why the cocci run catches some of the do_ioctl conversions, but
not all (e.g. kms_addfb_basic.c). Comments welcome from anyone more
familiar with Cocci than I am.

I'll be away until Tuesday, but will pick these back up then, if there are
any comments.

The tree is also available at:
git://git.collabora.co.uk/git/user/daniels/intel-gpu-tools#wip/atomic-blob

Have a great weekend.

Cheers,
Daniel

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH igt 1/8] lib/igt_core: Add igt_assert_neq_*() variants
  2015-10-01 16:34 [PATCH igt v6 0/8] Blob property and atomic modesetting tests Daniel Stone
@ 2015-10-01 16:34 ` Daniel Stone
  2015-10-01 16:34 ` [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd Daniel Stone
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Daniel Stone @ 2015-10-01 16:34 UTC (permalink / raw)
  To: intel-gfx; +Cc: daniel.vetter, thomas.wood

Similar to igt_assert_eq_*(), add variants for non-equality of types
other than int.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 lib/igt_core.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/lib/igt_core.h b/lib/igt_core.h
index f8bfbf0..9a5d9c5 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -454,6 +454,33 @@ void igt_exit(void) __attribute__((noreturn));
 #define igt_assert_neq(n1, n2) igt_assert_cmpint(n1, !=, ==, n2)
 
 /**
+ * igt_assert_neq_u32:
+ * @n1: first integer
+ * @n2: second integer
+ *
+ * Like igt_assert_neq(), but for uint32_t.
+ */
+#define igt_assert_neq_u32(n1, n2) igt_assert_cmpuint(n1, !=, ==, n2)
+
+/**
+ * igt_assert_neq_u64:
+ * @n1: first integer
+ * @n2: second integer
+ *
+ * Like igt_assert_neq_u32(), but for uint64_t.
+ */
+#define igt_assert_neq_u64(n1, n2) igt_assert_cmpu64(n1, !=, ==, n2)
+
+/**
+ * igt_assert_neq_double:
+ * @n1: first double
+ * @n2: second double
+ *
+ * Like igt_assert_neq(), but for doubles.
+ */
+#define igt_assert_neq_double(n1, n2) igt_assert_cmpdouble(n1, !=, ==, n2)
+
+/**
  * igt_assert_lte:
  * @n1: first integer
  * @n2: second integer
-- 
2.5.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd
  2015-10-01 16:34 [PATCH igt v6 0/8] Blob property and atomic modesetting tests Daniel Stone
  2015-10-01 16:34 ` [PATCH igt 1/8] lib/igt_core: Add igt_assert_neq_*() variants Daniel Stone
@ 2015-10-01 16:34 ` Daniel Stone
  2015-10-02  8:01   ` Daniel Vetter
  2015-10-01 16:34 ` [PATCH igt 3/8] lib/igt.cocci: Add greater-than to igt_assert_lt* Daniel Stone
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Daniel Stone @ 2015-10-01 16:34 UTC (permalink / raw)
  To: intel-gfx; +Cc: daniel.vetter, thomas.wood

Skip open-coding and assert that fds are valid.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 lib/igt_core.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/igt_core.h b/lib/igt_core.h
index 9a5d9c5..8f93e8e 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -507,6 +507,17 @@ void igt_exit(void) __attribute__((noreturn));
 #define igt_assert_lt(n1, n2) igt_assert_cmpint(n1, <, >=, n2)
 
 /**
+ * igt_assert_fd:
+ * @fd: file descriptor
+ *
+ * Fails (sub-) test if the given file descriptor is not valid.
+ *
+ * Like igt_assert(), but displays the values being compared on failure instead
+ * of simply printing the stringified expression.
+ */
+#define igt_assert_fd(fd) igt_assert_lte(0, fd)
+
+/**
  * igt_require:
  * @expr: condition to test
  *
-- 
2.5.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH igt 3/8] lib/igt.cocci: Add greater-than to igt_assert_lt*
  2015-10-01 16:34 [PATCH igt v6 0/8] Blob property and atomic modesetting tests Daniel Stone
  2015-10-01 16:34 ` [PATCH igt 1/8] lib/igt_core: Add igt_assert_neq_*() variants Daniel Stone
  2015-10-01 16:34 ` [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd Daniel Stone
@ 2015-10-01 16:34 ` Daniel Stone
  2015-10-01 16:34 ` [PATCH igt 4/8] lib/drmtest: Add do_ioctl_err to expect failure Daniel Stone
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Daniel Stone @ 2015-10-01 16:34 UTC (permalink / raw)
  To: intel-gfx; +Cc: daniel.vetter, thomas.wood

Change m >= n patterns to igt_assert_lte(n, m), and ditto for strict
greater-than.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 lib/igt.cocci | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/igt.cocci b/lib/igt.cocci
index 3aee72f..b4f8ee4 100644
--- a/lib/igt.cocci
+++ b/lib/igt.cocci
@@ -161,6 +161,12 @@ int E3, E4;
 - igt_assert(E1 < E2);
 + igt_assert_lt_u32(E1, E2);
 |
+- igt_assert(E1 >= E2);
++ igt_assert_lte_u32(E2, E1);
+|
+- igt_assert(E1 > E2);
++ igt_assert_lt_u32(E2, E1);
+|
 - igt_assert(E3 == E4);
 + igt_assert_eq(E3, E4);
 |
@@ -172,6 +178,12 @@ int E3, E4;
 |
 - igt_assert(E3 < E4);
 + igt_assert_lt(E3, E4);
+|
+- igt_assert(E3 >= E4);
++ igt_assert_lte(E4, E3);
+|
+- igt_assert(E3 > E4);
++ igt_assert_lt(E4, E3);
 )
 
 // avoid unused-result warnings when compiling with _FORTIFY_SOURCE defined
-- 
2.5.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH igt 4/8] lib/drmtest: Add do_ioctl_err to expect failure
  2015-10-01 16:34 [PATCH igt v6 0/8] Blob property and atomic modesetting tests Daniel Stone
                   ` (2 preceding siblings ...)
  2015-10-01 16:34 ` [PATCH igt 3/8] lib/igt.cocci: Add greater-than to igt_assert_lt* Daniel Stone
@ 2015-10-01 16:34 ` Daniel Stone
  2015-10-01 16:34 ` [PATCH igt 5/8] lib/igt.cocci: De-opencode ioctls Daniel Stone
  2015-10-01 16:42 ` [PATCH igt 7/8] tests: Add blob-property test Daniel Stone
  5 siblings, 0 replies; 10+ messages in thread
From: Daniel Stone @ 2015-10-01 16:34 UTC (permalink / raw)
  To: intel-gfx; +Cc: daniel.vetter, thomas.wood

do_ioctl demands that the ioctl returns success; add a variant named
do_ioctl_err, which expects the ioctl to fail, and demands a particular
result.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 lib/drmtest.h | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/drmtest.h b/lib/drmtest.h
index bb50408..ed384ff 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -101,7 +101,23 @@ void gem_quiescent_gpu(int fd);
  * successfully executed.
  */
 #define do_ioctl(fd, ioc, ioc_data) do { \
-	igt_assert(drmIoctl((fd), (ioc), (ioc_data)) == 0); \
+	igt_assert_eq(drmIoctl((fd), (ioc), (ioc_data)), 0); \
+	errno = 0; \
+} while (0)
+
+/**
+ * do_ioctl_err:
+ * @fd: open i915 drm file descriptor
+ * @ioc: ioctl op definition from drm headers
+ * @ioc_data: data pointer for the ioctl operation
+ * @err: value to expect in errno
+ *
+ * This macro wraps drmIoctl() and uses igt_assert to check that it fails,
+ * returning a particular value in errno.
+ */
+#define do_ioctl_err(fd, ioc, ioc_data, err) do { \
+	igt_assert_eq(drmIoctl((fd), (ioc), (ioc_data)), -1); \
+	igt_assert_eq(errno, err); \
 	errno = 0; \
 } while (0)
 
-- 
2.5.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH igt 5/8] lib/igt.cocci: De-opencode ioctls
  2015-10-01 16:34 [PATCH igt v6 0/8] Blob property and atomic modesetting tests Daniel Stone
                   ` (3 preceding siblings ...)
  2015-10-01 16:34 ` [PATCH igt 4/8] lib/drmtest: Add do_ioctl_err to expect failure Daniel Stone
@ 2015-10-01 16:34 ` Daniel Stone
  2015-10-01 16:42 ` [PATCH igt 7/8] tests: Add blob-property test Daniel Stone
  5 siblings, 0 replies; 10+ messages in thread
From: Daniel Stone @ 2015-10-01 16:34 UTC (permalink / raw)
  To: intel-gfx; +Cc: daniel.vetter, thomas.wood

Use do_ioctl and do_ioctl_err where possible.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 lib/igt.cocci | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/igt.cocci b/lib/igt.cocci
index b4f8ee4..10abd21 100644
--- a/lib/igt.cocci
+++ b/lib/igt.cocci
@@ -213,3 +213,21 @@ expression list E;
 @@
 -func(E);
 +igt_assert_neq(func(E), -1);
+
+// replace open-coded do_ioctl
+@@
+expression a, b, c, e;
+@@
+(
+-do_or_die(drmIoctl(a, b, c));
++do_ioctl(a, b, c);
+|
+-igt_assert(drmIoctl(a, b, c) == 0);
++do_ioctl(a, b, c);
+|
+-igt_assert(drmIoctl(a, b, c) == -1 && errno == e);
++do_ioctl_err(a, b, c, e);
+|
+-igt_assert(drmIoctl(a, b, c) < 0 && errno == e);
++do_ioctl_err(a, b, c, e);
+)
-- 
2.5.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH igt 7/8] tests: Add blob-property test
  2015-10-01 16:34 [PATCH igt v6 0/8] Blob property and atomic modesetting tests Daniel Stone
                   ` (4 preceding siblings ...)
  2015-10-01 16:34 ` [PATCH igt 5/8] lib/igt.cocci: De-opencode ioctls Daniel Stone
@ 2015-10-01 16:42 ` Daniel Stone
  2015-10-02  8:04   ` Daniel Vetter
  5 siblings, 1 reply; 10+ messages in thread
From: Daniel Stone @ 2015-10-01 16:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: daniel.vetter, thomas.wood

Exercises the new blob-creation ioctl, testing lifetimes and behaviour
of user-created blobs, as well as exercising all the invariant
conditions we guarantee from modes exposed as blob properties.

v2: Renamed to core_prop_blob, skip test if blob not available.
v3: No changes.
v4: Consistently return 0/errno.
v5: Use do_ioctl_err and igt_assert_fd.
    Use igt_assert_*() helper macros rather than direct igt_assert().

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 tests/.gitignore       |   1 +
 tests/Makefile.sources |   1 +
 tests/core_prop_blob.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 230 insertions(+)
 create mode 100644 tests/core_prop_blob.c

diff --git a/tests/.gitignore b/tests/.gitignore
index dc8bb53..beda511 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -3,6 +3,7 @@ core_get_client_auth
 core_getclient
 core_getstats
 core_getversion
+core_prop_blob
 drm_auth
 drm_import_export
 drm_read
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 2e2e088..ac731f9 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -99,6 +99,7 @@ TESTS_progs = \
 	core_getclient \
 	core_getstats \
 	core_getversion \
+	core_prop_blob \
 	drm_auth \
 	drm_import_export \
 	drm_read \
diff --git a/tests/core_prop_blob.c b/tests/core_prop_blob.c
new file mode 100644
index 0000000..d704158
--- /dev/null
+++ b/tests/core_prop_blob.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright © 2014-2015 Intel Corporation
+ *
+ * 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 (including the next
+ * paragraph) 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.
+ *
+ * Authors:
+ *   Damien Lespiau <damien.lespiau@intel.com>
+ *   Daniel Stone <daniels@collabora.com>
+ */
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "drmtest.h"
+#include "igt_debugfs.h"
+#include "igt_kms.h"
+#include "igt_aux.h"
+
+IGT_TEST_DESCRIPTION("Tests behaviour of mass-data 'blob' properties.");
+
+static const struct drm_mode_modeinfo test_mode_valid = {
+	.clock = 1234,
+	.hdisplay = 640,
+	.hsync_start = 641,
+	.hsync_end = 642,
+	.htotal = 643,
+	.hskew = 0,
+	.vdisplay = 480,
+	.vsync_start = 481,
+	.vsync_end = 482,
+	.vtotal = 483,
+	.vscan = 0,
+	.vrefresh = 60000,
+	.flags = 0,
+	.type = 0,
+	.name = "FROMUSER",
+};
+
+
+#define ioctl_or_ret_errno(fd, ioc, ioc_data) { \
+	if (drmIoctl(fd, ioc, ioc_data) != 0) \
+		return errno; \
+}
+
+static int
+validate_prop(int fd, uint32_t prop_id)
+{
+	struct drm_mode_get_blob get;
+	struct drm_mode_modeinfo ret_mode;
+
+	get.blob_id = prop_id;
+	get.length = 0;
+	get.data = (uintptr_t) 0;
+	ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
+
+	if (get.length != sizeof(test_mode_valid))
+		return ENOMEM;
+
+	get.data = (uintptr_t) &ret_mode;
+	ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
+
+	if (memcmp(&ret_mode, &test_mode_valid, sizeof(test_mode_valid)) != 0)
+		return EINVAL;
+
+	return 0;
+}
+
+static uint32_t
+create_prop(int fd)
+{
+	struct drm_mode_create_blob create;
+
+	create.length = sizeof(test_mode_valid);
+	create.data = (uintptr_t) &test_mode_valid;
+
+	do_ioctl(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create);
+	igt_assert_neq_u32(create.blob_id, 0);
+
+	return create.blob_id;
+}
+
+static int
+destroy_prop(int fd, uint32_t prop_id)
+{
+	struct drm_mode_destroy_blob destroy;
+
+	destroy.blob_id = prop_id;
+	ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy);
+
+	return 0;
+}
+
+static void
+test_validate(int fd)
+{
+	struct drm_mode_create_blob create;
+	struct drm_mode_get_blob get;
+	char too_small[32];
+	uint32_t prop_id;
+
+	memset(too_small, 0, sizeof(too_small));
+
+	/* Outlandish size. */
+	create.length = 0x10000;
+	create.data = (uintptr_t) &too_small;
+	do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
+
+	/* Outlandish address. */
+	create.length = sizeof(test_mode_valid);
+	create.data = (uintptr_t) 0xdeadbeee;
+	do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
+
+	/* When we pass an incorrect size, the kernel should correct us. */
+	prop_id = create_prop(fd);
+	get.blob_id = prop_id;
+	get.length = sizeof(too_small);
+	get.data = (uintptr_t) too_small;
+	do_ioctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
+	igt_assert_eq_u32(get.length, sizeof(test_mode_valid));
+
+	get.blob_id = prop_id;
+	get.data = (uintptr_t) 0xdeadbeee;
+	do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
+}
+
+static void
+test_lifetime(int fd)
+{
+	int fd2;
+	uint32_t prop_id, prop_id2;
+
+	fd2 = drm_open_driver(DRIVER_ANY);
+	igt_assert_fd(fd2);
+
+	/* Ensure clients can see properties created by other clients. */
+	prop_id = create_prop(fd);
+	igt_assert_eq(validate_prop(fd, prop_id), 0);
+	igt_assert_eq(validate_prop(fd2, prop_id), 0);
+
+	/* ... but can't destroy them. */
+	igt_assert_eq(destroy_prop(fd2, prop_id), EPERM);
+
+	/* Make sure properties can't be accessed once explicitly destroyed. */
+	prop_id2 = create_prop(fd2);
+	igt_assert_eq(validate_prop(fd2, prop_id2), 0);
+	igt_assert_eq(destroy_prop(fd2, prop_id2), 0);
+	igt_assert_eq(validate_prop(fd2, prop_id2), ENOENT);
+	igt_assert_eq(validate_prop(fd, prop_id2), ENOENT);
+
+	/* Make sure properties are cleaned up on client exit. */
+	prop_id2 = create_prop(fd2);
+	igt_assert_eq(validate_prop(fd, prop_id2), 0);
+	igt_assert_eq(close(fd2), 0);
+	igt_assert_eq(validate_prop(fd, prop_id2), ENOENT);
+
+	igt_assert_eq(validate_prop(fd, prop_id), 0);
+	igt_assert_eq(destroy_prop(fd, prop_id), 0);
+	igt_assert_eq(validate_prop(fd, prop_id), ENOENT);
+}
+
+static void
+test_core(int fd)
+{
+	uint32_t prop_id;
+
+	/* The first hurdle. */
+	prop_id = create_prop(fd);
+	igt_assert_eq(validate_prop(fd, prop_id), 0);
+	igt_assert_eq(destroy_prop(fd, prop_id), 0);
+
+	/* Look up some invalid property IDs. They should fail. */
+	igt_assert_eq(validate_prop(fd, 0xffffffff), ENOENT);
+	igt_assert_eq(validate_prop(fd, 0), ENOENT);
+}
+
+static void
+test_basic(int fd)
+{
+	uint32_t prop_id;
+
+	/* A very simple gating test to ensure property support exists. */
+	prop_id = create_prop(fd);
+	igt_assert_eq(destroy_prop(fd, prop_id), 0);
+}
+
+igt_main
+{
+	int fd;
+
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_ANY);
+		igt_require(fd >= 0);
+		test_basic(fd);
+	}
+
+	igt_subtest("blob-prop-core")
+		test_core(fd);
+
+	igt_subtest("blob-prop-validate")
+		test_validate(fd);
+
+	igt_subtest("blob-prop-lifetime")
+		test_lifetime(fd);
+
+	igt_fixture
+		close(fd);
+}
-- 
2.5.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* Re: [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd
  2015-10-01 16:34 ` [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd Daniel Stone
@ 2015-10-02  8:01   ` Daniel Vetter
  2015-10-02  9:03     ` Morton, Derek J
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Vetter @ 2015-10-02  8:01 UTC (permalink / raw)
  To: Daniel Stone; +Cc: daniel.vetter, intel-gfx, thomas.wood

On Thu, Oct 01, 2015 at 05:34:02PM +0100, Daniel Stone wrote:
> Skip open-coding and assert that fds are valid.
> 
> Signed-off-by: Daniel Stone <daniels@collabora.com>
> ---
>  lib/igt_core.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index 9a5d9c5..8f93e8e 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -507,6 +507,17 @@ void igt_exit(void) __attribute__((noreturn));
>  #define igt_assert_lt(n1, n2) igt_assert_cmpint(n1, <, >=, n2)
>  
>  /**
> + * igt_assert_fd:
> + * @fd: file descriptor
> + *
> + * Fails (sub-) test if the given file descriptor is not valid.
> + *
> + * Like igt_assert(), but displays the values being compared on failure instead
> + * of simply printing the stringified expression.
> + */
> +#define igt_assert_fd(fd) igt_assert_lte(0, fd)

If we do this then I think some more verbose output would be nice, like

#igt_assert_fd(fd) igt_assert_f(fd >= 0, "file descriptor " #fd " failed\n");

Large-scale sed would be even more awesome ;-)
-Daniel

> +
> +/**
>   * igt_require:
>   * @expr: condition to test
>   *
> -- 
> 2.5.0
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* Re: [PATCH igt 7/8] tests: Add blob-property test
  2015-10-01 16:42 ` [PATCH igt 7/8] tests: Add blob-property test Daniel Stone
@ 2015-10-02  8:04   ` Daniel Vetter
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Vetter @ 2015-10-02  8:04 UTC (permalink / raw)
  To: Daniel Stone; +Cc: daniel.vetter, intel-gfx, thomas.wood

On Thu, Oct 01, 2015 at 05:42:55PM +0100, Daniel Stone wrote:
> Exercises the new blob-creation ioctl, testing lifetimes and behaviour
> of user-created blobs, as well as exercising all the invariant
> conditions we guarantee from modes exposed as blob properties.
> 
> v2: Renamed to core_prop_blob, skip test if blob not available.
> v3: No changes.
> v4: Consistently return 0/errno.
> v5: Use do_ioctl_err and igt_assert_fd.
>     Use igt_assert_*() helper macros rather than direct igt_assert().
> 
> Signed-off-by: Daniel Stone <daniels@collabora.com>

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> ---
>  tests/.gitignore       |   1 +
>  tests/Makefile.sources |   1 +
>  tests/core_prop_blob.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 230 insertions(+)
>  create mode 100644 tests/core_prop_blob.c
> 
> diff --git a/tests/.gitignore b/tests/.gitignore
> index dc8bb53..beda511 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -3,6 +3,7 @@ core_get_client_auth
>  core_getclient
>  core_getstats
>  core_getversion
> +core_prop_blob
>  drm_auth
>  drm_import_export
>  drm_read
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 2e2e088..ac731f9 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -99,6 +99,7 @@ TESTS_progs = \
>  	core_getclient \
>  	core_getstats \
>  	core_getversion \
> +	core_prop_blob \
>  	drm_auth \
>  	drm_import_export \
>  	drm_read \
> diff --git a/tests/core_prop_blob.c b/tests/core_prop_blob.c
> new file mode 100644
> index 0000000..d704158
> --- /dev/null
> +++ b/tests/core_prop_blob.c
> @@ -0,0 +1,228 @@
> +/*
> + * Copyright © 2014-2015 Intel Corporation
> + *
> + * 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 (including the next
> + * paragraph) 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.
> + *
> + * Authors:
> + *   Damien Lespiau <damien.lespiau@intel.com>
> + *   Daniel Stone <daniels@collabora.com>
> + */
> +
> +#include <errno.h>
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <string.h>
> +
> +#include "drmtest.h"
> +#include "igt_debugfs.h"
> +#include "igt_kms.h"
> +#include "igt_aux.h"
> +
> +IGT_TEST_DESCRIPTION("Tests behaviour of mass-data 'blob' properties.");
> +
> +static const struct drm_mode_modeinfo test_mode_valid = {
> +	.clock = 1234,
> +	.hdisplay = 640,
> +	.hsync_start = 641,
> +	.hsync_end = 642,
> +	.htotal = 643,
> +	.hskew = 0,
> +	.vdisplay = 480,
> +	.vsync_start = 481,
> +	.vsync_end = 482,
> +	.vtotal = 483,
> +	.vscan = 0,
> +	.vrefresh = 60000,
> +	.flags = 0,
> +	.type = 0,
> +	.name = "FROMUSER",
> +};
> +
> +
> +#define ioctl_or_ret_errno(fd, ioc, ioc_data) { \
> +	if (drmIoctl(fd, ioc, ioc_data) != 0) \
> +		return errno; \
> +}
> +
> +static int
> +validate_prop(int fd, uint32_t prop_id)
> +{
> +	struct drm_mode_get_blob get;
> +	struct drm_mode_modeinfo ret_mode;
> +
> +	get.blob_id = prop_id;
> +	get.length = 0;
> +	get.data = (uintptr_t) 0;
> +	ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
> +
> +	if (get.length != sizeof(test_mode_valid))
> +		return ENOMEM;
> +
> +	get.data = (uintptr_t) &ret_mode;
> +	ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
> +
> +	if (memcmp(&ret_mode, &test_mode_valid, sizeof(test_mode_valid)) != 0)
> +		return EINVAL;
> +
> +	return 0;
> +}
> +
> +static uint32_t
> +create_prop(int fd)
> +{
> +	struct drm_mode_create_blob create;
> +
> +	create.length = sizeof(test_mode_valid);
> +	create.data = (uintptr_t) &test_mode_valid;
> +
> +	do_ioctl(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create);
> +	igt_assert_neq_u32(create.blob_id, 0);
> +
> +	return create.blob_id;
> +}
> +
> +static int
> +destroy_prop(int fd, uint32_t prop_id)
> +{
> +	struct drm_mode_destroy_blob destroy;
> +
> +	destroy.blob_id = prop_id;
> +	ioctl_or_ret_errno(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy);
> +
> +	return 0;
> +}
> +
> +static void
> +test_validate(int fd)
> +{
> +	struct drm_mode_create_blob create;
> +	struct drm_mode_get_blob get;
> +	char too_small[32];
> +	uint32_t prop_id;
> +
> +	memset(too_small, 0, sizeof(too_small));
> +
> +	/* Outlandish size. */
> +	create.length = 0x10000;
> +	create.data = (uintptr_t) &too_small;
> +	do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
> +
> +	/* Outlandish address. */
> +	create.length = sizeof(test_mode_valid);
> +	create.data = (uintptr_t) 0xdeadbeee;
> +	do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
> +
> +	/* When we pass an incorrect size, the kernel should correct us. */
> +	prop_id = create_prop(fd);
> +	get.blob_id = prop_id;
> +	get.length = sizeof(too_small);
> +	get.data = (uintptr_t) too_small;
> +	do_ioctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
> +	igt_assert_eq_u32(get.length, sizeof(test_mode_valid));
> +
> +	get.blob_id = prop_id;
> +	get.data = (uintptr_t) 0xdeadbeee;
> +	do_ioctl_err(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create, EFAULT);
> +}
> +
> +static void
> +test_lifetime(int fd)
> +{
> +	int fd2;
> +	uint32_t prop_id, prop_id2;
> +
> +	fd2 = drm_open_driver(DRIVER_ANY);
> +	igt_assert_fd(fd2);
> +
> +	/* Ensure clients can see properties created by other clients. */
> +	prop_id = create_prop(fd);
> +	igt_assert_eq(validate_prop(fd, prop_id), 0);
> +	igt_assert_eq(validate_prop(fd2, prop_id), 0);
> +
> +	/* ... but can't destroy them. */
> +	igt_assert_eq(destroy_prop(fd2, prop_id), EPERM);
> +
> +	/* Make sure properties can't be accessed once explicitly destroyed. */
> +	prop_id2 = create_prop(fd2);
> +	igt_assert_eq(validate_prop(fd2, prop_id2), 0);
> +	igt_assert_eq(destroy_prop(fd2, prop_id2), 0);
> +	igt_assert_eq(validate_prop(fd2, prop_id2), ENOENT);
> +	igt_assert_eq(validate_prop(fd, prop_id2), ENOENT);
> +
> +	/* Make sure properties are cleaned up on client exit. */
> +	prop_id2 = create_prop(fd2);
> +	igt_assert_eq(validate_prop(fd, prop_id2), 0);
> +	igt_assert_eq(close(fd2), 0);
> +	igt_assert_eq(validate_prop(fd, prop_id2), ENOENT);
> +
> +	igt_assert_eq(validate_prop(fd, prop_id), 0);
> +	igt_assert_eq(destroy_prop(fd, prop_id), 0);
> +	igt_assert_eq(validate_prop(fd, prop_id), ENOENT);
> +}
> +
> +static void
> +test_core(int fd)
> +{
> +	uint32_t prop_id;
> +
> +	/* The first hurdle. */
> +	prop_id = create_prop(fd);
> +	igt_assert_eq(validate_prop(fd, prop_id), 0);
> +	igt_assert_eq(destroy_prop(fd, prop_id), 0);
> +
> +	/* Look up some invalid property IDs. They should fail. */
> +	igt_assert_eq(validate_prop(fd, 0xffffffff), ENOENT);
> +	igt_assert_eq(validate_prop(fd, 0), ENOENT);
> +}
> +
> +static void
> +test_basic(int fd)
> +{
> +	uint32_t prop_id;
> +
> +	/* A very simple gating test to ensure property support exists. */
> +	prop_id = create_prop(fd);
> +	igt_assert_eq(destroy_prop(fd, prop_id), 0);
> +}
> +
> +igt_main
> +{
> +	int fd;
> +
> +	igt_skip_on_simulation();
> +
> +	igt_fixture {
> +		fd = drm_open_driver(DRIVER_ANY);
> +		igt_require(fd >= 0);
> +		test_basic(fd);
> +	}
> +
> +	igt_subtest("blob-prop-core")
> +		test_core(fd);
> +
> +	igt_subtest("blob-prop-validate")
> +		test_validate(fd);
> +
> +	igt_subtest("blob-prop-lifetime")
> +		test_lifetime(fd);
> +
> +	igt_fixture
> +		close(fd);
> +}
> -- 
> 2.5.0
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* Re: [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd
  2015-10-02  8:01   ` Daniel Vetter
@ 2015-10-02  9:03     ` Morton, Derek J
  0 siblings, 0 replies; 10+ messages in thread
From: Morton, Derek J @ 2015-10-02  9:03 UTC (permalink / raw)
  To: Daniel Vetter, Daniel Stone
  Cc: Vetter, Daniel, intel-gfx@lists.freedesktop.org, Wood, Thomas

>
>
>-----Original Message-----
>From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf Of Daniel Vetter
>Sent: Friday, October 2, 2015 9:02 AM
>To: Daniel Stone
>Cc: Vetter, Daniel; intel-gfx@lists.freedesktop.org; Wood, Thomas
>Subject: Re: [Intel-gfx] [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd
>
>On Thu, Oct 01, 2015 at 05:34:02PM +0100, Daniel Stone wrote:
>> Skip open-coding and assert that fds are valid.
>> 
>> Signed-off-by: Daniel Stone <daniels@collabora.com>
>> ---
>>  lib/igt_core.h | 11 +++++++++++
>>  1 file changed, 11 insertions(+)
>> 
>> diff --git a/lib/igt_core.h b/lib/igt_core.h index 9a5d9c5..8f93e8e 
>> 100644
>> --- a/lib/igt_core.h
>> +++ b/lib/igt_core.h
>> @@ -507,6 +507,17 @@ void igt_exit(void) __attribute__((noreturn));  
>> #define igt_assert_lt(n1, n2) igt_assert_cmpint(n1, <, >=, n2)
>>  
>>  /**
>> + * igt_assert_fd:
>> + * @fd: file descriptor
>> + *
>> + * Fails (sub-) test if the given file descriptor is not valid.
>> + *
>> + * Like igt_assert(), but displays the values being compared on 
>> +failure instead
>> + * of simply printing the stringified expression.
>> + */
>> +#define igt_assert_fd(fd) igt_assert_lte(0, fd)
>
I think this will assert for valid fd's and not invalid ones.
From igt_core.h:
igt_assert_lte
Fails (sub-)test if the second integers is greater than the first.

>If we do this then I think some more verbose output would be nice, like
>
>#igt_assert_fd(fd) igt_assert_f(fd >= 0, "file descriptor " #fd " failed\n");
>
>Large-scale sed would be even more awesome ;-) -Daniel
>
>> +
>> +/**
>>   * igt_require:
>>   * @expr: condition to test
>>   *
>> --
>> 2.5.0
>> 
>> _______________________________________________
>> Intel-gfx mailing list
>> Intel-gfx@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
>
>--
>Daniel Vetter
>Software Engineer, Intel Corporation
>http://blog.ffwll.ch
>_______________________________________________
>Intel-gfx mailing list
>Intel-gfx@lists.freedesktop.org
>http://lists.freedesktop.org/mailman/listinfo/intel-gfx
>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

end of thread, other threads:[~2015-10-02  9:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-01 16:34 [PATCH igt v6 0/8] Blob property and atomic modesetting tests Daniel Stone
2015-10-01 16:34 ` [PATCH igt 1/8] lib/igt_core: Add igt_assert_neq_*() variants Daniel Stone
2015-10-01 16:34 ` [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd Daniel Stone
2015-10-02  8:01   ` Daniel Vetter
2015-10-02  9:03     ` Morton, Derek J
2015-10-01 16:34 ` [PATCH igt 3/8] lib/igt.cocci: Add greater-than to igt_assert_lt* Daniel Stone
2015-10-01 16:34 ` [PATCH igt 4/8] lib/drmtest: Add do_ioctl_err to expect failure Daniel Stone
2015-10-01 16:34 ` [PATCH igt 5/8] lib/igt.cocci: De-opencode ioctls Daniel Stone
2015-10-01 16:42 ` [PATCH igt 7/8] tests: Add blob-property test Daniel Stone
2015-10-02  8:04   ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).