|
| 1 | +/* Copyright (c) 2026 VillageSQL Contributors |
| 2 | + * |
| 3 | + * This program is free software; you can redistribute it and/or |
| 4 | + * modify it under the terms of the GNU General Public License |
| 5 | + * as published by the Free Software Foundation; either version 2 |
| 6 | + * of the License, or (at your option) any later version. |
| 7 | + * |
| 8 | + * This program is distributed in the hope that it will be useful, |
| 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | + * GNU General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU General Public License |
| 14 | + * along with this program; if not, see <https://www.gnu.org/licenses/>. |
| 15 | + */ |
| 16 | + |
| 17 | +// ABI v2 Compile-time Layout Checks |
| 18 | +// |
| 19 | +// Verifies the binary layout of protocol-2 fields in the main SDK headers. |
| 20 | +// A failure here means the server has broken ABI compatibility with extensions |
| 21 | +// compiled against VEF_PROTOCOL_2 headers. |
| 22 | +// |
| 23 | +// Sizes and offsets were derived from the 64-bit LP64 layout (Linux/macOS |
| 24 | +// x86-64 and ARM64) where: |
| 25 | +// pointer/size_t = 8 bytes (align 8), int/unsigned int = 4 bytes (align 4), |
| 26 | +// bool = 1 byte, double = 8 bytes, long long = 8 bytes, |
| 27 | +// enum : int / enum : unsigned int = 4 bytes (align 4). |
| 28 | + |
| 29 | +#include <gtest/gtest.h> |
| 30 | + |
| 31 | +#include <cstddef> |
| 32 | + |
| 33 | +#include "villagesql/sdk/include/villagesql/abi/types.h" |
| 34 | + |
| 35 | +// --------------------------------------------------------------------------- |
| 36 | +// vef_type_desc_t (protocol >= VEF_PROTOCOL_2 fields) |
| 37 | +// |
| 38 | +// Full layout including v1 and v2 fields: |
| 39 | +// vef_protocol_t protocol; // +0 |
| 40 | +// [4 bytes padding] |
| 41 | +// const char *name; // +8 |
| 42 | +// int64_t persisted_length; // +16 |
| 43 | +// int64_t max_decode_buffer_length; // +24 |
| 44 | +// vef_encode_func_t encode_func; // +32 (protocol >= 1) |
| 45 | +// vef_decode_func_t decode_func; // +40 (protocol >= 1) |
| 46 | +// vef_compare_func_t compare_func; // +48 (protocol >= 1) |
| 47 | +// vef_hash_func_t hash_func; // +56 (protocol >= 1) |
| 48 | +// vef_type_int_to_params_func_t int_to_params; // +64 (protocol >= 2) |
| 49 | +// vef_type_resolve_params_func_t resolve_params; // +72 (protocol >= 2) |
| 50 | +// const char *encode_vdf_name; // +80 (protocol >= 2) |
| 51 | +// const char *decode_vdf_name; // +88 (protocol >= 2) |
| 52 | +// const char *compare_vdf_name; // +96 (protocol >= 2) |
| 53 | +// const char *hash_vdf_name; // +104 (protocol >= 2) |
| 54 | +// --------------------------------------------------------------------------- |
| 55 | +static_assert(sizeof(vef_type_desc_t) == 112, |
| 56 | + "ABI v2 break: vef_type_desc_t size changed"); |
| 57 | +static_assert(offsetof(vef_type_desc_t, int_to_params) == 64, |
| 58 | + "ABI v2 break: vef_type_desc_t::int_to_params offset changed"); |
| 59 | +static_assert(offsetof(vef_type_desc_t, resolve_params) == 72, |
| 60 | + "ABI v2 break: vef_type_desc_t::resolve_params offset changed"); |
| 61 | +static_assert(offsetof(vef_type_desc_t, encode_vdf_name) == 80, |
| 62 | + "ABI v2 break: vef_type_desc_t::encode_vdf_name offset changed"); |
| 63 | +static_assert(offsetof(vef_type_desc_t, decode_vdf_name) == 88, |
| 64 | + "ABI v2 break: vef_type_desc_t::decode_vdf_name offset changed"); |
| 65 | +static_assert(offsetof(vef_type_desc_t, compare_vdf_name) == 96, |
| 66 | + "ABI v2 break: vef_type_desc_t::compare_vdf_name offset changed"); |
| 67 | +static_assert(offsetof(vef_type_desc_t, hash_vdf_name) == 104, |
| 68 | + "ABI v2 break: vef_type_desc_t::hash_vdf_name offset changed"); |
| 69 | + |
| 70 | +// Placeholder test so the binary links and runs. |
| 71 | +TEST(AbiV2Check, StaticAssertsPass) {} |
0 commit comments