summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2013-08-13 13:20:58 +0200
committerDaniel Vetter <daniel.vetter@ffwll.ch>2013-08-13 15:15:18 +0200
commit8f5387eb99b640771812d28a0b949aca729bf296 (patch)
tree4ccb29a62ff7c4f055cf18fe31c9482ad16ae698 /lib/drmtest.c
parent5e25fcc285240353ab15bd4c3a0d0e02d970f45b (diff)
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>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index e601edd1..d0e463eb 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -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 */