arc_unpacker: fix aarch64 build (#458984)

This commit is contained in:
Vladimír Čunát
2025-11-22 08:31:22 +00:00
committed by GitHub
2 changed files with 130 additions and 24 deletions
@@ -0,0 +1,101 @@
diff --git a/tests/test_support/audio_support.cc b/tests/test_support/audio_support.cc
index c26022e9..5f50d035 100644
--- a/tests/test_support/audio_support.cc
+++ b/tests/test_support/audio_support.cc
@@ -16,6 +16,7 @@
// along with arc_unpacker. If not, see <http://www.gnu.org/licenses/>.
#include "test_support/audio_support.h"
+#include <cstdlib>
#include "algo/format.h"
#include "algo/range.h"
#include "dec/microsoft/wav_audio_decoder.h"
@@ -44,13 +45,42 @@ res::Audio tests::get_test_audio()
void tests::compare_audio(
const res::Audio &actual, const res::Audio &expected)
{
+ // Allow for minor variances in audio samples within the specified
+ // threshold. Floating point calculations in some audio decoders yields
+ // slightly differing results across different CPU architectures.
+ //
+ // Affected tests:
+ // * tests/dec/cri/hca_audio_decoder_test.cc
+ // * tests/dec/entis/mio_audio_decoder_test.cc
+ static constexpr int tolerance = 1;
+
REQUIRE(actual.codec == expected.codec);
REQUIRE(actual.channel_count == expected.channel_count);
REQUIRE(actual.sample_rate == expected.sample_rate);
REQUIRE(actual.bits_per_sample == expected.bits_per_sample);
REQUIRE(actual.extra_codec_headers == expected.extra_codec_headers);
REQUIRE(actual.samples.size() == expected.samples.size());
+
+#ifdef __x86_64__
tests::compare_binary(actual.samples, expected.samples);
+#else
+ tests::compare_binary(
+ actual.samples,
+ expected.samples,
+ [](const bstr& bytes1, const bstr& bytes2) -> bool {
+ const auto samples1 = reinterpret_cast<const s16*>(bytes1.c_str());
+ const auto samples2 = reinterpret_cast<const s16*>(bytes2.c_str());
+ const auto n_samples = bytes1.size() / sizeof(*samples1);
+ // algo::range is a bit incomplete to work with std::all_of
+ for (const int i : algo::range(n_samples)) {
+ if (std::abs(samples1[i] - samples2[i]) > tolerance) {
+ return false;
+ }
+ }
+ return true;
+ }
+ );
+#endif
REQUIRE(actual.loops.size() == expected.loops.size());
for (const auto i : algo::range(expected.loops.size()))
diff --git a/tests/test_support/common.cc b/tests/test_support/common.cc
index b63ffa89..265ef7b1 100644
--- a/tests/test_support/common.cc
+++ b/tests/test_support/common.cc
@@ -40,3 +40,19 @@ void au::tests::compare_binary(const bstr &actual, const bstr &expected)
INFO(actual_dump << " != " << expected_dump);
REQUIRE(actual == expected);
}
+
+void au::tests::compare_binary(
+ const bstr &actual,
+ const bstr &expected,
+ std::function<bool(const bstr &, const bstr &)> compare)
+{
+ const auto max_size = 10000;
+ auto actual_dump = algo::hex(actual);
+ auto expected_dump = algo::hex(expected);
+ if (actual_dump.size() > max_size)
+ actual_dump = actual_dump.substr(0, max_size) + "(...)";
+ if (expected_dump.size() > max_size)
+ expected_dump = expected_dump.substr(0, max_size) + "(...)";
+ INFO(actual_dump << " != " << expected_dump);
+ REQUIRE(compare(actual, expected));
+}
diff --git a/tests/test_support/common.h b/tests/test_support/common.h
index 7d8be579..ecd5dcf8 100644
--- a/tests/test_support/common.h
+++ b/tests/test_support/common.h
@@ -17,6 +17,7 @@
#pragma once
+#include <functional>
#include "io/path.h"
#include "types.h"
@@ -27,4 +28,9 @@ namespace tests {
void compare_binary(const bstr &actual, const bstr &expected);
+ void compare_binary(
+ const bstr &actual,
+ const bstr &expected,
+ std::function<bool(const bstr &, const bstr &)> compare);
+
} }
+29 -24
View File
@@ -5,6 +5,7 @@
fetchpatch,
cmake,
makeWrapper,
ninja,
boost,
libpng,
libiconv,
@@ -26,22 +27,14 @@ stdenv.mkDerivation {
hash = "sha256-STbdWH7Mr3gpOrZvujblYrIIKEWBHzy1/BaNuh4teI8=";
};
patches = [
(fetchpatch {
name = "failing_tests.patch";
url = "https://aur.archlinux.org/cgit/aur.git/plain/failing_tests.patch?h=arc_unpacker-git&id=bda1ad9f69e6802e703b2e6913d71a36d76cfef9";
hash = "sha256-bClACsf/+SktyLAPtt7EcSqprkw8JVIi1ZLpcJcv9IE=";
})
(fetchpatch {
name = "include_cstdint.patch";
url = "https://aur.archlinux.org/cgit/aur.git/plain/include_cstdint.patch?h=arc_unpacker-git&id=8c5c5121b23813c7650db19cb617b409d8fdcc9f";
hash = "sha256-3BQ1v7s9enUK/js7Jqrqo2RdSRvGVd7hMcY4iL51SiE=";
})
];
patches = [ ./fix-test-float-variance.patch ];
postPatch = ''
cp ${catch2}/include/catch2/catch.hpp tests/test_support/catch.h
# missing includes
sed '1i#include <limits>' -i src/dec/eagls/pak_archive_decoder.cc # gcc12
sed '1i#include <cstdint>' -i src/types.h # gcc13
sed '1i#include <vector>' -i src/flow/cli_facade.h # gcc14
# cmake-4 support
@@ -53,6 +46,7 @@ stdenv.mkDerivation {
nativeBuildInputs = [
cmake
makeWrapper
ninja
catch2
];
@@ -66,15 +60,30 @@ stdenv.mkDerivation {
zlib
];
checkPhase = ''
runHook preCheck
checkPhase =
let
checkTarget = [
"~CatSystem INT archives"
]
++ lib.optionals (stdenv.hostPlatform.system == "aarch64-linux") [ "~Ivory WADY audio" ];
in
''
# Specify test targets
# https://catch2-temp.readthedocs.io/en/latest/command-line.html#specifying-which-tests-to-run
checkTarget=(${lib.escapeShellArgs checkTarget})
pushd ..
./build/run_tests
popd
runHook preCheck
runHook postCheck
'';
local flagsArray=()
concatTo flagsArray checkFlags checkFlagsArray checkTarget
pushd ..
echoCmd 'check flags' "''${flagsArray[@]}"
./build/run_tests "''${flagsArray[@]}"
popd
runHook postCheck
'';
installPhase = ''
runHook preInstall
@@ -88,8 +97,7 @@ stdenv.mkDerivation {
runHook postInstall
'';
# A few tests fail on aarch64-linux
doCheck = !(stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64);
doCheck = true;
meta = with lib; {
description = "Tool to extract files from visual novel archives";
@@ -98,8 +106,5 @@ stdenv.mkDerivation {
maintainers = with maintainers; [ midchildan ];
platforms = platforms.all;
mainProgram = "arc_unpacker";
# unit test failures
broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64;
};
}