From 47a2b7dc03e35d4eaf8148b87aeea8dd96723b4d Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 22 Apr 2008 16:08:23 -0700 Subject: Initial add of mmfs module. --- tests/Makefile.am | 4 +++- tests/mmfs_basic.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 tests/mmfs_basic.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index dce1754e..4a7b0119 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,5 @@ AM_CFLAGS = \ + -I $(top_srcdir)/linux-core \ -I $(top_srcdir)/shared-core \ -I $(top_srcdir)/libdrm @@ -22,7 +23,8 @@ TESTS = auth \ getstats \ lock \ setversion \ - updatedraw + updatedraw \ + mmfs_basic EXTRA_PROGRAMS = $(TESTS) CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) diff --git a/tests/mmfs_basic.c b/tests/mmfs_basic.c new file mode 100644 index 00000000..907dc585 --- /dev/null +++ b/tests/mmfs_basic.c @@ -0,0 +1,68 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include "mmfs.h" + +static void +create_mmfs_device() +{ + struct stat sb; + int ret; + + ret = stat(MMFS_DEVICE_PATH, &sb); + + if (ret == 0) + return; + + ret = mknod(MMFS_DEVICE_PATH, S_IFCHR | S_IRUSR | S_IWUSR, + makedev(MMFS_DEVICE_MAJOR, 0)); + + if (ret != 0) + errx(1, "mknod()"); +} + + +int main(int argc, char **argv) +{ + int fd; + + create_mmfs_device(); + + fd = open(MMFS_DEVICE_PATH, O_RDWR); + if (fd == -1) + errx(1, "open()"); + + close(fd); + + return 0; +} -- cgit v1.2.3 From 8665b666c7e2ecdee7d27e1ad540910a0223ba6d Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 23 Apr 2008 11:22:59 -0700 Subject: Move mmfs.h userland interface to shared-core. --- tests/Makefile.am | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 4a7b0119..97752774 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,4 @@ AM_CFLAGS = \ - -I $(top_srcdir)/linux-core \ -I $(top_srcdir)/shared-core \ -I $(top_srcdir)/libdrm -- cgit v1.2.3 From c1fec43b553ea93460b58995a1229e84d8bb45b4 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 23 Apr 2008 11:32:31 -0700 Subject: Extend the mmfs basic test to do a couple of ioctls. --- tests/mmfs_basic.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'tests') diff --git a/tests/mmfs_basic.c b/tests/mmfs_basic.c index 907dc585..b0ae8905 100644 --- a/tests/mmfs_basic.c +++ b/tests/mmfs_basic.c @@ -27,9 +27,11 @@ #include #include +#include #include #include #include +#include #include #include "mmfs.h" @@ -51,6 +53,65 @@ create_mmfs_device() errx(1, "mknod()"); } +static void +test_bad_unref(int fd) +{ + struct mmfs_unreference_args unref; + int ret; + + printf("Testing error return on bad unreference ioctl.\n"); + + unref.handle = 0x10101010; + ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref); + + assert(ret == -1 && errno == EINVAL); +} + +static void +test_bad_ioctl(int fd) +{ + int ret; + + printf("Testing error return on bad ioctl.\n"); + + ret = ioctl(fd, _IO(MMFS_IOCTL_BASE, 0xf0), 0); + + assert(ret == -1 && errno == EINVAL); +} + +static void +test_alloc_unref(int fd) +{ + struct mmfs_alloc_args alloc; + struct mmfs_unreference_args unref; + int ret; + + printf("Testing allocating and unreferencing an object.\n"); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = 16 * 1024; + ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); + assert(ret == 0); + + unref.handle = alloc.handle; + ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref); +} + +static void +test_alloc_close(int fd) +{ + struct mmfs_alloc_args alloc; + int ret; + + printf("Testing closing with an object allocated.\n"); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = 16 * 1024; + ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); + assert(ret == 0); + + close(fd); +} int main(int argc, char **argv) { @@ -62,6 +123,11 @@ int main(int argc, char **argv) if (fd == -1) errx(1, "open()"); + test_bad_ioctl(fd); + test_bad_unref(fd); + test_alloc_unref(fd); + test_alloc_close(fd); + close(fd); return 0; -- cgit v1.2.3 From 8c741ed54e1be63528e79222b600f37506c6d6d2 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 23 Apr 2008 13:06:58 -0700 Subject: Add pread/pwrite ioctls to mmfs. --- tests/Makefile.am | 3 +- tests/drmtest.c | 33 +++++++++++++ tests/drmtest.h | 1 + tests/mmfs_basic.c | 24 +--------- tests/mmfs_readwrite.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+), 24 deletions(-) create mode 100644 tests/mmfs_readwrite.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 97752774..e2931013 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,7 +23,8 @@ TESTS = auth \ lock \ setversion \ updatedraw \ - mmfs_basic + mmfs_basic \ + mmfs_readwrite EXTRA_PROGRAMS = $(TESTS) CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) diff --git a/tests/drmtest.c b/tests/drmtest.c index cae99a0c..58f71a6a 100644 --- a/tests/drmtest.c +++ b/tests/drmtest.c @@ -26,7 +26,9 @@ */ #include +#include #include "drmtest.h" +#include "mmfs.h" /** Open the first DRM device we can find, searching up to 16 device nodes */ int drm_open_any(void) @@ -81,3 +83,34 @@ int drm_open_any_master(void) abort(); } +static void +create_mmfs_device() +{ + struct stat sb; + int ret; + + ret = stat(MMFS_DEVICE_PATH, &sb); + + if (ret == 0) + return; + + ret = mknod(MMFS_DEVICE_PATH, S_IFCHR | S_IRUSR | S_IWUSR, + makedev(MMFS_DEVICE_MAJOR, 0)); + + if (ret != 0) + errx(1, "mknod()"); +} + +int +open_mmfs_device() +{ + int fd; + + create_mmfs_device(); + + fd = open(MMFS_DEVICE_PATH, O_RDWR); + if (fd == -1) + errx(1, "open()"); + + return fd; +} diff --git a/tests/drmtest.h b/tests/drmtest.h index afa0df4a..b84ada71 100644 --- a/tests/drmtest.h +++ b/tests/drmtest.h @@ -35,3 +35,4 @@ int drm_open_any(void); int drm_open_any_master(void); +int open_mmfs_device(); diff --git a/tests/mmfs_basic.c b/tests/mmfs_basic.c index b0ae8905..c6975b0b 100644 --- a/tests/mmfs_basic.c +++ b/tests/mmfs_basic.c @@ -35,24 +35,6 @@ #include #include "mmfs.h" -static void -create_mmfs_device() -{ - struct stat sb; - int ret; - - ret = stat(MMFS_DEVICE_PATH, &sb); - - if (ret == 0) - return; - - ret = mknod(MMFS_DEVICE_PATH, S_IFCHR | S_IRUSR | S_IWUSR, - makedev(MMFS_DEVICE_MAJOR, 0)); - - if (ret != 0) - errx(1, "mknod()"); -} - static void test_bad_unref(int fd) { @@ -117,11 +99,7 @@ int main(int argc, char **argv) { int fd; - create_mmfs_device(); - - fd = open(MMFS_DEVICE_PATH, O_RDWR); - if (fd == -1) - errx(1, "open()"); + fd = open_mmfs_device(); test_bad_ioctl(fd); test_bad_unref(fd); diff --git a/tests/mmfs_readwrite.c b/tests/mmfs_readwrite.c new file mode 100644 index 00000000..09d1967d --- /dev/null +++ b/tests/mmfs_readwrite.c @@ -0,0 +1,125 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "mmfs.h" + +#define MMFS_BUFFER_SIZE 16384 + +int do_read(int fd, int handle, void *buf, int offset, int size) +{ + struct mmfs_pread_args read; + + /* Ensure that we don't have any convenient data in buf in case + * we fail. + */ + memset(buf, 0xd0, size); + + memset(&read, 0, sizeof(read)); + read.handle = handle; + read.data = buf; + read.size = size; + read.offset = offset; + + return ioctl(fd, MMFS_IOCTL_PREAD, &read); +} + +int do_write(int fd, int handle, void *buf, int offset, int size) +{ + struct mmfs_pwrite_args write; + + memset(&write, 0, sizeof(write)); + write.handle = handle; + write.data = buf; + write.size = size; + write.offset = offset; + + return ioctl(fd, MMFS_IOCTL_PWRITE, &write); +} + +int main(int argc, char **argv) +{ + int fd; + struct mmfs_alloc_args alloc; + uint8_t expected[MMFS_BUFFER_SIZE]; + uint8_t buf[MMFS_BUFFER_SIZE]; + int ret; + int handle; + + fd = open_mmfs_device(); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = MMFS_BUFFER_SIZE; + ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); + assert(ret == 0); + handle = alloc.handle; + + printf("Testing contents of newly allocated object.\n"); + ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE); + assert(ret == 0); + memset(&expected, 0, sizeof(expected)); + assert(memcmp(expected, buf, sizeof(expected)) == 0); + + printf("Testing read beyond end of buffer.\n"); + ret = do_read(fd, handle, buf, MMFS_BUFFER_SIZE / 2, MMFS_BUFFER_SIZE); + assert(ret == -1 && errno == EINVAL); + + printf("Testing full write of buffer\n"); + memset(buf, 0, sizeof(buf)); + memset(buf + 1024, 0x01, 1024); + memset(expected + 1024, 0x01, 1024); + ret = do_write(fd, handle, buf, 0, MMFS_BUFFER_SIZE); + assert(ret == 0); + ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE); + assert(ret == 0); + assert(memcmp(buf, expected, sizeof(buf)) == 0); + + printf("Testing partial write of buffer\n"); + memset(buf + 4096, 0x02, 1024); + memset(expected + 4096, 0x02, 1024); + ret = do_write(fd, handle, buf + 4096, 4096, 1024); + assert(ret == 0); + ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE); + assert(ret == 0); + assert(memcmp(buf, expected, sizeof(buf)) == 0); + + printf("Testing partial read of buffer\n"); + ret = do_read(fd, handle, buf, 512, 1024); + assert(ret == 0); + assert(memcmp(buf, expected + 512, 1024) == 0); + + close(fd); + + return 0; +} -- cgit v1.2.3 From 22877864c204139fe1c46899bedd237e38f0e849 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 23 Apr 2008 14:52:30 -0700 Subject: Add mmap ioctl to mmfs. --- tests/Makefile.am | 3 +- tests/mmfs_mmap.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 tests/mmfs_mmap.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index e2931013..67cb034d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,7 +24,8 @@ TESTS = auth \ setversion \ updatedraw \ mmfs_basic \ - mmfs_readwrite + mmfs_readwrite \ + mmfs_mmap EXTRA_PROGRAMS = $(TESTS) CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) diff --git a/tests/mmfs_mmap.c b/tests/mmfs_mmap.c new file mode 100644 index 00000000..3cb6a853 --- /dev/null +++ b/tests/mmfs_mmap.c @@ -0,0 +1,129 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "mmfs.h" + +#define MMFS_BUFFER_SIZE 16384 + +int do_read(int fd, int handle, void *buf, int offset, int size) +{ + struct mmfs_pread_args read; + + /* Ensure that we don't have any convenient data in buf in case + * we fail. + */ + memset(buf, 0xd0, size); + + memset(&read, 0, sizeof(read)); + read.handle = handle; + read.data = buf; + read.size = size; + read.offset = offset; + + return ioctl(fd, MMFS_IOCTL_PREAD, &read); +} + +int do_write(int fd, int handle, void *buf, int offset, int size) +{ + struct mmfs_pwrite_args write; + + memset(&write, 0, sizeof(write)); + write.handle = handle; + write.data = buf; + write.size = size; + write.offset = offset; + + return ioctl(fd, MMFS_IOCTL_PWRITE, &write); +} + +int main(int argc, char **argv) +{ + int fd; + struct mmfs_alloc_args alloc; + struct mmfs_mmap_args mmap; + struct mmfs_unreference_args unref; + uint8_t expected[MMFS_BUFFER_SIZE]; + uint8_t buf[MMFS_BUFFER_SIZE]; + int ret; + int handle; + + fd = open_mmfs_device(); + + memset(&mmap, 0, sizeof(mmap)); + mmap.handle = 0x10101010; + mmap.offset = 0; + mmap.size = 4096; + printf("Testing mmaping of bad object.\n"); + ret = ioctl(fd, MMFS_IOCTL_MMAP, &mmap); + assert(ret == -1 && errno == EINVAL); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = MMFS_BUFFER_SIZE; + ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); + assert(ret == 0); + handle = alloc.handle; + + printf("Testing mmaping of newly allocated object.\n"); + mmap.handle = handle; + mmap.offset = 0; + mmap.size = MMFS_BUFFER_SIZE; + ret = ioctl(fd, MMFS_IOCTL_MMAP, &mmap); + assert(ret == 0); + + printf("Testing contents of newly allocated object.\n"); + memset(expected, 0, sizeof(expected)); + assert(memcmp(mmap.addr, expected, sizeof(expected)) == 0); + + printf("Testing coherency of writes and mmap reads.\n"); + memset(buf, 0, sizeof(buf)); + memset(buf + 1024, 0x01, 1024); + memset(expected + 1024, 0x01, 1024); + ret = do_write(fd, handle, buf, 0, MMFS_BUFFER_SIZE); + assert(ret == 0); + assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); + + printf("Testing that mapping stays after unreference\n"); + unref.handle = handle; + ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref); + assert(ret == 0); + assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); + + printf("Testing unmapping\n"); + munmap(mmap.addr, MMFS_BUFFER_SIZE); + + close(fd); + + return 0; +} -- cgit v1.2.3 From 3148c1636408cc422ab83c149a8963916dd376b0 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 29 Apr 2008 13:45:43 -0700 Subject: Move mmfs tests over to be drm tests. --- tests/Makefile.am | 6 +-- tests/mm_basic.c | 99 +++++++++++++++++++++++++++++++++++++ tests/mm_mmap.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/mm_readwrite.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++ tests/mmfs_basic.c | 112 ------------------------------------------ tests/mmfs_mmap.c | 129 ------------------------------------------------- tests/mmfs_readwrite.c | 125 ----------------------------------------------- 7 files changed, 356 insertions(+), 369 deletions(-) create mode 100644 tests/mm_basic.c create mode 100644 tests/mm_mmap.c create mode 100644 tests/mm_readwrite.c delete mode 100644 tests/mmfs_basic.c delete mode 100644 tests/mmfs_mmap.c delete mode 100644 tests/mmfs_readwrite.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 67cb034d..f997e26e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,9 +23,9 @@ TESTS = auth \ lock \ setversion \ updatedraw \ - mmfs_basic \ - mmfs_readwrite \ - mmfs_mmap + mm_basic \ + mm_readwrite \ + mm_mmap EXTRA_PROGRAMS = $(TESTS) CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) diff --git a/tests/mm_basic.c b/tests/mm_basic.c new file mode 100644 index 00000000..94240ee1 --- /dev/null +++ b/tests/mm_basic.c @@ -0,0 +1,99 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" + +static void +test_bad_unref(int fd) +{ + struct drm_mm_unreference_args unref; + int ret; + + printf("Testing error return on bad unreference ioctl.\n"); + + unref.handle = 0x10101010; + ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref); + + assert(ret == -1 && errno == EINVAL); +} + +static void +test_alloc_unref(int fd) +{ + struct drm_mm_alloc_args alloc; + struct drm_mm_unreference_args unref; + int ret; + + printf("Testing allocating and unreferencing an object.\n"); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = 16 * 1024; + ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc); + assert(ret == 0); + + unref.handle = alloc.handle; + ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref); +} + +static void +test_alloc_close(int fd) +{ + struct drm_mm_alloc_args alloc; + int ret; + + printf("Testing closing with an object allocated.\n"); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = 16 * 1024; + ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc); + assert(ret == 0); + + close(fd); +} + +int main(int argc, char **argv) +{ + int fd; + + fd = drm_open_any(); + + test_bad_unref(fd); + test_alloc_unref(fd); + test_alloc_close(fd); + + close(fd); + + return 0; +} diff --git a/tests/mm_mmap.c b/tests/mm_mmap.c new file mode 100644 index 00000000..e5c4538a --- /dev/null +++ b/tests/mm_mmap.c @@ -0,0 +1,129 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" + +#define OBJECT_SIZE 16384 + +int do_read(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_mm_pread_args read; + + /* Ensure that we don't have any convenient data in buf in case + * we fail. + */ + memset(buf, 0xd0, size); + + memset(&read, 0, sizeof(read)); + read.handle = handle; + read.data = buf; + read.size = size; + read.offset = offset; + + return ioctl(fd, DRM_IOCTL_MM_PREAD, &read); +} + +int do_write(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_mm_pwrite_args write; + + memset(&write, 0, sizeof(write)); + write.handle = handle; + write.data = buf; + write.size = size; + write.offset = offset; + + return ioctl(fd, DRM_IOCTL_MM_PWRITE, &write); +} + +int main(int argc, char **argv) +{ + int fd; + struct drm_mm_alloc_args alloc; + struct drm_mm_mmap_args mmap; + struct drm_mm_unreference_args unref; + uint8_t expected[OBJECT_SIZE]; + uint8_t buf[OBJECT_SIZE]; + int ret; + int handle; + + fd = drm_open_any(); + + memset(&mmap, 0, sizeof(mmap)); + mmap.handle = 0x10101010; + mmap.offset = 0; + mmap.size = 4096; + printf("Testing mmaping of bad object.\n"); + ret = ioctl(fd, DRM_IOCTL_MM_MMAP, &mmap); + assert(ret == -1 && errno == EINVAL); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc); + assert(ret == 0); + handle = alloc.handle; + + printf("Testing mmaping of newly allocated object.\n"); + mmap.handle = handle; + mmap.offset = 0; + mmap.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_MM_MMAP, &mmap); + assert(ret == 0); + + printf("Testing contents of newly allocated object.\n"); + memset(expected, 0, sizeof(expected)); + assert(memcmp(mmap.addr, expected, sizeof(expected)) == 0); + + printf("Testing coherency of writes and mmap reads.\n"); + memset(buf, 0, sizeof(buf)); + memset(buf + 1024, 0x01, 1024); + memset(expected + 1024, 0x01, 1024); + ret = do_write(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); + + printf("Testing that mapping stays after unreference\n"); + unref.handle = handle; + ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref); + assert(ret == 0); + assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); + + printf("Testing unmapping\n"); + munmap(mmap.addr, OBJECT_SIZE); + + close(fd); + + return 0; +} diff --git a/tests/mm_readwrite.c b/tests/mm_readwrite.c new file mode 100644 index 00000000..a778231a --- /dev/null +++ b/tests/mm_readwrite.c @@ -0,0 +1,125 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" + +#define OBJECT_SIZE 16384 + +int do_read(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_mm_pread_args read; + + /* Ensure that we don't have any convenient data in buf in case + * we fail. + */ + memset(buf, 0xd0, size); + + memset(&read, 0, sizeof(read)); + read.handle = handle; + read.data = buf; + read.size = size; + read.offset = offset; + + return ioctl(fd, DRM_IOCTL_MM_PREAD, &read); +} + +int do_write(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_mm_pwrite_args write; + + memset(&write, 0, sizeof(write)); + write.handle = handle; + write.data = buf; + write.size = size; + write.offset = offset; + + return ioctl(fd, DRM_IOCTL_MM_PWRITE, &write); +} + +int main(int argc, char **argv) +{ + int fd; + struct drm_mm_alloc_args alloc; + uint8_t expected[OBJECT_SIZE]; + uint8_t buf[OBJECT_SIZE]; + int ret; + int handle; + + fd = drm_open_any(); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc); + assert(ret == 0); + handle = alloc.handle; + + printf("Testing contents of newly allocated object.\n"); + ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + memset(&expected, 0, sizeof(expected)); + assert(memcmp(expected, buf, sizeof(expected)) == 0); + + printf("Testing read beyond end of buffer.\n"); + ret = do_read(fd, handle, buf, OBJECT_SIZE / 2, OBJECT_SIZE); + assert(ret == -1 && errno == EINVAL); + + printf("Testing full write of buffer\n"); + memset(buf, 0, sizeof(buf)); + memset(buf + 1024, 0x01, 1024); + memset(expected + 1024, 0x01, 1024); + ret = do_write(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + assert(memcmp(buf, expected, sizeof(buf)) == 0); + + printf("Testing partial write of buffer\n"); + memset(buf + 4096, 0x02, 1024); + memset(expected + 4096, 0x02, 1024); + ret = do_write(fd, handle, buf + 4096, 4096, 1024); + assert(ret == 0); + ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + assert(memcmp(buf, expected, sizeof(buf)) == 0); + + printf("Testing partial read of buffer\n"); + ret = do_read(fd, handle, buf, 512, 1024); + assert(ret == 0); + assert(memcmp(buf, expected + 512, 1024) == 0); + + close(fd); + + return 0; +} diff --git a/tests/mmfs_basic.c b/tests/mmfs_basic.c deleted file mode 100644 index c6975b0b..00000000 --- a/tests/mmfs_basic.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2008 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. - * - * Authors: - * Eric Anholt - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "mmfs.h" - -static void -test_bad_unref(int fd) -{ - struct mmfs_unreference_args unref; - int ret; - - printf("Testing error return on bad unreference ioctl.\n"); - - unref.handle = 0x10101010; - ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref); - - assert(ret == -1 && errno == EINVAL); -} - -static void -test_bad_ioctl(int fd) -{ - int ret; - - printf("Testing error return on bad ioctl.\n"); - - ret = ioctl(fd, _IO(MMFS_IOCTL_BASE, 0xf0), 0); - - assert(ret == -1 && errno == EINVAL); -} - -static void -test_alloc_unref(int fd) -{ - struct mmfs_alloc_args alloc; - struct mmfs_unreference_args unref; - int ret; - - printf("Testing allocating and unreferencing an object.\n"); - - memset(&alloc, 0, sizeof(alloc)); - alloc.size = 16 * 1024; - ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); - assert(ret == 0); - - unref.handle = alloc.handle; - ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref); -} - -static void -test_alloc_close(int fd) -{ - struct mmfs_alloc_args alloc; - int ret; - - printf("Testing closing with an object allocated.\n"); - - memset(&alloc, 0, sizeof(alloc)); - alloc.size = 16 * 1024; - ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); - assert(ret == 0); - - close(fd); -} - -int main(int argc, char **argv) -{ - int fd; - - fd = open_mmfs_device(); - - test_bad_ioctl(fd); - test_bad_unref(fd); - test_alloc_unref(fd); - test_alloc_close(fd); - - close(fd); - - return 0; -} diff --git a/tests/mmfs_mmap.c b/tests/mmfs_mmap.c deleted file mode 100644 index 3cb6a853..00000000 --- a/tests/mmfs_mmap.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright © 2008 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. - * - * Authors: - * Eric Anholt - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "mmfs.h" - -#define MMFS_BUFFER_SIZE 16384 - -int do_read(int fd, int handle, void *buf, int offset, int size) -{ - struct mmfs_pread_args read; - - /* Ensure that we don't have any convenient data in buf in case - * we fail. - */ - memset(buf, 0xd0, size); - - memset(&read, 0, sizeof(read)); - read.handle = handle; - read.data = buf; - read.size = size; - read.offset = offset; - - return ioctl(fd, MMFS_IOCTL_PREAD, &read); -} - -int do_write(int fd, int handle, void *buf, int offset, int size) -{ - struct mmfs_pwrite_args write; - - memset(&write, 0, sizeof(write)); - write.handle = handle; - write.data = buf; - write.size = size; - write.offset = offset; - - return ioctl(fd, MMFS_IOCTL_PWRITE, &write); -} - -int main(int argc, char **argv) -{ - int fd; - struct mmfs_alloc_args alloc; - struct mmfs_mmap_args mmap; - struct mmfs_unreference_args unref; - uint8_t expected[MMFS_BUFFER_SIZE]; - uint8_t buf[MMFS_BUFFER_SIZE]; - int ret; - int handle; - - fd = open_mmfs_device(); - - memset(&mmap, 0, sizeof(mmap)); - mmap.handle = 0x10101010; - mmap.offset = 0; - mmap.size = 4096; - printf("Testing mmaping of bad object.\n"); - ret = ioctl(fd, MMFS_IOCTL_MMAP, &mmap); - assert(ret == -1 && errno == EINVAL); - - memset(&alloc, 0, sizeof(alloc)); - alloc.size = MMFS_BUFFER_SIZE; - ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); - assert(ret == 0); - handle = alloc.handle; - - printf("Testing mmaping of newly allocated object.\n"); - mmap.handle = handle; - mmap.offset = 0; - mmap.size = MMFS_BUFFER_SIZE; - ret = ioctl(fd, MMFS_IOCTL_MMAP, &mmap); - assert(ret == 0); - - printf("Testing contents of newly allocated object.\n"); - memset(expected, 0, sizeof(expected)); - assert(memcmp(mmap.addr, expected, sizeof(expected)) == 0); - - printf("Testing coherency of writes and mmap reads.\n"); - memset(buf, 0, sizeof(buf)); - memset(buf + 1024, 0x01, 1024); - memset(expected + 1024, 0x01, 1024); - ret = do_write(fd, handle, buf, 0, MMFS_BUFFER_SIZE); - assert(ret == 0); - assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); - - printf("Testing that mapping stays after unreference\n"); - unref.handle = handle; - ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref); - assert(ret == 0); - assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); - - printf("Testing unmapping\n"); - munmap(mmap.addr, MMFS_BUFFER_SIZE); - - close(fd); - - return 0; -} diff --git a/tests/mmfs_readwrite.c b/tests/mmfs_readwrite.c deleted file mode 100644 index 09d1967d..00000000 --- a/tests/mmfs_readwrite.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright © 2008 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. - * - * Authors: - * Eric Anholt - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "mmfs.h" - -#define MMFS_BUFFER_SIZE 16384 - -int do_read(int fd, int handle, void *buf, int offset, int size) -{ - struct mmfs_pread_args read; - - /* Ensure that we don't have any convenient data in buf in case - * we fail. - */ - memset(buf, 0xd0, size); - - memset(&read, 0, sizeof(read)); - read.handle = handle; - read.data = buf; - read.size = size; - read.offset = offset; - - return ioctl(fd, MMFS_IOCTL_PREAD, &read); -} - -int do_write(int fd, int handle, void *buf, int offset, int size) -{ - struct mmfs_pwrite_args write; - - memset(&write, 0, sizeof(write)); - write.handle = handle; - write.data = buf; - write.size = size; - write.offset = offset; - - return ioctl(fd, MMFS_IOCTL_PWRITE, &write); -} - -int main(int argc, char **argv) -{ - int fd; - struct mmfs_alloc_args alloc; - uint8_t expected[MMFS_BUFFER_SIZE]; - uint8_t buf[MMFS_BUFFER_SIZE]; - int ret; - int handle; - - fd = open_mmfs_device(); - - memset(&alloc, 0, sizeof(alloc)); - alloc.size = MMFS_BUFFER_SIZE; - ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); - assert(ret == 0); - handle = alloc.handle; - - printf("Testing contents of newly allocated object.\n"); - ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE); - assert(ret == 0); - memset(&expected, 0, sizeof(expected)); - assert(memcmp(expected, buf, sizeof(expected)) == 0); - - printf("Testing read beyond end of buffer.\n"); - ret = do_read(fd, handle, buf, MMFS_BUFFER_SIZE / 2, MMFS_BUFFER_SIZE); - assert(ret == -1 && errno == EINVAL); - - printf("Testing full write of buffer\n"); - memset(buf, 0, sizeof(buf)); - memset(buf + 1024, 0x01, 1024); - memset(expected + 1024, 0x01, 1024); - ret = do_write(fd, handle, buf, 0, MMFS_BUFFER_SIZE); - assert(ret == 0); - ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE); - assert(ret == 0); - assert(memcmp(buf, expected, sizeof(buf)) == 0); - - printf("Testing partial write of buffer\n"); - memset(buf + 4096, 0x02, 1024); - memset(expected + 4096, 0x02, 1024); - ret = do_write(fd, handle, buf + 4096, 4096, 1024); - assert(ret == 0); - ret = do_read(fd, handle, buf, 0, MMFS_BUFFER_SIZE); - assert(ret == 0); - assert(memcmp(buf, expected, sizeof(buf)) == 0); - - printf("Testing partial read of buffer\n"); - ret = do_read(fd, handle, buf, 512, 1024); - assert(ret == 0); - assert(memcmp(buf, expected + 512, 1024) == 0); - - close(fd); - - return 0; -} -- cgit v1.2.3 From 81ba8ded7e01b21e600069977e496017c8966d66 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 29 Apr 2008 13:47:12 -0700 Subject: Remove the remainder of the mmfs device. --- tests/drmtest.c | 33 --------------------------------- tests/drmtest.h | 1 - 2 files changed, 34 deletions(-) (limited to 'tests') diff --git a/tests/drmtest.c b/tests/drmtest.c index 58f71a6a..5453b105 100644 --- a/tests/drmtest.c +++ b/tests/drmtest.c @@ -28,7 +28,6 @@ #include #include #include "drmtest.h" -#include "mmfs.h" /** Open the first DRM device we can find, searching up to 16 device nodes */ int drm_open_any(void) @@ -82,35 +81,3 @@ int drm_open_any_master(void) fprintf(stderr, "Couldn't find an un-controlled DRM device\n"); abort(); } - -static void -create_mmfs_device() -{ - struct stat sb; - int ret; - - ret = stat(MMFS_DEVICE_PATH, &sb); - - if (ret == 0) - return; - - ret = mknod(MMFS_DEVICE_PATH, S_IFCHR | S_IRUSR | S_IWUSR, - makedev(MMFS_DEVICE_MAJOR, 0)); - - if (ret != 0) - errx(1, "mknod()"); -} - -int -open_mmfs_device() -{ - int fd; - - create_mmfs_device(); - - fd = open(MMFS_DEVICE_PATH, O_RDWR); - if (fd == -1) - errx(1, "open()"); - - return fd; -} diff --git a/tests/drmtest.h b/tests/drmtest.h index b84ada71..afa0df4a 100644 --- a/tests/drmtest.h +++ b/tests/drmtest.h @@ -35,4 +35,3 @@ int drm_open_any(void); int drm_open_any_master(void); -int open_mmfs_device(); -- cgit v1.2.3 From c530011aaaf485157ba6284c0c32c0db83523b64 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 1 May 2008 16:35:12 -0700 Subject: Update mm tests for GEM rename. --- tests/Makefile.am | 6 +-- tests/gem_basic.c | 99 ++++++++++++++++++++++++++++++++++++++ tests/gem_mmap.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/gem_readwrite.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/mm_basic.c | 99 -------------------------------------- tests/mm_mmap.c | 129 -------------------------------------------------- tests/mm_readwrite.c | 125 ------------------------------------------------ 7 files changed, 356 insertions(+), 356 deletions(-) create mode 100644 tests/gem_basic.c create mode 100644 tests/gem_mmap.c create mode 100644 tests/gem_readwrite.c delete mode 100644 tests/mm_basic.c delete mode 100644 tests/mm_mmap.c delete mode 100644 tests/mm_readwrite.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index f997e26e..718cc436 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,9 +23,9 @@ TESTS = auth \ lock \ setversion \ updatedraw \ - mm_basic \ - mm_readwrite \ - mm_mmap + gem_basic \ + gem_readwrite \ + gem_mmap EXTRA_PROGRAMS = $(TESTS) CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) diff --git a/tests/gem_basic.c b/tests/gem_basic.c new file mode 100644 index 00000000..6e1f3ddb --- /dev/null +++ b/tests/gem_basic.c @@ -0,0 +1,99 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" + +static void +test_bad_unref(int fd) +{ + struct drm_gem_unreference unref; + int ret; + + printf("Testing error return on bad unreference ioctl.\n"); + + unref.handle = 0x10101010; + ret = ioctl(fd, DRM_IOCTL_GEM_UNREFERENCE, &unref); + + assert(ret == -1 && errno == EINVAL); +} + +static void +test_alloc_unref(int fd) +{ + struct drm_gem_alloc alloc; + struct drm_gem_unreference unref; + int ret; + + printf("Testing allocating and unreferencing an object.\n"); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = 16 * 1024; + ret = ioctl(fd, DRM_IOCTL_GEM_ALLOC, &alloc); + assert(ret == 0); + + unref.handle = alloc.handle; + ret = ioctl(fd, DRM_IOCTL_GEM_UNREFERENCE, &unref); +} + +static void +test_alloc_close(int fd) +{ + struct drm_gem_alloc alloc; + int ret; + + printf("Testing closing with an object allocated.\n"); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = 16 * 1024; + ret = ioctl(fd, DRM_IOCTL_GEM_ALLOC, &alloc); + assert(ret == 0); + + close(fd); +} + +int main(int argc, char **argv) +{ + int fd; + + fd = drm_open_any(); + + test_bad_unref(fd); + test_alloc_unref(fd); + test_alloc_close(fd); + + close(fd); + + return 0; +} diff --git a/tests/gem_mmap.c b/tests/gem_mmap.c new file mode 100644 index 00000000..2cdc9343 --- /dev/null +++ b/tests/gem_mmap.c @@ -0,0 +1,129 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" + +#define OBJECT_SIZE 16384 + +int do_read(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_gem_pread read; + + /* Ensure that we don't have any convenient data in buf in case + * we fail. + */ + memset(buf, 0xd0, size); + + memset(&read, 0, sizeof(read)); + read.handle = handle; + read.data = buf; + read.size = size; + read.offset = offset; + + return ioctl(fd, DRM_IOCTL_GEM_PREAD, &read); +} + +int do_write(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_gem_pwrite write; + + memset(&write, 0, sizeof(write)); + write.handle = handle; + write.data = buf; + write.size = size; + write.offset = offset; + + return ioctl(fd, DRM_IOCTL_GEM_PWRITE, &write); +} + +int main(int argc, char **argv) +{ + int fd; + struct drm_gem_alloc alloc; + struct drm_gem_mmap mmap; + struct drm_gem_unreference unref; + uint8_t expected[OBJECT_SIZE]; + uint8_t buf[OBJECT_SIZE]; + int ret; + int handle; + + fd = drm_open_any(); + + memset(&mmap, 0, sizeof(mmap)); + mmap.handle = 0x10101010; + mmap.offset = 0; + mmap.size = 4096; + printf("Testing mmaping of bad object.\n"); + ret = ioctl(fd, DRM_IOCTL_GEM_MMAP, &mmap); + assert(ret == -1 && errno == EINVAL); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_GEM_ALLOC, &alloc); + assert(ret == 0); + handle = alloc.handle; + + printf("Testing mmaping of newly allocated object.\n"); + mmap.handle = handle; + mmap.offset = 0; + mmap.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_GEM_MMAP, &mmap); + assert(ret == 0); + + printf("Testing contents of newly allocated object.\n"); + memset(expected, 0, sizeof(expected)); + assert(memcmp(mmap.addr, expected, sizeof(expected)) == 0); + + printf("Testing coherency of writes and mmap reads.\n"); + memset(buf, 0, sizeof(buf)); + memset(buf + 1024, 0x01, 1024); + memset(expected + 1024, 0x01, 1024); + ret = do_write(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); + + printf("Testing that mapping stays after unreference\n"); + unref.handle = handle; + ret = ioctl(fd, DRM_IOCTL_GEM_UNREFERENCE, &unref); + assert(ret == 0); + assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); + + printf("Testing unmapping\n"); + munmap(mmap.addr, OBJECT_SIZE); + + close(fd); + + return 0; +} diff --git a/tests/gem_readwrite.c b/tests/gem_readwrite.c new file mode 100644 index 00000000..5065732d --- /dev/null +++ b/tests/gem_readwrite.c @@ -0,0 +1,125 @@ +/* + * Copyright © 2008 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. + * + * Authors: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" + +#define OBJECT_SIZE 16384 + +int do_read(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_gem_pread read; + + /* Ensure that we don't have any convenient data in buf in case + * we fail. + */ + memset(buf, 0xd0, size); + + memset(&read, 0, sizeof(read)); + read.handle = handle; + read.data = buf; + read.size = size; + read.offset = offset; + + return ioctl(fd, DRM_IOCTL_GEM_PREAD, &read); +} + +int do_write(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_gem_pwrite write; + + memset(&write, 0, sizeof(write)); + write.handle = handle; + write.data = buf; + write.size = size; + write.offset = offset; + + return ioctl(fd, DRM_IOCTL_GEM_PWRITE, &write); +} + +int main(int argc, char **argv) +{ + int fd; + struct drm_gem_alloc alloc; + uint8_t expected[OBJECT_SIZE]; + uint8_t buf[OBJECT_SIZE]; + int ret; + int handle; + + fd = drm_open_any(); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_GEM_ALLOC, &alloc); + assert(ret == 0); + handle = alloc.handle; + + printf("Testing contents of newly allocated object.\n"); + ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + memset(&expected, 0, sizeof(expected)); + assert(memcmp(expected, buf, sizeof(expected)) == 0); + + printf("Testing read beyond end of buffer.\n"); + ret = do_read(fd, handle, buf, OBJECT_SIZE / 2, OBJECT_SIZE); + assert(ret == -1 && errno == EINVAL); + + printf("Testing full write of buffer\n"); + memset(buf, 0, sizeof(buf)); + memset(buf + 1024, 0x01, 1024); + memset(expected + 1024, 0x01, 1024); + ret = do_write(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + assert(memcmp(buf, expected, sizeof(buf)) == 0); + + printf("Testing partial write of buffer\n"); + memset(buf + 4096, 0x02, 1024); + memset(expected + 4096, 0x02, 1024); + ret = do_write(fd, handle, buf + 4096, 4096, 1024); + assert(ret == 0); + ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + assert(memcmp(buf, expected, sizeof(buf)) == 0); + + printf("Testing partial read of buffer\n"); + ret = do_read(fd, handle, buf, 512, 1024); + assert(ret == 0); + assert(memcmp(buf, expected + 512, 1024) == 0); + + close(fd); + + return 0; +} diff --git a/tests/mm_basic.c b/tests/mm_basic.c deleted file mode 100644 index 94240ee1..00000000 --- a/tests/mm_basic.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright © 2008 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. - * - * Authors: - * Eric Anholt - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "drm.h" - -static void -test_bad_unref(int fd) -{ - struct drm_mm_unreference_args unref; - int ret; - - printf("Testing error return on bad unreference ioctl.\n"); - - unref.handle = 0x10101010; - ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref); - - assert(ret == -1 && errno == EINVAL); -} - -static void -test_alloc_unref(int fd) -{ - struct drm_mm_alloc_args alloc; - struct drm_mm_unreference_args unref; - int ret; - - printf("Testing allocating and unreferencing an object.\n"); - - memset(&alloc, 0, sizeof(alloc)); - alloc.size = 16 * 1024; - ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc); - assert(ret == 0); - - unref.handle = alloc.handle; - ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref); -} - -static void -test_alloc_close(int fd) -{ - struct drm_mm_alloc_args alloc; - int ret; - - printf("Testing closing with an object allocated.\n"); - - memset(&alloc, 0, sizeof(alloc)); - alloc.size = 16 * 1024; - ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc); - assert(ret == 0); - - close(fd); -} - -int main(int argc, char **argv) -{ - int fd; - - fd = drm_open_any(); - - test_bad_unref(fd); - test_alloc_unref(fd); - test_alloc_close(fd); - - close(fd); - - return 0; -} diff --git a/tests/mm_mmap.c b/tests/mm_mmap.c deleted file mode 100644 index e5c4538a..00000000 --- a/tests/mm_mmap.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright © 2008 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. - * - * Authors: - * Eric Anholt - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "drm.h" - -#define OBJECT_SIZE 16384 - -int do_read(int fd, int handle, void *buf, int offset, int size) -{ - struct drm_mm_pread_args read; - - /* Ensure that we don't have any convenient data in buf in case - * we fail. - */ - memset(buf, 0xd0, size); - - memset(&read, 0, sizeof(read)); - read.handle = handle; - read.data = buf; - read.size = size; - read.offset = offset; - - return ioctl(fd, DRM_IOCTL_MM_PREAD, &read); -} - -int do_write(int fd, int handle, void *buf, int offset, int size) -{ - struct drm_mm_pwrite_args write; - - memset(&write, 0, sizeof(write)); - write.handle = handle; - write.data = buf; - write.size = size; - write.offset = offset; - - return ioctl(fd, DRM_IOCTL_MM_PWRITE, &write); -} - -int main(int argc, char **argv) -{ - int fd; - struct drm_mm_alloc_args alloc; - struct drm_mm_mmap_args mmap; - struct drm_mm_unreference_args unref; - uint8_t expected[OBJECT_SIZE]; - uint8_t buf[OBJECT_SIZE]; - int ret; - int handle; - - fd = drm_open_any(); - - memset(&mmap, 0, sizeof(mmap)); - mmap.handle = 0x10101010; - mmap.offset = 0; - mmap.size = 4096; - printf("Testing mmaping of bad object.\n"); - ret = ioctl(fd, DRM_IOCTL_MM_MMAP, &mmap); - assert(ret == -1 && errno == EINVAL); - - memset(&alloc, 0, sizeof(alloc)); - alloc.size = OBJECT_SIZE; - ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc); - assert(ret == 0); - handle = alloc.handle; - - printf("Testing mmaping of newly allocated object.\n"); - mmap.handle = handle; - mmap.offset = 0; - mmap.size = OBJECT_SIZE; - ret = ioctl(fd, DRM_IOCTL_MM_MMAP, &mmap); - assert(ret == 0); - - printf("Testing contents of newly allocated object.\n"); - memset(expected, 0, sizeof(expected)); - assert(memcmp(mmap.addr, expected, sizeof(expected)) == 0); - - printf("Testing coherency of writes and mmap reads.\n"); - memset(buf, 0, sizeof(buf)); - memset(buf + 1024, 0x01, 1024); - memset(expected + 1024, 0x01, 1024); - ret = do_write(fd, handle, buf, 0, OBJECT_SIZE); - assert(ret == 0); - assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); - - printf("Testing that mapping stays after unreference\n"); - unref.handle = handle; - ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref); - assert(ret == 0); - assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); - - printf("Testing unmapping\n"); - munmap(mmap.addr, OBJECT_SIZE); - - close(fd); - - return 0; -} diff --git a/tests/mm_readwrite.c b/tests/mm_readwrite.c deleted file mode 100644 index a778231a..00000000 --- a/tests/mm_readwrite.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright © 2008 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. - * - * Authors: - * Eric Anholt - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "drm.h" - -#define OBJECT_SIZE 16384 - -int do_read(int fd, int handle, void *buf, int offset, int size) -{ - struct drm_mm_pread_args read; - - /* Ensure that we don't have any convenient data in buf in case - * we fail. - */ - memset(buf, 0xd0, size); - - memset(&read, 0, sizeof(read)); - read.handle = handle; - read.data = buf; - read.size = size; - read.offset = offset; - - return ioctl(fd, DRM_IOCTL_MM_PREAD, &read); -} - -int do_write(int fd, int handle, void *buf, int offset, int size) -{ - struct drm_mm_pwrite_args write; - - memset(&write, 0, sizeof(write)); - write.handle = handle; - write.data = buf; - write.size = size; - write.offset = offset; - - return ioctl(fd, DRM_IOCTL_MM_PWRITE, &write); -} - -int main(int argc, char **argv) -{ - int fd; - struct drm_mm_alloc_args alloc; - uint8_t expected[OBJECT_SIZE]; - uint8_t buf[OBJECT_SIZE]; - int ret; - int handle; - - fd = drm_open_any(); - - memset(&alloc, 0, sizeof(alloc)); - alloc.size = OBJECT_SIZE; - ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc); - assert(ret == 0); - handle = alloc.handle; - - printf("Testing contents of newly allocated object.\n"); - ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); - assert(ret == 0); - memset(&expected, 0, sizeof(expected)); - assert(memcmp(expected, buf, sizeof(expected)) == 0); - - printf("Testing read beyond end of buffer.\n"); - ret = do_read(fd, handle, buf, OBJECT_SIZE / 2, OBJECT_SIZE); - assert(ret == -1 && errno == EINVAL); - - printf("Testing full write of buffer\n"); - memset(buf, 0, sizeof(buf)); - memset(buf + 1024, 0x01, 1024); - memset(expected + 1024, 0x01, 1024); - ret = do_write(fd, handle, buf, 0, OBJECT_SIZE); - assert(ret == 0); - ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); - assert(ret == 0); - assert(memcmp(buf, expected, sizeof(buf)) == 0); - - printf("Testing partial write of buffer\n"); - memset(buf + 4096, 0x02, 1024); - memset(expected + 4096, 0x02, 1024); - ret = do_write(fd, handle, buf + 4096, 4096, 1024); - assert(ret == 0); - ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); - assert(ret == 0); - assert(memcmp(buf, expected, sizeof(buf)) == 0); - - printf("Testing partial read of buffer\n"); - ret = do_read(fd, handle, buf, 512, 1024); - assert(ret == 0); - assert(memcmp(buf, expected + 512, 1024) == 0); - - close(fd); - - return 0; -} -- cgit v1.2.3 From effc6d998f080ba6f9c81d1b4b0e75a42be0238e Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 7 May 2008 16:00:58 -0700 Subject: GEM: fix testcases for new ioctl args. --- tests/gem_mmap.c | 14 ++++++++------ tests/gem_readwrite.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/gem_mmap.c b/tests/gem_mmap.c index 2cdc9343..4a7d6ecc 100644 --- a/tests/gem_mmap.c +++ b/tests/gem_mmap.c @@ -48,7 +48,7 @@ int do_read(int fd, int handle, void *buf, int offset, int size) memset(&read, 0, sizeof(read)); read.handle = handle; - read.data = buf; + read.data_ptr = (uintptr_t)buf; read.size = size; read.offset = offset; @@ -61,7 +61,7 @@ int do_write(int fd, int handle, void *buf, int offset, int size) memset(&write, 0, sizeof(write)); write.handle = handle; - write.data = buf; + write.data_ptr = (uintptr_t)buf; write.size = size; write.offset = offset; @@ -76,6 +76,7 @@ int main(int argc, char **argv) struct drm_gem_unreference unref; uint8_t expected[OBJECT_SIZE]; uint8_t buf[OBJECT_SIZE]; + uint8_t *addr; int ret; int handle; @@ -101,10 +102,11 @@ int main(int argc, char **argv) mmap.size = OBJECT_SIZE; ret = ioctl(fd, DRM_IOCTL_GEM_MMAP, &mmap); assert(ret == 0); + addr = (uint8_t *)(uintptr_t)mmap.addr_ptr; printf("Testing contents of newly allocated object.\n"); memset(expected, 0, sizeof(expected)); - assert(memcmp(mmap.addr, expected, sizeof(expected)) == 0); + assert(memcmp(addr, expected, sizeof(expected)) == 0); printf("Testing coherency of writes and mmap reads.\n"); memset(buf, 0, sizeof(buf)); @@ -112,16 +114,16 @@ int main(int argc, char **argv) memset(expected + 1024, 0x01, 1024); ret = do_write(fd, handle, buf, 0, OBJECT_SIZE); assert(ret == 0); - assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); + assert(memcmp(buf, addr, sizeof(buf)) == 0); printf("Testing that mapping stays after unreference\n"); unref.handle = handle; ret = ioctl(fd, DRM_IOCTL_GEM_UNREFERENCE, &unref); assert(ret == 0); - assert(memcmp(buf, mmap.addr, sizeof(buf)) == 0); + assert(memcmp(buf, addr, sizeof(buf)) == 0); printf("Testing unmapping\n"); - munmap(mmap.addr, OBJECT_SIZE); + munmap(addr, OBJECT_SIZE); close(fd); diff --git a/tests/gem_readwrite.c b/tests/gem_readwrite.c index 5065732d..1cc8a3e2 100644 --- a/tests/gem_readwrite.c +++ b/tests/gem_readwrite.c @@ -48,7 +48,7 @@ int do_read(int fd, int handle, void *buf, int offset, int size) memset(&read, 0, sizeof(read)); read.handle = handle; - read.data = buf; + read.data_ptr = (uintptr_t)buf; read.size = size; read.offset = offset; @@ -61,7 +61,7 @@ int do_write(int fd, int handle, void *buf, int offset, int size) memset(&write, 0, sizeof(write)); write.handle = handle; - write.data = buf; + write.data_ptr = (uintptr_t)buf; write.size = size; write.offset = offset; -- cgit v1.2.3 From 6e46a3c762919af05fcc6a08542faa7d185487a1 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 12 May 2008 15:42:20 -0700 Subject: [GEM] Update testcases for new API. --- tests/gem_basic.c | 46 ++++++++++++++++++++++------------------------ tests/gem_mmap.c | 20 ++++++++++---------- tests/gem_readwrite.c | 12 ++++++------ 3 files changed, 38 insertions(+), 40 deletions(-) (limited to 'tests') diff --git a/tests/gem_basic.c b/tests/gem_basic.c index 6e1f3ddb..8b8b63d0 100644 --- a/tests/gem_basic.c +++ b/tests/gem_basic.c @@ -36,48 +36,48 @@ #include "drm.h" static void -test_bad_unref(int fd) +test_bad_close(int fd) { - struct drm_gem_unreference unref; + struct drm_gem_close close; int ret; - printf("Testing error return on bad unreference ioctl.\n"); + printf("Testing error return on bad close ioctl.\n"); - unref.handle = 0x10101010; - ret = ioctl(fd, DRM_IOCTL_GEM_UNREFERENCE, &unref); + close.handle = 0x10101010; + ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close); assert(ret == -1 && errno == EINVAL); } static void -test_alloc_unref(int fd) +test_create_close(int fd) { - struct drm_gem_alloc alloc; - struct drm_gem_unreference unref; + struct drm_gem_create create; + struct drm_gem_close close; int ret; - printf("Testing allocating and unreferencing an object.\n"); + printf("Testing creating and closing an object.\n"); - memset(&alloc, 0, sizeof(alloc)); - alloc.size = 16 * 1024; - ret = ioctl(fd, DRM_IOCTL_GEM_ALLOC, &alloc); + memset(&create, 0, sizeof(create)); + create.size = 16 * 1024; + ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create); assert(ret == 0); - unref.handle = alloc.handle; - ret = ioctl(fd, DRM_IOCTL_GEM_UNREFERENCE, &unref); + close.handle = create.handle; + ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close); } static void -test_alloc_close(int fd) +test_create_fd_close(int fd) { - struct drm_gem_alloc alloc; + struct drm_gem_create create; int ret; printf("Testing closing with an object allocated.\n"); - memset(&alloc, 0, sizeof(alloc)); - alloc.size = 16 * 1024; - ret = ioctl(fd, DRM_IOCTL_GEM_ALLOC, &alloc); + memset(&create, 0, sizeof(create)); + create.size = 16 * 1024; + ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create); assert(ret == 0); close(fd); @@ -89,11 +89,9 @@ int main(int argc, char **argv) fd = drm_open_any(); - test_bad_unref(fd); - test_alloc_unref(fd); - test_alloc_close(fd); - - close(fd); + test_bad_close(fd); + test_create_close(fd); + test_create_fd_close(fd); return 0; } diff --git a/tests/gem_mmap.c b/tests/gem_mmap.c index 4a7d6ecc..3f8e27a0 100644 --- a/tests/gem_mmap.c +++ b/tests/gem_mmap.c @@ -71,9 +71,9 @@ int do_write(int fd, int handle, void *buf, int offset, int size) int main(int argc, char **argv) { int fd; - struct drm_gem_alloc alloc; + struct drm_gem_create create; struct drm_gem_mmap mmap; - struct drm_gem_unreference unref; + struct drm_gem_close unref; uint8_t expected[OBJECT_SIZE]; uint8_t buf[OBJECT_SIZE]; uint8_t *addr; @@ -90,13 +90,13 @@ int main(int argc, char **argv) ret = ioctl(fd, DRM_IOCTL_GEM_MMAP, &mmap); assert(ret == -1 && errno == EINVAL); - memset(&alloc, 0, sizeof(alloc)); - alloc.size = OBJECT_SIZE; - ret = ioctl(fd, DRM_IOCTL_GEM_ALLOC, &alloc); + memset(&create, 0, sizeof(create)); + create.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create); assert(ret == 0); - handle = alloc.handle; + handle = create.handle; - printf("Testing mmaping of newly allocated object.\n"); + printf("Testing mmaping of newly created object.\n"); mmap.handle = handle; mmap.offset = 0; mmap.size = OBJECT_SIZE; @@ -104,7 +104,7 @@ int main(int argc, char **argv) assert(ret == 0); addr = (uint8_t *)(uintptr_t)mmap.addr_ptr; - printf("Testing contents of newly allocated object.\n"); + printf("Testing contents of newly created object.\n"); memset(expected, 0, sizeof(expected)); assert(memcmp(addr, expected, sizeof(expected)) == 0); @@ -116,9 +116,9 @@ int main(int argc, char **argv) assert(ret == 0); assert(memcmp(buf, addr, sizeof(buf)) == 0); - printf("Testing that mapping stays after unreference\n"); + printf("Testing that mapping stays after close\n"); unref.handle = handle; - ret = ioctl(fd, DRM_IOCTL_GEM_UNREFERENCE, &unref); + ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &unref); assert(ret == 0); assert(memcmp(buf, addr, sizeof(buf)) == 0); diff --git a/tests/gem_readwrite.c b/tests/gem_readwrite.c index 1cc8a3e2..a48f9847 100644 --- a/tests/gem_readwrite.c +++ b/tests/gem_readwrite.c @@ -71,7 +71,7 @@ int do_write(int fd, int handle, void *buf, int offset, int size) int main(int argc, char **argv) { int fd; - struct drm_gem_alloc alloc; + struct drm_gem_create create; uint8_t expected[OBJECT_SIZE]; uint8_t buf[OBJECT_SIZE]; int ret; @@ -79,13 +79,13 @@ int main(int argc, char **argv) fd = drm_open_any(); - memset(&alloc, 0, sizeof(alloc)); - alloc.size = OBJECT_SIZE; - ret = ioctl(fd, DRM_IOCTL_GEM_ALLOC, &alloc); + memset(&create, 0, sizeof(create)); + create.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create); assert(ret == 0); - handle = alloc.handle; + handle = create.handle; - printf("Testing contents of newly allocated object.\n"); + printf("Testing contents of newly created object.\n"); ret = do_read(fd, handle, buf, 0, OBJECT_SIZE); assert(ret == 0); memset(&expected, 0, sizeof(expected)); -- cgit v1.2.3 From 2655005762b8915d5f44d1d1ee7e6c2eb34841d7 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 11 Jun 2008 14:42:40 -0700 Subject: [gem] Move potentially device-specific ioctls to the intel driver. This is the create (may want location flags), pread/pwrite/mmap (performance tuning hints), and set_domain (will 32 bits be enough for everyone?) ioctls. Left in the generic set are just flink/open/close. The 2D driver must be updated for this change, and API but not ABI is broken for 3D. The driver version is bumped to mark this. --- tests/gem_basic.c | 9 +++++---- tests/gem_mmap.c | 19 ++++++++++--------- tests/gem_readwrite.c | 13 +++++++------ 3 files changed, 22 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/gem_basic.c b/tests/gem_basic.c index 8b8b63d0..b2176fba 100644 --- a/tests/gem_basic.c +++ b/tests/gem_basic.c @@ -34,6 +34,7 @@ #include #include #include "drm.h" +#include "i915_drm.h" static void test_bad_close(int fd) @@ -52,7 +53,7 @@ test_bad_close(int fd) static void test_create_close(int fd) { - struct drm_gem_create create; + struct drm_i915_gem_create create; struct drm_gem_close close; int ret; @@ -60,7 +61,7 @@ test_create_close(int fd) memset(&create, 0, sizeof(create)); create.size = 16 * 1024; - ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create); + ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create); assert(ret == 0); close.handle = create.handle; @@ -70,14 +71,14 @@ test_create_close(int fd) static void test_create_fd_close(int fd) { - struct drm_gem_create create; + struct drm_i915_gem_create create; int ret; printf("Testing closing with an object allocated.\n"); memset(&create, 0, sizeof(create)); create.size = 16 * 1024; - ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create); + ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create); assert(ret == 0); close(fd); diff --git a/tests/gem_mmap.c b/tests/gem_mmap.c index 3f8e27a0..c3a51883 100644 --- a/tests/gem_mmap.c +++ b/tests/gem_mmap.c @@ -34,12 +34,13 @@ #include #include #include "drm.h" +#include "i915_drm.h" #define OBJECT_SIZE 16384 int do_read(int fd, int handle, void *buf, int offset, int size) { - struct drm_gem_pread read; + struct drm_i915_gem_pread read; /* Ensure that we don't have any convenient data in buf in case * we fail. @@ -52,12 +53,12 @@ int do_read(int fd, int handle, void *buf, int offset, int size) read.size = size; read.offset = offset; - return ioctl(fd, DRM_IOCTL_GEM_PREAD, &read); + return ioctl(fd, DRM_IOCTL_I915_GEM_PREAD, &read); } int do_write(int fd, int handle, void *buf, int offset, int size) { - struct drm_gem_pwrite write; + struct drm_i915_gem_pwrite write; memset(&write, 0, sizeof(write)); write.handle = handle; @@ -65,14 +66,14 @@ int do_write(int fd, int handle, void *buf, int offset, int size) write.size = size; write.offset = offset; - return ioctl(fd, DRM_IOCTL_GEM_PWRITE, &write); + return ioctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &write); } int main(int argc, char **argv) { int fd; - struct drm_gem_create create; - struct drm_gem_mmap mmap; + struct drm_i915_gem_create create; + struct drm_i915_gem_mmap mmap; struct drm_gem_close unref; uint8_t expected[OBJECT_SIZE]; uint8_t buf[OBJECT_SIZE]; @@ -87,12 +88,12 @@ int main(int argc, char **argv) mmap.offset = 0; mmap.size = 4096; printf("Testing mmaping of bad object.\n"); - ret = ioctl(fd, DRM_IOCTL_GEM_MMAP, &mmap); + ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap); assert(ret == -1 && errno == EINVAL); memset(&create, 0, sizeof(create)); create.size = OBJECT_SIZE; - ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create); + ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create); assert(ret == 0); handle = create.handle; @@ -100,7 +101,7 @@ int main(int argc, char **argv) mmap.handle = handle; mmap.offset = 0; mmap.size = OBJECT_SIZE; - ret = ioctl(fd, DRM_IOCTL_GEM_MMAP, &mmap); + ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap); assert(ret == 0); addr = (uint8_t *)(uintptr_t)mmap.addr_ptr; diff --git a/tests/gem_readwrite.c b/tests/gem_readwrite.c index a48f9847..54b25ea3 100644 --- a/tests/gem_readwrite.c +++ b/tests/gem_readwrite.c @@ -34,12 +34,13 @@ #include #include #include "drm.h" +#include "i915_drm.h" #define OBJECT_SIZE 16384 int do_read(int fd, int handle, void *buf, int offset, int size) { - struct drm_gem_pread read; + struct drm_i915_gem_pread read; /* Ensure that we don't have any convenient data in buf in case * we fail. @@ -52,12 +53,12 @@ int do_read(int fd, int handle, void *buf, int offset, int size) read.size = size; read.offset = offset; - return ioctl(fd, DRM_IOCTL_GEM_PREAD, &read); + return ioctl(fd, DRM_IOCTL_I915_GEM_PREAD, &read); } int do_write(int fd, int handle, void *buf, int offset, int size) { - struct drm_gem_pwrite write; + struct drm_i915_gem_pwrite write; memset(&write, 0, sizeof(write)); write.handle = handle; @@ -65,13 +66,13 @@ int do_write(int fd, int handle, void *buf, int offset, int size) write.size = size; write.offset = offset; - return ioctl(fd, DRM_IOCTL_GEM_PWRITE, &write); + return ioctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &write); } int main(int argc, char **argv) { int fd; - struct drm_gem_create create; + struct drm_i915_gem_create create; uint8_t expected[OBJECT_SIZE]; uint8_t buf[OBJECT_SIZE]; int ret; @@ -81,7 +82,7 @@ int main(int argc, char **argv) memset(&create, 0, sizeof(create)); create.size = OBJECT_SIZE; - ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create); + ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create); assert(ret == 0); handle = create.handle; -- cgit v1.2.3 From 1bdf35fe19c1aa02b301375b3cae7ad29adacef8 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 28 Jul 2008 11:24:00 -0700 Subject: intel-gem: Fix regression tests. Main fix is an oops that was triggered by the gtt pwrite path when we don't have the gtt initialized. Also, settle on -EBADF for "bad object handle", and -EINVAL for "reading/writing beyond object boundary". --- tests/gem_mmap.c | 2 +- tests/gem_readwrite.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/gem_mmap.c b/tests/gem_mmap.c index c3a51883..b5c15463 100644 --- a/tests/gem_mmap.c +++ b/tests/gem_mmap.c @@ -89,7 +89,7 @@ int main(int argc, char **argv) mmap.size = 4096; printf("Testing mmaping of bad object.\n"); ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap); - assert(ret == -1 && errno == EINVAL); + assert(ret == -1 && errno == EBADF); memset(&create, 0, sizeof(create)); create.size = OBJECT_SIZE; diff --git a/tests/gem_readwrite.c b/tests/gem_readwrite.c index 54b25ea3..bd1d232b 100644 --- a/tests/gem_readwrite.c +++ b/tests/gem_readwrite.c @@ -94,6 +94,7 @@ int main(int argc, char **argv) printf("Testing read beyond end of buffer.\n"); ret = do_read(fd, handle, buf, OBJECT_SIZE / 2, OBJECT_SIZE); + printf("%d %d\n", ret, errno); assert(ret == -1 && errno == EINVAL); printf("Testing full write of buffer\n"); @@ -120,6 +121,14 @@ int main(int argc, char **argv) assert(ret == 0); assert(memcmp(buf, expected + 512, 1024) == 0); + printf("Testing read of bad buffer handle\n"); + ret = do_read(fd, 1234, buf, 0, 1024); + assert(ret == -1 && errno == EBADF); + + printf("Testing write of bad buffer handle\n"); + ret = do_write(fd, 1234, buf, 0, 1024); + assert(ret == -1 && errno == EBADF); + close(fd); return 0; -- cgit v1.2.3