[PATCH i-g-t 27/33] Replace a bunch of open-coded igt_asserts with igt_assert_fd()

Lyude lyude at redhat.com
Fri Jun 7 23:08:15 UTC 2019


From: Lyude Paul <lyude at redhat.com>

This finishes the job we started in the last commit, and fixes the false
positives that were picked up by the igt_assert_comparisons.cocci
script which should have been using igt_assert_fd() instead of one of
the other comparison macros.

Signed-off-by: Lyude Paul <lyude at redhat.com>
---
 lib/igt_aux.c                   |  2 +-
 lib/igt_core.c                  |  2 +-
 lib/igt_debugfs.c               |  6 +++---
 lib/igt_dummyload.c             |  6 +++---
 lib/igt_frame.c                 |  2 +-
 lib/igt_psr.c                   |  2 +-
 lib/igt_sysfs.c                 |  2 +-
 tests/debugfs_test.c            |  5 ++---
 tests/i915/gem_concurrent_all.c |  4 ++--
 tests/i915/gem_eio.c            |  8 ++++----
 tests/i915/gem_exec_fence.c     |  4 ++--
 tests/i915/gem_reset_stats.c    |  8 ++++----
 tests/kms_chamelium.c           |  2 +-
 tests/kms_dp_dsc.c              |  2 +-
 tests/kms_vrr.c                 |  2 +-
 tests/perf.c                    |  2 +-
 tests/perf_pmu.c                | 12 ++++++------
 tests/vgem_basic.c              |  6 +++---
 18 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index d3817616..2648d0e4 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1200,7 +1200,7 @@ static void igt_save_module_param(const char *name, const char *file_path)
 	strncpy(data->name, name, PARAM_NAME_MAX_SZ - 1);
 
 	fd = open(file_path, O_RDONLY);
