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