Commit 8deba38a authored by Chris Wilson's avatar Chris Wilson

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's avatarChris Wilson <chris@chris-wilson.co.uk>
parent 0e1f5e3e
......@@ -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);
}
......@@ -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__ */
......@@ -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;
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment