[Intel-gfx] [PATCH 02/10] tests: Use igt macros more
Daniel Vetter
daniel.vetter at ffwll.ch
Wed May 14 11:53:35 CEST 2014
Often just folding together of the common if (cond) printf;
abort|igt_skip|igt_fail; pattern. But in a few cases I've ripped out
more since the igt macros will already print the condition and errno.
A few tests where more work (like ripping out return codes en masse)
is needed left as-is.
Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
tests/gem_ctx_bad_destroy.c | 19 +++---------------
tests/gem_ctx_create.c | 9 ++-------
tests/gem_dummy_reloc_loop.c | 7 ++-----
tests/gem_hang.c | 8 +++-----
tests/gem_linear_blits.c | 10 ++++------
tests/gem_lut_handle.c | 12 ++---------
tests/gem_media_fill.c | 8 +++-----
tests/gem_mmap_offset_exhaustion.c | 6 +-----
tests/gem_multi_bsd_sync_loop.c | 15 ++------------
tests/gem_pread_after_blit.c | 22 ++++++++------------
tests/gem_reg_read.c | 24 +++++-----------------
tests/gem_render_copy.c | 13 ++++--------
tests/gem_render_copy_redux.c | 8 +++-----
tests/gem_render_linear_blits.c | 15 +++++---------
tests/gem_render_tiled_blits.c | 15 +++++---------
tests/gem_set_tiling_vs_blt.c | 9 +++++----
tests/gem_set_tiling_vs_gtt.c | 12 +++++------
tests/gem_storedw_loop_vebox.c | 7 +------
tests/gem_tiled_blits.c | 10 ++++------
tests/gem_tiled_fence_blits.c | 10 ++++------
tests/gem_tiled_pread.c | 20 ++++++++-----------
tests/gem_userptr_blits.c | 16 +++++----------
tests/gen3_mixed_blits.c | 15 +++++---------
tests/gen3_render_linear_blits.c | 15 +++++---------
tests/gen3_render_mixed_blits.c | 15 +++++---------
tests/gen3_render_tiledx_blits.c | 15 +++++---------
tests/gen3_render_tiledy_blits.c | 15 +++++---------
tests/kms_setmode.c | 6 ++----
tests/pm_psr.c | 41 +++++++++++---------------------------
tests/pm_rc6_residency.c | 22 ++++++++------------
30 files changed, 131 insertions(+), 288 deletions(-)
diff --git a/tests/gem_ctx_bad_destroy.c b/tests/gem_ctx_bad_destroy.c
index 97a706660dc1..77091314bf0c 100644
--- a/tests/gem_ctx_bad_destroy.c
+++ b/tests/gem_ctx_bad_destroy.c
@@ -43,19 +43,6 @@ struct local_drm_i915_context_destroy {
#define CONTEXT_DESTROY_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2e, struct local_drm_i915_context_destroy)
-static void handle_bad(int ret, int lerrno, int expected, const char *desc)
-{
- if (ret != 0 && lerrno != expected) {
- fprintf(stderr, "%s - errno was %d, but should have been %d\n",
- desc, lerrno, expected);
- igt_fail(1);
- } else if (ret == 0) {
- fprintf(stderr, "%s - Command succeeded, but should have failed\n",
- desc);
- igt_fail(1);
- }
-}
-
igt_simple_main
{
struct local_drm_i915_context_destroy destroy;
@@ -75,17 +62,17 @@ igt_simple_main
/* try double destroy */
ret = drmIoctl(fd, CONTEXT_DESTROY_IOCTL, &destroy);
- handle_bad(ret, errno, ENOENT, "double destroy");
+ igt_assert(ret != 0 && errno == ENOENT);
/* destroy something random */
destroy.ctx_id = 2;
ret = drmIoctl(fd, CONTEXT_DESTROY_IOCTL, &destroy);
- handle_bad(ret, errno, ENOENT, "random destroy");
+ igt_assert(ret != 0 && errno == ENOENT);
/* Try to destroy the default context */
destroy.ctx_id = 0;
ret = drmIoctl(fd, CONTEXT_DESTROY_IOCTL, &destroy);
- handle_bad(ret, errno, ENOENT, "default destroy");
+ igt_assert(ret != 0 && errno == ENOENT);
close(fd);
}
diff --git a/tests/gem_ctx_create.c b/tests/gem_ctx_create.c
index 57494fc44638..522e7b1ca022 100644
--- a/tests/gem_ctx_create.c
+++ b/tests/gem_ctx_create.c
@@ -52,13 +52,8 @@ igt_simple_main
fd = drm_open_any_render();
ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
- if (ret != 0 && (errno == ENODEV || errno == EINVAL)) {
- igt_skip("Kernel is too old, or contexts not supported: %s\n",
- strerror(errno));
- } else if (ret != 0) {
- fprintf(stderr, "%s\n", strerror(errno));
- igt_fail(1);
- }
+ igt_skip_on(ret != 0 && (errno == ENODEV || errno == EINVAL));
+ igt_assert(ret == 0);
igt_assert(create.ctx_id != 0);
close(fd);
diff --git a/tests/gem_dummy_reloc_loop.c b/tests/gem_dummy_reloc_loop.c
index 21c8c578e961..4fe07860b69c 100644
--- a/tests/gem_dummy_reloc_loop.c
+++ b/tests/gem_dummy_reloc_loop.c
@@ -205,11 +205,8 @@ igt_main
{
unsigned int target_flink;
char buffer_name[32];
- if (dri_bo_flink(target_buffer, &target_flink)) {
- igt_info("fail to get flink for target buffer\n");
- igt_assert_f(0, "fail to create global "
- "gem_handle for target buffer\n");
- }
+ igt_assert(dri_bo_flink(target_buffer, &target_flink) == 0);
+
for (i = 0; i < NUM_FD; i++) {
sprintf(buffer_name, "Target buffer %d\n", i);
mfd[i] = drm_open_any();
diff --git a/tests/gem_hang.c b/tests/gem_hang.c
index 656d9cd1f67a..8ebf60677206 100644
--- a/tests/gem_hang.c
+++ b/tests/gem_hang.c
@@ -72,11 +72,9 @@ int main(int argc, char **argv)
{
int fd;
- if (argc != 2) {
- fprintf(stderr, "usage: %s <disabled pipe number>\n",
- argv[0]);
- igt_fail(-1);
- }
+ igt_assert_f(argc == 2,
+ "usage: %s <disabled pipe number>\n",
+ argv[0]);
bad_pipe = atoi(argv[1]);
diff --git a/tests/gem_linear_blits.c b/tests/gem_linear_blits.c
index c8b6f8907a11..3a2fd8dd19fe 100644
--- a/tests/gem_linear_blits.c
+++ b/tests/gem_linear_blits.c
@@ -178,12 +178,10 @@ check_bo(int fd, uint32_t handle, uint32_t val)
gem_read(fd, handle, 0, linear, sizeof(linear));
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (linear[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, linear[i], i * 4);
- abort();
- }
+ igt_assert_f(linear[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, linear[i], i * 4);
val++;
}
}
diff --git a/tests/gem_lut_handle.c b/tests/gem_lut_handle.c
index 14e39778b24e..d3f6f732577f 100644
--- a/tests/gem_lut_handle.c
+++ b/tests/gem_lut_handle.c
@@ -169,16 +169,8 @@ static int many_exec(int fd, uint32_t batch, int num_exec, int num_reloc, unsign
return ret;
}
-#define _fail(x) ((x) == -ENOENT)
-#define ASSERT(x, y) do { \
- if (!(x)) { \
- fprintf(stderr, "%s:%d failed, errno=%d\n", \
- __FUNCTION__, __LINE__, -y); \
- abort(); \
- } \
-} while (0)
-#define fail(x) ASSERT(_fail(x), x)
-#define pass(x) ASSERT(!_fail(x), x)
+#define fail(x) igt_assert((x) == -ENOENT)
+#define pass(x) igt_assert((x) == 0)
igt_simple_main
{
diff --git a/tests/gem_media_fill.c b/tests/gem_media_fill.c
index cb081d8bde2b..db2380b44ca1 100644
--- a/tests/gem_media_fill.c
+++ b/tests/gem_media_fill.c
@@ -92,11 +92,9 @@ scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
gem_read(data->drm_fd, buf->bo->handle, 0,
data->linear, sizeof(data->linear));
val = data->linear[y * WIDTH + x];
- if (val != color) {
- fprintf(stderr, "Expected 0x%02x, found 0x%02x at (%d,%d)\n",
- color, val, x, y);
- abort();
- }
+ igt_assert_f(val == color,
+ "Expected 0x%02x, found 0x%02x at (%d,%d)\n",
+ color, val, x, y);
}
igt_simple_main
diff --git a/tests/gem_mmap_offset_exhaustion.c b/tests/gem_mmap_offset_exhaustion.c
index d5939ecbdfd2..914fe6ebb188 100644
--- a/tests/gem_mmap_offset_exhaustion.c
+++ b/tests/gem_mmap_offset_exhaustion.c
@@ -59,11 +59,7 @@ create_and_map_bo(int fd)
handle = gem_create(fd, OBJECT_SIZE);
ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-
- if (!ptr) {
- fprintf(stderr, "mmap failed\n");
- igt_assert(ptr);
- }
+ igt_assert(ptr);
/* touch it to force it into the gtt */
*ptr = 0;
diff --git a/tests/gem_multi_bsd_sync_loop.c b/tests/gem_multi_bsd_sync_loop.c
index b01764aec399..003da42fa05e 100644
--- a/tests/gem_multi_bsd_sync_loop.c
+++ b/tests/gem_multi_bsd_sync_loop.c
@@ -125,12 +125,8 @@ igt_simple_main
{
unsigned int target_flink;
char buffer_name[32];
- if (dri_bo_flink(target_buffer, &target_flink)) {
- printf("fail to get flink for target buffer\n");
- igt_assert_f(0, "fail to create global gem handle"
- " for allocated buffer\n");
- goto fail_flink;
- }
+ igt_assert(dri_bo_flink(target_buffer, &target_flink) == 0);
+
for (i = 0; i < NUM_FD; i++) {
sprintf(buffer_name, "Target buffer %d\n", i);
mfd[i] = drm_open_any();
@@ -165,11 +161,4 @@ igt_simple_main
drm_intel_bufmgr_destroy(bufmgr);
close(fd);
- return;
-
-fail_flink:
- drm_intel_bo_unreference(target_buffer);
- drm_intel_bufmgr_destroy(bufmgr);
-
- close(fd);
}
diff --git a/tests/gem_pread_after_blit.c b/tests/gem_pread_after_blit.c
index e80ff1740553..0b8bfa6ccf40 100644
--- a/tests/gem_pread_after_blit.c
+++ b/tests/gem_pread_after_blit.c
@@ -88,13 +88,10 @@ verify_large_read(drm_intel_bo *bo, uint32_t val)
drm_intel_bo_get_subdata(bo, 0, size, buf);
for (i = 0; i < size / 4; i++) {
- if (buf[i] != val) {
- fprintf(stderr,
- "Unexpected value 0x%08x instead of "
- "0x%08x at offset 0x%08x (%p)\n",
- buf[i], val, i * 4, buf);
- abort();
- }
+ igt_assert_f(buf[i] == val,
+ "Unexpected value 0x%08x instead of "
+ "0x%08x at offset 0x%08x (%p)\n",
+ buf[i], val, i * 4, buf);
val++;
}
}
@@ -113,13 +110,10 @@ verify_small_read(drm_intel_bo *bo, uint32_t val)
drm_intel_bo_get_subdata(bo, offset, PAGE_SIZE, buf);
for (i = 0; i < PAGE_SIZE; i += 4) {
- if (buf[i / 4] != val) {
- fprintf(stderr,
- "Unexpected value 0x%08x instead of "
- "0x%08x at offset 0x%08x\n",
- buf[i / 4], val, i * 4);
- abort();
- }
+ igt_assert_f(buf[i / 4] == val,
+ "Unexpected value 0x%08x instead of "
+ "0x%08x at offset 0x%08x\n",
+ buf[i / 4], val, i * 4);
val++;
}
}
diff --git a/tests/gem_reg_read.c b/tests/gem_reg_read.c
index b4a6650a64d4..ac0fc1a7fef3 100644
--- a/tests/gem_reg_read.c
+++ b/tests/gem_reg_read.c
@@ -39,19 +39,6 @@ struct local_drm_i915_reg_read {
#define REG_READ_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x31, struct local_drm_i915_reg_read)
-static void handle_bad(int ret, int expected, const char *desc)
-{
- if (ret != 0 && errno != expected) {
- fprintf(stderr, "%s - errno was %d, but should have been %d\n",
- desc, errno, expected);
- igt_fail(1);
- } else if (ret == 0) {
- fprintf(stderr, "%s - Command succeeded, but should have failed\n",
- desc);
- igt_fail(1);
- }
-}
-
static uint64_t timer_query(int fd)
{
struct local_drm_i915_reg_read reg_read;
@@ -79,15 +66,14 @@ igt_simple_main
reg_read.val = timer_query(fd);
sleep(1);
- if (timer_query(fd) == reg_read.val) {
- fprintf(stderr, "Timer isn't moving, probably busted\n");
- igt_fail(1);
- }
+ /* Check that timer is moving and isn't busted. */
+ igt_assert(timer_query(fd) != reg_read.val);
/* bad reg */
reg_read.offset = 0x12345678;
- handle_bad(drmIoctl(fd, REG_READ_IOCTL, ®_read),
- EINVAL, "bad register");
+ ret = drmIoctl(fd, REG_READ_IOCTL, ®_read);
+
+ igt_assert(ret != 0 && errno == ENOENT);
close(fd);
}
diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c
index 331b7ce5c6a2..fd26b43f8cdf 100644
--- a/tests/gem_render_copy.c
+++ b/tests/gem_render_copy.c
@@ -80,10 +80,7 @@ static void scratch_buf_write_to_png(struct igt_buf *buf, const char *filename)
igt_buf_height(buf),
buf->stride);
ret = cairo_surface_write_to_png(surface, filename);
- if (ret != CAIRO_STATUS_SUCCESS) {
- fprintf(stderr, "%s: %s\n", __func__,
- cairo_status_to_string(ret));
- }
+ igt_assert(ret == CAIRO_STATUS_SUCCESS);
cairo_surface_destroy(surface);
drm_intel_bo_unmap(buf->bo);
}
@@ -115,11 +112,9 @@ scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
gem_read(data->drm_fd, buf->bo->handle, 0,
data->linear, sizeof(data->linear));
val = data->linear[y * WIDTH + x];
- if (val != color) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x at (%d,%d)\n",
- color, val, x, y);
- abort();
- }
+ igt_assert_f(val == color,
+ "Expected 0x%08x, found 0x%08x at (%d,%d)\n",
+ color, val, x, y);
}
int main(int argc, char **argv)
diff --git a/tests/gem_render_copy_redux.c b/tests/gem_render_copy_redux.c
index 4becb6074583..73dcb7228894 100644
--- a/tests/gem_render_copy_redux.c
+++ b/tests/gem_render_copy_redux.c
@@ -128,11 +128,9 @@ scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
gem_read(data->fd, buf->bo->handle, 0,
data->linear, sizeof(data->linear));
val = data->linear[y * WIDTH + x];
- if (val != color) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x at (%d,%d)\n",
- color, val, x, y);
- abort();
- }
+ igt_assert_f(val == color,
+ "Expected 0x%08x, found 0x%08x at (%d,%d)\n",
+ color, val, x, y);
}
static void copy(data_t *data)
diff --git a/tests/gem_render_linear_blits.c b/tests/gem_render_linear_blits.c
index 7b316bdffb60..fd7c2be20ee9 100644
--- a/tests/gem_render_linear_blits.c
+++ b/tests/gem_render_linear_blits.c
@@ -73,12 +73,10 @@ check_bo(int fd, uint32_t handle, uint32_t val)
gem_read(fd, handle, 0, linear, sizeof(linear));
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (linear[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, linear[i], i * 4);
- abort();
- }
+ igt_assert_f(linear[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, linear[i], i * 4);
val++;
}
}
@@ -97,10 +95,7 @@ int main(int argc, char **argv)
fd = drm_open_any();
render_copy = igt_get_render_copyfunc(intel_get_drm_devid(fd));
- if (render_copy == NULL) {
- printf("no render-copy function, doing nothing\n");
- return 77;
- }
+ igt_require(render_copy);
bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
diff --git a/tests/gem_render_tiled_blits.c b/tests/gem_render_tiled_blits.c
index a9a88866b4d1..8b74e2b419d8 100644
--- a/tests/gem_render_tiled_blits.c
+++ b/tests/gem_render_tiled_blits.c
@@ -85,12 +85,10 @@ check_bo(struct intel_batchbuffer *batch, struct igt_buf *buf, uint32_t val)
ptr = data;
}
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (ptr[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, ptr[i], i * 4);
- abort();
- }
+ igt_assert_f(ptr[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, ptr[i], i * 4);
val++;
}
if (ptr != data)
@@ -115,10 +113,7 @@ int main(int argc, char **argv)
devid = intel_get_drm_devid(fd);
render_copy = igt_get_render_copyfunc(devid);
- if (render_copy == NULL) {
- printf("no render-copy function, doing nothing\n");
- return 77;
- }
+ igt_require(render_copy);
snoop = 1;
if (IS_GEN2(devid)) /* chipset only handles cached -> uncached */
diff --git a/tests/gem_set_tiling_vs_blt.c b/tests/gem_set_tiling_vs_blt.c
index 3fac012e8cf5..d9751552047e 100644
--- a/tests/gem_set_tiling_vs_blt.c
+++ b/tests/gem_set_tiling_vs_blt.c
@@ -134,8 +134,9 @@ static void do_test(uint32_t tiling, unsigned stride,
/* note we need a bo bigger than batches, otherwise the buffer reuse
* trick will fail. */
test_bo = drm_intel_bo_alloc(bufmgr, "busy bo", TEST_SIZE, 4096);
- if (test_bo_handle != test_bo->handle)
- fprintf(stderr, "libdrm reuse trick failed\n");
+ /* double check that the reuse trick worked */
+ igt_assert(test_bo_handle == test_bo->handle);
+
test_bo_handle = test_bo->handle;
/* ensure we have the right tiling before we start. */
ret = drm_intel_bo_set_tiling(test_bo, &tiling, stride);
@@ -176,8 +177,8 @@ static void do_test(uint32_t tiling, unsigned stride,
drm_intel_bo_unreference(test_bo);
test_bo = drm_intel_bo_alloc_for_render(bufmgr, "tiled busy bo", TEST_SIZE, 4096);
- if (test_bo_handle != test_bo->handle)
- fprintf(stderr, "libdrm reuse trick failed\n");
+ /* double check that the reuse trick worked */
+ igt_assert(test_bo_handle == test_bo->handle);
ret = drm_intel_bo_set_tiling(test_bo, &tiling_after, stride_after);
igt_assert(ret == 0);
diff --git a/tests/gem_set_tiling_vs_gtt.c b/tests/gem_set_tiling_vs_gtt.c
index dc6ee5be0e65..e0ef2b7bb701 100644
--- a/tests/gem_set_tiling_vs_gtt.c
+++ b/tests/gem_set_tiling_vs_gtt.c
@@ -105,13 +105,11 @@ igt_simple_main
+ half*tile_height + ofs;
uint32_t val = data[data_i];
- if (ptr[i] != val) {
- printf("mismatch at %i, row=%i, half=%i, ofs=%i\n",
- i, row, half, ofs);
- printf("read: 0x%08x, expected: 0x%08x\n",
- ptr[i], val);
- igt_assert(0);
- }
+ igt_assert_f(ptr[i] == val,
+ "mismatch at %i, row=%i, half=%i, ofs=%i, "
+ "read: 0x%08x, expected: 0x%08x\n",
+ i, row, half, ofs,
+ ptr[i], val);
}
diff --git a/tests/gem_storedw_loop_vebox.c b/tests/gem_storedw_loop_vebox.c
index eb8783f0791a..b8215fc4919c 100644
--- a/tests/gem_storedw_loop_vebox.c
+++ b/tests/gem_storedw_loop_vebox.c
@@ -80,12 +80,7 @@ store_dword_loop(int divider)
drm_intel_bo_map(target_buffer, 0);
buf = target_buffer->virtual;
- if (buf[0] != val) {
- fprintf(stderr,
- "value mismatch: cur 0x%08x, stored 0x%08x\n",
- buf[0], val);
- igt_fail(-1);
- }
+ igt_assert_cmpint (buf[0], ==, val);
drm_intel_bo_unmap(target_buffer);
diff --git a/tests/gem_tiled_blits.c b/tests/gem_tiled_blits.c
index ac7013440ac9..cb135ce4020c 100644
--- a/tests/gem_tiled_blits.c
+++ b/tests/gem_tiled_blits.c
@@ -105,12 +105,10 @@ check_bo(drm_intel_bo *bo, uint32_t start_val)
linear = linear_bo->virtual;
for (i = 0; i < 1024 * 1024 / 4; i++) {
- if (linear[i] != start_val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- start_val, linear[i], i * 4);
- abort();
- }
+ igt_assert_f(linear[i] == start_val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ start_val, linear[i], i * 4);
start_val++;
}
drm_intel_bo_unmap(linear_bo);
diff --git a/tests/gem_tiled_fence_blits.c b/tests/gem_tiled_fence_blits.c
index bd2935f20546..e3f322e3dbf8 100644
--- a/tests/gem_tiled_fence_blits.c
+++ b/tests/gem_tiled_fence_blits.c
@@ -94,12 +94,10 @@ check_bo(int fd, drm_intel_bo *bo, uint32_t start_val)
gem_read(fd, bo->handle, 0, linear, sizeof(linear));
for (i = 0; i < 1024 * 1024 / 4; i++) {
- if (linear[i] != start_val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- start_val, linear[i], i * 4);
- abort();
- }
+ igt_assert_f(linear[i] == start_val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ start_val, linear[i], i * 4);
start_val++;
}
}
diff --git a/tests/gem_tiled_pread.c b/tests/gem_tiled_pread.c
index 6eb6834e518b..4815b72473e0 100644
--- a/tests/gem_tiled_pread.c
+++ b/tests/gem_tiled_pread.c
@@ -211,21 +211,17 @@ igt_simple_main
swizzle_str = "bit9^10^11";
break;
default:
- fprintf(stderr, "Bad swizzle bits; %d\n",
- swizzle);
- abort();
+ igt_assert_f(0, "Bad swizzle bits; %d\n",
+ swizzle);
}
expected_val = calculate_expected(swizzled_offset);
found_val = linear[(j - offset) / 4];
- if (expected_val != found_val) {
- fprintf(stderr,
- "Bad read [%d]: %d instead of %d at 0x%08x "
- "for read from 0x%08x to 0x%08x, swizzle=%s\n",
- i, found_val, expected_val, j,
- offset, offset + len,
- swizzle_str);
- abort();
- }
+ igt_assert_f(expected_val == found_val,
+ "Bad read [%d]: %d instead of %d at 0x%08x "
+ "for read from 0x%08x to 0x%08x, swizzle=%s\n",
+ i, found_val, expected_val, j,
+ offset, offset + len,
+ swizzle_str);
}
}
diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c
index b78edf8c4ed0..86c5d6669ed6 100644
--- a/tests/gem_userptr_blits.c
+++ b/tests/gem_userptr_blits.c
@@ -401,12 +401,10 @@ check_cpu(uint32_t *ptr, uint32_t val)
int i;
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (ptr[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, ptr[i], i * 4);
- abort();
- }
+ igt_assert_f(ptr[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, ptr[i], i * 4);
val++;
}
}
@@ -770,11 +768,7 @@ static int test_coherency(int fd, int count)
igt_info("Using 2x%d 1MiB buffers\n", count);
ret = posix_memalign((void **)&memory, PAGE_SIZE, count*sizeof(linear));
- if (ret != 0 || memory == NULL) {
- fprintf(stderr, "Unable to allocate %lld bytes\n",
- (long long)count*sizeof(linear));
- return 1;
- }
+ igt_assert(ret == 0 && memory);
gpu = malloc(sizeof(uint32_t)*count*4);
gpu_val = gpu + count;
diff --git a/tests/gen3_mixed_blits.c b/tests/gen3_mixed_blits.c
index bd1d7cf41ac3..75d61a58d46b 100644
--- a/tests/gen3_mixed_blits.c
+++ b/tests/gen3_mixed_blits.c
@@ -448,12 +448,10 @@ check_bo(int fd, uint32_t handle, uint32_t val)
v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
igt_assert(v);
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (v[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, v[i], i * 4);
- abort();
- }
+ igt_assert_f(v[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, v[i], i * 4);
val++;
}
munmap(v, WIDTH*HEIGHT*4);
@@ -469,10 +467,7 @@ int main(int argc, char **argv)
fd = drm_open_any();
- if (!IS_GEN3(intel_get_drm_devid(fd))) {
- printf("gen3-only test, doing nothing\n");
- return 77;
- }
+ igt_require(IS_GEN3(intel_get_drm_devid(fd)));
count = 0;
if (argc > 1)
diff --git a/tests/gen3_render_linear_blits.c b/tests/gen3_render_linear_blits.c
index 5ac711cd8555..7fe368d61822 100644
--- a/tests/gen3_render_linear_blits.c
+++ b/tests/gen3_render_linear_blits.c
@@ -317,12 +317,10 @@ check_bo(int fd, uint32_t handle, uint32_t val)
gem_read(fd, handle, 0, linear, sizeof(linear));
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (linear[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, linear[i], i * 4);
- abort();
- }
+ igt_assert_f(linear[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, linear[i], i * 4);
val++;
}
}
@@ -337,10 +335,7 @@ int main(int argc, char **argv)
fd = drm_open_any();
- if (!IS_GEN3(intel_get_drm_devid(fd))) {
- printf("gen3-only test, doing nothing\n");
- return 77;
- }
+ igt_require(IS_GEN3(intel_get_drm_devid(fd)));
count = 0;
if (argc > 1)
diff --git a/tests/gen3_render_mixed_blits.c b/tests/gen3_render_mixed_blits.c
index 8c6cf7df6127..77ac0e2f28c8 100644
--- a/tests/gen3_render_mixed_blits.c
+++ b/tests/gen3_render_mixed_blits.c
@@ -336,12 +336,10 @@ check_bo(int fd, uint32_t handle, uint32_t val)
v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
igt_assert(v);
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (v[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, v[i], i * 4);
- abort();
- }
+ igt_assert_f(v[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, v[i], i * 4);
val++;
}
munmap(v, WIDTH*HEIGHT*4);
@@ -357,10 +355,7 @@ int main(int argc, char **argv)
fd = drm_open_any();
- if (!IS_GEN3(intel_get_drm_devid(fd))) {
- printf("gen3-only test, doing nothing\n");
- return 77;
- }
+ igt_require(IS_GEN3(intel_get_drm_devid(fd)));
count = 0;
if (argc > 1)
diff --git a/tests/gen3_render_tiledx_blits.c b/tests/gen3_render_tiledx_blits.c
index e9c0679e9ed6..95c0c96bba6b 100644
--- a/tests/gen3_render_tiledx_blits.c
+++ b/tests/gen3_render_tiledx_blits.c
@@ -323,12 +323,10 @@ check_bo(int fd, uint32_t handle, uint32_t val)
v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
igt_assert(v);
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (v[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, v[i], i * 4);
- abort();
- }
+ igt_assert_f(v[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, v[i], i * 4);
val++;
}
munmap(v, WIDTH*HEIGHT*4);
@@ -344,10 +342,7 @@ int main(int argc, char **argv)
fd = drm_open_any();
- if (!IS_GEN3(intel_get_drm_devid(fd))) {
- printf("gen3-only test, doing nothing\n");
- return 77;
- }
+ igt_require(IS_GEN3(intel_get_drm_devid(fd)));
count = 0;
if (argc > 1)
diff --git a/tests/gen3_render_tiledy_blits.c b/tests/gen3_render_tiledy_blits.c
index 93803fbe70ee..1b9a41961dd2 100644
--- a/tests/gen3_render_tiledy_blits.c
+++ b/tests/gen3_render_tiledy_blits.c
@@ -323,12 +323,10 @@ check_bo(int fd, uint32_t handle, uint32_t val)
v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
igt_assert(v);
for (i = 0; i < WIDTH*HEIGHT; i++) {
- if (v[i] != val) {
- fprintf(stderr, "Expected 0x%08x, found 0x%08x "
- "at offset 0x%08x\n",
- val, v[i], i * 4);
- abort();
- }
+ igt_assert_f(v[i] == val,
+ "Expected 0x%08x, found 0x%08x "
+ "at offset 0x%08x\n",
+ val, v[i], i * 4);
val++;
}
munmap(v, WIDTH*HEIGHT*4);
@@ -344,10 +342,7 @@ int main(int argc, char **argv)
fd = drm_open_any();
- if (!IS_GEN3(intel_get_drm_devid(fd))) {
- printf("gen3-only test, doing nothing\n");
- return 77;
- }
+ igt_require(IS_GEN3(intel_get_drm_devid(fd)));
count = 0;
if (argc > 1)
diff --git a/tests/kms_setmode.c b/tests/kms_setmode.c
index 02d5850a6e35..0b765a9c4cb5 100644
--- a/tests/kms_setmode.c
+++ b/tests/kms_setmode.c
@@ -709,10 +709,8 @@ int main(int argc, char **argv)
igt_skip_on_simulation();
- if (dry_run && filter_test_id) {
- fprintf(stderr, "only one of -d and -t is accepted\n");
- exit(1);
- }
+ igt_assert_f(!(dry_run && filter_test_id),
+ "only one of -d and -t is accepted\n");
igt_fixture {
drm_fd = drm_open_any();
diff --git a/tests/pm_psr.c b/tests/pm_psr.c
index 4ba121f10a38..3ab7e7a04870 100644
--- a/tests/pm_psr.c
+++ b/tests/pm_psr.c
@@ -38,44 +38,29 @@
static int get_perf(const char *path)
{
int ret, perf;
- bool sink, source, enabled;
FILE *file;
char str[4];
file = fopen(path, "r");
- if (file == NULL) {
- fprintf(stderr, "Couldn't open %s (%d)\n", path, errno);
- abort();
- }
+ igt_assert(file);
ret = fscanf(file, "Sink_Support: %s\n", str);
- if (ret == 0)
- igt_skip("i915_edp_psr_status format not supported by this test case\n");
- sink = strcmp(str, "yes") == 0;
+ igt_skip_on_f(ret == 0,
+ "i915_edp_psr_status format not supported by this test case\n");
+ igt_require(strcmp(str, "yes") == 0);
ret = fscanf(file, "Source_OK: %s\n", str);
igt_assert(ret != 0);
- source = strcmp(str, "yes") == 0;
+
+ igt_require(strcmp(str, "yes") == 0);
+
ret = fscanf(file, "Enabled: %s\n", str);
igt_assert(ret != 0);
- enabled = strcmp(str, "yes") == 0;
+ igt_assert(strcmp(str, "yes") == 0);
+
ret = fscanf(file, "Performance_Counter: %i", &perf);
igt_assert(ret != 0);
- if (!sink)
- igt_skip("This panel does not support PSR.\n");
-
- if (!source)
- igt_skip("This Hardware does not support or isn't ready for PSR\n");
-
- if (!enabled) {
- fprintf(stderr, "PSR should be enabled\n");
- igt_fail(1);
- }
-
- if (perf == 0) {
- fprintf(stderr, "PSR state never achieved\n");
- igt_fail(1);
- }
+ igt_assert(perf);
fclose(file);
return perf;
@@ -96,8 +81,6 @@ igt_simple_main
sleep(SLEEP_DURATION / 1000);
perf2 = get_perf(path);
- if (perf1 == perf2) {
- fprintf(stderr, "Unable to enter PSR state again\n");
- igt_fail(1);
- }
+ igt_assert_f(perf1 != perf2,
+ "Unable to enter PSR state again\n");
}
diff --git a/tests/pm_rc6_residency.c b/tests/pm_rc6_residency.c
index 84eb8a909019..197ab0022d51 100644
--- a/tests/pm_rc6_residency.c
+++ b/tests/pm_rc6_residency.c
@@ -44,10 +44,8 @@ static unsigned int readit(const char *path)
FILE *file;
file = fopen(path, "r");
- if (file == NULL) {
- fprintf(stderr, "Couldn't open %s (%d)\n", path, errno);
- abort();
- }
+ igt_assert_f(file,
+ "Couldn't open %s (%d)\n", path, errno);
scanned = fscanf(file, "%u", &ret);
igt_assert(scanned == 1);
@@ -108,14 +106,10 @@ igt_simple_main
(value2p - value1p) +
(value2 - value1);
- if (diff > (SLEEP_DURATION + RC6_FUDGE)) {
- fprintf(stderr, "Diff was too high. That is unpossible\n");
- igt_fail(1);
- }
- if (diff < (SLEEP_DURATION - RC6_FUDGE)) {
- fprintf(stderr, "GPU was not in RC6 long enough. Check that "
- "the GPU is as idle as possible (ie. no X, "
- "running and running no other tests)\n");
- igt_fail(1);
- }
+ igt_assert_f(diff <= (SLEEP_DURATION + RC6_FUDGE),
+ "Diff was too high. That is unpossible\n");
+ igt_assert_f(diff >= (SLEEP_DURATION - RC6_FUDGE),
+ "GPU was not in RC6 long enough. Check that "
+ "the GPU is as idle as possible (ie. no X, "
+ "running and running no other tests)\n");
}
--
1.9.2
More information about the Intel-gfx
mailing list