mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2026-08-20 21:02:59 +00:00
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:
+14
-12
@@ -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 */
|
||||
|
||||
+33
-25
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "xf86drm.h"
|
||||
#include "xf86drmMode.h"
|
||||
#include "i915_drm.h"
|
||||
#include "intel_batchbuffer.h"
|
||||
#include "intel_chipset.h"
|
||||
#include "intel_gpu_tools.h"
|
||||
@@ -104,41 +105,48 @@ bool __igt_run_subtest(const char *subtest_name);
|
||||
igt_success())
|
||||
bool igt_only_list_subtests(void);
|
||||
void igt_skip(void);
|
||||
void __igt_skip_check(const char *file, const int line,
|
||||
const char *func, const char *check);
|
||||
void igt_success(void);
|
||||
void igt_fail(int exitcode) __attribute__((noreturn));
|
||||
void __igt_fail_assert(int exitcode, const char *file,
|
||||
const int line, const char *func, const char *assertion)
|
||||
__attribute__((noreturn));
|
||||
void igt_exit(void);
|
||||
/**
|
||||
* igt_assert - fails (sub-)test if a condition is not met
|
||||
*
|
||||
* Should be used everywhere where a test checks results.
|
||||
*/
|
||||
#define igt_assert(expr) do { if (!(expr)) __igt_fail_assert(99, __FILE__, __LINE__, __func__, #expr ); } while (0)
|
||||
/**
|
||||
* igt_require - skip a (sub-)test if a condition is not met
|
||||
*
|
||||
* This is useful to streamline the skip logic since it allows for a more flat
|
||||
* code control flow.
|
||||
*/
|
||||
#define igt_require(expr) do { if (!(expr)) __igt_skip_check(__FILE__, __LINE__, __func__, #expr ); } while (0)
|
||||
|
||||
/* check functions which auto-skip tests by calling igt_skip() */
|
||||
void gem_check_caching(int fd);
|
||||
static inline bool gem_check_vebox(int fd)
|
||||
void gem_require_caching(int fd);
|
||||
static inline void gem_require_ring(int fd, int ring_id)
|
||||
{
|
||||
if (gem_has_vebox(fd))
|
||||
return true;
|
||||
|
||||
igt_skip();
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool gem_check_bsd(int fd)
|
||||
{
|
||||
if (HAS_BSD_RING(intel_get_drm_devid(fd)))
|
||||
return true;
|
||||
|
||||
igt_skip();
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool gem_check_blt(int fd)
|
||||
{
|
||||
if (HAS_BLT_RING(intel_get_drm_devid(fd)))
|
||||
return true;
|
||||
|
||||
igt_skip();
|
||||
return false;
|
||||
switch (ring_id) {
|
||||
case I915_EXEC_RENDER:
|
||||
return;
|
||||
case I915_EXEC_BLT:
|
||||
igt_require(HAS_BLT_RING(intel_get_drm_devid(fd)));
|
||||
return;
|
||||
case I915_EXEC_BSD:
|
||||
igt_require(HAS_BSD_RING(intel_get_drm_devid(fd)));
|
||||
return;
|
||||
case I915_EXEC_VEBOX:
|
||||
igt_require(gem_has_vebox(fd));
|
||||
return;
|
||||
default:
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* helpers to automatically reduce test runtime in simulation */
|
||||
|
||||
Reference in New Issue
Block a user