Skip to content

Commit

Permalink
Fix testing of the standard library with Emscripten
Browse files Browse the repository at this point in the history
This does need EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" avoid several OOMs.
  • Loading branch information
bjorn3 authored and gitbot committed Mar 4, 2025
1 parent e525a7b commit 3bb41fe
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions alloc/benches/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ pub fn iter_10k(b: &mut Bencher) {
}

#[bench]
#[cfg_attr(target_os = "emscripten", ignore)] // hits an OOM
pub fn iter_1m(b: &mut Bencher) {
bench_iter(b, 1_000, 1_000_000);
}
Expand Down
11 changes: 11 additions & 0 deletions alloc/benches/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,25 @@ rotate!(rotate_medium_half, gen_random, 9158, 9158 / 2);
rotate!(rotate_medium_half_plus_one, gen_random, 9158, 9158 / 2 + 1);

// Intended to use more RAM than the machine has cache
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by1, gen_random, 5 * 1024 * 1024, 1);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by9199_u64, gen_random, 5 * 1024 * 1024, 9199);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by9199_bytes, gen_random_bytes, 5 * 1024 * 1024, 9199);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by9199_strings, gen_strings, 5 * 1024 * 1024, 9199);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by9199_big, gen_big_random, 5 * 1024 * 1024, 9199);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by1234577_u64, gen_random, 5 * 1024 * 1024, 1234577);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by1234577_bytes, gen_random_bytes, 5 * 1024 * 1024, 1234577);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by1234577_strings, gen_strings, 5 * 1024 * 1024, 1234577);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_by1234577_big, gen_big_random, 5 * 1024 * 1024, 1234577);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_half, gen_random, 5 * 1024 * 1024, 5 * 1024 * 1024 / 2);
#[cfg(not(target_os = "emscripten"))] // hits an OOM
rotate!(rotate_huge_half_plus_one, gen_random, 5 * 1024 * 1024, 5 * 1024 * 1024 / 2 + 1);
5 changes: 5 additions & 0 deletions alloc/benches/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ fn bench_in_place_collect_droppable(b: &mut Bencher) {
})
}

// node.js gives out of memory error to use with length 1_100_000
#[cfg(target_os = "emscripten")]
const LEN: usize = 4096;

#[cfg(not(target_os = "emscripten"))]
const LEN: usize = 16384;

#[bench]
Expand Down
9 changes: 8 additions & 1 deletion alloc/tests/sort/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ use crate::sort::{Sort, known_good_stable_sort, patterns};
#[cfg(miri)]
const TEST_LENGTHS: &[usize] = &[2, 3, 4, 7, 10, 15, 20, 24, 33, 50, 100, 171, 300];

#[cfg(not(miri))]
// node.js gives out of memory error to use with length 1_100_000
#[cfg(all(not(miri), target_os = "emscripten"))]
const TEST_LENGTHS: &[usize] = &[
2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 17, 20, 24, 30, 32, 33, 35, 50, 100, 200, 500, 1_000,
2_048, 5_000, 10_000, 100_000,
];

#[cfg(all(not(miri), not(target_os = "emscripten")))]
const TEST_LENGTHS: &[usize] = &[
2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 17, 20, 24, 30, 32, 33, 35, 50, 100, 200, 500, 1_000,
2_048, 5_000, 10_000, 100_000, 1_100_000,
Expand Down
1 change: 1 addition & 0 deletions alloc/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ fn try_unwrap() {
}

#[test]
#[cfg_attr(any(target_os = "emscripten", target_os = "wasi"), ignore)] // no threads
fn into_inner() {
for _ in 0..100
// ^ Increase chances of hitting potential race conditions
Expand Down
1 change: 1 addition & 0 deletions std/src/io/copy/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ mod io_benches {
use crate::io::prelude::*;

#[bench]
#[cfg_attr(target_os = "emscripten", ignore)] // no /dev
fn bench_copy_buf_reader(b: &mut Bencher) {
let mut file_in = File::open("/dev/zero").expect("opening /dev/zero failed");
// use dyn to avoid specializations unrelated to readbuf
Expand Down
2 changes: 1 addition & 1 deletion std/tests/pipe_subprocess.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(anonymous_pipe)]

fn main() {
#[cfg(all(not(miri), any(unix, windows)))]
#[cfg(all(not(miri), any(unix, windows), not(target_os = "emscripten")))]
{
use std::io::{Read, pipe};
use std::{env, process};
Expand Down
3 changes: 2 additions & 1 deletion std/tests/process_spawning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::{env, fs, process, str};
mod common;

#[test]
#[cfg_attr(any(miri, target_os = "wasi"), ignore)] // Process spawning not supported by Miri and wasi
// Process spawning not supported by Miri, Emscripten and wasi
#[cfg_attr(any(miri, target_os = "emscripten", target_os = "wasi"), ignore)]
fn issue_15149() {
// If we're the parent, copy our own binary to a new directory.
let my_path = env::current_exe().unwrap();
Expand Down

0 comments on commit 3bb41fe

Please sign in to comment.