intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH i-g-t] tests: Adding kms_dp_aux_dev test.
@ 2015-09-28 23:54 Rafael Antognolli
  2015-09-29  7:47 ` Daniel Vetter
  2015-09-29  7:53 ` Jani Nikula
  0 siblings, 2 replies; 6+ messages in thread
From: Rafael Antognolli @ 2015-09-28 23:54 UTC (permalink / raw)
  To: intel-gfx, dri-devel

This new test makes some basic testing on the proposed drm_dp_aux_dev
interface. If the feature is enabled and the drm_dp_aux_dev class is
present, it will check for available DP aux channels and test them for:
	- basic seek to 0 and read 1 byte
	- seek to the last address and read, to confirm 0 is returned
	- seek one more byte and confirm that EINVAL is returned
	- try to read 64 bytes when at 8 bytes from the end of the
	address space
	- try to read 64 bytes at the address 0.

So far, no write checks are done.

Signed-off-by: Rafael Antognolli <rafael.antognolli@intel.com>
---
 tests/.gitignore       |   1 +
 tests/Makefile.sources |   1 +
 tests/kms_dp_aux_dev.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 136 insertions(+)
 create mode 100644 tests/kms_dp_aux_dev.c

diff --git a/tests/.gitignore b/tests/.gitignore
index dc8bb53..efdad75 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -127,6 +127,7 @@ kms_3d
 kms_addfb_basic
 kms_crtc_background_color
 kms_cursor_crc
+kms_dp_aux_dev
 kms_draw_crc
 kms_fbc_crc
 kms_fbcon_fbt
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 2e2e088..dc07737 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -64,6 +64,7 @@ TESTS_progs_M = \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
 	kms_cursor_crc \
+	kms_dp_aux_dev \
 	kms_draw_crc \
 	kms_fbc_crc \
 	kms_fbcon_fbt \
diff --git a/tests/kms_dp_aux_dev.c b/tests/kms_dp_aux_dev.c
new file mode 100644
index 0000000..aab8c95
--- /dev/null
+++ b/tests/kms_dp_aux_dev.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/** @file kms_dp_aux_dev.c
+ *
+ * This is a test of functionality of drm_dp_aux_dev.
+ */
+
+#include "igt.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <drm.h>
+
+#define DRM_DP_AUX_SYSFS_PATH "/sys/class/drm_dp_aux_dev"
+
+IGT_TEST_DESCRIPTION("Test of drm_aux_dev nodes.");
+
+static void drm_dp_aux_test(const char *devname)
+{
+	char basedir[] = "/dev/";
+	char name[256 + sizeof(basedir)];
+	off_t address;
+	uint8_t buf;
+	uint8_t bigbuf[64];
+	int fd;
+
+	ssize_t res;
+
+ 	snprintf(name, sizeof(name), "%s%s", basedir, devname);
+ 	igt_info("Running test on %s\n", name);
+ 
+	/* Check if this DP aux channel is connected before continuing tests */
+ 	fd = open(name, O_RDONLY);
+ 	igt_assert_lte(0, fd);
+ 	address = lseek(fd, 0x0, SEEK_SET);
+ 	igt_assert_eq(address, 0x0);
+ 	res = read(fd, &buf, sizeof(buf));
+ 	igt_skip_on(res < 0 && errno == ETIMEDOUT);
+ 
+
+	/* Channel is connected, start tests */
+ 	igt_assert_eq(res, sizeof(buf));
+
+	/* Test reads on the end of address space */
+	address = lseek(fd, 0, SEEK_END);
+	igt_assert_eq(address, 1 << 20);
+	res = read(fd, &buf, sizeof(buf));
+	igt_assert_eq(res, 0);
+
+	address = lseek(fd, 1, SEEK_CUR);
+	igt_assert_eq(address, -1);
+	igt_assert_eq(errno, EINVAL);
+
+	address = lseek(fd, -8, SEEK_END);
+	res = read(fd, bigbuf, sizeof(bigbuf));
+	igt_assert_eq(res, 8);
+
+	/* Test reading more than 16 bytes at once */
+	address = lseek(fd, 0, SEEK_SET);
+	res = read(fd, bigbuf, sizeof(bigbuf));
+	igt_assert_eq(res, sizeof(bigbuf));
+}
+
+static void for_each_dp_aux(DIR *dir)
+{
+	int count = 0;
+	struct dirent *dirent;
+
+	if (!dir)
+		return;
+
+	rewinddir(dir);
+	while ((dirent = readdir(dir))) {
+		if (dirent->d_name[0] == '.')
+			continue;
+
+		count++;
+		igt_subtest(dirent->d_name)
+			drm_dp_aux_test(dirent->d_name);
+	}
+
+	closedir(dir);
+}
+
+igt_main
+{
+	struct stat st;
+	DIR *dir = NULL;
+
+	igt_fixture {
+		int count = 0;
+		struct dirent *dirent;
+
+		igt_require(stat(DRM_DP_AUX_SYSFS_PATH, &st) == 0);
+		igt_require(S_ISDIR(st.st_mode));
+
+		dir = opendir(DRM_DP_AUX_SYSFS_PATH);
+		igt_require(dir);
+
+		while ((dirent = readdir(dir))) {
+			if (dirent->d_name[0] != '.')
+				count++;
+		}
+
+		igt_require(count > 0);
+	}
+
+	for_each_dp_aux(dir);
+}
-- 
2.4.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH i-g-t] tests: Adding kms_dp_aux_dev test.
@ 2016-02-19 21:24 Rafael Antognolli
  2016-02-19 22:13 ` Ville Syrjälä
  0 siblings, 1 reply; 6+ messages in thread
From: Rafael Antognolli @ 2016-02-19 21:24 UTC (permalink / raw)
  To: intel-gfx; +Cc: paulo.r.zanoni

This new test makes some basic testing on the proposed drm_dp_aux_dev
interface. If the feature is enabled and the drm_dp_aux_dev class is
present, it will check for available DP aux channels and test them for:
	- basic seek to 0 and read 1 byte
	- seek to the last address and read, to confirm 0 is returned
	- seek one more byte and confirm that EINVAL is returned
	- try to read 64 bytes when at 8 bytes from the end of the
	address space
	- try to read 64 bytes at the address 0.

So far, no write checks are done.

Signed-off-by: Rafael Antognolli <rafael.antognolli@intel.com>
---
 tests/Makefile.sources |   1 +
 tests/kms_dp_aux_dev.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 178 insertions(+)
 create mode 100644 tests/kms_dp_aux_dev.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index f8b18b0..7920e23 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -79,6 +79,7 @@ TESTS_progs_M = \
 	kms_atomic \
 	kms_chv_cursor_fail \
 	kms_cursor_crc \
+	kms_dp_aux_dev \
 	kms_draw_crc \
 	kms_fbc_crc \
 	kms_fbcon_fbt \
diff --git a/tests/kms_dp_aux_dev.c b/tests/kms_dp_aux_dev.c
new file mode 100644
index 0000000..92e96dd
--- /dev/null
+++ b/tests/kms_dp_aux_dev.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/** @file kms_dp_aux_dev.c
+ *
+ * This is a test of functionality of drm_dp_aux_dev.
+ */
+
+#include "igt.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <drm.h>
+
+#define MAX_CONNECTORS 32
+#define DRM_DP_AUX_SYSFS_PATH "/sys/class/drm_dp_aux_dev"
+
+IGT_TEST_DESCRIPTION("Test of drm_aux_dev nodes.");
+
+static void seek_too_far(int fd)
+{
+	off_t address;
+	uint8_t buf;
+	uint8_t bigbuf[64];
+	ssize_t res;
+
+	/* Test reads on the end of address space */
+	address = lseek(fd, 0, SEEK_END);
+	igt_assert_eq(address, 1 << 20);
+	res = read(fd, &buf, sizeof(buf));
+	igt_assert_eq(res, 0);
+
+	address = lseek(fd, 1, SEEK_CUR);
+	igt_assert_eq(address, -1);
+	igt_assert_eq(errno, EINVAL);
+
+	address = lseek(fd, -8, SEEK_END);
+	res = read(fd, bigbuf, sizeof(bigbuf));
+	igt_assert_eq(res, 8);
+}
+
+static void read_large_chunk(int fd)
+{
+	uint8_t bigbuf[64];
+	ssize_t res;
+
+	/* Test reading more than 16 bytes at once */
+	lseek(fd, 0, SEEK_SET);
+	res = read(fd, bigbuf, sizeof(bigbuf));
+	igt_assert_eq(res, sizeof(bigbuf));
+}
+
+static void basic_seek_and_read(int fd)
+{
+	char buf;
+	ssize_t res;
+	off_t address;
+
+	address = lseek(fd, 0x0, SEEK_SET);
+	igt_assert_eq(address, 0x0);
+
+	res = read(fd, &buf, sizeof(buf));
+	igt_assert_eq(res, sizeof(buf));
+}
+
+static int count = 0;
+static int fds[MAX_CONNECTORS];
+static bool checked_connections = false;
+static bool connected[MAX_CONNECTORS];
+
+static bool check_aux_connected(int fd)
+{
+	char buf;
+	ssize_t res;
+
+	res = read(fd, &buf, sizeof(buf));
+	igt_assert(res >= 0 || errno == ETIMEDOUT);
+	if (res < 0 && errno == ETIMEDOUT)
+		return false;
+	else
+		return true;
+}
+
+static void for_each_dp_aux(void (*fn)(int))
+{
+	int i;
+	int total = 0;
+
+	for (i = 0; i < count; i++) {
+		igt_assert_fd(fds[i]);
+
+		/* The first time that this loop is executed, check if each aux
+		 * dp is connected and store that result for the next pass
+		 */
+		if (!checked_connections)
+			connected[i] = check_aux_connected(fds[i]);
+
+		if (connected[i]) {
+			fn(fds[i]);
+			total++;
+		}
+	}
+
+	checked_connections = true;
+
+	igt_require(total > 0);
+}
+
+igt_main
+{
+	struct stat st;
+	DIR *dir = NULL;
+
+	igt_fixture {
+		struct dirent *dirent;
+		const char basedir[] = "/dev/";
+		size_t len_base = sizeof(basedir);
+
+		igt_require(stat(DRM_DP_AUX_SYSFS_PATH, &st) == 0);
+		igt_require(S_ISDIR(st.st_mode));
+
+		dir = opendir(DRM_DP_AUX_SYSFS_PATH);
+		igt_require(dir);
+
+		/* store each dp aux dev for later use */
+		while ((dirent = readdir(dir))) {
+			char entry[len_base + NAME_MAX];
+			if (dirent->d_name[0] == '.')
+				continue;
+
+			snprintf(entry, sizeof(entry), "%s%s", basedir, dirent->d_name);
+			fds[count] = open(entry, O_RDONLY);
+			count++;
+		}
+		igt_require(count > 0);
+	}
+
+	igt_subtest("basic_seek_and_read")
+		for_each_dp_aux(basic_seek_and_read);
+
+	igt_subtest("seek-too-far")
+		for_each_dp_aux(seek_too_far);
+
+	igt_subtest("read-large-chunk")
+		for_each_dp_aux(read_large_chunk);
+
+	igt_fixture {
+		int i;
+		for (i = 0; i < count; i++)
+			close(fds[i]);
+		closedir(dir);
+	}
+}
-- 
2.5.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-19 22:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-28 23:54 [PATCH i-g-t] tests: Adding kms_dp_aux_dev test Rafael Antognolli
2015-09-29  7:47 ` Daniel Vetter
2015-09-29  7:53 ` Jani Nikula
2015-09-29 16:01   ` Ville Syrjälä
  -- strict thread matches above, loose matches on Subject: below --
2016-02-19 21:24 Rafael Antognolli
2016-02-19 22:13 ` Ville Syrjälä

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).