-	igt_assert(fd >= 0);
+	igt_assert_fd(fd);
 
 	n = read(fd, data->original_value, PARAM_VALUE_MAX_SZ);
 	igt_assert_f(n > 0 && n < PARAM_VALUE_MAX_SZ,
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 6b9f0425..be1160c0 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -570,7 +570,7 @@ static void oom_adjust_for_doom(void)
 	const char always_kill[] = "1000";
 
 	fd = open("/proc/self/oom_score_adj", O_WRONLY);
-	igt_assert(fd != -1);
+	igt_assert_fd(fd);
 	igt_assert(write(fd, always_kill, sizeof(always_kill)) == sizeof(always_kill));
 	close(fd);
 
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 6eebd2b9..0c4bc53c 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -651,13 +651,13 @@ pipe_crc_new(int fd, enum pipe pipe, const char *source, int flags)
 	igt_assert(source);
 
 	debugfs = igt_debugfs_dir(fd);
-	igt_assert(debugfs != -1);
+	igt_assert_fd(debugfs);
 
 	pipe_crc = calloc(1, sizeof(struct _igt_pipe_crc));
 
 	sprintf(buf, "crtc-%d/crc/control", pipe);
 	pipe_crc->ctl_fd = openat(debugfs, buf, O_WRONLY);
-	igt_assert(pipe_crc->ctl_fd != -1);
+	igt_assert_fd(pipe_crc->ctl_fd);
 
 	pipe_crc->crc_fd = -1;
 	pipe_crc->fd = fd;
@@ -802,7 +802,7 @@ void igt_pipe_crc_start(igt_pipe_crc_t *pipe_crc)
 
 	igt_set_timeout(10, "Opening crc fd, and poll for first CRC.");
 	pipe_crc->crc_fd = openat(pipe_crc->dir, buf, pipe_crc->flags);
-	igt_assert(pipe_crc->crc_fd != -1);
+	igt_assert_fd(pipe_crc->crc_fd);
 
 	pfd.fd = pipe_crc->crc_fd;
 	pfd.events = POLLIN;
diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index d00fc715..dab6e309 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -245,7 +245,7 @@ emit_recursive_batch(igt_spin_t *spin,
 		if (opts->flags & IGT_SPIN_FENCE_OUT) {
 			int _fd = execbuf->rsvd2 >> 32;
 
-			igt_assert(_fd >= 0);
+			igt_assert_fd(_fd);
 			if (fence_fd == -1) {
 				fence_fd = _fd;
 			} else {
@@ -255,7 +255,7 @@ emit_recursive_batch(igt_spin_t *spin,
 				close(old_fd);
 				close(_fd);
 			}
-			igt_assert(fence_fd >= 0);
+			igt_assert_fd(fence_fd);
 		}
 	}
 
@@ -572,7 +572,7 @@ uint32_t igt_cork_plug(struct igt_cork *cork, int fd)
  */
 void igt_cork_unplug(struct igt_cork *cork)
 {
-	igt_assert(cork->fd != -1);
+	igt_assert_fd(cork->fd);
 
 	switch (cork->type) {
 	case CORK_SYNC_FD:
diff --git a/lib/igt_frame.c b/lib/igt_frame.c
index 45523a79..2b8dba0c 100644
--- a/lib/igt_frame.c
+++ b/lib/igt_frame.c
@@ -129,7 +129,7 @@ void igt_write_compared_frames_to_png(cairo_surface_t *reference,
 			 igt_frame_dump_path, test_name, subtest_name);
 
 	fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
-	igt_assert(fd >= 0);
+	igt_assert_fd(fd);
 
 	igt_debug("Writing dump report to %s...\n", path);
 
diff --git a/lib/igt_psr.c b/lib/igt_psr.c
index 9aa7c357..7adb47d1 100644
--- a/lib/igt_psr.c
+++ b/lib/igt_psr.c
@@ -145,7 +145,7 @@ static bool psr_set(int debugfs_fd, int mode)
 	/* Restore original value on exit */
 	if (psr_restore_debugfs_fd == -1) {
 		psr_restore_debugfs_fd = dup(debugfs_fd);
-		igt_assert(psr_restore_debugfs_fd >= 0);
+		igt_assert_fd(psr_restore_debugfs_fd);
 		igt_install_exit_handler(restore_psr_debugfs);
 	}
 
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index c439944d..2d8ae0ab 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -644,7 +644,7 @@ void fbcon_blink_enable(bool enable)
 			 sizeof(fbcon_cursor_blink_prev_value));
 		if (r > 0) {
 			fbcon_cursor_blink_fd = dup(fd);
-			igt_assert(fbcon_cursor_blink_fd >= 0);
+			igt_assert_fd(fbcon_cursor_blink_fd);
 			igt_install_exit_handler(fbcon_cursor_blink_restore);
 		}
 	}
diff --git a/tests/debugfs_test.c b/tests/debugfs_test.c
index 6a87d90a..bb63d79c 100644
--- a/tests/debugfs_test.c
+++ b/tests/debugfs_test.c
@@ -50,9 +50,8 @@ static void read_and_discard_sysfs_entries(int path_fd, int indent)
 			continue;
 		if (dirent->d_type == DT_DIR) {
 			int sub_fd = -1;
-			igt_assert((sub_fd =
-				    openat(path_fd, dirent->d_name, O_RDONLY |
-					   O_DIRECTORY)) > 0);
+			igt_assert_fd(sub_fd = openat(path_fd, dirent->d_name,
+						      O_RDONLY | O_DIRECTORY));
 			igt_debug("%sEntering subdir %s\n", tabs, dirent->d_name);
 			read_and_discard_sysfs_entries(sub_fd, indent + 1);
 			close(sub_fd);
diff --git a/tests/i915/gem_concurrent_all.c b/tests/i915/gem_concurrent_all.c
index 89fe616c..af3cbad0 100644
--- a/tests/i915/gem_concurrent_all.c
+++ b/tests/i915/gem_concurrent_all.c
@@ -448,7 +448,7 @@ vgem_create_bo(const struct buffers *b)
 	struct vgem_bo vgem;
 	struct dmabuf *dmabuf;
 
-	igt_assert(vgem_drv != -1);
+	igt_assert_fd(vgem_drv);
 
 	vgem.width = b->width;
 	vgem.height = b->height;
@@ -462,7 +462,7 @@ vgem_create_bo(const struct buffers *b)
 
 	do_ioctl(vgem_drv, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
 	gem_close(vgem_drv, args.handle);
-	igt_assert(args.fd != -1);
+	igt_assert_fd(args.fd);
 
 	bo = drm_intel_bo_gem_create_from_prime(b->bufmgr, args.fd, vgem.size);
 	igt_assert(bo);
diff --git a/tests/i915/gem_eio.c b/tests/i915/gem_eio.c
index 5396a04e..c4c0bcc8 100644
--- a/tests/i915/gem_eio.c
+++ b/tests/i915/gem_eio.c
@@ -456,7 +456,7 @@ static void test_inflight(int fd, unsigned int wait)
 		for (unsigned int n = 0; n < max; n++) {
 			gem_execbuf_wr(fd, &execbuf);
 			fence[n] = execbuf.rsvd2 >> 32;
-			igt_assert(fence[n] != -1);
+			igt_assert_fd(fence[n]);
 		}
 
 		check_wait(fd, obj[1].handle, wait, NULL);
@@ -509,7 +509,7 @@ static void test_inflight_suspend(int fd)
 	for (unsigned int n = 0; n < max; n++) {
 		gem_execbuf_wr(fd, &execbuf);
 		fence[n] = execbuf.rsvd2 >> 32;
-		igt_assert(fence[n] != -1);
+		igt_assert_fd(fence[n]);
 	}
 
 	igt_set_autoresume_delay(30);
@@ -590,7 +590,7 @@ static void test_inflight_contexts(int fd, unsigned int wait)
 			execbuf.rsvd1 = ctx[n];
 			gem_execbuf_wr(fd, &execbuf);
 			fence[n] = execbuf.rsvd2 >> 32;
-			igt_assert(fence[n] != -1);
+			igt_assert_fd(fence[n]);
 		}
 
 		check_wait(fd, obj[1].handle, wait, NULL);
@@ -698,7 +698,7 @@ static void test_inflight_internal(int fd, unsigned int wait)
 		gem_execbuf_wr(fd, &execbuf);
 
 		fences[nfence] = execbuf.rsvd2 >> 32;
-		igt_assert(fences[nfence] != -1);
+		igt_assert_fd(fences[nfence]);
 		nfence++;
 	}
 
diff --git a/tests/i915/gem_exec_fence.c b/tests/i915/gem_exec_fence.c
index 0befb54f..1d026891 100644
--- a/tests/i915/gem_exec_fence.c
+++ b/tests/i915/gem_exec_fence.c
@@ -176,7 +176,7 @@ static void test_fence_busy(int fd, unsigned ring, unsigned flags)
 	execbuf.rsvd2 = -1;
 	gem_execbuf_wr(fd, &execbuf);
 	fence = execbuf.rsvd2 >> 32;
-	igt_assert(fence != -1);
+	igt_assert_fd(fence);
 
 	igt_assert(gem_bo_busy(fd, obj.handle));
 	igt_assert(fence_busy(fence));
@@ -270,7 +270,7 @@ static void test_fence_busy_all(int fd, unsigned flags)
 		execbuf.rsvd2 = -1;
 		gem_execbuf_wr(fd, &execbuf);
 		fence = execbuf.rsvd2 >> 32;
-		igt_assert(fence != -1);
+		igt_assert_fd(fence);
 
 		if (all < 0) {
 			all = fence;
diff --git a/tests/i915/gem_reset_stats.c b/tests/i915/gem_reset_stats.c
index 11ad9dbd..ac5d5984 100644
--- a/tests/i915/gem_reset_stats.c
+++ b/tests/i915/gem_reset_stats.c
@@ -82,7 +82,7 @@ static int noop(int fd, uint32_t ctx, const struct intel_execution_engine *e)
 
 	memset(&exec, 0, sizeof(exec));
 	exec.handle = gem_create(fd, 4096);
-	igt_assert((int)exec.handle > 0);
+	igt_assert_fd((int)exec.handle);
 	gem_write(fd, exec.handle, 0, &bbe, sizeof(bbe));
 
 	memset(&eb, 0, sizeof(eb));
@@ -228,7 +228,7 @@ static void test_rs(const struct intel_execution_engine *e,
 		if (i == hang_index)
 			inject_hang(fd[i], 0, e, ASYNC);
 		else
-			igt_assert(noop(fd[i], 0, e) > 0);
+			igt_assert_fd(noop(fd[i], 0, e));
 	}
 	sync_gpu();
 
@@ -271,7 +271,7 @@ static void test_rs_ctx(const struct intel_execution_engine *e,
 
 	for (i = 0; i < num_fds; i++) {
 		fd[i] = drm_open_driver(DRIVER_INTEL);
-		igt_assert(fd[i]);
+		igt_assert_fd(fd[i]);
 		assert_reset_status(i, fd[i], 0, RS_NO_ERROR);
 
 		for (j = 0; j < num_ctx; j++) {
@@ -295,7 +295,7 @@ static void test_rs_ctx(const struct intel_execution_engine *e,
 			if (i == hang_index && j == hang_context)
 				inject_hang(fd[i], ctx[i][j], e, ASYNC);
 			else
-				igt_assert(noop(fd[i], ctx[i][j], e) > 0);
+				igt_assert_fd(noop(fd[i], ctx[i][j], e));
 		}
 	}
 	sync_gpu();
diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
index 187ca9da..3e5ce6f9 100644
--- a/tests/kms_chamelium.c
+++ b/tests/kms_chamelium.c
@@ -947,7 +947,7 @@ static void audio_state_start(struct audio_state *state, const char *name)
 							      state->capture.rate,
 							      state->capture.channels,
 							      &state->dump_path);
-		igt_assert(state->dump_fd >= 0);
+		igt_assert_fd(state->dump_fd);
 	}
 }
 
diff --git a/tests/kms_dp_dsc.c b/tests/kms_dp_dsc.c
index e2e3aaa0..7a28a03c 100644
--- a/tests/kms_dp_dsc.c
+++ b/tests/kms_dp_dsc.c
@@ -144,7 +144,7 @@ static void save_force_dsc_en(data_t *data)
 	strcat(file_name, "/i915_dsc_fec_support");
 	force_dsc_restore_fd = openat(igt_debugfs_dir(data->drm_fd),
 				      file_name, O_WRONLY);
-	igt_assert(force_dsc_restore_fd >= 0);
+	igt_assert_fd(force_dsc_restore_fd);
 }
 
 static void restore_force_dsc_en(void)
diff --git a/tests/kms_vrr.c b/tests/kms_vrr.c
index 9801b40a..0981145e 100644
--- a/tests/kms_vrr.c
+++ b/tests/kms_vrr.c
@@ -109,7 +109,7 @@ static range_t get_vrr_range(data_t *data, igt_output_t *output)
 	range_t range;
 
 	fd = igt_debugfs_connector_dir(data->drm_fd, output->name, O_RDONLY);
-	igt_assert(fd >= 0);
+	igt_assert_fd(fd);
 
 	res = igt_debugfs_simple_read(fd, "vrr_range", buf, sizeof(buf));
 	igt_require(res > 0);
diff --git a/tests/perf.c b/tests/perf.c
index 5891c872..0441c62b 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -241,7 +241,7 @@ __perf_open(int fd, struct drm_i915_perf_open_param *param, bool prevent_pm)
 
 	if (prevent_pm) {
 		pm_fd = open("/dev/cpu_dma_latency", O_RDWR);
-		igt_assert(pm_fd >= 0);
+		igt_assert_fd(pm_fd);
 
 		igt_assert_eq(write(pm_fd, &pm_value, sizeof(pm_value)), sizeof(pm_value));
 	}
diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c
index c861911e..2cfbd368 100644
--- a/tests/perf_pmu.c
+++ b/tests/perf_pmu.c
@@ -55,7 +55,7 @@ static int open_pmu(uint64_t config)
 
 	fd = perf_i915_open(config);
 	igt_skip_on(fd < 0 && errno == ENODEV);
-	igt_assert(fd >= 0);
+	igt_assert_fd(fd);
 
 	return fd;
 }
