1 /* 2 * Copyright © 2016 Broadcom 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #include "igt.h" 25 #include "igt_vc4.h" 26 #include <unistd.h> 27 #include <stdlib.h> 28 #include <stdio.h> 29 #include <string.h> 30 #include <fcntl.h> 31 #include <inttypes.h> 32 #include <errno.h> 33 #include <sys/stat.h> 34 #include <sys/ioctl.h> 35 #include "vc4_drm.h" 36 37 igt_main 38 { 39 int fd; 40 41 igt_fixture { 42 fd = drm_open_driver(DRIVER_VC4); 43 } 44 45 igt_subtest("create-bo-4096") { 46 int handle = igt_vc4_create_bo(fd, 4096); 47 gem_close(fd, handle); 48 } 49 50 igt_subtest("create-bo-0") { 51 struct drm_vc4_create_bo arg = { 52 .size = 0, 53 }; 54 do_ioctl_err(fd, DRM_IOCTL_VC4_CREATE_BO, &arg, EINVAL); 55 } 56 57 igt_subtest("create-bo-zeroed") { 58 int fd2 = drm_open_driver(DRIVER_VC4); 59 int handle; 60 uint32_t *map; 61 /* A size different from any used in our other tests, to try 62 * to convince it to land as the only one of its size in the 63 * kernel BO cache 64 */ 65 size_t size = 3 * 4096, i; 66 67 /* Make a BO and free it on our main fd. */ 68 handle = igt_vc4_create_bo(fd, size); 69 map = igt_vc4_mmap_bo(fd, handle, size, PROT_READ | PROT_WRITE); 70 memset(map, 0xd0, size); 71 munmap(map, size); 72 gem_close(fd, handle); 73 74 /* Now, allocate a BO on the other fd and make sure it doesn't 75 * have the old contents. 76 */ 77 handle = igt_vc4_create_bo(fd2, size); 78 map = igt_vc4_mmap_bo(fd2, handle, size, PROT_READ | PROT_WRITE); 79 for (i = 0; i < size / 4; i++) 80 igt_assert_eq_u32(map[i], 0x0); 81 munmap(map, size); 82 gem_close(fd2, handle); 83 84 close(fd2); 85 } 86 87 igt_fixture 88 close(fd); 89 } 90