tests: use drmtest_skip() in caching ioctl helpers

This way we can rip out all the skip handling from the test control flow,
and additionally (by using drmtest_retval()) even get correct exit codes.

The only tricky part is that when we only want ot skip parts of a test
(like for gem_pread and gem_pwrite) we need to split out those parts as
subtests. But no addition of control-flow is required, the set/longjmp
magic in the helpers all makes it happen.

Also we make extensive use of the behaviour of drmtest_skip to skip
all subsequent subtests if it is called outside of a subtest. This allows
us to re-flatten the control flow a lot.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Daniel Vetter 2013-08-12 10:43:59 +02:00
parent a4038d3853
commit 7553ad6e10
9 changed files with 177 additions and 170 deletions

View File

@ -40,6 +40,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <linux/kd.h> #include <linux/kd.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h>
#include "drm_fourcc.h" #include "drm_fourcc.h"
#include "drmtest.h" #include "drmtest.h"
@ -392,23 +393,26 @@ struct local_drm_i915_gem_caching {
#define LOCAL_DRM_IOCTL_I915_GEM_GET_CACHEING \ #define LOCAL_DRM_IOCTL_I915_GEM_GET_CACHEING \
DRM_IOWR(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_GET_CACHEING, struct local_drm_i915_gem_caching) DRM_IOWR(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_GET_CACHEING, struct local_drm_i915_gem_caching)
int gem_has_caching(int fd) void gem_check_caching(int fd)
{ {
struct local_drm_i915_gem_caching arg; struct local_drm_i915_gem_caching arg;
int ret; int ret;
arg.handle = gem_create(fd, 4096); arg.handle = gem_create(fd, 4096);
if (arg.handle == 0) assert(arg.handle != 0);
return 0;
arg.caching = 0; arg.caching = 0;
ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg); ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg);
gem_close(fd, arg.handle); gem_close(fd, arg.handle);
return ret == 0; if (ret != 0) {
if (!drmtest_only_list_subtests())
printf("no set_caching support detected\n");
drmtest_skip();
}
} }
int gem_set_caching(int fd, uint32_t handle, int caching) void gem_set_caching(int fd, uint32_t handle, int caching)
{ {
struct local_drm_i915_gem_caching arg; struct local_drm_i915_gem_caching arg;
int ret; int ret;
@ -416,7 +420,11 @@ int gem_set_caching(int fd, uint32_t handle, int caching)
arg.handle = handle; arg.handle = handle;
arg.caching = caching; arg.caching = caching;
ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg); ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg);
return ret == 0 ? 0 : -errno;
if (ret != 0 && (errno == ENOTTY || errno == EINVAL))
drmtest_skip();
else
assert(ret == 0);
} }
uint32_t gem_get_caching(int fd, uint32_t handle) uint32_t gem_get_caching(int fd, uint32_t handle)

View File

@ -54,8 +54,8 @@ bool gem_has_bsd(int fd);
bool gem_has_blt(int fd); bool gem_has_blt(int fd);
bool gem_has_vebox(int fd); bool gem_has_vebox(int fd);
int gem_get_num_rings(int fd); int gem_get_num_rings(int fd);
int gem_has_caching(int fd); void gem_check_caching(int fd);
int gem_set_caching(int fd, uint32_t handle, int caching); void gem_set_caching(int fd, uint32_t handle, int caching);
uint32_t gem_get_caching(int fd, uint32_t handle); uint32_t gem_get_caching(int fd, uint32_t handle);
uint32_t gem_flink(int fd, uint32_t handle); uint32_t gem_flink(int fd, uint32_t handle);
uint32_t gem_open(int fd, uint32_t name); uint32_t gem_open(int fd, uint32_t name);

View File

