[igt-dev] [PATCH i-g-t v4 08/11] tests/i915/vm_bind: Add userptr subtest
Niranjana Vishwanathapura
niranjana.vishwanathapura at intel.com
Tue Oct 18 07:17:02 UTC 2022
Add userptr object type to vm_bind_basic test.
v2: Run all tests for userptr type
Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura at intel.com>
---
tests/i915/i915_vm_bind_basic.c | 79 +++++++++++++++++++++++++++------
1 file changed, 65 insertions(+), 14 deletions(-)
diff --git a/tests/i915/i915_vm_bind_basic.c b/tests/i915/i915_vm_bind_basic.c
index ede76ba095..5316d1b9e8 100644
--- a/tests/i915/i915_vm_bind_basic.c
+++ b/tests/i915/i915_vm_bind_basic.c
@@ -81,10 +81,12 @@ struct mapping {
#define TEST_LMEM BIT(0)
#define TEST_SKIP_UNBIND BIT(1)
#define TEST_SHARE_VM BIT(2)
+#define TEST_USERPTR BIT(3)
#define is_lmem(cfg) ((cfg)->flags & TEST_LMEM)
#define do_unbind(cfg) (!((cfg)->flags & TEST_SKIP_UNBIND))
#define do_share_vm(cfg) ((cfg)->flags & TEST_SHARE_VM)
+#define is_userptr(cfg) ((cfg)->flags & TEST_USERPTR)
struct test_cfg {
const char *name;
@@ -248,15 +250,24 @@ static void create_src_objs(int fd, struct test_cfg *cfg, uint32_t src[], uint32
uint32_t num_cmds, void *src_addr[])
{
int i;
- struct igt_collection *set = get_region_set(fd, cfg, is_lmem(cfg) && (num_cmds == 1));
- uint32_t region;
- for (i = 0; i < num_cmds; i++) {
- region = igt_collection_get_value(set, i % set->size);
- src[i] = gem_create_in_memory_regions(fd, size, region);
- igt_info("Src obj 0x%x created in region 0x%x:0x%x\n", src[i],
- MEMORY_TYPE_FROM_REGION(region), MEMORY_INSTANCE_FROM_REGION(region));
- src_addr[i] = gem_mmap__cpu(fd, src[i], 0, size, PROT_WRITE);
+ if (is_userptr(cfg)) {
+ for (i = 0; i < num_cmds; i++) {
+ igt_assert(posix_memalign(&src_addr[i], SZ_2M * MAX_CTXTS, size) == 0);
+ gem_userptr(fd, src_addr[i], size, 0, 0, &src[i]);
+ igt_info("Src userptr obj 0x%x created\n", src[i]);
+ }
+ } else {
+ struct igt_collection *set = get_region_set(fd, cfg, is_lmem(cfg) && (num_cmds == 1));
+ uint32_t region;
+
+ for (i = 0; i < num_cmds; i++) {
+ region = igt_collection_get_value(set, i % set->size);
+ src[i] = gem_create_in_memory_regions(fd, size, region);
+ igt_info("Src obj 0x%x created in region 0x%x:0x%x\n", src[i],
+ MEMORY_TYPE_FROM_REGION(region), MEMORY_INSTANCE_FROM_REGION(region));
+ src_addr[i] = gem_mmap__cpu(fd, src[i], 0, size, PROT_WRITE);
+ }
}
}
@@ -269,19 +280,29 @@ static void destroy_src_objs(int fd, struct test_cfg *cfg, uint32_t src[], uint3
igt_assert(gem_munmap(src_addr[i], size) == 0);
igt_debug("Closing object 0x%x\n", src[i]);
gem_close(fd, src[i]);
+ if (is_userptr(cfg))
+ free(src_addr[i]);
}
}
static uint32_t create_dst_obj(int fd, struct test_cfg *cfg, uint32_t size, void **dst_addr)
{
uint32_t dst;
- struct igt_collection *set = get_region_set(fd, cfg, is_lmem(cfg));
- uint32_t region = igt_collection_get_value(set, 0);
- dst = gem_create_in_memory_regions(fd, size, region);
- igt_info("Dst obj 0x%x created in region 0x%x:0x%x\n", dst,
- MEMORY_TYPE_FROM_REGION(region), MEMORY_INSTANCE_FROM_REGION(region));
- *dst_addr = gem_mmap__cpu(fd, dst, 0, size, PROT_WRITE);
+ if (is_userptr(cfg)) {
+ igt_assert(posix_memalign(dst_addr, SZ_2M * MAX_CTXTS, size) == 0);
+
+ gem_userptr(fd, *dst_addr, size, 0, 0, &dst);
+ igt_info("Dst userptr obj 0x%x created\n", dst);
+ } else {
+ struct igt_collection *set = get_region_set(fd, cfg, is_lmem(cfg));
+ uint32_t region = igt_collection_get_value(set, 0);
+
+ dst = gem_create_in_memory_regions(fd, size, igt_collection_get_value(set, 0));
+ igt_info("Dst obj 0x%x created in region 0x%x:0x%x\n", dst,
+ MEMORY_TYPE_FROM_REGION(region), MEMORY_INSTANCE_FROM_REGION(region));
+ *dst_addr = gem_mmap__cpu(fd, dst, 0, size, PROT_WRITE);
+ }
return dst;
}
@@ -291,6 +312,9 @@ static void destroy_dst_obj(int fd, struct test_cfg *cfg, uint32_t dst, uint32_t
igt_assert(gem_munmap(dst_addr, size) == 0);
igt_debug("Closing object 0x%x\n", dst);
gem_close(fd, dst);
+
+ if (is_userptr(cfg))
+ free(dst_addr);
}
static void pattern_fill_buf(void *src_addr[], uint32_t size, uint32_t num_cmds, uint32_t npages)
@@ -460,6 +484,25 @@ static void run_test(int fd, const intel_ctx_t *base_ctx, struct test_cfg *cfg,
gem_vm_destroy(fd, shared_vm_id);
}
+static int has_userptr(int fd)
+{
+ uint32_t handle = 0;
+ void *ptr;
+ int ret;
+
+ assert(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE) == 0);
+ ret = __gem_userptr(fd, ptr, PAGE_SIZE, 0, 0, &handle);
+ if (ret != 0) {
+ free(ptr);
+ return 0;
+ }
+
+ gem_close(fd, handle);
+ free(ptr);
+
+ return handle != 0;
+}
+
igt_main
{
struct test_cfg *t, tests[] = {
@@ -510,6 +553,14 @@ igt_main
igt_dynamic_f("%s", r->name)
run_test(fd, ctx, &cfg, e);
}
+
+ if (has_userptr(fd)) {
+ struct test_cfg cfg = *t;
+
+ cfg.flags |= TEST_USERPTR;
+ igt_dynamic("userptr")
+ run_test(fd, ctx, &cfg, e);
+ }
}
}
--
2.21.0.rc0.32.g243a4c7e27
More information about the igt-dev
mailing list