igt/gem_exec_reloc: Exercise read-only relocation arrays

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2016-04-01 20:07:13 +01:00
parent aec81019e1
commit 3dd5fe8ab2

View File

@ -94,6 +94,7 @@ static void write_dword(int fd,
}
enum mode { MEM, CPU, WC, GTT };
#define RO 0x100
static void from_mmap(int fd, uint64_t size, enum mode mode)
{
uint32_t bbe = MI_BATCH_BUFFER_END;
@ -112,7 +113,7 @@ static void from_mmap(int fd, uint64_t size, enum mode mode)
gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));
max = size / sizeof(*relocs);
switch (mode) {
switch (mode & ~RO) {
case MEM:
relocs = mmap(0, size,
PROT_WRITE, MAP_PRIVATE | MAP_ANON,
@ -153,6 +154,9 @@ static void from_mmap(int fd, uint64_t size, enum mode mode)
obj.relocation_count = max;
obj.relocs_ptr = (uintptr_t)relocs;
if (mode & RO)
mprotect(relocs, size, PROT_READ);
memset(&execbuf, 0, sizeof(execbuf));
execbuf.buffers_ptr = (uintptr_t)&obj;
execbuf.buffer_count = 1;
@ -327,6 +331,8 @@ igt_main
for (size = 4096; size <= 4ull*1024*1024*1024; size <<= 1) {
igt_subtest_f("mmap-%u", find_last_set(size) - 1)
from_mmap(fd, size, MEM);
igt_subtest_f("readonly-%u", find_last_set(size) - 1)
from_mmap(fd, size, MEM | RO);
igt_subtest_f("cpu-%u", find_last_set(size) - 1)
from_mmap(fd, size, CPU);
igt_subtest_f("wc-%u", find_last_set(size) - 1)