tests: introduce igt_require

Since igt_skip has funny control flow we can abuse it and make it work
like a special kind of assert which automatically skips tests if a
requirement fails.

Note that in places where we have a less strict test which should
always succeed (e.g. ioctl works or isn't available) the igt_assert
should be place before the igt_require with the more strict
requirements. Otherwise we'll skip a test instead of properly failing
it.

Convert a few users of igt_skip over to igt_require to showcase its
use.

v2: s/gem_check_/gem_require_/ so that we consistently use "require"
to indicate magic check that can call igt_skip. Imo hiding the
igt_require for feature checks is ok, but for more traditional assert
like use cases an explicit igt_require might be better.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Daniel Vetter
2013-08-13 13:20:58 +02:00
parent 5e25fcc285
commit 8f5387eb99
8 changed files with 83 additions and 91 deletions
+14 -12
View File
@@ -393,7 +393,7 @@ struct local_drm_i915_gem_caching {
#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)
void gem_check_caching(int fd)
void gem_require_caching(int fd)
{
struct local_drm_i915_gem_caching arg;
int ret;
@@ -405,11 +405,7 @@ void gem_check_caching(int fd)
ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg);
gem_close(fd, arg.handle);
if (ret != 0) {
if (!igt_only_list_subtests())
printf("no set_caching support detected\n");
igt_skip();
}
igt_require(ret == 0);
}
void gem_set_caching(int fd, uint32_t handle, int caching)
@@ -421,10 +417,8 @@ void gem_set_caching(int fd, uint32_t handle, int caching)
arg.caching = caching;
ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg);
if (ret != 0 && (errno == ENOTTY || errno == EINVAL))
igt_skip();
else
igt_assert(ret == 0);
igt_assert(ret == 0 || (errno == ENOTTY || errno == EINVAL));
igt_require(ret == 0);
}
uint32_t gem_get_caching(int fd, uint32_t handle)
@@ -770,6 +764,15 @@ void igt_skip(void)
exit(77);
}
void __igt_skip_check(const char *file, const int line,
const char *func, const char *check)
{
printf("Test requirement not met in function %s, file %s:%i:\n"
"Test requirement: (%s)\n",
func, file, line, check);
igt_skip();
}
void igt_success(void)
{
succeeded_one = true;
@@ -847,8 +850,7 @@ void igt_skip_on_simulation(void)
if (igt_only_list_subtests())
return;
if (igt_run_in_simulation())
igt_skip();
igt_require(!igt_run_in_simulation());
}
/* other helpers */