[PATCH i-g-t 2/3] tests/gem_exec_kamil: Add simple igt tests
Kamil Konieczny
kamil.konieczny at linux.intel.com
Thu Oct 21 13:30:27 UTC 2021
Simple test for trybot.
Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
tests/i915/gem_exec_kamil.c | 181 +++++++++++-------------------------
1 file changed, 53 insertions(+), 128 deletions(-)
diff --git a/tests/i915/gem_exec_kamil.c b/tests/i915/gem_exec_kamil.c
index 94366b30..fb58d47e 100644
--- a/tests/i915/gem_exec_kamil.c
+++ b/tests/i915/gem_exec_kamil.c
@@ -26,9 +26,9 @@
#include "i915/gem_create.h"
-IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl rings.");
+IGT_TEST_DESCRIPTION("Simple tests for experiment and learning.");
-static void gem(int fd)
+static void basic(int fd)
{
uint32_t bb = gem_create(fd, 4096); // todo: why fd+1 works ???
@@ -37,67 +37,9 @@ static void gem(int fd)
igt_info("bb closed: %x\n", bb);
}
-static void offsety(int i915)
-{
- uint32_t obiekt = gem_create(i915, 8192);
- uint32_t bb = gem_create(i915, 4096);
- uint32_t fake = gem_create(i915, 0x5000);
- const uint32_t bbe = MI_BATCH_BUFFER_END;
- int i;
- uint32_t *ptr;
-
- struct drm_i915_gem_execbuffer2 execbuf;
- struct drm_i915_gem_exec_object2 obj[3];
- struct drm_i915_gem_relocation_entry reloc = {};
-
- gem_write(i915, bb, 0, &bbe, sizeof(bbe));
-
- ptr = gem_mmap__cpu_coherent(i915, bb, 0, 4096, PROT_READ);
- for (i = 0; i < 8; i++)
- igt_info("[%04x]: %08x\n", i, ptr[i]);
- gem_munmap(ptr, 4096);
-
- memset(&execbuf, 0, sizeof(execbuf));
- execbuf.buffers_ptr = to_user_pointer(obj);
- execbuf.buffer_count = 3;
-
- memset(obj, 0, sizeof(obj));
- obj[0].handle = fake;
- obj[0].offset = 0;
- obj[0].flags = EXEC_OBJECT_PINNED;
- obj[1].handle = obiekt;
- obj[1].alignment = 0x2000;
- obj[2].handle = bb;
- obj[2].relocation_count = 1;
- obj[2].relocs_ptr = to_user_pointer(&reloc);
- obj[2].offset = 0;
- // offset = 0 with PINNED page will cause test fail, conflict with offset for fake
- // obj[2].flags = EXEC_OBJECT_PINNED;
-
- reloc.presumed_offset = -1;
- reloc.offset = 16;
- reloc.read_domains = I915_GEM_DOMAIN_INSTRUCTION;
- reloc.write_domain = I915_GEM_DOMAIN_INSTRUCTION;
- reloc.target_handle = obj[1].handle;
-
- igt_info("A obj[0].offset: %llx, handle: %u\n", obj[0].offset, obj[0].handle);
- igt_info("A obj[1].offset: %llx, handle: %u\n", obj[1].offset, obj[1].handle);
- igt_info("A obj[2].offset: %llx, handle: %u\n", obj[2].offset, obj[2].handle);
- gem_execbuf(i915, &execbuf);
-
- igt_info("B obj[0].offset: %llx, handle: %u\n", obj[0].offset, obj[0].handle);
- igt_info("B obj[1].offset: %llx, handle: %u\n", obj[1].offset, obj[1].handle);
- igt_info("B obj[2].offset: %llx, handle: %u\n", obj[2].offset, obj[2].handle);
-
- ptr = gem_mmap__cpu_coherent(i915, bb, 0, 4096, PROT_READ);
- for (i = 0; i < 8; i++)
- igt_info("[%04x]: %08x\n", i, ptr[i]);
- gem_munmap(ptr, 4096);
-}
-
#define MI_COPY ((2 << 29) | (0x53 << 22) | (3 << 20) | 8)
-static void copyrnd(int i915, bool use_reloc)
+static void copyrnd(int i915, bool use_reloc, uint64_t off, int child)
{
uint32_t src = gem_create(i915, 4096);
uint32_t dst = gem_create(i915, 4096);
@@ -123,14 +65,14 @@ static void copyrnd(int i915, bool use_reloc)
// dst
batch[i++] = 0; // Y1, X1 top, left
batch[i++] = (1 << 16) | 0x400; // Y2, X2 bottom, right 0,1024 ??? 1 or 0 ???
- batch[i++] = 0x1000; // dst addr low-endian
- batch[i++] = 0; // dst addr high bits
+ batch[i++] = off + 0x1000; // dst addr low-endian
+ batch[i++] = off >> 32; // dst addr high bits
// src
batch[i++] = 0; // Y1, X1 top, left
batch[i++] = 1024; // src pitch
//
- batch[i++] = 0x2000; // src addr low-endian
- batch[i++] = 0; // src addr
+ batch[i++] = off + 0x2000; // src addr low-endian
+ batch[i++] = off >> 32; // src addr
igt_assert((i % 2) == 0);
batch[i++] = MI_BATCH_BUFFER_END;
batch[i++] = 0; // MI_NOP
@@ -148,7 +90,7 @@ static void copyrnd(int i915, bool use_reloc)
obj[1].flags = EXEC_OBJECT_WRITE;
obj[1].handle = dst;
obj[2].handle = bb;
- obj[2].offset = 0;
+ obj[2].offset = off;
if (use_reloc) {
memset(reloc, 0, sizeof(reloc));
reloc[0].offset = 4*sizeof(uint32_t);
@@ -164,15 +106,15 @@ static void copyrnd(int i915, bool use_reloc)
obj[2].relocation_count = 2;
obj[2].relocs_ptr = to_user_pointer(reloc);
} else {
- obj[0].offset = 0x2000;
+ obj[0].offset = off + 0x2000;
obj[0].flags = EXEC_OBJECT_PINNED;
- obj[1].offset = 0x1000;
+ obj[1].offset = off + 0x1000;
obj[1].flags |= EXEC_OBJECT_PINNED;
}
gem_execbuf(i915, &execbuf);
i = getpid();
- sprintf(myaddr, "%04x s/d %06" PRIx64 "/%06" PRIx64, i,
+ sprintf(myaddr, "%02d %04x s/d %06" PRIx64 "/%06" PRIx64, child, i,
(uint64_t)obj[0].offset, (uint64_t)obj[1].offset);
//igt_info("%s\n", myaddr);
//
@@ -198,32 +140,53 @@ static void copyrnd(int i915, bool use_reloc)
igt_info("%s %s %s\n", myaddr, mybuff, mybatch);
}
-static void fork_ten(int i915)
+static void forkten(int i915, int N)
{
int child;
- time_t t;
- const int n = 10;
-
- /* Intializes random number generator */
+ //time_t t;
+ uint64_t ahnd;
+ uint64_t offsetbase, size = 0x4000, align = 0x4000;
+ uint32_t alloc_handle;
+
+ igt_info("parent: %d\n", getpid());
+ intel_allocator_multiprocess_start();
+ ahnd = intel_allocator_open(i915, 0, INTEL_ALLOCATOR_SIMPLE);
//srand((unsigned) time(&t));
- srand(42); //3137417);
+ srand(42); // or other magic, like 3137
- // igt_fork() - re-worked macro
- for (child = 0; child < n; ++child) {
+ for (child = 0; child < N; ++child) {
if(__igt_fork())
break;
}
- if (child == n) { // parent
- igt_waitchildren_timeout(3, "fork_ten wait timeout"); //int seconds, const char *reason
- } else { // children
- //srand((unsigned) time(&t));
- for (int i=0; i < 2*child; ++i) rand();
-
- usleep(1000 + (rand() % 8000));
- copyrnd(i915, true);
- exit(0);
+ if (child == N) { // parent
+ igt_waitchildren_timeout(3, "forkten wait timeout"); //seconds, reason
+ igt_assert_eq(intel_allocator_close(ahnd), true);
+ intel_allocator_multiprocess_stop();
+ return;
}
+
+ // children
+ // srand((unsigned) time(&t));
+ for (int i=0; i <= child; ++i)
+ rand();
+
+ igt_info("child: %02d\n", child);
+ usleep(1000 + (rand() % 20000));
+ ahnd = intel_allocator_open(i915, 0, INTEL_ALLOCATOR_SIMPLE);
+ alloc_handle = child + 1;
+
+ offsetbase = intel_allocator_alloc_with_strategy(ahnd, alloc_handle, size, align,
+ ALLOC_STRATEGY_LOW_TO_HIGH);
+ //offsetbase = intel_allocator_alloc(ahnd, child, size, align);
+ igt_info("child %02d offset %06" PRIx64 "\n", child+1, offsetbase);
+ //igt_assert((offsetbase >> 32) == 0);
+ //copyrnd(i915, true, 0);
+ copyrnd(i915, false, offsetbase, child);
+ intel_allocator_free(ahnd, alloc_handle);
+ intel_allocator_close(ahnd);
+ igt_info("child: %02d exit\n", child+1);
+ exit(0);
}
igt_main
@@ -234,52 +197,14 @@ igt_main
fd = drm_open_driver(DRIVER_INTEL);
}
- igt_subtest("gem") {
- gem(fd);
- }
- igt_subtest("offsety") {
- offsety(fd);
- }
- igt_subtest("copyrnd-noreloc") {
- copyrnd(fd, false);
- }
- igt_subtest("copyrnd-reloc") {
- copyrnd(fd, true);
+ igt_subtest("basic") {
+ basic(fd);
}
- igt_subtest("fork-ten") {
- fork_ten(fd);
- }
- igt_subtest("exec") {
+ igt_subtest("forkten") {
+ forkten(fd, 10);
}
-/* igt_subtest_with_dynamic("basic") {
- for_each_combination(regions, 1, set) {
- char *sub_name = memregion_dynamic_subtest_name(regions);
- struct drm_i915_gem_exec_object2 exec;
- uint32_t region = igt_collection_get_value(regions, 0);
-
- batch_size = gem_get_batch_size(fd, MEMORY_TYPE_FROM_REGION(region));
- memset(&exec, 0, sizeof(exec));
- exec.handle = batch_create(fd, batch_size, region);
- for_each_ctx_engine(fd, ctx, e) {
- igt_dynamic_f("%s-%s", e->name, sub_name) {
- struct drm_i915_gem_execbuffer2 execbuf = {
- .buffers_ptr = to_user_pointer(&exec),
- .buffer_count = 1,
- .flags = e->flags,
- .rsvd1 = ctx->id,
- };
-
- gem_execbuf(fd, &execbuf);
- }
- }
- gem_sync(fd, exec.handle);
- gem_close(fd, exec.handle);
- free(sub_name);
- }
- }
-*/
igt_fixture {
close(fd);
}
--
2.30.2
More information about the Intel-gfx-trybot
mailing list