diff options
-rw-r--r-- | lib/igt_debugfs.c | 35 | ||||
-rw-r--r-- | lib/igt_debugfs.h | 1 | ||||
-rw-r--r-- | lib/igt_kms.c | 25 | ||||
-rw-r--r-- | tests/gem_workarounds.c | 15 | ||||
-rw-r--r-- | tests/kms_pipe_crc_basic.c | 37 | ||||
-rw-r--r-- | tests/kms_psr_sink_crc.c | 15 | ||||
-rw-r--r-- | tests/kms_sink_crc_basic.c | 14 | ||||
-rw-r--r-- | tests/kms_universal_plane.c | 6 | ||||
-rw-r--r-- | tests/perf.c | 24 | ||||
-rw-r--r-- | tools/intel_dp_compliance.c | 16 |
10 files changed, 78 insertions, 110 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index bd9ea3f0..d64694c7 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -222,34 +222,6 @@ int igt_debugfs_open(int device, const char *filename, int mode) } /** - * igt_debugfs_fopen: - * @filename: name of the debugfs node to open - * @mode: mode string as used by fopen() - * - * This opens a debugfs file as a libc FILE. The filename should be - * relative to the drm device's root, i.e. without "drm/<minor>". - * - * Returns: - * The libc FILE pointer for the debugfs file or NULL if that didn't work out. - */ -FILE *igt_debugfs_fopen(int device, - const char *filename, - const char *mode) -{ - FILE *file; - int fd; - - fd = igt_debugfs_open(device, filename, O_RDWR); - if (fd < 0) - return NULL; - - file = fdopen(fd, mode); - close(fd); - - return file; -} - -/** * __igt_debugfs_read: * @filename: file name * @buf: buffer where the contents will be stored, allocated by the caller @@ -281,14 +253,16 @@ void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size) * * Returns: True if the @substring is found to occur in @filename */ -bool igt_debugfs_search(int fd, const char *filename, const char *substring) +bool igt_debugfs_search(int device, const char *filename, const char *substring) { FILE *file; size_t n = 0; char *line = NULL; bool matched = false; + int fd; - file = igt_debugfs_fopen(fd, filename, "r"); + fd = igt_debugfs_open(device, filename, O_RDONLY); + file = fdopen(fd, "r"); igt_assert(file); while (getline(&line, &n, file) >= 0) { @@ -299,6 +273,7 @@ bool igt_debugfs_search(int fd, const char *filename, const char *substring) free(line); fclose(file); + close(fd); return matched; } diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h index cdad562d..7b846a83 100644 --- a/lib/igt_debugfs.h +++ b/lib/igt_debugfs.h @@ -36,7 +36,6 @@ const char *igt_debugfs_mount(void); int igt_debugfs_dir(int device); int igt_debugfs_open(int fd, const char *filename, int mode); -FILE *igt_debugfs_fopen(int fd, const char *filename, const char *mode); void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size); bool igt_debugfs_search(int fd, const char *filename, const char *substring); diff --git a/lib/igt_kms.c b/lib/igt_kms.c index d9f96725..5811414f 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -1324,34 +1324,34 @@ static void parse_crtc(char *info, struct kmstest_crtc *crtc) igt_assert_eq(ret, 2); } -void kmstest_get_crtc(int fd, enum pipe pipe, struct kmstest_crtc *crtc) +void kmstest_get_crtc(int device, enum pipe pipe, struct kmstest_crtc *crtc) { char tmp[256]; - FILE *fid; - const char *mode = "r"; + FILE *file; int ncrtc; int line; long int n; + int fd; - fid = igt_debugfs_fopen(fd, "i915_display_info", mode); - - igt_skip_on(fid == NULL); + fd = igt_debugfs_open(device, "i915_display_info", O_RDONLY); + file = fdopen(fd, "r"); + igt_skip_on(file == NULL); ncrtc = 0; line = 0; - while (fgets(tmp, 256, fid) != NULL) { + while (fgets(tmp, 256, file) != NULL) { if ((strstr(tmp, "CRTC") != NULL) && (line > 0)) { if (strstr(tmp, "active=yes") != NULL) { crtc->active = true; parse_crtc(tmp, crtc); - n = ftell(fid); - crtc->n_planes = parse_planes(fid, NULL); + n = ftell(file); + crtc->n_planes = parse_planes(file, NULL); crtc->planes = calloc(crtc->n_planes, sizeof(*crtc->planes)); igt_assert_f(crtc->planes, "Failed to allocate memory for %d planes\n", crtc->n_planes); - fseek(fid, n, SEEK_SET); - parse_planes(fid, crtc->planes); + fseek(file, n, SEEK_SET); + parse_planes(file, crtc->planes); if (crtc->pipe != pipe) { free(crtc->planes); @@ -1365,7 +1365,8 @@ void kmstest_get_crtc(int fd, enum pipe pipe, struct kmstest_crtc *crtc) line++; } - fclose(fid); + fclose(file); + close(fd); igt_skip_on(ncrtc == 0); } 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()); diff --git a/tools/intel_dp_compliance.c b/tools/intel_dp_compliance.c index 4b4d255d..c40548e7 100644 --- a/tools/intel_dp_compliance.c +++ b/tools/intel_dp_compliance.c @@ -227,17 +227,27 @@ static void clear_test_active(void) fflush(test_active_fp); } +static FILE *fopenat(int dir, const char *name, const char *mode) +{ + int fd = openat(dir, name, O_RDWR); + return fdopen(fd, mode); +} + static void setup_debugfs_files(void) { - test_type_fp = igt_debugfs_fopen(drm_fd, INTEL_DP_TEST_TYPE_FILE, "r"); + int dir = igt_debugfs_dir(drm_fd); + + test_type_fp = fopenat(dir, INTEL_DP_TEST_TYPE_FILE, "r"); igt_require(test_type_fp); - test_data_fp = igt_debugfs_fopen(drm_fd, INTEL_DP_TEST_DATA_FILE, "r"); + test_data_fp = fopenat(dir, INTEL_DP_TEST_DATA_FILE, "r"); igt_require(test_data_fp); - test_active_fp = igt_debugfs_fopen(drm_fd, INTEL_DP_TEST_ACTIVE_FILE, "w+"); + test_active_fp = fopenat(dir, INTEL_DP_TEST_ACTIVE_FILE, "w+"); igt_require(test_active_fp); + close(dir); + /* Reset the active flag for safety */ clear_test_active(); } |