From 24bece097801a9d4de1770610361bcf521385835 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Wed, 2 Oct 2024 07:00:03 -0400 Subject: [PATCH] Patch for OOM in tests on 32-bit platforms --- ...-by-allocating-less-memory-by-runnin.patch | 71 +++++++++++++++++++ brotli-fix-metadata.diff | 2 +- rust-brotli.spec | 22 ++---- rust2rpm.toml | 34 +++------ 4 files changed, 88 insertions(+), 41 deletions(-) create mode 100644 0001-Fix-32-bit-tests-by-allocating-less-memory-by-runnin.patch diff --git a/0001-Fix-32-bit-tests-by-allocating-less-memory-by-runnin.patch b/0001-Fix-32-bit-tests-by-allocating-less-memory-by-runnin.patch new file mode 100644 index 0000000..edba55f --- /dev/null +++ b/0001-Fix-32-bit-tests-by-allocating-less-memory-by-runnin.patch @@ -0,0 +1,71 @@ +From 64a98f1bdc2a37c4dd1f29ee6886ed5f4688439e Mon Sep 17 00:00:00 2001 +From: Daniel Reiter Horn +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 + diff --git a/brotli-fix-metadata.diff b/brotli-fix-metadata.diff index 8e4d818..cc49baa 100644 --- a/brotli-fix-metadata.diff +++ b/brotli-fix-metadata.diff @@ -1,5 +1,5 @@ --- 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 @@ "compression", "no-std", diff --git a/rust-brotli.spec b/rust-brotli.spec index de3bb73..c1af70e 100644 --- a/rust-brotli.spec +++ b/rust-brotli.spec @@ -32,6 +32,11 @@ Patch: brotli-fix-metadata.diff # Cargo.toml (which are applied manually to the normalized Cargo.toml in the # crate). 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 @@ -222,24 +227,7 @@ find -type f -name '*.rs' -executable -exec chmod -x '{}' + %if %{with check} %check -%if 0%{?__isa_bits} != 32 %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 %changelog diff --git a/rust2rpm.toml b/rust2rpm.toml index 1e84b19..bee1e34 100644 --- a/rust2rpm.toml +++ b/rust2rpm.toml @@ -36,29 +36,6 @@ pre = [ "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]] number = 10 file = "brotli-6.0.0-license-accuracy.patch" @@ -70,3 +47,14 @@ comments = [ 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)\ + """ +]