@ -30,8 +30,10 @@ TESTS_progs_M = \
gem_linear_blits \ gem_linear_blits \
gem_mmap_gtt \ gem_mmap_gtt \
gem_partial_pwrite_pread \ gem_partial_pwrite_pread \
gem_pread \
gem_pread_after_blit \ gem_pread_after_blit \
gem_prw_concurrent_blit \ gem_prw_concurrent_blit \
gem_pwrite \
gem_pwrite_pread \ gem_pwrite_pread \
gem_ringfill \ gem_ringfill \
gem_set_tiling_vs_blt \ gem_set_tiling_vs_blt \
@ -73,8 +75,6 @@ TESTS_progs = \
gem_mmap_offset_exhaustion \ gem_mmap_offset_exhaustion \
gem_pin \ gem_pin \
gem_pipe_control_store_loop \ gem_pipe_control_store_loop \
gem_pread \
gem_pwrite \
gem_readwrite \ gem_readwrite \
gem_reg_read \ gem_reg_read \
gem_reloc_overflow \ gem_reloc_overflow \

View File

@ -118,10 +118,7 @@ int main(int argc, char **argv)
fd = drm_open_any(); fd = drm_open_any();
if (!gem_has_caching(fd)) { gem_check_caching(fd);
printf("no set_caching support detected\n");
return 77;
}
devid = intel_get_drm_devid(fd); devid = intel_get_drm_devid(fd);
if (IS_GEN2(devid)) /* chipset only handles cached -> uncached */ if (IS_GEN2(devid)) /* chipset only handles cached -> uncached */

View File

@ -257,17 +257,8 @@ static void do_tests(int cache_level, const char *suffix)
{ {
char name[80]; char name[80];
if (cache_level != -1) { if (cache_level != -1)
switch (gem_set_caching(fd, scratch_bo->handle, cache_level)) { gem_set_caching(fd, scratch_bo->handle, cache_level);
case 0: break;
case -EINVAL:
case -ENOTTY:
return;
default:
assert(0);
return;
}
}
snprintf(name, sizeof(name), "reads%s", suffix); snprintf(name, sizeof(name), "reads%s", suffix);
drmtest_subtest_block(name) drmtest_subtest_block(name)
@ -315,5 +306,5 @@ int main(int argc, char **argv)
close(fd); close(fd);
return 0; return drmtest_retval();
} }

View File

@ -93,9 +93,10 @@ int main(int argc, char **argv)
{ -1 }, { -1 },
}, *c; }, *c;
drmtest_subtest_init(argc, argv);
drmtest_skip_on_simulation(); drmtest_skip_on_simulation();
if (argc > 1) if (argc > 1 && atoi(argv[1]))
object_size = atoi(argv[1]); object_size = atoi(argv[1]);
if (object_size == 0) if (object_size == 0)
object_size = OBJECT_SIZE; object_size = OBJECT_SIZE;
@ -106,6 +107,7 @@ int main(int argc, char **argv)
dst = gem_create(fd, object_size); dst = gem_create(fd, object_size);
src = malloc(object_size); src = malloc(object_size);
drmtest_subtest_block("normal") {
for (count = 1; count <= 1<<17; count <<= 1) { for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end; struct timeval start, end;
@ -118,10 +120,11 @@ int main(int argc, char **argv)
bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6)); bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
fflush(stdout); fflush(stdout);
} }
}
for (c = cache; c->level != -1; c++) { for (c = cache; c->level != -1; c++) {
if (gem_set_caching(fd, dst, c->level)) drmtest_subtest_block(c->name) {
continue; gem_set_caching(fd, dst, c->level);
for (count = 1; count <= 1<<17; count <<= 1) { for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end; struct timeval start, end;
@ -136,11 +139,12 @@ int main(int argc, char **argv)
fflush(stdout); fflush(stdout);
} }
} }
}
free(src); free(src);
gem_close(fd, dst); gem_close(fd, dst);
close(fd); close(fd);
return 0; return drmtest_retval();
} }

View File

