[igt-dev] [PATCH v2 2/2] tests/debugfs_test: Add subtest guc_log_relay

Piotr Piorkowski piotr.piorkowski at intel.com
Tue Apr 24 07:50:04 UTC 2018


From: Piotr Piórkowski <piotr.piorkowski at intel.com>

We doesn't have any tests to verify functionality of i915_guc_log_relay.
I think we should test this component.

Let's add simple subtest to debugfs_test, which will test if guc
is enabled:
- opening the i915_guc_log_relay and creating a file guc_log0,
- flushing GuC log buffer,
- closing i915_guc_log_relay with removing from debugfs guc_log0.
Otherwise, the test will check if the attempt to open the guc_log_relay
returns an error ENODEV.

v2:
- guc isn't required for run the subtest (Chris)
- rewrite subtest as function (Michal Winiarski)
- add case when the guc is not enabled

Signed-off-by: Piotr Piórkowski <piotr.piorkowski at intel.com>
Cc: Sagar Arun Kamble <sagar.a.kamble at intel.com>
Cc: Lukasz Fiedorowicz <lukasz.fiedorowicz at intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko at intel.com>
Cc: Michał Winiarski <michal.winiarski at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/debugfs_test.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/tests/debugfs_test.c b/tests/debugfs_test.c
index 2e87e442..c7a953b1 100644
--- a/tests/debugfs_test.c
+++ b/tests/debugfs_test.c
@@ -26,6 +26,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <errno.h>
 
 static void read_and_discard_sysfs_entries(int path_fd, int indent)
 {
@@ -87,6 +88,95 @@ static void read_and_discard_sysfs_entries(int path_fd, int indent)
 	closedir(dir);
 }
 
+static bool is_guc_loaded(int gfx_fd)
+{
+	bool load;
+
+	load = igt_debugfs_search(gfx_fd, "i915_guc_load_status",
+				"\tstatus: fetch SUCCESS, load SUCCESS");
+	igt_debug("GuC %s loaded\n", load ? "is" : "is not");
+
+	return load;
+}
+
+#define I915_GUC_LOG_RELAY_FILE  "i915_guc_log_relay"
+#define GUC_LOG_FILE  "guc_log0"
+
+static void check_guc_log_relay(int gfx_fd)
+{
+
+	int page_size = getpagesize();
+	int fd_relay = -1, fd_log = -1;
+	ssize_t read_size;
+	uint8_t *buffer;
+	bool guc_is_loaded;
+	int debugfs;
+
+	guc_is_loaded = is_guc_loaded(gfx_fd);
+
+	debugfs = igt_debugfs_dir(gfx_fd);
+	fd_relay = openat(debugfs, I915_GUC_LOG_RELAY_FILE, O_RDWR);
+
+	if (!guc_is_loaded) {
+		igt_debug("Case when GuC is disabled\n");
+		igt_debug("Attempt open file %s return value: %d ( %m )\n",
+			  I915_GUC_LOG_RELAY_FILE, errno);
+
+		igt_assert(errno == ENODEV);
+		return;
+	}
+
+	igt_debug("Case when GuC is enabled\n");
+
+	igt_assert(fd_relay > 0);
+	/*
+	 * The GUC_LOG_FILE should be created
+	 *	after opening the I915_GUC_LOG_RELAY_FILE file
+	 */
+	fd_log = igt_debugfs_open(gfx_fd, GUC_LOG_FILE, O_RDONLY);
+	igt_assert(fd_log > 0);
+
+	/*
+	 * We want to check flush and read from GUC_LOG_FILE.
+	 * First, we read all available bytes from buffer
+	 * (if any bytes are ready to be read).
+	 */
+	buffer = malloc(page_size);
+	do {
+		read_size = read(fd_log, buffer, page_size);
+		igt_debug("Shall attempt to read %d bytes from file %s.\n"
+			  "The number of bytes actually read: %li\n",
+			  page_size, GUC_LOG_FILE, read_size);
+	} while (read_size != 0);
+
+	/*
+	 * When buffer is empty, we trigger a flush
+	 * by sending anything to the file
+	 * I915_GUC_LOG_RELAY_FILE
+	 */
+	write(fd_relay, buffer, 1);
+
+	/* We read again and now we should get some bytes */
+	read_size = read(fd_log, buffer, page_size);
+
+	free(buffer);
+
+	igt_debug("Shall attempt to read %d bytes from file %s.\n"
+		  "The number of bytes actually read: %li\n",
+		  page_size, GUC_LOG_FILE, read_size);
+
+
+	igt_assert(read_size > 0);
+
+	/*
+	 * Now we try close the I915_GUC_LOG_RELAY_FILE file.
+	 * This should cause the GUC_LOG_FILE file to be closed
+	 * and removed from debugfs
+	 */
+	close(fd_relay);
+	igt_assert(!igt_debugfs_has_filename(gfx_fd, GUC_LOG_FILE));
+}
+
 igt_main
 {
 	int fd = -1, debugfs;
@@ -173,6 +263,9 @@ igt_main
 		igt_success();
 	}
 
+	igt_subtest("guc_log_relay")
+		check_guc_log_relay(fd);
+
 	igt_fixture {
 		igt_display_fini(&display);
 		close(debugfs);
-- 
2.14.3



More information about the igt-dev mailing list