1 /* 2 * Copyright (C) 2020 Collabora, Ltd. 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 FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 */ 23 24 #include "compiler.h" 25 #include "bi_test.h" 26 27 #include <gtest/gtest.h> 28 #include "mesa-gtest-extras.h" 29 30 class PackFormats : public testing::Test 31 { 32 protected: PackFormats()33 PackFormats() { 34 util_dynarray_init(&result, NULL); 35 } ~PackFormats()36 ~PackFormats() { 37 util_dynarray_fini(&result); 38 } 39 result_as_u64_array()40 const uint64_t *result_as_u64_array() { return reinterpret_cast<uint64_t *>(result.data); } 41 42 struct util_dynarray result; 43 }; 44 45 TEST_F(PackFormats, 1) 46 { 47 /* Test case from the blob */ 48 struct bi_packed_tuple tuples[] = { 49 { 0x2380cb1c02200000, 0x10e0 }, 50 }; 51 52 uint64_t header = 0x021000011800; 53 54 bi_pack_format(&result, 1, tuples, 1, header, 0, 0, true); 55 56 const uint64_t expected[] = { 57 0x80cb1c022000004a, 58 0x10800008c000e023, 59 }; 60 61 ASSERT_EQ(result.size, 16); 62 ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 2); 63 } 64 65 TEST_F(PackFormats, 2) 66 { 67 struct bi_packed_tuple tuples[] = { 68 { 0x9380cb6044000044, 0xf65 }, 69 { 0xaf8721a05c000081, 0x1831 }, 70 }; 71 72 bi_pack_format(&result, 0, tuples, 2, 0x52800011800, 0, 0, false); 73 bi_pack_format(&result, 2, tuples, 2, 0x52800011800, 0, 0, false); 74 75 const uint64_t expected[] = { 76 0x80cb604400004429, 77 0x29400008c0076593, 78 0x8721a05c00008103, 79 0x60000000000031af, 80 }; 81 82 ASSERT_EQ(result.size, 32); 83 ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 4); 84 } 85 86 TEST_F(PackFormats, 3) 87 { 88 struct bi_packed_tuple tuples[] = { 89 { 0x93805b8040000000, 0xf65 }, 90 { 0x93886db05c000000, 0xf65 }, 91 { 0xb380cb180c000080, 0x18b1 }, 92 }; 93 94 bi_pack_format(&result, 0, tuples, 3, 0x3100000000, 0, 0, true); 95 bi_pack_format(&result, 3, tuples, 3, 0x3100000000, 0, 0, true); 96 bi_pack_format(&result, 4, tuples, 3, 0x3100000000, 0, 0, true); 97 98 const uint64_t expected[] = { 99 0x805b804000000029, 100 0x0188000000076593, 101 0x886db05c00000021, 102 0x58c0600004076593, 103 0x0000000000000044, 104 0x60002c6ce0300000, 105 }; 106 107 ASSERT_EQ(result.size, 48); 108 ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 6); 109 } 110 111 TEST_F(PackFormats, 4) 112 { 113 struct bi_packed_tuple tuples[] = { 114 { 0xad8c87004000005f, 0x2f18 }, 115 { 0xad8c87385c00004f, 0x2f18 }, 116 { 0xad8c87385c00006e, 0x2f18 }, 117 { 0xb380cb182c000080, 0x18b1 }, 118 }; 119 120 uint64_t EC0 = (0x10000001ff000000) >> 4; 121 122 bi_pack_format(&result, 0, tuples, 4, 0x3100000000, EC0, 0, false); 123 bi_pack_format(&result, 3, tuples, 4, 0x3100000000, EC0, 0, false); 124 bi_pack_format(&result, 6, tuples, 4, 0x3100000000, EC0, 0, false); 125 126 const uint64_t expected[] = { 127 0x8c87004000005f2d, 128 0x01880000000718ad, 129 0x8c87385c00004f25, 130 0x39c2e000037718ad, 131 0x80cb182c00008005, 132 0xac01c62b6320b1b3, 133 }; 134 135 ASSERT_EQ(result.size, 48); 136 ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 6); 137 } 138 139 TEST_F(PackFormats, 5) 140 { 141 struct bi_packed_tuple tuples[] = { 142 { 0x9380688040000000, 0xf65 }, 143 { 0xd4057300c000040, 0xf26 }, 144 { 0x1f80cb1858000000, 0x19ab }, 145 { 0x937401f85c000000, 0xf65 }, 146 { 0xb380cb180c000080, 0x18a1 }, 147 }; 148 149 uint64_t EC0 = (0x183f800000) >> 4; 150 151 bi_pack_format(&result, 0, tuples, 5, 0x3100000000, EC0, 0, true); 152 bi_pack_format(&result, 3, tuples, 5, 0x3100000000, EC0, 0, true); 153 bi_pack_format(&result, 7, tuples, 5, 0x3100000000, EC0, 0, true); 154 bi_pack_format(&result, 8, tuples, 5, 0x3100000000, EC0, 0, true); 155 156 const uint64_t expected[] = { 157 0x8068804000000029, 158 0x0188000000076593, 159 0x4057300c00004021, 160 0x58c2c0000007260d, 161 0x7401f85c0000008b, 162 0x00006ac7e0376593, 163 0x80cb180c00008053, 164 0x000000183f80a1b3, 165 }; 166 167 ASSERT_EQ(result.size, 64); 168 ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 8); 169 } 170 171 TEST_F(PackFormats, 6) 172 { 173 struct bi_packed_tuple tuples[] = { 174 { 0xad8c870068000048, 0x2f18 }, 175 { 0xad8c87385c000050, 0x2f18 }, 176 { 0xad8c87385c00006a, 0x2f18 }, 177 { 0xad8c87385c000074, 0x2f18 }, 178 { 0xad8c87385c000020, 0x2f18 }, 179 { 0xad8c87385c000030, 0x2f18 }, 180 }; 181 182 uint64_t EC0 = (0x345678912345670) >> 4; 183 184 bi_pack_format(&result, 0, tuples, 6, 0x60000011800, EC0, 0, false); 185 bi_pack_format(&result, 3, tuples, 6, 0x60000011800, EC0, 0, false); 186 bi_pack_format(&result, 5, tuples, 6, 0x60000011800, EC0, 0, false); 187 bi_pack_format(&result, 9, tuples, 6, 0x60000011800, EC0, 0, false); 188 bi_pack_format(&result, 10, tuples, 6, 0x60000011800, EC0, 0, false); 189 190 const uint64_t expected[] = { 191 0x8c8700680000482d, 192 0x30000008c00718ad, 193 0x8c87385c00005025, 194 0x39c2e000035718ad, 195 0x8c87385c00007401, 196 0xb401c62b632718ad, 197 0x8c87385c00002065, 198 0x39c2e000018718ad, 199 0x3456789123456706, 200 0xa001c62b63200000, 201 }; 202 203 ASSERT_EQ(result.size, 80); 204 ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 10); 205 } 206 207 TEST_F(PackFormats, 7) 208 { 209 struct bi_packed_tuple tuples[] = { 210 { 0x9020074040000083, 0xf65 }, 211 { 0x90000d4058100080, 0xf65 }, 212 { 0x90000a3058700082, 0xf65 }, 213 { 0x9020074008114581, 0xf65 }, 214 { 0x90000d0058000080, 0xf65 }, 215 { 0x9000083058700082, 0xf65 }, 216 { 0x2380cb199ac38400, 0x327a }, 217 }; 218 219 bi_pack_format(&result, 0, tuples, 7, 0x3000100000, 0, 0, true); 220 bi_pack_format(&result, 3, tuples, 7, 0x3000100000, 0, 0, true); 221 bi_pack_format(&result, 5, tuples, 7, 0x3000100000, 0, 0, true); 222 bi_pack_format(&result, 9, tuples, 7, 0x3000100000, 0, 0, true); 223 bi_pack_format(&result, 11, tuples, 7, 0x3000100000, 0, 0, true); 224 225 const uint64_t expected[] = { 226 0x2007404000008329, 227 0x0180008000076590, 228 0x000d405810008021, 229 0x5182c38004176590, 230 0x2007400811458101, 231 0x2401d96400076590, 232 0x000d005800008061, 233 0x4182c38004176590, 234 0x80cb199ac3840047, 235 0x3801d96400027a23, 236 }; 237 238 ASSERT_EQ(result.size, 80); 239 ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 10); 240 } 241 242 TEST_F(PackFormats, 8) 243 { 244 struct bi_packed_tuple tuples[] = { 245 { 0x442087037a2f8643, 0x3021 }, 246 { 0x84008d0586100043, 0x200 }, 247 { 0x7c008d0028014543, 0x0 }, 248 { 0x1c00070058200081, 0x1980 }, 249 { 0x1600dd878320400, 0x200 }, 250 { 0x49709c1b08308900, 0x200 }, 251 { 0x6c2007807881ca00, 0x40 }, 252 { 0x8d70fc0d94900083, 0x800 }, 253 }; 254 255 uint64_t EC0 = (0x32e635d0) >> 4; 256 257 bi_pack_format(&result, 0, tuples, 8, 0x61001311800, EC0, 0, true); 258 bi_pack_format(&result, 3, tuples, 8, 0x61001311800, EC0, 0, true); 259 bi_pack_format(&result, 5, tuples, 8, 0x61001311800, EC0, 0, true); 260 bi_pack_format(&result, 9, tuples, 8, 0x61001311800, EC0, 0, true); 261 bi_pack_format(&result, 12, tuples, 8, 0x61001311800, EC0, 0, true); 262 bi_pack_format(&result, 13, tuples, 8, 0x61001311800, EC0, 0, true); 263 264 const uint64_t expected[] = { 265 0x2087037a2f86432e, 266 0x30800988c0002144, 267 0x008d058610004320, 268 0x6801400a2a1a0084, 269 0x0007005820008101, 270 0x0c00001f0021801c, 271 0x600dd87832040060, 272 0xe0d8418448020001, 273 0x2007807881ca00c0, 274 0xc6ba80125c20406c, 275 0x70fc0d9490008359, 276 0x0000000032e0008d, 277 }; 278 279 ASSERT_EQ(result.size, 96); 280 ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 12); 281 } 282