@@ -66,7 +66,7 @@ static int open_group(uint64_t config, int group)
 
 	fd = perf_i915_open_group(config, group);
 	igt_skip_on(fd < 0 && errno == ENODEV);
-	igt_assert(fd >= 0);
+	igt_assert_fd(fd);
 
 	return fd;
 }
@@ -1013,7 +1013,7 @@ static void init_other(unsigned int i, bool valid)
 	fd = perf_i915_open(__I915_PMU_OTHER(i));
 	igt_require(!(fd < 0 && errno == ENODEV));
 	if (valid) {
-		igt_assert(fd >= 0);
+		igt_assert_fd(fd);
 	} else {
 		igt_assert_lt(fd, 0);
 		return;
@@ -1029,7 +1029,7 @@ static void read_other(unsigned int i, bool valid)
 	fd = perf_i915_open(__I915_PMU_OTHER(i));
 	igt_require(!(fd < 0 && errno == ENODEV));
 	if (valid) {
-		igt_assert(fd >= 0);
+		igt_assert_fd(fd);
 	} else {
 		igt_assert_lt(fd, 0);
 		return;
@@ -1198,7 +1198,7 @@ test_interrupts(int gem_fd)
 			close(old_fd);
 		}
 
-		igt_assert(fence_fd >= 0);
+		igt_assert_fd(fence_fd);
 	}
 
 	/* Wait for idle state. */
