[igt-dev] [PATCH i-g-t v2 8/8] tests/i915/vm_bind: Add userptr subtest
Niranjana Vishwanathapura
niranjana.vishwanathapura at intel.com
Mon Oct 3 06:13:20 UTC 2022
Add userptr object type to vm_bind_basic test.
Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura at intel.com>
---
tests/i915/i915_vm_bind_basic.c | 73 ++++++++++++++++++++++++++-------
1 file changed, 59 insertions(+), 14 deletions(-)
diff --git a/tests/i915/i915_vm_bind_basic.c b/tests/i915/i915_vm_bind_basic.c
index 0e87e45812..13cd45f777 100644
--- a/tests/i915/i915_vm_bind_basic.c
+++ b/tests/i915/i915_vm_bind_basic.c
@@ -80,10 +80,12 @@ struct mapping {
#define TEST_SMEM 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_SMEM))
#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;
@@ -265,15 +267,23 @@ 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);
- 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, size) == 0);
+ gem_userptr(fd, src_addr[i], size, 0, 0, &src[i]);
+ }
+ } else {
+ struct igt_collection *set = get_region_set(fd, cfg);
+ 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);
+ }
}
}
@@ -286,19 +296,28 @@ 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);
- 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, size) == 0);
+
+ gem_userptr(fd, *dst_addr, size, 0, 0, &dst);
+ } else {
+ struct igt_collection *set = get_region_set(fd, 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;
}
@@ -308,6 +327,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)
@@ -475,6 +497,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;
+}
+
static int vm_bind_version(int fd)
{
struct drm_i915_getparam gp;
@@ -503,6 +544,7 @@ igt_main
{"2M", SZ_2M, 1, 1, 0},
{"smem", 0, 1, 1, TEST_SMEM},
{"smem_multi_cmds", 0, MAX_CMDS, 1, TEST_SMEM},
+ {"userptr", 0, 1, 1, TEST_USERPTR},
{ }
};
int fd;
@@ -533,6 +575,9 @@ igt_main
for_each_ctx_engine(fd, ctx, e) {
if (e->class == I915_ENGINE_CLASS_COPY) {
igt_dynamic(e->name) {
+ if (is_userptr(t))
+ igt_require(has_userptr(fd));
+
run_test(fd, ctx, t, e);
}
}
--
2.21.0.rc0.32.g243a4c7e27
More information about the igt-dev
mailing list