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