Add some explicit testcases for the create_ext placements extension. Signed-off-by: Matthew Auld <matthew.auld@xxxxxxxxx> Cc: Dominik Grzegorzek <dominik.grzegorzek@xxxxxxxxx> Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx> Acked-by: Petri Latvala <petri.latvala@xxxxxxxxx> --- tests/i915/gem_create.c | 188 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c index 8acc2f52..167d7d28 100644 --- a/tests/i915/gem_create.c +++ b/tests/i915/gem_create.c @@ -290,6 +290,184 @@ static void size_update(int fd) igt_assert_neq(create.size, size_initial_nonaligned); } +static void create_ext_placement_sanity_check(int fd) +{ + struct drm_i915_query_memory_regions *regions; + struct drm_i915_gem_create_ext_memory_regions setparam_region = { + .base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS }, + }; + struct drm_i915_gem_memory_class_instance *uregions; + struct drm_i915_gem_memory_class_instance region_smem = { + .memory_class = I915_MEMORY_CLASS_SYSTEM, + .memory_instance = 0, + }; + struct drm_i915_gem_memory_class_instance region_invalid = { + .memory_class = -1, + .memory_instance = -1, + }; + uint64_t size; + uint32_t handle; + int i; + + regions = gem_get_query_memory_regions(fd); + igt_assert(regions); + igt_assert(regions->num_regions); + + /* + * extensions should be optional, giving us the normal gem_create + * behaviour. + */ + size = PAGE_SIZE; + igt_assert_eq(__gem_create_ext(fd, &size, &handle, 0), 0); + gem_close(fd, handle); + + /* Try some uncreative invalid combinations */ + setparam_region.regions = to_user_pointer(®ion_smem); + setparam_region.num_regions = 0; + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + + setparam_region.regions = to_user_pointer(®ion_smem); + setparam_region.num_regions = regions->num_regions + 1; + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + + setparam_region.regions = to_user_pointer(®ion_smem); + setparam_region.num_regions = -1; + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + + setparam_region.regions = to_user_pointer(®ion_invalid); + setparam_region.num_regions = 1; + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + + setparam_region.regions = to_user_pointer(®ion_invalid); + setparam_region.num_regions = 0; + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + + uregions = calloc(regions->num_regions + 1, sizeof(uint32_t)); + + for (i = 0; i < regions->num_regions; i++) + uregions[i] = regions->regions[i].region; + + setparam_region.regions = to_user_pointer(uregions); + setparam_region.num_regions = regions->num_regions + 1; + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + + if (regions->num_regions > 1) { + for (i = 0; i < regions->num_regions; i++) { + struct drm_i915_gem_memory_class_instance dups[] = { + regions->regions[i].region, + regions->regions[i].region, + }; + + setparam_region.regions = to_user_pointer(dups); + setparam_region.num_regions = 2; + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + } + } + + uregions[rand() % regions->num_regions].memory_class = -1; + uregions[rand() % regions->num_regions].memory_instance = -1; + setparam_region.regions = to_user_pointer(uregions); + setparam_region.num_regions = regions->num_regions; + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + + free(uregions); + + { + struct drm_i915_gem_create_ext_memory_regions setparam_region_next; + + setparam_region.regions = to_user_pointer(®ion_smem); + setparam_region.num_regions = 1; + + setparam_region_next = setparam_region; + setparam_region.base.next_extension = + to_user_pointer(&setparam_region_next); + + size = PAGE_SIZE; + igt_assert_neq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + setparam_region.base.next_extension = 0; + } + + free(regions); +} + +static void create_ext_placement_all(int fd) +{ + struct drm_i915_query_memory_regions *regions; + struct drm_i915_gem_create_ext_memory_regions setparam_region = { + .base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS }, + }; + struct drm_i915_gem_memory_class_instance *uregions; + uint64_t size; + uint32_t handle; + int i; + + regions = gem_get_query_memory_regions(fd); + igt_assert(regions); + igt_assert(regions->num_regions); + + uregions = calloc(regions->num_regions, sizeof(*uregions)); + + for (i = 0; i < regions->num_regions; i++) + uregions[i] = regions->regions[i].region; + + setparam_region.regions = to_user_pointer(uregions); + setparam_region.num_regions = regions->num_regions; + + size = PAGE_SIZE; + igt_assert_eq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + gem_close(fd, handle); + free(uregions); + free(regions); +} + +static void create_ext_placement_each(int fd) +{ + struct drm_i915_query_memory_regions *regions; + struct drm_i915_gem_create_ext_memory_regions setparam_region = { + .base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS }, + }; + int i; + + regions = gem_get_query_memory_regions(fd); + igt_assert(regions); + igt_assert(regions->num_regions); + + for (i = 0; i < regions->num_regions; i++) { + struct drm_i915_gem_memory_class_instance region = + regions->regions[i].region; + uint64_t size; + uint32_t handle; + + setparam_region.regions = to_user_pointer(®ion); + setparam_region.num_regions = 1; + + size = PAGE_SIZE; + igt_assert_eq(__gem_create_ext(fd, &size, &handle, + &setparam_region.base), 0); + gem_close(fd, handle); + } + + free(regions); +} + igt_main { int fd = -1; @@ -315,4 +493,14 @@ igt_main igt_subtest("busy-create") busy_create(fd, 30); + + igt_subtest("create-ext-placement-sanity-check") + create_ext_placement_sanity_check(fd); + + igt_subtest("create-ext-placement-each") + create_ext_placement_each(fd); + + igt_subtest("create-ext-placement-all") + create_ext_placement_all(fd); + } -- 2.26.3 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx