Skip to content
/ rust Public
forked from rust-lang/rust

Commit b58221e

Browse files
authored
Rollup merge of rust-lang#135948 - bjorn3:update_emscripten_std_tests, r=Mark-Simulacrum
Update emscripten std tests This disables a bunch of emscripten tests that test things emscripten doesn't support and re-enables a whole bunch of tests which now work just fine on emscripten. Tested with `EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" ./x.py test library/ --target wasm32-unknown-emscripten`.
2 parents 61e572b + 6b18473 commit b58221e

File tree

23 files changed

+64
-68
lines changed

23 files changed

+64
-68
lines changed

Diff for: library/alloc/benches/btree/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ pub fn iter_10k(b: &mut Bencher) {
353353
}
354354

355355
#[bench]
356+
#[cfg_attr(target_os = "emscripten", ignore)] // hits an OOM
356357
pub fn iter_1m(b: &mut Bencher) {
357358
bench_iter(b, 1_000, 1_000_000);
358359
}

Diff for: library/alloc/benches/slice.rs

+11
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,25 @@ rotate!(rotate_medium_half, gen_random, 9158, 9158 / 2);
366366
rotate!(rotate_medium_half_plus_one, gen_random, 9158, 9158 / 2 + 1);
367367

368368
// Intended to use more RAM than the machine has cache
369+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
369370
rotate!(rotate_huge_by1, gen_random, 5 * 1024 * 1024, 1);
371+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
370372
rotate!(rotate_huge_by9199_u64, gen_random, 5 * 1024 * 1024, 9199);
373+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
371374
rotate!(rotate_huge_by9199_bytes, gen_random_bytes, 5 * 1024 * 1024, 9199);
375+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
372376
rotate!(rotate_huge_by9199_strings, gen_strings, 5 * 1024 * 1024, 9199);
377+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
373378
rotate!(rotate_huge_by9199_big, gen_big_random, 5 * 1024 * 1024, 9199);
379+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
374380
rotate!(rotate_huge_by1234577_u64, gen_random, 5 * 1024 * 1024, 1234577);
381+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
375382
rotate!(rotate_huge_by1234577_bytes, gen_random_bytes, 5 * 1024 * 1024, 1234577);
383+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
376384
rotate!(rotate_huge_by1234577_strings, gen_strings, 5 * 1024 * 1024, 1234577);
385+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
377386
rotate!(rotate_huge_by1234577_big, gen_big_random, 5 * 1024 * 1024, 1234577);
387+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
378388
rotate!(rotate_huge_half, gen_random, 5 * 1024 * 1024, 5 * 1024 * 1024 / 2);
389+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
379390
rotate!(rotate_huge_half_plus_one, gen_random, 5 * 1024 * 1024, 5 * 1024 * 1024 / 2 + 1);

Diff for: library/alloc/benches/vec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,11 @@ fn bench_in_place_collect_droppable(b: &mut Bencher) {
547547
})
548548
}
549549

550+
// node.js gives out of memory error to use with length 1_100_000
551+
#[cfg(target_os = "emscripten")]
552+
const LEN: usize = 4096;
553+
554+
#[cfg(not(target_os = "emscripten"))]
550555
const LEN: usize = 16384;
551556

552557
#[bench]

Diff for: library/alloc/tests/collections/binary_heap.rs

-2
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,7 @@ fn test_retain_catch_unwind() {
502502
// even if the order might not be correct.
503503
//
504504
// Destructors must be called exactly once per element.
505-
// FIXME: re-enable emscripten once it can unwind again
506505
#[test]
507-
#[cfg(not(target_os = "emscripten"))]
508506
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
509507
fn panic_safe() {
510508
use std::cmp;

Diff for: library/alloc/tests/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ fn test_rng() -> rand_xorshift::XorShiftRng {
9494
rand::SeedableRng::from_seed(seed)
9595
}
9696

97-
// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
98-
// See https://github.com/kripken/emscripten-fastcomp/issues/169
99-
#[cfg(not(target_os = "emscripten"))]
10097
#[test]
10198
fn test_boxed_hasher() {
10299
let ordinary_hash = hash(&5u32);

Diff for: library/alloc/tests/slice.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,6 @@ fn test_box_slice_clone() {
14141414

14151415
#[test]
14161416
#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
1417-
#[cfg_attr(target_os = "emscripten", ignore)]
14181417
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
14191418
fn test_box_slice_clone_panics() {
14201419
use std::sync::Arc;

Diff for: library/alloc/tests/sort/tests.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ use crate::sort::{Sort, known_good_stable_sort, patterns};
1111
#[cfg(miri)]
1212
const TEST_LENGTHS: &[usize] = &[2, 3, 4, 7, 10, 15, 20, 24, 33, 50, 100, 171, 300];
1313

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

Diff for: library/alloc/tests/sync.rs

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ fn try_unwrap() {
128128
}
129129

130130
#[test]
131+
#[cfg_attr(any(target_os = "emscripten", target_os = "wasi"), ignore)] // no threads
131132
fn into_inner() {
132133
for _ in 0..100
133134
// ^ Increase chances of hitting potential race conditions

Diff for: library/alloc/tests/vec.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1587,9 +1587,7 @@ fn extract_if_complex() {
15871587
}
15881588
}
15891589

1590-
// FIXME: re-enable emscripten once it can unwind again
15911590
#[test]
1592-
#[cfg(not(target_os = "emscripten"))]
15931591
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
15941592
fn extract_if_consumed_panic() {
15951593
use std::rc::Rc;
@@ -1640,9 +1638,7 @@ fn extract_if_consumed_panic() {
16401638
}
16411639
}
16421640

1643-
// FIXME: Re-enable emscripten once it can catch panics
16441641
#[test]
1645-
#[cfg(not(target_os = "emscripten"))]
16461642
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
16471643
fn extract_if_unconsumed_panic() {
16481644
use std::rc::Rc;

Diff for: library/core/tests/hash/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ fn test_custom_state() {
141141
// const { assert!(hash(&Custom { hash: 6 }) == 6) };
142142
}
143143

144-
// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
145-
// See https://github.com/kripken/emscripten-fastcomp/issues/169
146-
#[cfg(not(target_os = "emscripten"))]
147144
#[test]
148145
fn test_indirect_hasher() {
149146
let mut hasher = MyHasher { hash: 0 };

Diff for: library/core/tests/num/flt2dec/random.rs

-6
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ where
8484
F: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>]) -> Option<(&'a [u8], i16)>,
8585
G: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>]) -> (&'a [u8], i16),
8686
{
87-
if cfg!(target_os = "emscripten") {
88-
return; // using rng pulls in i128 support, which doesn't work
89-
}
9087
let mut rng = crate::test_rng();
9188
let f32_range = Uniform::new(0x0000_0001u32, 0x7f80_0000);
9289
iterate("f32_random_equivalence_test", k, n, f, g, |_| {
@@ -100,9 +97,6 @@ where
10097
F: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>]) -> Option<(&'a [u8], i16)>,
10198
G: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>]) -> (&'a [u8], i16),
10299
{
103-
if cfg!(target_os = "emscripten") {
104-
return; // using rng pulls in i128 support, which doesn't work
105-
}
106100
let mut rng = crate::test_rng();
107101
let f64_range = Uniform::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
108102
iterate("f64_random_equivalence_test", k, n, f, g, |_| {

Diff for: library/core/tests/num/ops.rs

+29-23
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ macro_rules! test_op {
5151
};
5252
}
5353

54-
test_op!(test_neg_defined, Neg::neg(0), 0, i8, i16, i32, i64, f32, f64);
55-
#[cfg(not(target_os = "emscripten"))]
56-
test_op!(test_neg_defined_128, Neg::neg(0), 0, i128);
54+
test_op!(test_neg_defined, Neg::neg(0), 0, i8, i16, i32, i64, i128, f32, f64);
5755

5856
test_op!(test_not_defined_bool, Not::not(true), false, bool);
5957

@@ -69,17 +67,17 @@ macro_rules! test_arith_op {
6967
i16,
7068
i32,
7169
i64,
70+
i128,
7271
isize,
7372
u8,
7473
u16,
7574
u32,
7675
u64,
76+
u128,
7777
usize,
7878
f32,
7979
f64
8080
);
81-
#[cfg(not(target_os = "emscripten"))]
82-
impls_defined!($op, $method($lhs, $rhs), 0, i128, u128);
8381
}
8482
};
8583
($fn_name:ident, $op:ident::$method:ident(&mut $lhs:literal, $rhs:literal)) => {
@@ -93,17 +91,17 @@ macro_rules! test_arith_op {
9391
i16,
9492
i32,
9593
i64,
94+
i128,
9695
isize,
9796
u8,
9897
u16,
9998
u32,
10099
u64,
100+
u128,
101101
usize,
102102
f32,
103103
f64
104104
);
105-
#[cfg(not(target_os = "emscripten"))]
106-
impls_defined!($op, $method(&mut $lhs, $rhs), 0, i128, u128);
107105
}
108106
};
109107
}
@@ -131,15 +129,15 @@ macro_rules! test_bitop {
131129
i16,
132130
i32,
133131
i64,
132+
i128,
134133
isize,
135134
u8,
136135
u16,
137136
u32,
138137
u64,
138+
u128,
139139
usize
140140
);
141-
#[cfg(not(target_os = "emscripten"))]
142-
impls_defined!($op, $method(0, 0), 0, i128, u128);
143141
impls_defined!($op, $method(false, false), false, bool);
144142
}
145143
};
@@ -156,15 +154,15 @@ macro_rules! test_bitop_assign {
156154
i16,
157155
i32,
158156
i64,
157+
i128,
159158
isize,
160159
u8,
161160
u16,
162161
u32,
163162
u64,
163+
u128,
164164
usize
165165
);
166-
#[cfg(not(target_os = "emscripten"))]
167-
impls_defined!($op, $method(&mut 0, 0), 0, i128, u128);
168166
impls_defined!($op, $method(&mut false, false), false, bool);
169167
}
170168
};
@@ -182,9 +180,11 @@ macro_rules! test_shift_inner {
182180
$(impl_defined!($op, $method(0,0), 0, $lt, $rt);)+
183181
};
184182
($op:ident::$method:ident, $lt:ty) => {
185-
test_shift_inner!($op::$method, $lt, i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
186-
#[cfg(not(target_os = "emscripten"))]
187-
test_shift_inner!($op::$method, $lt, i128, u128);
183+
test_shift_inner!(
184+
$op::$method, $lt,
185+
i8, i16, i32, i64, i128, isize,
186+
u8, u16, u32, u64, u128, usize
187+
);
188188
};
189189
}
190190

