[igt-dev] [PATCH i-g-t v3 3/4] tests/i915/gem_mmap_offset: Add new API test for gem_mmap_offset

Zbigniew KempczyƄski zbigniew.kempczynski at intel.com
Thu Nov 21 17:07:52 UTC 2019


On Wed, Nov 20, 2019 at 07:50:55PM +0000, Chris Wilson wrote:
> > +igt_main
> > +{
> > +       uint8_t *addr;
> > +       uint32_t obj_size, batch_size;
> > +       uint32_t mem_type, mem_instance;
> > +       uint32_t region;
> > +       int fd;
> > +       const struct intel_memory_region *mr;
> > +       struct local_i915_query_memory_region_info *query_info;
> > +
> > +       igt_fixture {
> > +               fd = drm_open_driver(DRIVER_INTEL);
> > +               gem_require_mmap_offset(fd);
> > +               igt_require(gem_mmap__has_wc(fd));
> > +
> > +               query_info = gem_query_memory_regions(fd);
> > +               igt_assert(query_info);
> 
> This ioctl will be available before memory regions uAPI, and we will be
> expecting coverage...

You mean i915_query.c test should be extended to do similar?

> 
> gem_mmap_offset_regions
> or
> gem_memory_regions_mmap
> 
> or just igt_subtest_group {}
> 
> And do we have a plan for switching to something like i915_gem_ instead?

I tried to understand and I'm sorry I don't get what you mean.

> 
> > +       }
> > +
> > +       for (mr = intel_memory_regions; mr->region_name; mr++) {
> 
> See igt_subtest_with_dynamic

I wondered to provide macro similar to existing - for_each_memory_region.

I'm taking a look how to use dynamic test here. 

> > +               mem_type = mr->memory_type;
> > +               mem_instance = mr->memory_instance;
> > +               region = INTEL_MEMORY_REGION_ID(mem_type, mem_instance);
> > +               batch_size = gem_get_batch_size(fd, region);
> > +               obj_size = 4 * batch_size;
> > +
> > +               igt_subtest_f("bad-object-%s", mr->region_name) {
> > +                       uint32_t real_handle;
> > +                       uint32_t handles[20];
> > +                       int i = 0;
> > +
> > +                       gem_query_require_region(query_info, region);
> > +
> > +                       real_handle = gem_create_in_memory_regions(fd, obj_size,
> > +                                                                  region);
> > +
> > +                       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_WC,
> > +                               };
> > +
> > +                               igt_debug("Trying MMAP IOCTL with handle %x\n",
> > +                                         handles[i]);
> > +                               igt_assert_eq(mmap_offset_ioctl(fd, &arg),
> > +                                             -ENOENT);
> > +                       }
> > +
> > +                       gem_close(fd, real_handle);
> > +               }
> > +
> > +               igt_subtest_f("basic-%s", mr->region_name) {
> > +                       uint32_t handle;
> > +                       uint64_t flags;
> > +                       uint8_t *expected;
> > +                       uint8_t *buf;
> > +
> > +                       gem_query_require_region(query_info, region);
> > +
> > +                       handle = gem_create_in_memory_regions(fd, obj_size,
> > +                                                             region);
> > +                       flags = LOCAL_I915_MMAP_OFFSET_WC;
> > +                       addr = __gem_mmap_offset(fd, handle, 0, obj_size,
> > +                                                PROT_READ | PROT_WRITE,
> > +                                                flags);
> > +                       igt_assert(addr);
> > +
> > +                       igt_debug("Testing contents of newly created object.\n");
> > +                       expected = calloc(obj_size, sizeof(*expected));
> > +                       igt_assert_eq(memcmp(addr, expected, obj_size), 0);
> > +                       free(expected);
> > +
> > +                       igt_debug("Testing coherency of writes and mmap reads.\n");
> > +                       buf = calloc(obj_size, sizeof(*buf));
> > +                       memset(buf + 1024, 0x01, 1024);
> > +                       gem_write(fd, handle, 0, buf, obj_size);
> > +                       igt_assert_eq(memcmp(buf, addr, obj_size), 0);
> > +
> > +                       igt_debug("Testing that mapping stays after close\n");
> > +                       gem_close(fd, handle);
> > +                       igt_assert_eq(memcmp(buf, addr, obj_size), 0);
> > +                       free(buf);
> > +
> > +                       igt_debug("Testing unmapping\n");
> > +                       munmap(addr, obj_size);
> > +               }
> > +
> > +               igt_subtest_f("short-mmap-%s", mr->region_name) {
> > +                       uint32_t handle;
> 
> Not supported in vanilla ioctl, coming to an extension near you :)
> -Chris
Hmm, still not get it :/

Zbigniew


More information about the igt-dev mailing list