Re: [Intel-gfx] [PATCH i-g-t v2] tests: Adding kms_dp_aux_dev test.

2016-03-02 Thread Ville Syrjälä
On Tue, Mar 01, 2016 at 02:54:24PM -0800, Rafael Antognolli wrote:
> 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.
> 
> v2:
>  - compare DP version, max link rate and max lane count
>  - check seek position after reading
>  - merge all subtests into a single one.
> 
> Signed-off-by: Rafael Antognolli 

lgtm

> ---
>  tests/Makefile.sources |   1 +
>  tests/kms_dp_aux_dev.c | 190 
> +
>  2 files changed, 191 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 000..088d980
> --- /dev/null
> +++ b/tests/kms_dp_aux_dev.c
> @@ -0,0 +1,190 @@
> +/*
> + * Copyright © 2016 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#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 basic_seek_and_read(int fd)
> +{
> + off_t address;
> + uint8_t buf;
> + uint8_t bigbuf[64];
> + ssize_t res;
> +
> + /* Basic seek and read */
> + address = lseek(fd, 0x0, SEEK_SET);
> + igt_assert_eq(address, 0x0);
> +
> + res = read(fd, , sizeof(buf)); /* read DP version */
> + igt_assert_eq(res, sizeof(buf));
> +
> + address = lseek(fd, 0, SEEK_CUR);
> + igt_assert_eq(address, 0x1);
> +
> + igt_assert((buf == 0x10) || (buf == 0x11) || (buf == 0x12));
> +
> + res = read(fd, , sizeof(buf)); /* read max link rate */
> + igt_assert_eq(res, sizeof(buf));
> +
> + address = lseek(fd, 0, SEEK_CUR);
> + igt_assert_eq(address, 0x2);
> +
> + igt_assert((buf == 0x06) || (buf == 0x0a) || (buf == 0x14));
> +
> + res = read(fd, , sizeof(buf)); /* read max max lane count */
> + igt_assert_eq(res, sizeof(buf));
> +
> + address = lseek(fd, 0, SEEK_CUR);
> + igt_assert_eq(address, 0x3);
> +
> + buf &= 0xf;
> + igt_assert((buf == 0x1) || (buf == 0x2) || (buf == 0x4));
> +
> + /* Test reads on the end of address space */
> + address = lseek(fd, 0, SEEK_END);
> + igt_assert_eq(address, 1 << 20);
> + res = read(fd, , sizeof(buf));
> + igt_assert_eq(res, 0);
> +
> + address = lseek(fd, 0, SEEK_CUR);
> + igt_assert_eq(address, 1 << 20);
> +
> + 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);
> +
> + address = lseek(fd, 0, SEEK_CUR);
> + igt_assert_eq(address, 1 << 20);
> +
> + /* Test reading more than 16 bytes at once */
> + 

[Intel-gfx] [PATCH i-g-t v2] tests: Adding kms_dp_aux_dev test.

2016-03-01 Thread Rafael Antognolli
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.

v2:
 - compare DP version, max link rate and max lane count
 - check seek position after reading
 - merge all subtests into a single one.

Signed-off-by: Rafael Antognolli 
---
 tests/Makefile.sources |   1 +
 tests/kms_dp_aux_dev.c | 190 +
 2 files changed, 191 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 000..088d980
--- /dev/null
+++ b/tests/kms_dp_aux_dev.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright © 2016 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#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 basic_seek_and_read(int fd)
+{
+   off_t address;
+   uint8_t buf;
+   uint8_t bigbuf[64];
+   ssize_t res;
+
+   /* Basic seek and read */
+   address = lseek(fd, 0x0, SEEK_SET);
+   igt_assert_eq(address, 0x0);
+
+   res = read(fd, , sizeof(buf)); /* read DP version */
+   igt_assert_eq(res, sizeof(buf));
+
+   address = lseek(fd, 0, SEEK_CUR);
+   igt_assert_eq(address, 0x1);
+
+   igt_assert((buf == 0x10) || (buf == 0x11) || (buf == 0x12));
+
+   res = read(fd, , sizeof(buf)); /* read max link rate */
+   igt_assert_eq(res, sizeof(buf));
+
+   address = lseek(fd, 0, SEEK_CUR);
+   igt_assert_eq(address, 0x2);
+
+   igt_assert((buf == 0x06) || (buf == 0x0a) || (buf == 0x14));
+
+   res = read(fd, , sizeof(buf)); /* read max max lane count */
+   igt_assert_eq(res, sizeof(buf));
+
+   address = lseek(fd, 0, SEEK_CUR);
+   igt_assert_eq(address, 0x3);
+
+   buf &= 0xf;
+   igt_assert((buf == 0x1) || (buf == 0x2) || (buf == 0x4));
+
+   /* Test reads on the end of address space */
+   address = lseek(fd, 0, SEEK_END);
+   igt_assert_eq(address, 1 << 20);
+   res = read(fd, , sizeof(buf));
+   igt_assert_eq(res, 0);
+
+   address = lseek(fd, 0, SEEK_CUR);
+   igt_assert_eq(address, 1 << 20);
+
+   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);
+
+   address = lseek(fd, 0, SEEK_CUR);
+   igt_assert_eq(address, 1 << 20);
+
+   /* 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));
+
+   address = lseek(fd, 0, SEEK_CUR);
+   igt_assert_eq(address, 64);
+}
+
+static int count = 0;
+static int fds[MAX_CONNECTORS];
+static