@@ -195,9 +195,11 @@ macro_rules! test_shift {
195195
($test_name:ident, $op:ident::$method:ident) => {
196196
#[test]
197197
fn $test_name() {
198-
test_shift!($op::$method, i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
199-
#[cfg(not(target_os = "emscripten"))]
200-
test_shift!($op::$method, i128, u128);
198+
test_shift!(
199+
$op::$method,
200+
i8, i16, i32, i64, i128, isize,
201+
u8, u16, u32, u64, u128, usize
202+
);
201203
}
202204
};
203205
}
@@ -207,9 +209,11 @@ macro_rules! test_shift_assign_inner {
207209
$(impl_defined!($op, $method(&mut 0,0), 0, $lt, $rt);)+
208210
};
209211
($op:ident::$method:ident, $lt:ty) => {
210-
test_shift_assign_inner!($op::$method, $lt, i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
211-
#[cfg(not(target_os = "emscripten"))]
212-
test_shift_assign_inner!($op::$method, $lt, i128, u128);
212+
test_shift_assign_inner!(
213+
$op::$method, $lt,
214+
i8, i16, i32, i64, i128, isize,
215+
u8, u16, u32, u64, u128, usize
216+
);
213217
};
214218
}
215219

@@ -220,9 +224,11 @@ macro_rules! test_shift_assign {
220224
($test_name:ident, $op:ident::$method:ident) => {
221225
#[test]
222226
fn $test_name() {
223-
test_shift_assign!($op::$method, i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
224-
#[cfg(not(target_os = "emscripten"))]
225-
test_shift_assign!($op::$method, i128, u128);
227+
test_shift_assign!(
228+
$op::$method,
229+
i8, i16, i32, i64, i128, isize,
230+
u8, u16, u32, u64, u128, usize
231+
);
226232
}
227233
};
228234
}

Diff for: library/core/tests/num/wrapping.rs

-2
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ wrapping_test!(test_wrapping_i8, i8, i8::MIN, i8::MAX);
6464
wrapping_test!(test_wrapping_i16, i16, i16::MIN, i16::MAX);
6565
wrapping_test!(test_wrapping_i32, i32, i32::MIN, i32::MAX);
6666
wrapping_test!(test_wrapping_i64, i64, i64::MIN, i64::MAX);
67-
#[cfg(not(target_os = "emscripten"))]
6867
wrapping_test!(test_wrapping_i128, i128, i128::MIN, i128::MAX);
6968
wrapping_test!(test_wrapping_isize, isize, isize::MIN, isize::MAX);
7069
wrapping_test!(test_wrapping_u8, u8, u8::MIN, u8::MAX);
7170
wrapping_test!(test_wrapping_u16, u16, u16::MIN, u16::MAX);
7271
wrapping_test!(test_wrapping_u32, u32, u32::MIN, u32::MAX);
7372
wrapping_test!(test_wrapping_u64, u64, u64::MIN, u64::MAX);
74-
#[cfg(not(target_os = "emscripten"))]
7573
wrapping_test!(test_wrapping_u128, u128, u128::MIN, u128::MAX);
7674
wrapping_test!(test_wrapping_usize, usize, usize::MIN, usize::MAX);
7775

Diff for: library/std/src/f64/tests.rs

-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ fn test_neg_zero() {
112112
assert_eq!(Fp::Zero, neg_zero.classify());
113113
}
114114

115-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
116115
#[test]
117116
fn test_one() {
118117
let one: f64 = 1.0f64;
@@ -165,7 +164,6 @@ fn test_is_finite() {
165164
assert!((-109.2f64).is_finite());
166165
}
167166

168-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
169167
#[test]
170168
fn test_is_normal() {
171169
let nan: f64 = f64::NAN;
@@ -183,7 +181,6 @@ fn test_is_normal() {
183181
assert!(!1e-308f64.is_normal());
184182
}
185183

186-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
187184
#[test]
188185
fn test_classify() {
189186
let nan: f64 = f64::NAN;

Diff for: library/std/src/io/copy/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ mod io_benches {
126126
use crate::io::prelude::*;
127127

128128
#[bench]
129+
#[cfg_attr(target_os = "emscripten", ignore)] // no /dev
129130
fn bench_copy_buf_reader(b: &mut Bencher) {
130131
let mut file_in = File::open("/dev/zero").expect("opening /dev/zero failed");
131132
// use dyn to avoid specializations unrelated to readbuf

Diff for: library/std/src/io/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::mem::MaybeUninit;
77
use crate::ops::Deref;
88

99
#[test]
10-
#[cfg_attr(target_os = "emscripten", ignore)]
1110
fn read_until() {
1211
let mut buf = Cursor::new(&b"12"[..]);
1312
let mut v = Vec::new();
@@ -359,7 +358,6 @@ fn chain_zero_length_read_is_not_eof() {
359358
}
360359

361360
#[bench]
362-
#[cfg_attr(target_os = "emscripten", ignore)]
363361
#[cfg_attr(miri, ignore)] // Miri isn't fast...
364362
fn bench_read_to_end(b: &mut test::Bencher) {
365363
b.iter(|| {

Diff for: library/std/src/sys/alloc/wasm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This is an implementation of a global allocator on wasm targets when
2-
//! emscripten is not in use. In that situation there's no actual runtime for us
3-
//! to lean on for allocation, so instead we provide our own!
2+
//! emscripten or wasi is not in use. In that situation there's no actual runtime
3+
//! for us to lean on for allocation, so instead we provide our own!
44
//!
55
//! The wasm instruction set has two instructions for getting the current
66
//! amount of memory and growing the amount of memory. These instructions are the

Diff for: library/std/src/sys/pal/wasi/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! System bindings for the wasm/web platform
22
//!
33
//! This module contains the facade (aka platform-specific) implementations of
4-
//! OS level functionality for wasm. Note that this wasm is *not* the emscripten
5-
//! wasm, so we have no runtime here.
4+
//! OS level functionality for wasm.
65
//!
76
//! This is all super highly experimental and not actually intended for
87
//! wide/production use yet, it's still all in the experimental category. This

Diff for: library/std/src/sys/pal/wasm/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! This module contains the facade (aka platform-specific) implementations of
44
//! OS level functionality for wasm. Note that this wasm is *not* the emscripten
5-
//! wasm, so we have no runtime here.
5+
//! or wasi wasm, so we have no runtime here.
66
//!
77
//! This is all super highly experimental and not actually intended for
88
//! wide/production use yet, it's still all in the experimental category. This

Diff for: library/std/tests/pipe_subprocess.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(anonymous_pipe)]
22

33
fn main() {
4-
#[cfg(all(not(miri), any(unix, windows)))]
4+
#[cfg(all(not(miri), any(unix, windows), not(target_os = "emscripten")))]
55
{
66
use std::io::{Read, pipe};
77
use std::{env, process};

0 commit comments

Comments
 (0)