@ -131,11 +131,12 @@ static void do_test(int fd, int cache_level,
int loop) int loop)
{ {
if (cache_level != -1) { if (cache_level != -1) {
if (gem_set_caching(fd, tmp[0]->handle, cache_level) || gem_set_caching(fd, tmp[0]->handle, cache_level);
gem_set_caching(fd, tmp[1]->handle, cache_level)) gem_set_caching(fd, tmp[1]->handle, cache_level);
return;
} }
printf("meh");
do { do {
/* First, do a full-buffer read after blitting */ /* First, do a full-buffer read after blitting */
intel_copy_bo(batch, tmp[0], src[0], width, height); intel_copy_bo(batch, tmp[0], src[0], width, height);
@ -235,5 +236,5 @@ main(int argc, char **argv)
close(fd); close(fd);
return 0; return drmtest_retval();
} }

View File

@ -102,7 +102,10 @@ int main(int argc, char **argv)
drmtest_skip_on_simulation(); drmtest_skip_on_simulation();
if (argc > 1) drmtest_subtest_init(argc, argv);
drmtest_skip_on_simulation();
if (argc > 1 && atoi(argv[1]))
object_size = atoi(argv[1]); object_size = atoi(argv[1]);
if (object_size == 0) if (object_size == 0)
object_size = OBJECT_SIZE; object_size = OBJECT_SIZE;
@ -113,6 +116,7 @@ int main(int argc, char **argv)
dst = gem_create(fd, object_size); dst = gem_create(fd, object_size);
src = malloc(object_size); src = malloc(object_size);
drmtest_subtest_block("normal") {
for (count = 1; count <= 1<<17; count <<= 1) { for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end; struct timeval start, end;
@ -125,10 +129,11 @@ int main(int argc, char **argv)
bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6)); bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
fflush(stdout); fflush(stdout);
} }
}
for (c = cache; c->level != -1; c++) { for (c = cache; c->level != -1; c++) {
if (gem_set_caching(fd, dst, c->level)) drmtest_subtest_block(c->name) {
continue; gem_set_caching(fd, dst, c->level);
for (count = 1; count <= 1<<17; count <<= 1) { for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end; struct timeval start, end;
@ -143,11 +148,12 @@ int main(int argc, char **argv)
fflush(stdout); fflush(stdout);
} }
} }
}
free(src); free(src);
gem_close(fd, dst); gem_close(fd, dst);
close(fd); close(fd);
return 0; return drmtest_retval();
} }

View File

@ -398,8 +398,9 @@ int main(int argc, char **argv)
src = gem_create(fd, object_size); src = gem_create(fd, object_size);
tmp = malloc(object_size); tmp = malloc(object_size);
if (gem_set_caching(fd, src, 0) == 0 && gem_set_caching(fd, src, 0);
gem_set_caching(fd, dst, 0) == 0) { gem_set_caching(fd, dst, 0);
drmtest_subtest_block("uncached-copy-correctness") drmtest_subtest_block("uncached-copy-correctness")
test_copy(fd, src, dst, tmp, object_size); test_copy(fd, src, dst, tmp, object_size);
drmtest_subtest_block("uncached-copy-performance") { drmtest_subtest_block("uncached-copy-performance") {
@ -433,10 +434,10 @@ int main(int argc, char **argv)
fflush(stdout); fflush(stdout);
} }
} }
}
if (gem_set_caching(fd, src, 1) == 0 && gem_set_caching(fd, src, 1);
gem_set_caching(fd, dst, 1) == 0) { gem_set_caching(fd, dst, 1);
drmtest_subtest_block("snooped-copy-correctness") drmtest_subtest_block("snooped-copy-correctness")
test_copy(fd, src, dst, tmp, object_size); test_copy(fd, src, dst, tmp, object_size);
drmtest_subtest_block("snooped-copy-performance") { drmtest_subtest_block("snooped-copy-performance") {
@ -470,10 +471,10 @@ int main(int argc, char **argv)
fflush(stdout); fflush(stdout);
} }
} }
}
if (gem_set_caching(fd, src, 2) == 0 && gem_set_caching(fd, src, 2);
gem_set_caching(fd, dst, 2) == 0) { gem_set_caching(fd, dst, 2);
drmtest_subtest_block("display-copy-correctness") drmtest_subtest_block("display-copy-correctness")
test_copy(fd, src, dst, tmp, object_size); test_copy(fd, src, dst, tmp, object_size);
drmtest_subtest_block("display-copy-performance") { drmtest_subtest_block("display-copy-performance") {
@ -507,7 +508,6 @@ int main(int argc, char **argv)
fflush(stdout); fflush(stdout);
} }
} }
}
free(tmp); free(tmp);
gem_close(fd, src); gem_close(fd, src);
@ -515,5 +515,5 @@ int main(int argc, char **argv)
close(fd); close(fd);
return 0; return drmtest_retval();
} }