[PATCH i-g-t 8/9] tests/fbdev: Add tests for accessing framebuffer near EOF

Chris Wilson chris at chris-wilson.co.uk
Mon Nov 23 12:34:27 UTC 2020


From: Thomas Zimmermann <tzimmermann at suse.de>

Fbdev has some specific behavior when reading/writing near the EOF, which
the eof test checks. If at least one bytes has been written, the number
of bytes has to be returned, otherwise an error code (if any) has to be
returned, or otherwise 0 has to returned. Not all drivers get this right.

v4:
	* replace igt_require() by igt_assert() in "eof" (Petri)
	* add eof test to CI
v3:
	* put igt_describe() before igt_subtest() (Petri)

Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/fbdev.c                         | 52 ++++++++++++++++++++++++++-
 tests/intel-ci/fast-feedback.testlist |  1 +
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/tests/fbdev.c b/tests/fbdev.c
index 629e893a2..b6f85254c 100644
--- a/tests/fbdev.c
+++ b/tests/fbdev.c
@@ -79,7 +79,8 @@ static void framebuffer_tests(int fd)
 			   PROT_WRITE, MAP_SHARED, fd, 0);
 		igt_assert(map != MAP_FAILED);
 
-		buf = malloc(fix_info.smem_len);
+		/* allocate two additional bytes for eof test */
+		buf = malloc(fix_info.smem_len + 2);
 		igt_require(buf);
 
 		ret = sysconf(_SC_PAGESIZE);
@@ -201,6 +202,55 @@ static void framebuffer_tests(int fd)
 			     pos - map);
 	}
 
+	igt_describe("Check framebuffer access near EOF");
+	igt_subtest("eof") {
+		unsigned long lastindex = fix_info.smem_len - 1;
+		unsigned char * const maplast = map + lastindex;
+		unsigned char * const buflast = buf + lastindex;
+		ssize_t ret;
+
+		*buflast = 0x55;
+
+		/* write across EOF; set remaining bytes */
+		ret = pwrite(fd, buflast, 2, lastindex);
+		igt_assert_f(ret == 1, "write crossed EOF, ret=%zd\n", ret);
+		igt_assert_f(*maplast == *buflast,
+			     "write buffer differs from mapped framebuffer at final byte, "
+			     "maplast=%u buflast=%u\n", *maplast, *buflast);
+
+		/* write at EOF; get ENOSPC */
+		ret = pwrite(fd, &buflast[1], 1, lastindex + 1);
+		igt_assert_f(ret == -1 && errno == ENOSPC,
+			     "write at EOF, ret=%zd\n", ret);
+
+		*maplast = 0;
+
+		/* write final byte */
+		ret = pwrite(fd, buflast, 1, lastindex);
+		igt_assert_f(ret == 1, "write before EOF, ret=%zd\n", ret);
+		igt_assert_f(*maplast == *buflast,
+			     "write buffer differs from mapped framebuffer at final byte, "
+			     "maplast=%u buflast=%u\n", *maplast, *buflast);
+
+		/* write after EOF; get EFBIG */
+		ret = pwrite(fd, &buflast[2], 1, lastindex + 2);
+		igt_assert_f(ret == -1 && errno == EFBIG,
+			     "write after EOF, ret=%zd\n", ret);
+
+		*maplast = 0;
+
+		/* read across the EOF; get remaining bytes */
+		ret = pread(fd, buflast, 2, lastindex);
+		igt_assert_f(ret == 1, "read before EOF, ret=%zd\n", ret);
+		igt_assert_f(*maplast == *buflast,
+			     "read buffer differs from mapped framebuffer at final byte, "
+			     "maplast=%u buflast=%u\n", *maplast, *buflast);
+
+		/* read after EOF; get 0 */
+		ret = pread(fd, &buflast[1], 1, lastindex + 1);
+		igt_assert_f(ret == 0, "read at EOF, ret=%zd\n", ret);
+	}
+
 	igt_fixture {
 		free(buf);
 		/* don't leave garbage on the screen */
diff --git a/tests/intel-ci/fast-feedback.testlist b/tests/intel-ci/fast-feedback.testlist
index 58e2ac1c5..9e0b71e9b 100644
--- a/tests/intel-ci/fast-feedback.testlist
+++ b/tests/intel-ci/fast-feedback.testlist
@@ -2,6 +2,7 @@
 
 igt at core_auth@basic-auth
 igt at debugfs_test@read_all_entries
+igt at fbdev@eof
 igt at fbdev@info
 igt at fbdev@read
 igt at fbdev@write
-- 
2.29.2



More information about the Intel-gfx-trybot mailing list