Skip to contentSkip to conversation

Blob property and atomic modesetting tests

PATCH In review Daniel Stone 3 participants 10 messages Oct 1, 2015 – Oct 2, 2015 Library code

lore
Share & tools
lore
#0 lore raw

v6 cover Blob property and atomic modesetting tests

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
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#1 lore raw

PATCH v6 1/8 lib/igt_core: Add igt_assert_neq_*() variants

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

---
 lib/igt_core.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
lib/igt_core.h +27 -0
index f8bfbf0..9a5d9c5 100644
@@ -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
Signature · 6 lines
2.5.0

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

PATCH v6 2/8 lib/igt_core: Add igt_assert_fd

In reply to Daniel Stone

Skip open-coding and assert that fds are valid.

---
 lib/igt_core.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/igt_core.h +11 -0
index 9a5d9c5..8f93e8e 100644
@@ -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
  *
Signature · 6 lines
2.5.0

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

Re: [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd

Quoted 14 lines · Daniel Stone

Skip open-coding and assert that fds are valid.

---
 lib/igt_core.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/igt_core.h +0 -0
index 9a5d9c5..8f93e8e 100644
@@ -507,6 +507,17 @@ void igt_exit(void) __attribute__((noreturn));
 #define igt_assert_lt(n1, n2) igt_assert_cmpint(n1, <, >=, n2)
 

lib/igt_core.h void igt_exit(void) __attribute__((noreturn)); · line 518

Quoted 10 lines
lib/igt_core.h +9 -0
 /**
+ * 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

Quoted 12 lines
lib/igt_core.h +2 -0
+
+/**
  * igt_require:
  * @expr: condition to test
  *
Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Re: [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd

Quoted 24 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Friday, October 2, 2015 9:02 AM
To: Daniel Stone
Cc: Vetter, Daniel; [email protected]; Wood, Thomas
Subject: Re: [Intel-gfx] [PATCH igt 2/8] lib/igt_core: Add igt_assert_fd

Quoted 14 lines · Daniel Stone

Skip open-coding and assert that fds are valid.

---
 lib/igt_core.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/igt_core.h index 9a5d9c5..8f93e8e renamed from lib/igt_core.h +0 -0

100644

lib/igt_core.h +0 -0
@@ -507,6 +507,17 @@ void igt_exit(void) __attribute__((noreturn));  
 #define igt_assert_lt(n1, n2) igt_assert_cmpint(n1, <, >=, n2)
 
Quoted 12 lines

lib/igt_core.h void igt_exit(void) __attribute__((noreturn)); · line 518

Quoted 11 lines
lib/igt_core.h +10 -0
 /**
+ * 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.

Quoted 14 lines

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

Quoted 8 lines
lib/igt_core.h +2 -1
+
+/**
  * igt_require:
  * @expr: condition to test
  *
--

2.5.0

Quoted 14 lines
Quoted 4 lines

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

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

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

#5 lore raw

PATCH v6 3/8 lib/igt.cocci: Add greater-than to igt_assert_lt*

In reply to Daniel Stone

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

---
 lib/igt.cocci | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/igt.cocci +12 -0
index 3aee72f..b4f8ee4 100644
@@ -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
Signature · 6 lines
2.5.0

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

PATCH v6 4/8 lib/drmtest: Add do_ioctl_err to expect failure

In reply to Daniel Stone

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.

---
 lib/drmtest.h | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
lib/drmtest.h +17 -1
index bb50408..ed384ff 100644
@@ -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)
 
Signature · 6 lines
2.5.0

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

PATCH v6 5/8 lib/igt.cocci: De-opencode ioctls

In reply to Daniel Stone

Use do_ioctl and do_ioctl_err where possible.

---
 lib/igt.cocci | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
lib/igt.cocci +18 -0
index b4f8ee4..10abd21 100644
@@ -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);
+)
Signature · 6 lines
2.5.0

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

PATCH v6 7/8 tests: Add blob-property test

In reply to Daniel Stone

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().

---
 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
tests/.gitignore +1 -0
index dc8bb53..beda511 100644
@@ -3,6 +3,7 @@ core_get_client_auth
 core_getclient
 core_getstats
 core_getversion
+core_prop_blob
 drm_auth
 drm_import_export
 drm_read
tests/Makefile.sources +1 -0
index 2e2e088..ac731f9 100644
@@ -99,6 +99,7 @@ TESTS_progs = \
 	core_getclient \
 	core_getstats \
 	core_getversion \
+	core_prop_blob \
 	drm_auth \
 	drm_import_export \
 	drm_read \
tests/core_prop_blob.c new file +228 -0

228 lines not on this page · raw message

Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v6 7/8
#9 lore raw

Re: [PATCH igt 7/8] tests: Add blob-property test

Quoted 11 lines · Daniel Stone

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().

Quoted 272 lines
---
 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
tests/.gitignore +1 -0
index dc8bb53..beda511 100644
@@ -3,6 +3,7 @@ core_get_client_auth
 core_getclient
 core_getstats
 core_getversion
+core_prop_blob
 drm_auth
 drm_import_export
 drm_read
tests/Makefile.sources +1 -0
index 2e2e088..ac731f9 100644
@@ -99,6 +99,7 @@ TESTS_progs = \
 	core_getclient \
 	core_getstats \
 	core_getversion \
+	core_prop_blob \
 	drm_auth \
 	drm_import_export \
 	drm_read \
tests/core_prop_blob.c new file +228 -0
new file mode 100644
index 0000000..d704158
@@ -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 <[email protected]>
+ *   Daniel Stone <[email protected]>
+ */
+
+#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);
+}
Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx