diff mbox

[igt] tests: Add KMS blob-property test

Message ID 1431183433-14960-1-git-send-email-daniels@collabora.com (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Stone May 9, 2015, 2:57 p.m. UTC
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.

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

Kernel support:
http://lists.freedesktop.org/archives/dri-devel/2015-May/082530.html

libdrm support:
http://lists.freedesktop.org/archives/dri-devel/2015-May/082569.html

Comments

Thomas Wood May 12, 2015, 3:36 p.m. UTC | #1
On 9 May 2015 at 15:57, Daniel Stone <daniels@collabora.com> 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.

Since this isn't really a kms test, the test name should probably be
prefixed with "core", rather than "kms". The "core" prefix is used for
tests of drm ioctls and behaviour.


>
> Signed-off-by: Daniel Stone <daniels@collabora.com>
> ---
>  tests/.gitignore       |   1 +
>  tests/Makefile.sources |   1 +
>  tests/kms_prop_blob.c  | 226 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 228 insertions(+)
>  create mode 100644 tests/kms_prop_blob.c
>
> Kernel support:
> http://lists.freedesktop.org/archives/dri-devel/2015-May/082530.html
>
> libdrm support:
> http://lists.freedesktop.org/archives/dri-devel/2015-May/082569.html
>
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 86795c0..eb505d0 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -138,6 +138,7 @@ kms_mmio_vs_cs_flip
>  kms_pipe_b_c_ivb
>  kms_pipe_crc_basic
>  kms_plane
> +kms_prop_blob
>  kms_psr_sink_crc
>  kms_pwrite_crc
>  kms_render
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 12f27f9..9a89167 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -70,6 +70,7 @@ TESTS_progs_M = \
>         kms_pipe_b_c_ivb \
>         kms_pipe_crc_basic \
>         kms_plane \
> +       kms_prop_blob \
>         kms_psr_sink_crc \
>         kms_render \
>         kms_rotation_crc \
> diff --git a/tests/kms_prop_blob.c b/tests/kms_prop_blob.c
> new file mode 100644
> index 0000000..03b85a9
> --- /dev/null
> +++ b/tests/kms_prop_blob.c
> @@ -0,0 +1,226 @@
> +/*
> + * 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",
> +};
> +
> +
> +static int
> +validate_prop(int fd, uint32_t prop_id)
> +{
> +       struct drm_mode_get_blob get;
> +       struct drm_mode_modeinfo ret_mode;
> +       int err;
> +
> +       get.blob_id = prop_id;
> +       get.length = 0;
> +       get.data = (uintptr_t) 0;
> +
> +       err = drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
> +       if (err != 0)
> +               return err;
> +
> +       if (get.length != sizeof(test_mode_valid))
> +               return ENOMEM;
> +
> +       get.data = (uintptr_t) &ret_mode;
> +
> +       err = drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
> +       if (err != 0)
> +               return err;
> +
> +       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);
> +
> +       return create.blob_id;
> +}
> +
> +static int
> +destroy_prop(int fd, uint32_t prop_id)
> +{
> +       struct drm_mode_destroy_blob destroy;
> +       int err;
> +
> +       destroy.blob_id = prop_id;
> +       err = drmIoctl(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy);
> +       return err;
> +}
> +
> +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;
> +       int ret;
> +
> +       memset(too_small, 0, sizeof(too_small));
> +
> +       /* Outlandish size. */
> +       create.length = 0x10000;
> +       create.data = (uintptr_t) &too_small;
> +       ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create);
> +       igt_assert(ret != 0 && errno == EFAULT);
> +
> +       /* Outlandish address. */
> +       create.length = sizeof(test_mode_valid);
> +       create.data = (uintptr_t) 0xdeadbeee;
> +       ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create);
> +       igt_assert(ret != 0 && errno == EFAULT);
> +
> +       /* When we pass an incorrect size, the kernel should correct us. */
> +       prop_id = create_prop(fd);
> +       igt_assert(prop_id != 0);
> +       get.blob_id = prop_id;
> +       get.length = sizeof(too_small);
> +       get.data = (uintptr_t) too_small;
> +       ret = drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
> +       igt_assert(ret == 0);
> +       igt_assert(get.length == sizeof(test_mode_valid));
> +
> +       get.blob_id = prop_id;
> +       get.data = (uintptr_t) 0xdeadbeee;
> +       ret = drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
> +       igt_assert(ret != 0 && errno == EFAULT);
> +}
> +
> +static void
> +test_lifetime(int fd)
> +{
> +       int fd2;
> +       uint32_t prop_id, prop_id2;
> +
> +       fd2 = drm_open_any();
> +
> +       /* Ensure clients can see properties created by other clients. */
> +       prop_id = create_prop(fd);
> +       igt_assert(prop_id != 0);
> +       igt_assert(validate_prop(fd, prop_id) == 0);
> +       igt_assert(validate_prop(fd2, prop_id) == 0);
> +
> +       /* ... but can't destroy them. */
> +       igt_assert(destroy_prop(fd2, prop_id) != 0);
> +
> +       /* Make sure properties can't be accessed once explicitly destroyed. */
> +       prop_id2 = create_prop(fd2);
> +       igt_assert(prop_id2 != 0);
> +       igt_assert(validate_prop(fd2, prop_id2) == 0);
> +       igt_assert(destroy_prop(fd2, prop_id2) == 0);
> +       igt_assert(validate_prop(fd2, prop_id2) != 0);
> +       igt_assert(validate_prop(fd, prop_id2) != 0);
> +
> +       /* Make sure properties are cleaned up on client exit. */
> +       prop_id2 = create_prop(fd2);
> +       igt_assert(prop_id != 0);
> +       igt_assert(validate_prop(fd, prop_id2) == 0);
> +       close(fd2);
> +       igt_assert(validate_prop(fd, prop_id2) != 0);
> +
> +       igt_assert(validate_prop(fd, prop_id) == 0);
> +       igt_assert(destroy_prop(fd, prop_id) == 0);
> +       igt_assert(validate_prop(fd, prop_id) != 0);
> +}
> +
> +static void
> +test_core(int fd)
> +{
> +       uint32_t prop_id;
> +
> +       /* The first hurdle. */
> +       prop_id = create_prop(fd);
> +       igt_assert(prop_id != 0);
> +       igt_assert(validate_prop(fd, prop_id) == 0);
> +       igt_assert(destroy_prop(fd, prop_id) == 0);
> +
> +       /* Look up some invalid property IDs. They should fail. */
> +       igt_assert(validate_prop(fd, 0xffffffff) != 0);
> +       igt_assert(validate_prop(fd, 0) != 0);
> +
> +}
> +
> +igt_main
> +{
> +       int fd;
> +
> +       igt_skip_on_simulation();
> +
> +       igt_fixture
> +               fd = drm_open_any();
> +
> +       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.4.0
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Daniel Stone May 12, 2015, 3:38 p.m. UTC | #2
Hi,

On Tue, 12 May, 2015 at 4:36 PM, Thomas Wood <thomas.wood@intel.com> 
wrote:
> On 9 May 2015 at 15:57, Daniel Stone <daniels@collabora.com> 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.
> 
> Since this isn't really a kms test, the test name should probably be
> prefixed with "core", rather than "kms". The "core" prefix is used for
> tests of drm ioctls and behaviour.

Fair point, well made; will respin.

Cheers,
Daniel
diff mbox

Patch

diff --git a/tests/.gitignore b/tests/.gitignore
index 86795c0..eb505d0 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -138,6 +138,7 @@  kms_mmio_vs_cs_flip
 kms_pipe_b_c_ivb
 kms_pipe_crc_basic
 kms_plane
+kms_prop_blob
 kms_psr_sink_crc
 kms_pwrite_crc
 kms_render
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 12f27f9..9a89167 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -70,6 +70,7 @@  TESTS_progs_M = \
 	kms_pipe_b_c_ivb \
 	kms_pipe_crc_basic \
 	kms_plane \
+	kms_prop_blob \
 	kms_psr_sink_crc \
 	kms_render \
 	kms_rotation_crc \
diff --git a/tests/kms_prop_blob.c b/tests/kms_prop_blob.c
new file mode 100644
index 0000000..03b85a9
--- /dev/null
+++ b/tests/kms_prop_blob.c
@@ -0,0 +1,226 @@ 
+/*
+ * 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",
+};
+
+
+static int
+validate_prop(int fd, uint32_t prop_id)
+{
+	struct drm_mode_get_blob get;
+	struct drm_mode_modeinfo ret_mode;
+	int err;
+
+	get.blob_id = prop_id;
+	get.length = 0;
+	get.data = (uintptr_t) 0;
+
+	err = drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
+	if (err != 0)
+		return err;
+
+	if (get.length != sizeof(test_mode_valid))
+		return ENOMEM;
+
+	get.data = (uintptr_t) &ret_mode;
+
+	err = drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
+	if (err != 0)
+		return err;
+
+	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);
+
+	return create.blob_id;
+}
+
+static int
+destroy_prop(int fd, uint32_t prop_id)
+{
+	struct drm_mode_destroy_blob destroy;
+	int err;
+
+	destroy.blob_id = prop_id;
+	err = drmIoctl(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy);
+	return err;
+}
+
+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;
+	int ret;
+
+	memset(too_small, 0, sizeof(too_small));
+
+	/* Outlandish size. */
+	create.length = 0x10000;
+	create.data = (uintptr_t) &too_small;
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create);
+	igt_assert(ret != 0 && errno == EFAULT);
+
+	/* Outlandish address. */
+	create.length = sizeof(test_mode_valid);
+	create.data = (uintptr_t) 0xdeadbeee;
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create);
+	igt_assert(ret != 0 && errno == EFAULT);
+
+	/* When we pass an incorrect size, the kernel should correct us. */
+	prop_id = create_prop(fd);
+	igt_assert(prop_id != 0);
+	get.blob_id = prop_id;
+	get.length = sizeof(too_small);
+	get.data = (uintptr_t) too_small;
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
+	igt_assert(ret == 0);
+	igt_assert(get.length == sizeof(test_mode_valid));
+
+	get.blob_id = prop_id;
+	get.data = (uintptr_t) 0xdeadbeee;
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &get);
+	igt_assert(ret != 0 && errno == EFAULT);
+}
+
+static void
+test_lifetime(int fd)
+{
+	int fd2;
+	uint32_t prop_id, prop_id2;
+
+	fd2 = drm_open_any();
+
+	/* Ensure clients can see properties created by other clients. */
+	prop_id = create_prop(fd);
+	igt_assert(prop_id != 0);
+	igt_assert(validate_prop(fd, prop_id) == 0);
+	igt_assert(validate_prop(fd2, prop_id) == 0);
+
+	/* ... but can't destroy them. */
+	igt_assert(destroy_prop(fd2, prop_id) != 0);
+
+	/* Make sure properties can't be accessed once explicitly destroyed. */
+	prop_id2 = create_prop(fd2);
+	igt_assert(prop_id2 != 0);
+	igt_assert(validate_prop(fd2, prop_id2) == 0);
+	igt_assert(destroy_prop(fd2, prop_id2) == 0);
+	igt_assert(validate_prop(fd2, prop_id2) != 0);
+	igt_assert(validate_prop(fd, prop_id2) != 0);
+
+	/* Make sure properties are cleaned up on client exit. */
+	prop_id2 = create_prop(fd2);
+	igt_assert(prop_id != 0);
+	igt_assert(validate_prop(fd, prop_id2) == 0);
+	close(fd2);
+	igt_assert(validate_prop(fd, prop_id2) != 0);
+
+	igt_assert(validate_prop(fd, prop_id) == 0);
+	igt_assert(destroy_prop(fd, prop_id) == 0);
+	igt_assert(validate_prop(fd, prop_id) != 0);
+}
+
+static void
+test_core(int fd)
+{
+	uint32_t prop_id;
+
+	/* The first hurdle. */
+	prop_id = create_prop(fd);
+	igt_assert(prop_id != 0);
+	igt_assert(validate_prop(fd, prop_id) == 0);
+	igt_assert(destroy_prop(fd, prop_id) == 0);
+
+	/* Look up some invalid property IDs. They should fail. */
+	igt_assert(validate_prop(fd, 0xffffffff) != 0);
+	igt_assert(validate_prop(fd, 0) != 0);
+
+}
+
+igt_main
+{
+	int fd;
+
+	igt_skip_on_simulation();
+
+	igt_fixture
+		fd = drm_open_any();
+
+	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);
+}