[igt-dev] [RFC PATCH 3/4] tests/i915/gem_mmap_offset: Add new API test for gem_mmap_offset

Kempczynski, Zbigniew zbigniew.kempczynski at intel.com
Tue Oct 22 07:30:47 UTC 2019


On Wed, 2019-08-14 at 12:21 +0200, Lukasz Kalamarz wrote:
> This test is a copy/paste of few gem_mmap subtests, due to good
> coverage in previous one. We also need to be sure that we cover
> all available memory regions.
> 
> Signed-off-by: Lukasz Kalamarz <lukasz.kalamarz at intel.com>
> Cc: Matthew Auld <matthew.auld at intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
> ---
>  tests/Makefile.sources       |   3 +
>  tests/i915/gem_mmap_offset.c | 197 +++++++++++++++++++++++++++++++++++
>  tests/meson.build            |   1 +
>  3 files changed, 201 insertions(+)
>  create mode 100644 tests/i915/gem_mmap_offset.c
> 
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 250dbd33..cd7daf4f 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -307,6 +307,9 @@ gem_mmap_SOURCES = i915/gem_mmap.c
>  TESTS_progs += gem_mmap_gtt
>  gem_mmap_gtt_SOURCES = i915/gem_mmap_gtt.c
>  
> +TESTS_progs += gem_mmap_offset
> +gem_mmap_offset_SOURCES = i915/gem_mmap_offset.c
> +
>  TESTS_progs += gem_mmap_offset_exhaustion
>  gem_mmap_offset_exhaustion_SOURCES = i915/gem_mmap_offset_exhaustion.c
>  
> diff --git a/tests/i915/gem_mmap_offset.c b/tests/i915/gem_mmap_offset.c
> new file mode 100644
> index 00000000..8c5ed17e
> --- /dev/null
> +++ b/tests/i915/gem_mmap_offset.c
> @@ -0,0 +1,197 @@
> +/*
> + * Copyright © 2019 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.
> + */
> +
> +#include "igt.h"
> +#include <errno.h>
> +#include <sys/stat.h>
> +#include <sys/ioctl.h>
> +#include "drm.h"
> +
> +IGT_TEST_DESCRIPTION("Basic MMAP_OFFSET IOCTL tests for mem regions\n");
> +
> +int fd;
> +
> +static const char * const mmap_offset_flags[] = {
> +	[LOCAL_I915_MMAP_OFFSET_WC] = "wc",
> +	[LOCAL_I915_MMAP_OFFSET_WB] = "wb",
> +	[LOCAL_I915_MMAP_OFFSET_UC] = "uc"
> +};
> +

I guess you have some behavior you don't expect here. I mean you assign 
indices at LOCAL_...WC/WB/UC (1, 2, 4). Check comment below in the loop.

> +static int mmap_offset_ioctl(int i915, struct local_i915_gem_mmap_offset
> *arg)
> +{
> +	int err = 0;
> +
> +	if (igt_ioctl(i915, LOCAL_IOCTL_I915_GEM_MMAP_OFFSET, arg))
> +		err = -errno;
> +
> +	errno = 0;
> +	return err;
> +}

Can this be part of ioctl_wrappers.[ch]?

