[igt-dev] [PATCH v3 4/8] tests/fbdev: Add tests for unaligned reads on framebuffer memory

Thomas Zimmermann tzimmermann at suse.de
Tue Nov 10 07:50:58 UTC 2020


The tests for unaligned reads start and stop reading within pages.

v3:
	* put igt_describe() before igt_subtest() (Petri)

Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>
---
 tests/fbdev.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/tests/fbdev.c b/tests/fbdev.c
index 97d66217..a6376c3b 100644
--- a/tests/fbdev.c
+++ b/tests/fbdev.c
@@ -64,10 +64,13 @@ static void mode_tests(int fd)
 static void framebuffer_tests(int fd)
 {
 	struct fb_fix_screeninfo fix_info;
-	void *map;
-	void *buf;
+	unsigned char *map;
+	unsigned char *buf;
+	size_t pagesize;
 
 	igt_fixture {
+		long ret;
+
 		igt_require(ioctl(fd, FBIOGET_FSCREENINFO, &fix_info) == 0);
 		igt_require(fix_info.smem_len);
 
@@ -77,6 +80,10 @@ static void framebuffer_tests(int fd)
 
 		buf = malloc(fix_info.smem_len);
 		igt_assert(buf);
+
+		ret = sysconf(_SC_PAGESIZE);
+		igt_assert(ret != -1);
+		pagesize = ret;
 	}
 
 	igt_describe("Check read operations on framebuffer memory");
@@ -99,6 +106,35 @@ static void framebuffer_tests(int fd)
 		igt_require_f(!cmp, "read buffer differs from mapped framebuffer for 0x55\n");
 	}
 
+	igt_describe("Check read operations on unaligned locations in framebuffer memory");
+	igt_subtest("unaligned-read") {
+		off_t off;
+		size_t len;
+		ssize_t ret;
+		const unsigned char *pos;
+
+		off = pagesize + (pagesize >> 2); // 1.25 * pagesize
+		len = (pagesize << 2) + (pagesize >> 1); // 4.5 * pagesize
+		igt_require_f((off + len) < fix_info.smem_len, "framebuffer too small\n");
+
+		/* read at unaligned location and compare */
+		memset(map, 0, fix_info.smem_len);
+		memset(&map[off], 0x55, len);
+		memset(buf, 0xff, fix_info.smem_len);
+		ret = pread(fd, &buf[off], len, off);
+		igt_require_f(ret == (ssize_t)len, "pread failed, ret=%zd\n", ret);
+		pos = memchr(buf, 0x55, fix_info.smem_len);
+		igt_require_f(pos, "0x55 not found within read buffer\n");
+		igt_require_f(pos == &buf[off], "0x55 found at pos %zu, expected %lld\n",
+			     pos - buf, (long long)off);
+		pos = memchr(&buf[off], 0xff, fix_info.smem_len - off);
+		igt_require_f(pos, "0xff not found within read buffer\n");
+		igt_require_f(pos == &buf[off + len], "0xff found at pos %zu, expected %lld\n",
+			     pos - buf, (long long)(off + len));
+		pos = memchr(&buf[off + len], 0x55, fix_info.smem_len - off + len);
+		igt_require_f(pos, "found 0x55 at pos %zu, none expected\n", pos - buf);
+	}
+
 	igt_fixture {
 		free(buf);
 		memset(map, 0, fix_info.smem_len); // don't leave garbage on the screen
-- 
2.29.2



More information about the igt-dev mailing list