Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2021 Collabora, Ltd. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | |
| 28 | #include <assert.h> |
| 29 | |
| 30 | #include <libweston/libweston.h> |
| 31 | #include <libweston-internal.h> |
| 32 | #include "shared/weston-drm-fourcc.h" |
| 33 | |
| 34 | #include "weston-test-client-helper.h" |
| 35 | #include "weston-test-fixture-compositor.h" |
| 36 | |
| 37 | /* Add multiple formats to weston_drm_format_array and add the same set of |
| 38 | * modifiers to each format. */ |
| 39 | #define ADD_FORMATS_AND_MODS(dest, formats, mods) \ |
| 40 | do { \ |
| 41 | unsigned int i; \ |
| 42 | for (i = 0; i < ARRAY_LENGTH(formats); i++) \ |
| 43 | format_array_add_format_and_modifiers(dest, (formats)[i], \ |
| 44 | mods, ARRAY_LENGTH(mods)); \ |
| 45 | } while (0) |
| 46 | |
| 47 | /* Same as ADD_FORMATS_AND_MODS, but add the formats in reverse order. */ |
| 48 | #define ADD_FORMATS_AND_MODS_REVERSE(dest, formats, mods) \ |
| 49 | do { \ |
| 50 | int i; \ |
| 51 | for (i = ARRAY_LENGTH(formats) - 1; i >= 0; i--) \ |
| 52 | format_array_add_format_and_modifiers(dest, (formats)[i], \ |
| 53 | mods, ARRAY_LENGTH(mods)); \ |
| 54 | } while (0) |
| 55 | |
| 56 | static void |
| 57 | format_array_add_format_and_modifiers(struct weston_drm_format_array *formats, |
| 58 | uint32_t format, uint64_t *modifiers, |
| 59 | unsigned int num_modifiers) |
| 60 | { |
| 61 | struct weston_drm_format *fmt; |
| 62 | unsigned int i; |
| 63 | int ret; |
| 64 | |
| 65 | fmt = weston_drm_format_array_add_format(formats, format); |
| 66 | assert(fmt); |
| 67 | |
| 68 | for (i = 0; i < num_modifiers; i++) { |
| 69 | ret = weston_drm_format_add_modifier(fmt, modifiers[i]); |
| 70 | assert(ret == 0); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | TEST(basic_operations) |
| 75 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 76 | struct weston_drm_format_array format_array; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 77 | struct weston_drm_format *fmt; |
| 78 | uint32_t formats[] = {1, 2, 3, 4, 5}; |
| 79 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 80 | unsigned int i, j; |
| 81 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 82 | weston_drm_format_array_init(&format_array); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 83 | |
Leandro Ribeiro | 60c7fee | 2021-10-06 12:05:40 -0300 | [diff] [blame] | 84 | assert(weston_drm_format_array_count_pairs(&format_array) == 0); |
| 85 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 86 | ADD_FORMATS_AND_MODS(&format_array, formats, modifiers); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 87 | |
| 88 | for (i = 0; i < ARRAY_LENGTH(formats); i++) { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 89 | fmt = weston_drm_format_array_find_format(&format_array, formats[i]); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 90 | assert(fmt && fmt->format == formats[i]); |
| 91 | for (j = 0; j < ARRAY_LENGTH(modifiers); j++) |
| 92 | assert(weston_drm_format_has_modifier(fmt, modifiers[j])); |
| 93 | } |
| 94 | |
Leandro Ribeiro | 60c7fee | 2021-10-06 12:05:40 -0300 | [diff] [blame] | 95 | assert(weston_drm_format_array_count_pairs(&format_array) == |
| 96 | ARRAY_LENGTH(formats) * ARRAY_LENGTH(modifiers)); |
| 97 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 98 | weston_drm_format_array_fini(&format_array); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | TEST(compare_arrays_same_content) |
| 102 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 103 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 104 | uint32_t formats[] = {1, 2, 3, 4, 5}; |
| 105 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 106 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 107 | weston_drm_format_array_init(&format_array_A); |
| 108 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 109 | |
| 110 | /* Both are empty arrays, so they have the same content. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 111 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 112 | |
| 113 | /* Test non-empty arrays with same content. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 114 | ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); |
| 115 | ADD_FORMATS_AND_MODS(&format_array_B, formats, modifiers); |
| 116 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 117 | |
| 118 | /* Test non-empty arrays with same content, but add elements to B in |
| 119 | * reverse order. This is important as in the future we may keep |
| 120 | * DRM-format arrays ordered to improve performance. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 121 | weston_drm_format_array_fini(&format_array_B); |
| 122 | weston_drm_format_array_init(&format_array_B); |
| 123 | ADD_FORMATS_AND_MODS_REVERSE(&format_array_B, formats, modifiers); |
| 124 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 125 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 126 | weston_drm_format_array_fini(&format_array_A); |
| 127 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | TEST(compare_arrays_exclusive_content) |
| 131 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 132 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 133 | uint32_t formats_A[] = {1, 2, 3, 4, 5}; |
| 134 | uint32_t formats_B[] = {6, 7, 8, 9, 10}; |
| 135 | uint64_t modifiers_A[] = {11, 12, 13, 14, 15}; |
| 136 | uint64_t modifiers_B[] = {16, 17, 18, 19, 20}; |
| 137 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 138 | weston_drm_format_array_init(&format_array_A); |
| 139 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 140 | |
| 141 | /* Arrays with formats that are mutually exclusive. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 142 | ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A); |
| 143 | ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B); |
| 144 | assert(!weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 145 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 146 | weston_drm_format_array_fini(&format_array_A); |
| 147 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | TEST(replace_array) |
| 151 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 152 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 153 | uint32_t formats[] = {1, 2, 3, 4, 5}; |
| 154 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 155 | int ret; |
| 156 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 157 | weston_drm_format_array_init(&format_array_A); |
| 158 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 159 | |
| 160 | /* Replace content of B with the content of A, so they should |
| 161 | * have the same content. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 162 | ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); |
| 163 | ret = weston_drm_format_array_replace(&format_array_B, &format_array_A); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 164 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 165 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 166 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 167 | weston_drm_format_array_fini(&format_array_A); |
| 168 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | TEST(remove_from_array) |
| 172 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 173 | struct weston_drm_format_array format_array_A, format_array_B, format_array_C; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 174 | uint32_t formats_A[] = {1, 2, 3, 4, 5}; |
| 175 | uint32_t formats_B[] = {1, 2, 3, 4}; |
| 176 | uint32_t formats_C[] = {1, 2, 3, 4, 6}; |
| 177 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 178 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 179 | weston_drm_format_array_init(&format_array_A); |
| 180 | weston_drm_format_array_init(&format_array_B); |
| 181 | weston_drm_format_array_init(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 182 | |
| 183 | /* After removing latest added format from array A, it should |
| 184 | * be equal to B. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 185 | ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers); |
| 186 | ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers); |
| 187 | weston_drm_format_array_remove_latest_format(&format_array_A); |
| 188 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 189 | |
| 190 | /* Add 6 to the format array A, so it should be equal to C. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 191 | ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){6}, modifiers); |
| 192 | ADD_FORMATS_AND_MODS(&format_array_C, formats_C, modifiers); |
| 193 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 194 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 195 | weston_drm_format_array_fini(&format_array_A); |
| 196 | weston_drm_format_array_fini(&format_array_B); |
| 197 | weston_drm_format_array_fini(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | TEST(join_arrays) |
| 201 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 202 | struct weston_drm_format_array format_array_A, format_array_B; |
| 203 | struct weston_drm_format_array format_array_C; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 204 | uint32_t formats_A[] = {1, 2, 6, 9, 10}; |
| 205 | uint32_t formats_B[] = {2, 5, 7, 9, 10}; |
| 206 | uint64_t modifiers_A[] = {1, 2, 3, 4, 7}; |
| 207 | uint64_t modifiers_B[] = {0, 2, 3, 5, 6}; |
| 208 | uint64_t modifiers_join[] = {0, 1, 2, 3, 4, 5, 6, 7}; |
| 209 | int ret; |
| 210 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 211 | weston_drm_format_array_init(&format_array_A); |
| 212 | weston_drm_format_array_init(&format_array_B); |
| 213 | weston_drm_format_array_init(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 214 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 215 | ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A); |
| 216 | ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B); |
| 217 | ret = weston_drm_format_array_join(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 218 | assert(ret == 0); |
| 219 | |
| 220 | /* The result of the joint (which is saved in A) should have |
| 221 | * the same content as C. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 222 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){1}, modifiers_A); |
| 223 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){2}, modifiers_join); |
| 224 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){5}, modifiers_B); |
| 225 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){6}, modifiers_A); |
| 226 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){7}, modifiers_B); |
| 227 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_join); |
| 228 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_join); |
| 229 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 230 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 231 | weston_drm_format_array_fini(&format_array_A); |
| 232 | weston_drm_format_array_fini(&format_array_B); |
| 233 | weston_drm_format_array_fini(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | TEST(join_arrays_same_content) |
| 237 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 238 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 239 | uint32_t formats[] = {1, 2, 3, 4, 5}; |
| 240 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 241 | int ret; |
| 242 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 243 | weston_drm_format_array_init(&format_array_A); |
| 244 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 245 | |
| 246 | /* Joint of empty arrays must be empty. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 247 | ret = weston_drm_format_array_join(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 248 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 249 | assert(format_array_A.arr.size == 0); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 250 | |
| 251 | /* Join B, which is empty, with A, which is non-empty. The joint (which |
| 252 | * is saved in B) should have the same content as A. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 253 | ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); |
| 254 | ret = weston_drm_format_array_join(&format_array_B, &format_array_A); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 255 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 256 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 257 | |
| 258 | /* Now A and B are non-empty and have the same content. The joint (which |
| 259 | * is saved in A) should not change its content. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 260 | ret = weston_drm_format_array_join(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 261 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 262 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 263 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 264 | weston_drm_format_array_fini(&format_array_A); |
| 265 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TEST(join_arrays_exclusive_content) |
| 269 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 270 | struct weston_drm_format_array format_array_A, format_array_B; |
| 271 | struct weston_drm_format_array format_array_C; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 272 | uint32_t formats_A[] = {1, 2, 3, 4, 5}; |
| 273 | uint32_t formats_B[] = {6, 7, 8, 9, 10}; |
| 274 | uint32_t formats_C[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; |
| 275 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 276 | int ret; |
| 277 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 278 | weston_drm_format_array_init(&format_array_A); |
| 279 | weston_drm_format_array_init(&format_array_B); |
| 280 | weston_drm_format_array_init(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 281 | |
| 282 | /* The joint of DRM-format arrays A and B should be equal to C. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 283 | ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers); |
| 284 | ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers); |
| 285 | ADD_FORMATS_AND_MODS(&format_array_C, formats_C, modifiers); |
| 286 | ret = weston_drm_format_array_join(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 287 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 288 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 289 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 290 | weston_drm_format_array_fini(&format_array_A); |
| 291 | weston_drm_format_array_fini(&format_array_B); |
| 292 | weston_drm_format_array_fini(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | TEST(join_arrays_modifier_invalid) |
| 296 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 297 | struct weston_drm_format_array format_array_A, format_array_B; |
| 298 | struct weston_drm_format_array format_array_C; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 299 | uint64_t regular_modifiers[] = {1, 2, 3, 4, 5}; |
| 300 | uint64_t modifier_invalid[] = {DRM_FORMAT_MOD_INVALID}; |
| 301 | uint64_t regular_modifiers_plus_invalid[] = {1, 2, 3, 4, 5, DRM_FORMAT_MOD_INVALID}; |
| 302 | int ret; |
| 303 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 304 | weston_drm_format_array_init(&format_array_A); |
| 305 | weston_drm_format_array_init(&format_array_B); |
| 306 | weston_drm_format_array_init(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 307 | |
| 308 | /* DRM-format array A has only one format with MOD_INVALID, and B has |
| 309 | * the same format but with a regular set of formats. The joint should |
| 310 | * contain both MOD_INVALID and the regular modifiers. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 311 | ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifier_invalid); |
| 312 | ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, regular_modifiers); |
| 313 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){1}, regular_modifiers_plus_invalid); |
| 314 | ret = weston_drm_format_array_join(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 315 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 316 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 317 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 318 | weston_drm_format_array_fini(&format_array_A); |
| 319 | weston_drm_format_array_fini(&format_array_B); |
| 320 | weston_drm_format_array_fini(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | TEST(intersect_arrays) |
| 324 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 325 | struct weston_drm_format_array format_array_A, format_array_B; |
| 326 | struct weston_drm_format_array format_array_C; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 327 | uint32_t formats_A[] = {1, 2, 6, 9, 10}; |
| 328 | uint32_t formats_B[] = {2, 5, 7, 9, 10}; |
| 329 | uint64_t modifiers_A[] = {1, 2, 3, 4, 7}; |
| 330 | uint64_t modifiers_B[] = {0, 2, 3, 5, 6}; |
| 331 | uint64_t modifiers_intersect[] = {2, 3}; |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 332 | int ret; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 333 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 334 | weston_drm_format_array_init(&format_array_A); |
| 335 | weston_drm_format_array_init(&format_array_B); |
| 336 | weston_drm_format_array_init(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 337 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 338 | ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A); |
| 339 | ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B); |
| 340 | ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 341 | assert(ret == 0); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 342 | |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 343 | /* The result of the intersection (stored in A) should have the same |
| 344 | * content as C. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 345 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){2}, modifiers_intersect); |
| 346 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_intersect); |
| 347 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_intersect); |
| 348 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 349 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 350 | weston_drm_format_array_fini(&format_array_A); |
| 351 | weston_drm_format_array_fini(&format_array_B); |
| 352 | weston_drm_format_array_fini(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | TEST(intersect_arrays_same_content) |
| 356 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 357 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 358 | uint32_t formats[] = {1, 2, 3, 4, 5}; |
| 359 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 360 | int ret; |
| 361 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 362 | weston_drm_format_array_init(&format_array_A); |
| 363 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 364 | |
| 365 | /* The intersection between two empty arrays must be an |
| 366 | * empty array. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 367 | ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 368 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 369 | assert(format_array_A.arr.size == 0); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 370 | |
| 371 | /* DRM-format arrays A and B have the same content, so the intersection |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 372 | * should be equal to them. A keeps the result of the intersection, and B |
| 373 | * does not change. So we compare them. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 374 | ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); |
| 375 | ret = weston_drm_format_array_replace(&format_array_B, &format_array_A); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 376 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 377 | ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 378 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 379 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 380 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 381 | weston_drm_format_array_fini(&format_array_A); |
| 382 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | TEST(intersect_arrays_exclusive_formats) |
| 386 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 387 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 388 | uint64_t formats_A[] = {1, 2, 3, 4, 5}; |
| 389 | uint64_t formats_B[] = {6, 7, 8, 9, 10}; |
| 390 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 391 | int ret; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 392 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 393 | weston_drm_format_array_init(&format_array_A); |
| 394 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 395 | |
| 396 | /* DRM-format arrays A and B have formats that are mutually exclusive, |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 397 | * so the intersection (which is stored in A) must be empty. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 398 | ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers); |
| 399 | ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers); |
| 400 | ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 401 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 402 | assert(format_array_A.arr.size == 0); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 403 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 404 | weston_drm_format_array_fini(&format_array_A); |
| 405 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | TEST(intersect_arrays_exclusive_modifiers) |
| 409 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 410 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 411 | uint64_t modifiers_A[] = {1, 2, 3, 4, 5}; |
| 412 | uint64_t modifiers_B[] = {6, 7, 8, 9, 10}; |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 413 | int ret; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 414 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 415 | weston_drm_format_array_init(&format_array_A); |
| 416 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 417 | |
| 418 | /* Both DRM-format arrays A and B have the same format but with modifier |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 419 | * sets that are mutually exclusive. The intersection (which is stored |
| 420 | * in A) between mutually exclusive modifier must be empty, and so the |
| 421 | * format should not be added to the array. So the array must also be |
| 422 | * empty. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 423 | ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifiers_A); |
| 424 | ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, modifiers_B); |
| 425 | ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); |
Leandro Ribeiro | c51d4ad | 2021-08-30 12:52:26 -0300 | [diff] [blame] | 426 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 427 | assert(format_array_A.arr.size == 0); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 428 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 429 | weston_drm_format_array_fini(&format_array_A); |
| 430 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | TEST(subtract_arrays) |
| 434 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 435 | struct weston_drm_format_array format_array_A, format_array_B; |
| 436 | struct weston_drm_format_array format_array_C; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 437 | uint32_t formats_A[] = {1, 2, 6, 9, 10}; |
| 438 | uint32_t formats_B[] = {2, 5, 7, 9, 10}; |
| 439 | uint64_t modifiers_A[] = {1, 2, 3, 4, 7}; |
| 440 | uint64_t modifiers_B[] = {0, 2, 3, 5, 6}; |
| 441 | uint64_t modifiers_subtract[] = {1, 4, 7}; |
| 442 | int ret; |
| 443 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 444 | weston_drm_format_array_init(&format_array_A); |
| 445 | weston_drm_format_array_init(&format_array_B); |
| 446 | weston_drm_format_array_init(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 447 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 448 | ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A); |
| 449 | ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B); |
| 450 | ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 451 | assert(ret == 0); |
| 452 | |
| 453 | /* The result of the subtraction (which is saved in A) should have |
| 454 | * the same content as C. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 455 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){1}, modifiers_A); |
| 456 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){2}, modifiers_subtract); |
| 457 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){6}, modifiers_A); |
| 458 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_subtract); |
| 459 | ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_subtract); |
| 460 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 461 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 462 | weston_drm_format_array_fini(&format_array_A); |
| 463 | weston_drm_format_array_fini(&format_array_B); |
| 464 | weston_drm_format_array_fini(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | TEST(subtract_arrays_same_content) |
| 468 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 469 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 470 | uint32_t formats[] = {1, 2, 3, 4, 5}; |
| 471 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 472 | int ret; |
| 473 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 474 | weston_drm_format_array_init(&format_array_A); |
| 475 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 476 | |
| 477 | /* Minuend and subtrahend have the same content. The subtraction |
| 478 | * (which is saved in A) should be an empty array. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 479 | ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); |
| 480 | ret = weston_drm_format_array_replace(&format_array_B, &format_array_A); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 481 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 482 | ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 483 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 484 | assert(format_array_A.arr.size == 0); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 485 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 486 | weston_drm_format_array_fini(&format_array_A); |
| 487 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | TEST(subtract_arrays_exclusive_formats) |
| 491 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 492 | struct weston_drm_format_array format_array_A, format_array_B; |
| 493 | struct weston_drm_format_array format_array_C; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 494 | uint32_t formats_A[] = {1, 2, 3, 4, 5}; |
| 495 | uint32_t formats_B[] = {6, 7, 8, 9, 10}; |
| 496 | uint64_t modifiers[] = {11, 12, 13, 14, 15}; |
| 497 | int ret; |
| 498 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 499 | weston_drm_format_array_init(&format_array_A); |
| 500 | weston_drm_format_array_init(&format_array_B); |
| 501 | weston_drm_format_array_init(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 502 | |
| 503 | /* Minuend and subtrahend have mutually exclusive formats. The |
| 504 | * subtraction (which is saved in A) should be equal the minuend. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 505 | ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers); |
| 506 | ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers); |
| 507 | ret = weston_drm_format_array_replace(&format_array_C, &format_array_A); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 508 | assert(ret == 0); |
| 509 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 510 | ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 511 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 512 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 513 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 514 | weston_drm_format_array_fini(&format_array_A); |
| 515 | weston_drm_format_array_fini(&format_array_B); |
| 516 | weston_drm_format_array_fini(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | TEST(subtract_arrays_exclusive_modifiers) |
| 520 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 521 | struct weston_drm_format_array format_array_A, format_array_B; |
| 522 | struct weston_drm_format_array format_array_C; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 523 | uint64_t modifiers_A[] = {1, 2, 3, 4, 5}; |
| 524 | uint64_t modifiers_B[] = {6, 7, 8, 9, 10}; |
| 525 | int ret; |
| 526 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 527 | weston_drm_format_array_init(&format_array_A); |
| 528 | weston_drm_format_array_init(&format_array_B); |
| 529 | weston_drm_format_array_init(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 530 | |
| 531 | /* Minuend and subtrahend have the same format but with modifiers that |
| 532 | * are mutually exclusive. The subtraction (which is saved in A) should |
| 533 | * contain the format and the modifier set of the minuend. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 534 | ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifiers_A); |
| 535 | ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, modifiers_B); |
| 536 | ret = weston_drm_format_array_replace(&format_array_C, &format_array_A); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 537 | assert(ret == 0); |
| 538 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 539 | ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 540 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 541 | assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 542 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 543 | weston_drm_format_array_fini(&format_array_A); |
| 544 | weston_drm_format_array_fini(&format_array_B); |
| 545 | weston_drm_format_array_fini(&format_array_C); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | TEST(subtract_arrays_modifier_invalid) |
| 549 | { |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 550 | struct weston_drm_format_array format_array_A, format_array_B; |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 551 | uint64_t modifier_invalid[] = {DRM_FORMAT_MOD_INVALID}; |
| 552 | uint64_t regular_modifiers_plus_invalid[] = {1, 2, 3, 4, 5, DRM_FORMAT_MOD_INVALID}; |
| 553 | int ret; |
| 554 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 555 | weston_drm_format_array_init(&format_array_A); |
| 556 | weston_drm_format_array_init(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 557 | |
| 558 | /* The minuend has a format with modifier set that contains MOD_INVALID |
| 559 | * and the subtrahend contains the same format but with a regular set of |
| 560 | * modifiers + MOD_INVALID. So the subtraction between the modifiers |
| 561 | * sets results in empty, and so the format should not be included to |
| 562 | * the result. As it is the only format in the minuend, the resulting |
| 563 | * array must be empty. */ |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 564 | ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifier_invalid); |
| 565 | ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, regular_modifiers_plus_invalid); |
| 566 | ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 567 | assert(ret == 0); |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 568 | assert(format_array_A.arr.size == 0); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 569 | |
Leandro Ribeiro | 0750cea | 2021-08-30 16:32:03 -0300 | [diff] [blame] | 570 | weston_drm_format_array_fini(&format_array_A); |
| 571 | weston_drm_format_array_fini(&format_array_B); |
Leandro Ribeiro | 859e3f2 | 2021-03-15 17:48:45 -0300 | [diff] [blame] | 572 | } |