> +
> +igt_main
> +{
> +	uint8_t *addr;
> +	uint32_t obj_size, batch_size;
> +	uint8_t mem_type;
> +	uint32_t id;
> +	uint32_t num_regions;
> +	int ret;
> +	const struct intel_memory_region *mr;
> +	struct local_i915_query_memory_region_info *query_info;
> +
> +	igt_fixture {
> +		fd = drm_open_driver(DRIVER_INTEL);
> +		igt_require(gem_has_mmap_offset(fd));
> +
> +		query_info = gem_get_query_memory_regions(fd);
> +		igt_assert(query_info);
> +		num_regions = query_info->num_regions;
> +	}
> +
> +	for (mr = intel_memory_regions; mr->region_name; mr++) {
> +		mem_type = mr->mem_region_type;
> +		id = mr->id;
> +
> +		batch_size = gem_get_batch_size(fd, mem_type);
> +		obj_size = 4 * batch_size;
> +
> +		igt_subtest_f("bad-object-%s", mr->region_name) {
> +			uint32_t real_handle = gem_create(fd, batch_size);
> +			uint32_t handles[20];
> +			int i = 0;
> +
> +			ret = -1;
> +
> +			ret = gem_find_memory_region_in_query(query_info,
> +							      num_regions,
> id);
> +			igt_require(ret);
> +
> +			ret = gem_bo_set_memory_region(fd, real_handle, id);
> +			igt_assert_eq(ret, 0);
> +
> +			handles[i++] = 0xdeadbeef;
> +			for (int bit = 0; bit < 16; bit++)
> +				handles[i++] = real_handle | (1 << (bit +
> 16));
> +			handles[i] = real_handle + 1;
> +
> +			for (; i < 0; i--) {
> +				struct local_i915_gem_mmap_offset arg = {
> +					.handle = handles[i],
> +					.flags = LOCAL_I915_MMAP_OFFSET_WB,
> +				};
> +
> +				igt_debug("Trying to set memory region\n");
> +				ret = gem_bo_set_memory_region(fd, arg.handle,
> +							       id);
> +				igt_assert_eq(ret, -EINVAL);
> +
> +				igt_debug("Trying MMAP IOCTL with handle
> %x\n",
> +					  handles[i]);
> +				igt_assert_eq(mmap_offset_ioctl(fd, &arg),
> +					      -EINVAL);
> +			}
> +
> +			gem_close(fd, real_handle);
> +		}
> +
> +		for (unsigned flags = 0; flags < LOCAL_I915_MMAP_OFFSET_FLAGS
> + 1; flags++) {

Loop iterates from 0 -> 7, but only indices 1,2,4 have values assigned inside
the array. So you're performing same tests few times passing combined or-ed
flags. It depends to driver which flag it will honor and what order it be.

> +
> +			igt_subtest_f("basic-%s-%s", mmap_offset_flags[flags],
> +				      mr->region_name) {
> +				struct local_i915_gem_mmap_offset arg = {
> +					.handle = gem_create(fd, obj_size),
> +					.flags = flags,
> +				};
> +
> +				uint8_t *expected;
> +				uint8_t *buf;
> +
> +				ret =
> gem_find_memory_region_in_query(query_info,
> +								      num_regi
> ons,
> +								      id);
> +				igt_require(ret);
> +
> +				ret = gem_bo_set_memory_region(fd, arg.handle,
> +							       id);
> +				igt_assert_eq(ret, 0);
> +
> +				igt_assert_eq(mmap_offset_ioctl(fd, &arg), 0);
> +				addr = mmap64(0, obj_size, PROT_READ |
> PROT_WRITE,
> +					      MAP_SHARED, fd, arg.offset);
> +				igt_assert(addr != MAP_FAILED);
> +
> +				igt_info("Testing contents of newly created
> object.\n");
> +				expected = calloc(obj_size, sizeof(expected));

I guess you wanted to use sizeof(*expected). Same issues below. 

> +				memset(expected, 0, obj_size *
> sizeof(expected));
> +				igt_assert_eq(memcmp(addr, expected,
> obj_size), 0);
> +				free(expected);
> +
> +				igt_info("Testing coherency of writes and mmap
> reads.\n");
> +				buf = calloc(obj_size, sizeof(buf));
> +				memset(buf, 0, obj_size * sizeof(buf));
> +				memset(buf + 1024, 0x01, 1024);
> +				gem_write(fd, arg.handle, 0, buf, obj_size);
> +				igt_assert_eq(memcmp(buf, addr, obj_size), 0);
> +
> +				igt_info("Testing that mapping stays after
> close\n");
> +				gem_close(fd, arg.handle);
> +				igt_assert_eq(memcmp(buf, addr, obj_size), 0);
> +				free(buf);
> +
> +				igt_info("Testing unmapping\n");
> +				munmap(addr, obj_size);
> +			}
> +
> +			igt_subtest_f("short-mmap-%s-%s",
> mmap_offset_flags[flags],
> +				      mr->region_name) {
> +				uint32_t handle = gem_create(fd, obj_size);
> +
> +				ret = -1;
> +
> +				ret =
> gem_find_memory_region_in_query(query_info,
> +								      num_regi
> ons,
> +								      id);
> +
> +				igt_require(ret);
> +
> +				ret = gem_bo_set_memory_region(fd, handle,
> id);
> +				igt_assert_eq(ret, 0);
> +
> +				igt_assert(obj_size > batch_size);
> +
> +				addr = __gem_mmap_offset(fd, handle, 0,
> +							 batch_size,
> PROT_WRITE,
> +							 flags);
> +				memset(addr, 0, batch_size);
> +				munmap(addr, batch_size);
> +
> +				gem_close(fd, handle);
> +			}
> +		}
> +	}
> +
> +	igt_fixture {
> +		free(query_info);
> +		close(fd);
> +	}
> +}
> diff --git a/tests/meson.build b/tests/meson.build
> index 34a74025..236aaede 100644
> --- a/tests/meson.build
> +++ b/tests/meson.build
> @@ -167,6 +167,7 @@ i915_progs = [
>  	'gem_media_vme',
>  	'gem_mmap',
>  	'gem_mmap_gtt',
> +	'gem_mmap_offset',
>  	'gem_mmap_offset_exhaustion',
>  	'gem_mmap_wc',
>  	'gem_partial_pwrite_pread',

Zbigniew


More information about the igt-dev mailing list