summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-03-24 20:52:44 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2017-03-24 21:35:25 +0000
commite08ed8a272fda96b8f7224985177f313c3b2ddf6 (patch)
tree5fdba2e2cade4db9f64582e6414c3372a5681180 /tests
parent58de785468782f29e6eb1d32d47b55b3d234dfcf (diff)
lib/debugfs: Phase out igt_debugfs_fopen()
Wrapping fdopen() proved dangerous, the underlying fd is not refcounted, and we must close it in the library or else we easily leak and exhaust all fd. Since we can't provide igt_debugfs_fopen(), move the burden onto the caller for those that require a stream FILE*. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'tests')
-rw-r--r--tests/gem_workarounds.c15
-rw-r--r--tests/kms_pipe_crc_basic.c37
-rw-r--r--tests/kms_psr_sink_crc.c15
-rw-r--r--tests/kms_sink_crc_basic.c14
-rw-r--r--tests/kms_universal_plane.c6
-rw-r--r--tests/perf.c24
6 files changed, 47 insertions, 64 deletions
diff --git a/tests/gem_workarounds.c b/tests/gem_workarounds.c
index 08a1d09a..5d2a1086 100644
--- a/tests/gem_workarounds.c
+++ b/tests/gem_workarounds.c
@@ -28,6 +28,8 @@
#define _GNU_SOURCE
#include "igt.h"
+#include <fcntl.h>
+
enum operation {
GPU_RESET,
SUSPEND_RESUME,
@@ -122,20 +124,21 @@ static void check_workarounds(enum operation op)
igt_main
{
igt_fixture {
- int fd = drm_open_driver_master(DRIVER_INTEL);
- const int gen = intel_gen(intel_get_drm_devid(fd));
+ int device = drm_open_driver_master(DRIVER_INTEL);
+ const int gen = intel_gen(intel_get_drm_devid(device));
struct pci_device *pci_dev;
FILE *file;
char *line = NULL;
size_t line_size;
- int i;
+ int i, fd;
pci_dev = intel_get_pci_device();
igt_require(pci_dev);
- intel_register_access_init(pci_dev, 0, fd);
+ intel_register_access_init(pci_dev, 0, device);
- file = igt_debugfs_fopen(fd, "i915_wa_registers", "r");
+ fd = igt_debugfs_open(device, "i915_wa_registers", O_RDONLY);
+ file = fdopen(fd, "r");
igt_assert(getline(&line, &line_size, file) > 0);
igt_debug("i915_wa_registers: %s", line);
sscanf(line, "Workarounds applied: %d", &num_wa_regs);
@@ -164,6 +167,8 @@ igt_main
free(line);
fclose(file);
+ close(fd);
+ close(device);
}
igt_subtest("basic-read")
diff --git a/tests/kms_pipe_crc_basic.c b/tests/kms_pipe_crc_basic.c
index f3c58390..a6996d43 100644
--- a/tests/kms_pipe_crc_basic.c
+++ b/tests/kms_pipe_crc_basic.c
@@ -23,6 +23,7 @@
*/
#include "igt.h"
+#include "igt_sysfs.h"
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
@@ -45,42 +46,18 @@ static struct {
static void test_bad_command(data_t *data, const char *cmd)
{
- FILE *ctl;
- size_t written;
+ int dir = igt_debugfs_dir(data->drm_fd);
- ctl = igt_debugfs_fopen(data->drm_fd, "i915_display_crc_ctl", "r+");
- igt_require(ctl);
-
- written = fwrite(cmd, 1, strlen(cmd), ctl);
- fflush(ctl);
- igt_assert_eq(written, strlen(cmd));
- igt_assert(ferror(ctl));
- igt_assert_eq(errno, EINVAL);
-
- fclose(ctl);
+ igt_require(igt_sysfs_set(dir, "i915_display_crc_ctl", cmd));
+ close(dir);
}
static void test_bad_source(data_t *data)
{
- FILE *f;
- size_t written;
- const char *source = "foo";
-
- f = igt_debugfs_fopen(data->drm_fd, "crtc-0/crc/control", "w");
- if (!f) {
- test_bad_command(data, "pipe A foo");
- return;
- }
-
- written = fwrite(source, 1, strlen(source), f);
- fflush(f);
- igt_assert_eq(written, strlen(source));
- igt_assert(!ferror(f));
- fclose(f);
+ int dir = igt_debugfs_dir(data->drm_fd);
- f = igt_debugfs_fopen(data->drm_fd, "crtc-0/crc/data", "w");
- igt_assert(!f);
- igt_assert_eq(errno, EINVAL);
+ igt_require(igt_sysfs_set(dir, "crtc-0/crc/control", "foo"));
+ close(dir);
}
#define N_CRCS 3
diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c
index f66a7543..bd3fa5e9 100644
--- a/tests/kms_psr_sink_crc.c
+++ b/tests/kms_psr_sink_crc.c
@@ -23,6 +23,7 @@
*/
#include "igt.h"
+#include "igt_sysfs.h"
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
@@ -223,19 +224,15 @@ static bool wait_psr_entry(data_t *data)
}
static void get_sink_crc(data_t *data, char *crc) {
- int ret;
- FILE *file;
+ int dir;
if (igt_interactive_debug)
return;
- file = igt_debugfs_fopen(data->drm_fd, "i915_sink_crc_eDP1", "r");
- igt_require(file);
-
- ret = fscanf(file, "%s\n", crc);
- igt_require_f(ret > 0, "Sink CRC is unreliable on this machine. Try manual debug with --interactive-debug=no-crc\n");
-
- fclose(file);
+ dir = igt_debugfs_dir(data->drm_fd);
+ igt_require_f(igt_sysfs_scanf(dir, "i915_sink_crc_eDP1", "%s\n", crc),
+ "Sink CRC is unreliable on this machine. Try manual debug with --interactive-debug=no-crc\n");
+ close(dir);
igt_debug("%s\n", crc);
igt_debug_wait_for_keypress("crc");
diff --git a/tests/kms_sink_crc_basic.c b/tests/kms_sink_crc_basic.c
index f8f814f2..c547e6e3 100644
--- a/tests/kms_sink_crc_basic.c
+++ b/tests/kms_sink_crc_basic.c
@@ -23,6 +23,7 @@
*/
#include "igt.h"
+#include "igt_sysfs.h"
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
@@ -47,16 +48,13 @@ typedef struct {
} data_t;
static void get_crc(data_t *data, char *crc) {
- int ret;
- FILE *file;
-
- file = igt_debugfs_fopen(data->drm_fd, "i915_sink_crc_eDP1", "r");
- igt_require(file);
+ int dir;
- ret = fscanf(file, "%s\n", crc);
- igt_require(ret > 0);
+ dir = igt_debugfs_dir(data->drm_fd);
+ igt_require_f(igt_sysfs_scanf(dir, "i915_sink_crc_eDP1", "%s\n", crc),
+ "Sink CRC is unreliable on this machine. Try manual debug with --interactive-debug=no-crc\n");
+ close(dir);
- fclose(file);
/* Black screen is always invalid */
igt_assert(strcmp(crc, CRC_BLACK) != 0);
diff --git a/tests/kms_universal_plane.c b/tests/kms_universal_plane.c
index 991204ce..39fa1f1d 100644
--- a/tests/kms_universal_plane.c
+++ b/tests/kms_universal_plane.c
@@ -26,6 +26,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+#include <fcntl.h>
typedef struct {
@@ -549,13 +550,16 @@ i915_gem_fb_count(data_t *data)
{
char buf[1024];
FILE *fp;
+ int fd;
int count = 0;
- fp = igt_debugfs_fopen(data->drm_fd, "i915_gem_framebuffer", "r");
+ fd = igt_debugfs_open(data->drm_fd, "i915_gem_framebuffer", O_RDONLY);
+ fp = fdopen(fd, "r");
igt_require(fp);
while (fgets(buf, sizeof(buf), fp) != NULL)
count++;
fclose(fp);
+ close(fd);
return count;
}
diff --git a/tests/perf.c b/tests/perf.c
index 17925eea..2a66bb63 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -193,7 +193,7 @@ static bool hsw_undefined_a_counters[45] = {
static int drm_fd = -1;
static uint32_t devid;
-static int device = -1;
+static int card = -1;
static uint64_t hsw_render_basic_id = UINT64_MAX;
static uint64_t gt_min_freq_mhz_saved = 0;
@@ -281,7 +281,7 @@ sysfs_read(const char *file)
{
char buf[512];
- snprintf(buf, sizeof(buf), "/sys/class/drm/card%d/%s", device, file);
+ snprintf(buf, sizeof(buf), "/sys/class/drm/card%d/%s", card, file);
return read_u64_file(buf);
}
@@ -291,22 +291,24 @@ sysfs_write(const char *file, uint64_t val)
{
char buf[512];
- snprintf(buf, sizeof(buf), "/sys/class/drm/card%d/%s", device, file);
+ snprintf(buf, sizeof(buf), "/sys/class/drm/card%d/%s", card, file);
write_u64_file(buf, val);
}
static char *
-read_debugfs_record(int fd, const char *file, const char *key)
+read_debugfs_record(int device, const char *file, const char *key)
{
FILE *fp;
+ int fd;
char *line = NULL;
size_t line_buf_size = 0;
int len = 0;
int key_len = strlen(key);
char *value = NULL;
- fp = igt_debugfs_fopen(fd, file, "r");
+ fd = igt_debugfs_open(device, file, O_RDONLY);
+ fp = fdopen(fd, "r");
igt_require(fp);
while ((len = getline(&line, &line_buf_size, fp)) > 0) {
@@ -326,8 +328,8 @@ read_debugfs_record(int fd, const char *file, const char *key)
igt_assert(!"reached");
done:
free(line);
- if (fp)
- fclose(fp);
+ fclose(fp);
+ close(fd);
return value;
}
@@ -350,11 +352,11 @@ lookup_hsw_render_basic_id(void)
{
char buf[256];
- igt_assert_neq(device, -1);
+ igt_assert_neq(card, -1);
snprintf(buf, sizeof(buf),
"/sys/class/drm/card%d/metrics/403d8832-1a27-4aa6-a64e-f5389ce7b212/id",
- device);
+ card);
return try_read_u64_file(buf, &hsw_render_basic_id);
}
@@ -2225,7 +2227,7 @@ test_i915_ref_count(void)
drm_fd = __drm_open_driver(DRIVER_INTEL);
devid = intel_get_drm_devid(drm_fd);
- device = drm_get_card();
+ card = drm_get_card();
igt_require(IS_HASWELL(devid));
igt_require(lookup_hsw_render_basic_id());
@@ -2296,7 +2298,7 @@ igt_main
igt_assert_eq(drm_fd, -1);
drm_fd = drm_open_driver_render(DRIVER_INTEL);
devid = intel_get_drm_devid(drm_fd);
- device = drm_get_card();
+ card = drm_get_card();
igt_require(IS_HASWELL(devid));
igt_require(lookup_hsw_render_basic_id());