diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2016-06-20 19:21:26 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2016-06-20 19:23:03 +0100 |
commit | 8deba38a3af34354680984186bdc80cfc6734138 (patch) | |
tree | d101ac1a74a2476360f97ad43483d6392709ae3a /lib | |
parent | 0e1f5e3e796ae383daeb8f1aa394ce5f030e7bb9 (diff) |
igt/vgem_basic: Exercise opening sysfs/debugfs
For fun, debugfs/.../names currently explodes, so lets capture that and
make sure that basic access to debugfs does no harm.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/igt_debugfs.c | 51 | ||||
-rw-r--r-- | lib/igt_debugfs.h | 2 | ||||
-rw-r--r-- | lib/igt_sysfs.c | 1 |
3 files changed, 41 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; |