nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 101 lines 3.7 kB view raw
1diff --git a/tests/test_support/audio_support.cc b/tests/test_support/audio_support.cc 2index c26022e9..5f50d035 100644 3--- a/tests/test_support/audio_support.cc 4+++ b/tests/test_support/audio_support.cc 5@@ -16,6 +16,7 @@ 6 // along with arc_unpacker. If not, see <http://www.gnu.org/licenses/>. 7 8 #include "test_support/audio_support.h" 9+#include <cstdlib> 10 #include "algo/format.h" 11 #include "algo/range.h" 12 #include "dec/microsoft/wav_audio_decoder.h" 13@@ -44,13 +45,42 @@ res::Audio tests::get_test_audio() 14 void tests::compare_audio( 15 const res::Audio &actual, const res::Audio &expected) 16 { 17+ // Allow for minor variances in audio samples within the specified 18+ // threshold. Floating point calculations in some audio decoders yields 19+ // slightly differing results across different CPU architectures. 20+ // 21+ // Affected tests: 22+ // * tests/dec/cri/hca_audio_decoder_test.cc 23+ // * tests/dec/entis/mio_audio_decoder_test.cc 24+ static constexpr int tolerance = 1; 25+ 26 REQUIRE(actual.codec == expected.codec); 27 REQUIRE(actual.channel_count == expected.channel_count); 28 REQUIRE(actual.sample_rate == expected.sample_rate); 29 REQUIRE(actual.bits_per_sample == expected.bits_per_sample); 30 REQUIRE(actual.extra_codec_headers == expected.extra_codec_headers); 31 REQUIRE(actual.samples.size() == expected.samples.size()); 32+ 33+#ifdef __x86_64__ 34 tests::compare_binary(actual.samples, expected.samples); 35+#else 36+ tests::compare_binary( 37+ actual.samples, 38+ expected.samples, 39+ [](const bstr& bytes1, const bstr& bytes2) -> bool { 40+ const auto samples1 = reinterpret_cast<const s16*>(bytes1.c_str()); 41+ const auto samples2 = reinterpret_cast<const s16*>(bytes2.c_str()); 42+ const auto n_samples = bytes1.size() / sizeof(*samples1); 43+ // algo::range is a bit incomplete to work with std::all_of 44+ for (const int i : algo::range(n_samples)) { 45+ if (std::abs(samples1[i] - samples2[i]) > tolerance) { 46+ return false; 47+ } 48+ } 49+ return true; 50+ } 51+ ); 52+#endif 53 54 REQUIRE(actual.loops.size() == expected.loops.size()); 55 for (const auto i : algo::range(expected.loops.size())) 56diff --git a/tests/test_support/common.cc b/tests/test_support/common.cc 57index b63ffa89..265ef7b1 100644 58--- a/tests/test_support/common.cc 59+++ b/tests/test_support/common.cc 60@@ -40,3 +40,19 @@ void au::tests::compare_binary(const bstr &actual, const bstr &expected) 61 INFO(actual_dump << " != " << expected_dump); 62 REQUIRE(actual == expected); 63 } 64+ 65+void au::tests::compare_binary( 66+ const bstr &actual, 67+ const bstr &expected, 68+ std::function<bool(const bstr &, const bstr &)> compare) 69+{ 70+ const auto max_size = 10000; 71+ auto actual_dump = algo::hex(actual); 72+ auto expected_dump = algo::hex(expected); 73+ if (actual_dump.size() > max_size) 74+ actual_dump = actual_dump.substr(0, max_size) + "(...)"; 75+ if (expected_dump.size() > max_size) 76+ expected_dump = expected_dump.substr(0, max_size) + "(...)"; 77+ INFO(actual_dump << " != " << expected_dump); 78+ REQUIRE(compare(actual, expected)); 79+} 80diff --git a/tests/test_support/common.h b/tests/test_support/common.h 81index 7d8be579..ecd5dcf8 100644 82--- a/tests/test_support/common.h 83+++ b/tests/test_support/common.h 84@@ -17,6 +17,7 @@ 85 86 #pragma once 87 88+#include <functional> 89 #include "io/path.h" 90 #include "types.h" 91 92@@ -27,4 +28,9 @@ namespace tests { 93 94 void compare_binary(const bstr &actual, const bstr &expected); 95 96+ void compare_binary( 97+ const bstr &actual, 98+ const bstr &expected, 99+ std::function<bool(const bstr &, const bstr &)> compare); 100+ 101 } }