summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/igt_debugfs.c51
-rw-r--r--lib/igt_debugfs.h2
-rw-r--r--lib/igt_sysfs.c1
-rw-r--r--tests/vgem_basic.c65
4 files changed, 106 insertions, 13 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 2ea12a04..3cc22cbf 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -87,28 +87,30 @@ typedef struct {
char dri_path[128];
} igt_debugfs_t;
-static bool __igt_debugfs_init(igt_debugfs_t *debugfs)
+static const char *__debugfs_mount(void)
{
- const char *path = "/sys/kernel/debug";
struct stat st;
- int n;
- if (stat("/debug/dri", &st) == 0) {
- path = "/debug/dri";
- goto find_minor;
- }
+ if (stat("/debug/dri", &st) == 0)
+ return "/debug/dri";
if (stat("/sys/kernel/debug/dri", &st) == 0)
- goto find_minor;
+ return "/sys/kernel/debug/dri";
igt_assert(stat("/sys/kernel/debug", &st) == 0);
+ igt_assert(mount("debug", "/sys/kernel/debug", "debugfs", 0, 0) == 0);
+ return "/sys/kernel/debug/dri";
+}
- mount("debug", "/sys/kernel/debug", "debugfs", 0, 0);
+static bool __igt_debugfs_init(igt_debugfs_t *debugfs)
+{
+ struct stat st;
+ int n;
-find_minor:
- strcpy(debugfs->root, path);
+ strcpy(debugfs->root, __debugfs_mount());
for (n = 0; n < 16; n++) {
- int len = sprintf(debugfs->dri_path, "%s/dri/%d", path, n);
+ int len = sprintf(debugfs->dri_path,
+ "%s/dri/%d", debugfs->root, n);
sprintf(debugfs->dri_path + len, "/i915_error_state");
if (stat(debugfs->dri_path, &st) == 0) {
debugfs->dri_path[len] = '\0';
@@ -117,7 +119,6 @@ find_minor:
}
debugfs->dri_path[0] = '\0';
-
return false;
}
@@ -796,3 +797,27 @@ int igt_get_stable_obj_count(int driver)
return obj_count;
}
+
+/* Non-i915 specific debugfs API */
+
+/**
+ * igt_debugfs_dir:
+ * @device: fd of the device (or -1 to default to Intel)
+ *
+ * This opens the debugfs directory corresponding to device for use
+ * with igt_debugfs_set() and igt_debugfs_get().
+ *
+ * Returns:
+ * The directory fd, or -1 on failure.
+ */
+int igt_debugfs_dir(int fd)
+{
+ struct stat st;
+ char path[256];
+
+ if (fstat(fd, &st) || !S_ISCHR(st.st_mode))
+ return -1;
+
+ sprintf(path, "%s/%d", __debugfs_mount(), (int)(st.st_rdev & 0xff));
+ return open(path, O_RDONLY);
+}
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index d08fc237..7390fc57 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -175,4 +175,6 @@ void igt_enable_prefault(void);
*/
int igt_get_stable_obj_count(int driver);
+int igt_debugfs_dir(int fd);
+
#endif /* __IGT_DEBUGFS_H__ */
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 1b31d7af..61b94c64 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -179,6 +179,7 @@ char *igt_sysfs_get(int dir, const char *attr)
if (!newbuf)
break;
+ buf = newbuf;
len *= 2;
offset += ret;
rem = len - offset - 1;
diff --git a/tests/vgem_basic.c b/tests/vgem_basic.c
index 4e8408f2..b4337ee1 100644
--- a/tests/vgem_basic.c
+++ b/tests/vgem_basic.c
@@ -23,8 +23,12 @@
#include "igt.h"
#include "igt_vgem.h"
+#include "igt_debugfs.h"
+#include "igt_sysfs.h"
#include <sys/mman.h>
+#include <sys/stat.h>
+#include <dirent.h>
IGT_TEST_DESCRIPTION("Basic sanity check of Virtual GEM module (vGEM).");
@@ -140,6 +144,62 @@ static void test_dmabuf_mmap(int fd)
munmap(ptr, bo.size);
}
+static void test_sysfs_read(int fd)
+{
+ int dir = igt_sysfs_open(fd, NULL);
+ DIR *dirp = fdopendir(dir);
+ struct dirent *de;
+
+ while ((de = readdir(dirp))) {
+ struct stat st;
+
+ if (*de->d_name == '.')
+ continue;
+
+ if (fstatat(dir, de->d_name, &st, 0))
+ continue;
+
+ if (S_ISDIR(st.st_mode))
+ continue;
+
+ igt_debug("Reading %s\n", de->d_name);
+ igt_set_timeout(1, "vgem sysfs read stalled");
+ free(igt_sysfs_get(dir, de->d_name));
+ igt_reset_timeout();
+ }
+
+ closedir(dirp);
+ close(dir);
+}
+
+static void test_debugfs_read(int fd)
+{
+ int dir = igt_debugfs_dir(fd);
+ DIR *dirp = fdopendir(dir);
+ struct dirent *de;
+
+ while ((de = readdir(dirp))) {
+ struct stat st;
+
+ if (*de->d_name == '.')
+ continue;
+
+ if (fstatat(dir, de->d_name, &st, 0))
+ continue;
+
+ if (S_ISDIR(st.st_mode))
+ continue;
+
+ igt_debug("Reading %s\n", de->d_name);
+ igt_set_timeout(1, "vgem debugfs read stalled");
+ free(igt_sysfs_get(dir, de->d_name));
+ igt_reset_timeout();
+ }
+
+ closedir(dirp);
+ close(dir);
+}
+
static bool has_prime_export(int fd)
{
uint64_t value;
@@ -176,6 +236,11 @@ igt_main
test_dmabuf_mmap(fd);
}
+ igt_subtest("sysfs")
+ test_sysfs_read(fd);
+ igt_subtest("debugfs")
+ test_debugfs_read(fd);
+
igt_fixture {
close(fd);
}