1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-17 05:05:14 +03:00
aports/testing/squashfs-tools-ng/0001-Fix-struct-offset-testing-in-ABI-test-case.patch
Ryan Barnett f65bb4292b testing/squashfs-tools-ng: upgrade to 1.1.3
Pulled in patch for fixing test case for ABI on x86. Fixes issue with
incorrect struct assumptio.

  https://github.com/AgentD/squashfs-tools-ng/issues/93

Signed-off-by: Ryan Barnett <ryanbarnett3@gmail.com>
2021-09-23 21:29:15 +00:00

127 lines
5 KiB
Diff

From 349a98c2153f6d993c926007cb9eb7cc386c1be0 Mon Sep 17 00:00:00 2001
From: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Date: Sun, 12 Sep 2021 23:52:40 +0200
Subject: [PATCH 1/2] Fix struct offset testing in ABI test case
The intention of the (severely incomplete) ABI test case is to detect
changes to the ABI of libsquashfs. Currently it tries to blurt out if
the layout of some structure is changed unintentionally.
Unfortunately, the test uses some unportable assumptions. Among other
things, it was assumed that a 64 bit field will always require 64 bit
alignment. This is apparently no the case on 32 bit x86.
This patch makes the check work on 32 bit and 64 bit x86, by adding
an additional runtime check that relies on the __alignof__ extension
offered by gcc and clang (the only 2 compilers that are really
supported at the moment).
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
[Retrieved from https://github.com/AgentD/squashfs-tools-ng/issues/93]
Signed-off-by: Ryan Barnett <ryanbarnett3@gmail.com>
---
tests/libsqfs/abi.c | 71 +++++++++++++++++++++++++++++++++------------
1 file changed, 52 insertions(+), 19 deletions(-)
diff --git a/tests/libsqfs/abi.c b/tests/libsqfs/abi.c
index 04bbc30..d409f67 100644
--- a/tests/libsqfs/abi.c
+++ b/tests/libsqfs/abi.c
@@ -35,8 +35,14 @@ static void test_compressor_opt_struct(void)
sizeof(sqfs_u32));
TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, level),
(2 * sizeof(sqfs_u32)));
- TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, opt),
- (4 * sizeof(sqfs_u32)));
+
+ if (__alignof__(sqfs_compressor_config_t) == __alignof__(sqfs_u32)) {
+ TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, opt),
+ (3 * sizeof(sqfs_u32)));
+ } else if (__alignof__(sqfs_compressor_config_t) == __alignof__(sqfs_u64)) {
+ TEST_EQUAL_UI(offsetof(sqfs_compressor_config_t, opt),
+ (4 * sizeof(sqfs_u32)));
+ }
}
static const char *names[] = {
@@ -65,33 +71,60 @@ static void test_compressor_names(void)
static void test_blockproc_stats(void)
{
sqfs_block_processor_stats_t stats;
+ size_t off;
+
+ TEST_EQUAL_UI(sizeof(stats.size), sizeof(size_t));
+ TEST_EQUAL_UI(sizeof(stats.input_bytes_read), sizeof(sqfs_u64));
+ TEST_EQUAL_UI(sizeof(stats.output_bytes_generated), sizeof(sqfs_u64));
+ TEST_EQUAL_UI(sizeof(stats.data_block_count), sizeof(sqfs_u64));
+ TEST_EQUAL_UI(sizeof(stats.frag_block_count), sizeof(sqfs_u64));
+ TEST_EQUAL_UI(sizeof(stats.sparse_block_count), sizeof(sqfs_u64));
+ TEST_EQUAL_UI(sizeof(stats.total_frag_count), sizeof(sqfs_u64));
+ TEST_EQUAL_UI(sizeof(stats.actual_frag_count), sizeof(sqfs_u64));
- TEST_ASSERT(sizeof(stats) >= (8 * sizeof(sqfs_u64)));
+ if (__alignof__(stats) == __alignof__(sqfs_u32)) {
+ TEST_ASSERT(sizeof(stats) >=
+ (sizeof(sqfs_u32) + 7 * sizeof(sqfs_u64)));
+ } else if (__alignof__(stats) == __alignof__(sqfs_u64)) {
+ TEST_ASSERT(sizeof(stats) >= (8 * sizeof(sqfs_u64)));
+ }
TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t, size), 0);
+
+ if (sizeof(size_t) < sizeof(sqfs_u64) &&
+ (__alignof__(sqfs_block_processor_stats_t) ==
+ __alignof__(sqfs_u64))) {
+ off = sizeof(sqfs_u64);
+ } else {
+ off = sizeof(stats.size);
+ }
+
TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
- input_bytes_read), sizeof(sqfs_u64));
- TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
- output_bytes_generated), 2 * sizeof(sqfs_u64));
+ input_bytes_read), off);
+ off += sizeof(sqfs_u64);
+
TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
- data_block_count), 3 * sizeof(sqfs_u64));
+ output_bytes_generated), off);
+ off += sizeof(sqfs_u64);
+
TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
- frag_block_count), 4 * sizeof(sqfs_u64));
+ data_block_count), off);
+ off += sizeof(sqfs_u64);
+
TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
- sparse_block_count), 5 * sizeof(sqfs_u64));
+ frag_block_count), off);
+ off += sizeof(sqfs_u64);
+
TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
- total_frag_count), 6 * sizeof(sqfs_u64));
+ sparse_block_count), off);
+ off += sizeof(sqfs_u64);
+
TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
- actual_frag_count), 7 * sizeof(sqfs_u64));
+ total_frag_count), off);
+ off += sizeof(sqfs_u64);
- TEST_EQUAL_UI(sizeof(stats.size), sizeof(size_t));
- TEST_EQUAL_UI(sizeof(stats.input_bytes_read), sizeof(sqfs_u64));
- TEST_EQUAL_UI(sizeof(stats.output_bytes_generated), sizeof(sqfs_u64));
- TEST_EQUAL_UI(sizeof(stats.data_block_count), sizeof(sqfs_u64));
- TEST_EQUAL_UI(sizeof(stats.frag_block_count), sizeof(sqfs_u64));
- TEST_EQUAL_UI(sizeof(stats.sparse_block_count), sizeof(sqfs_u64));
- TEST_EQUAL_UI(sizeof(stats.total_frag_count), sizeof(sqfs_u64));
- TEST_EQUAL_UI(sizeof(stats.actual_frag_count), sizeof(sqfs_u64));
+ TEST_EQUAL_UI(offsetof(sqfs_block_processor_stats_t,
+ actual_frag_count), off);
}
static void test_blockproc_desc(void)
--
2.31.1