@@ -1442,7 +1442,7 @@ test_rc6(int gem_fd, unsigned int flags)
 
 	/* Wake up device and check no RC6. */
 	fw = igt_open_forcewake_handle(gem_fd);
-	igt_assert(fw >= 0);
+	igt_assert_fd(fw);
 	usleep(1e3); /* wait for the rc6 cycle counter to stop ticking */
 
 	prev = pmu_read_single(fd);
diff --git a/tests/vgem_basic.c b/tests/vgem_basic.c
index 526636dd..56b7c498 100644
--- a/tests/vgem_basic.c
+++ b/tests/vgem_basic.c
@@ -335,7 +335,7 @@ static void test_unload(void)
 	igt_require(module_unload() == 0);
 
 	vgem = __drm_open_driver(DRIVER_VGEM);
-	igt_assert(vgem != -1);
+	igt_assert_fd(vgem);
 
 	/* The driver should stop the module from unloading */
 	igt_assert_f(module_unload() != 0,
@@ -352,7 +352,7 @@ static void test_unload(void)
 		     "No open(/dev/vgem), should be able to unload\n");
 
 	vgem = __drm_open_driver(DRIVER_VGEM);
-	igt_assert(vgem != -1);
+	igt_assert_fd(vgem);
 	bo.width = 1024;
 	bo.height = 1;
 	bo.bpp = 32;
@@ -369,7 +369,7 @@ static void test_unload(void)
 		     "No open dmabuf, should be able to unload\n");
 
 	vgem = __drm_open_driver(DRIVER_VGEM);
-	igt_assert(vgem != -1);
+	igt_assert_fd(vgem);
 	bo.width = 1024;
 	bo.height = 1;
 	bo.bpp = 32;
-- 
2.21.0



More information about the Intel-gfx-trybot mailing list