Patch for OOM in tests on 32-bit platforms

epel10
Benjamin A. Beasley 5 months ago
parent 7257d65680
commit 24bece0978

@ -0,0 +1,71 @@
From 64a98f1bdc2a37c4dd1f29ee6886ed5f4688439e Mon Sep 17 00:00:00 2001
From: Daniel Reiter Horn <danielrh@users.sourceforge.net>
Date: Wed, 2 Oct 2024 00:43:00 -0700
Subject: [PATCH] Fix 32 bit tests by allocating less memory by running with
less parallelism in that case
---
src/enc/test.rs | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/src/enc/test.rs b/src/enc/test.rs
index 744472b..854d9b8 100755
--- a/src/enc/test.rs
+++ b/src/enc/test.rs
@@ -211,6 +211,34 @@ fn oneshot_compress(
(true, next_out_offset)
}
+static lock32: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0);
+
+/// 32bit systems do not have sufficient memory to compress multiple items
+/// at the same time with the current limits and defaults. So we instead spin
+/// until a process has completed compression. We cannot use proper locks
+/// in nostd, so we fall back to this simple spin lock.
+#[cfg(target_pointer_width = "32")]
+fn lock_if_32bit(){
+ use core::sync::atomic::Ordering;
+ loop {
+ let cur = lock32.fetch_add(1, Ordering::SeqCst);
+ if cur == 0 {
+ return;
+ }
+ lock32.fetch_sub(1, Ordering::SeqCst);
+ }
+}
+#[cfg(target_pointer_width = "32")]
+fn unlock_if_32bit(){
+ use core::sync::atomic::Ordering;
+ lock32.fetch_sub(1, Ordering::SeqCst);
+}
+#[cfg(not(target_pointer_width = "32"))]
+fn lock_if_32bit(){
+}
+#[cfg(not(target_pointer_width = "32"))]
+fn unlock_if_32bit(){
+}
fn oneshot_decompress(compressed: &[u8], output: &mut [u8]) -> (BrotliResult, usize, usize) {
let mut available_in: usize = compressed.len();
@@ -255,6 +283,7 @@ fn oneshot(
in_buffer_size: usize,
out_buffer_size: usize,
) -> (BrotliResult, usize, usize) {
+ lock_if_32bit();
let (success, mut available_in) = oneshot_compress(
input,
compressed,
@@ -268,7 +297,9 @@ fn oneshot(
//return (BrotliResult::ResultFailure, 0, 0);
available_in = compressed.len();
}
- oneshot_decompress(&mut compressed[..available_in], output)
+ let ret = oneshot_decompress(&mut compressed[..available_in], output);
+ unlock_if_32bit();
+ ret
}
#[test]
--
2.46.1

@ -1,5 +1,5 @@
--- brotli-6.0.0/Cargo.toml 1970-01-01T00:00:01+00:00 --- brotli-6.0.0/Cargo.toml 1970-01-01T00:00:01+00:00
+++ brotli-6.0.0/Cargo.toml 2024-10-01T14:59:41.120768+00:00 +++ brotli-6.0.0/Cargo.toml 2024-10-02T11:06:05.778047+00:00
@@ -34,8 +34,17 @@ @@ -34,8 +34,17 @@
"compression", "compression",
"no-std", "no-std",

@ -32,6 +32,11 @@ Patch: brotli-fix-metadata.diff
# Cargo.toml (which are applied manually to the normalized Cargo.toml in the # Cargo.toml (which are applied manually to the normalized Cargo.toml in the
# crate). # crate).
Patch10: brotli-6.0.0-license-accuracy.patch Patch10: brotli-6.0.0-license-accuracy.patch
# * Fix 32 bit tests by allocating less memory by running with less parallelism
# in that case:
# https://github.com/dropbox/rust-brotli/commit/0462558646c0d0c346f7e152377b33e9d9d507af
# (cherry-picked to 6.0.0)
Patch11: 0001-Fix-32-bit-tests-by-allocating-less-memory-by-runnin.patch
BuildRequires: cargo-rpm-macros >= 26 BuildRequires: cargo-rpm-macros >= 26
@ -222,24 +227,7 @@ find -type f -name '*.rs' -executable -exec chmod -x '{}' +
%if %{with check} %if %{with check}
%check %check
%if 0%{?__isa_bits} != 32
%cargo_test %cargo_test
%else
# Few tests fail with OOM on 32bit
# https://github.com/dropbox/rust-brotli/issues/42
skip="${skip-} --skip enc::test::test_roundtrip_10x10y"
skip="${skip-} --skip enc::test::test_roundtrip_64x"
skip="${skip-} --skip enc::test::test_roundtrip_asyoulik"
skip="${skip-} --skip enc::test::test_roundtrip_asyoulik9_5"
skip="${skip-} --skip enc::test::test_roundtrip_backward65536"
skip="${skip-} --skip enc::test::test_roundtrip_compressed_repeated"
skip="${skip-} --skip enc::test::test_roundtrip_monkey"
skip="${skip-} --skip enc::test::test_roundtrip_quickfox"
skip="${skip-} --skip enc::test::test_roundtrip_quickfox_repeated"
skip="${skip-} --skip enc::test::test_roundtrip_ukkonooa"
skip="${skip-} --skip enc::test::test_roundtrip_x"
%cargo_test -- -- --exact ${skip-}
%endif
%endif %endif
%changelog %changelog

@ -36,29 +36,6 @@ pre = [
"find -type f -name '*.rs' -executable -exec chmod -x '{}' +", "find -type f -name '*.rs' -executable -exec chmod -x '{}' +",
] ]
[scripts.check]
pre = [
"%if 0%{?__isa_bits} != 32",
]
post = [
"%else",
"# Few tests fail with OOM on 32bit",
"# https://github.com/dropbox/rust-brotli/issues/42",
"skip=\"${skip-} --skip enc::test::test_roundtrip_10x10y\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_64x\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_asyoulik\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_asyoulik9_5\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_backward65536\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_compressed_repeated\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_monkey\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_quickfox\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_quickfox_repeated\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_ukkonooa\"",
"skip=\"${skip-} --skip enc::test::test_roundtrip_x\"",
"%cargo_test -- -- --exact ${skip-}",
"%endif",
]
[[package.extra-patches]] [[package.extra-patches]]
number = 10 number = 10
file = "brotli-6.0.0-license-accuracy.patch" file = "brotli-6.0.0-license-accuracy.patch"
@ -70,3 +47,14 @@ comments = [
Cargo.toml in the crate).\ Cargo.toml in the crate).\
""" """
] ]
[[package.extra-patches]]
number = 11
file = "0001-Fix-32-bit-tests-by-allocating-less-memory-by-runnin.patch"
comments = [
"""\
Fix 32 bit tests by allocating less memory by running with less parallelism
in that case: \
https://github.com/dropbox/rust-brotli/commit/0462558646c0d0c346f7e152377b33e9d9d507af \
(cherry-picked to 6.0.0)\
"""
]

Loading…
Cancel
Save