1
- use super :: skip_pooling_allocator_tests;
1
+ use super :: { skip_pooling_allocator_tests, ErrorExt } ;
2
2
use wasmtime:: * ;
3
3
4
4
#[ test]
@@ -35,18 +35,17 @@ fn memory_limit() -> Result<()> {
35
35
// Module should fail to instantiate because it has too many memories
36
36
match Module :: new ( & engine, r#"(module (memory 1) (memory 1))"# ) {
37
37
Ok ( _) => panic ! ( "module instantiation should fail" ) ,
38
- Err ( e) => assert_eq ! (
39
- e. to_string( ) ,
40
- "defined memories count of 2 exceeds the per-instance limit of 1" ,
41
- ) ,
38
+ Err ( e) => {
39
+ e. assert_contains ( "defined memories count of 2 exceeds the per-instance limit of 1" )
40
+ }
42
41
}
43
42
44
43
// Module should fail to instantiate because the minimum is greater than
45
44
// the configured limit
46
45
match Module :: new ( & engine, r#"(module (memory 4))"# ) {
47
46
Ok ( _) => panic ! ( "module instantiation should fail" ) ,
48
- Err ( e) => assert_eq ! (
49
- e. to_string ( ) ,
47
+ Err ( e) =>
48
+ e. assert_contains (
50
49
"memory index 0 has a minimum byte size of 262144 which exceeds the limit of 0x30000 bytes" ,
51
50
) ,
52
51
}
@@ -244,18 +243,16 @@ fn table_limit() -> Result<()> {
244
243
// Module should fail to instantiate because it has too many tables
245
244
match Module :: new ( & engine, r#"(module (table 1 funcref) (table 1 funcref))"# ) {
246
245
Ok ( _) => panic ! ( "module compilation should fail" ) ,
247
- Err ( e) => assert_eq ! (
248
- e. to_string( ) ,
249
- "defined tables count of 2 exceeds the per-instance limit of 1" ,
250
- ) ,
246
+ Err ( e) => {
247
+ e. assert_contains ( "defined tables count of 2 exceeds the per-instance limit of 1" )
248
+ }
251
249
}
252
250
253
251
// Module should fail to instantiate because the minimum is greater than
254
252
// the configured limit
255
253
match Module :: new ( & engine, r#"(module (table 31 funcref))"# ) {
256
254
Ok ( _) => panic ! ( "module compilation should fail" ) ,
257
- Err ( e) => assert_eq ! (
258
- e. to_string( ) ,
255
+ Err ( e) => e. assert_contains (
259
256
"table index 0 has a minimum element size of 31 which exceeds the limit of 10" ,
260
257
) ,
261
258
}
@@ -634,26 +631,14 @@ fn instance_too_large() -> Result<()> {
634
631
config. allocation_strategy ( pool) ;
635
632
636
633
let engine = Engine :: new ( & config) ?;
637
- let expected = if cfg ! ( feature = "wmemcheck" ) {
638
- "\
639
- instance allocation for this module requires 336 bytes which exceeds the \
640
- configured maximum of 16 bytes; breakdown of allocation requirement:
641
-
642
- * 76.19% - 256 bytes - instance state management
643
- * 21.43% - 72 bytes - static vmctx data
644
- "
645
- } else {
646
- "\
647
- instance allocation for this module requires 240 bytes which exceeds the \
648
- configured maximum of 16 bytes; breakdown of allocation requirement:
649
-
650
- * 66.67% - 160 bytes - instance state management
651
- * 30.00% - 72 bytes - static vmctx data
652
- "
653
- } ;
654
634
match Module :: new ( & engine, "(module)" ) {
655
635
Ok ( _) => panic ! ( "should have failed to compile" ) ,
656
- Err ( e) => assert_eq ! ( e. to_string( ) , expected) ,
636
+ Err ( e) => {
637
+ e. assert_contains ( "exceeds the configured maximum of 16 bytes" ) ;
638
+ e. assert_contains ( "breakdown of allocation requirement" ) ;
639
+ e. assert_contains ( "instance state management" ) ;
640
+ e. assert_contains ( "static vmctx data" ) ;
641
+ }
657
642
}
658
643
659
644
let mut lots_of_globals = format ! ( "(module" ) ;
@@ -662,26 +647,14 @@ configured maximum of 16 bytes; breakdown of allocation requirement:
662
647
}
663
648
lots_of_globals. push_str ( ")" ) ;
664
649
665
- let expected = if cfg ! ( feature = "wmemcheck" ) {
666
- "\
667
- instance allocation for this module requires 1936 bytes which exceeds the \
668
- configured maximum of 16 bytes; breakdown of allocation requirement:
669
-
670
- * 13.22% - 256 bytes - instance state management
671
- * 82.64% - 1600 bytes - defined globals
672
- "
673
- } else {
674
- "\
675
- instance allocation for this module requires 1840 bytes which exceeds the \
676
- configured maximum of 16 bytes; breakdown of allocation requirement:
677
-
678
- * 8.70% - 160 bytes - instance state management
679
- * 86.96% - 1600 bytes - defined globals
680
- "
681
- } ;
682
650
match Module :: new ( & engine, & lots_of_globals) {
683
651
Ok ( _) => panic ! ( "should have failed to compile" ) ,
684
- Err ( e) => assert_eq ! ( e. to_string( ) , expected) ,
652
+ Err ( e) => {
653
+ e. assert_contains ( "exceeds the configured maximum of 16 bytes" ) ;
654
+ e. assert_contains ( "breakdown of allocation requirement" ) ;
655
+ e. assert_contains ( "defined globals" ) ;
656
+ e. assert_contains ( "instance state management" ) ;
657
+ }
685
658
}
686
659
687
660
Ok ( ( ) )
@@ -879,10 +852,9 @@ fn component_instance_size_limit() -> Result<()> {
879
852
880
853
match wasmtime:: component:: Component :: new ( & engine, "(component)" ) {
881
854
Ok ( _) => panic ! ( "should have hit limit" ) ,
882
- Err ( e) => assert_eq ! (
883
- e. to_string( ) ,
884
- "instance allocation for this component requires 48 bytes of `VMComponentContext` space \
885
- which exceeds the configured maximum of 1 bytes"
855
+ Err ( e) => e. assert_contains (
856
+ "instance allocation for this component requires 48 bytes of \
857
+ `VMComponentContext` space which exceeds the configured maximum of 1 bytes",
886
858
) ,
887
859
}
888
860
@@ -1047,10 +1019,9 @@ fn component_core_instances_limit() -> Result<()> {
1047
1019
"# ,
1048
1020
) {
1049
1021
Ok ( _) => panic ! ( "should have hit limit" ) ,
1050
- Err ( e) => assert_eq ! (
1051
- e. to_string( ) ,
1022
+ Err ( e) => e. assert_contains (
1052
1023
"The component transitively contains 2 core module instances, which exceeds the \
1053
- configured maximum of 1"
1024
+ configured maximum of 1",
1054
1025
) ,
1055
1026
}
1056
1027
@@ -1090,10 +1061,9 @@ fn component_memories_limit() -> Result<()> {
1090
1061
"# ,
1091
1062
) {
1092
1063
Ok ( _) => panic ! ( "should have hit limit" ) ,
1093
- Err ( e) => assert_eq ! (
1094
- e. to_string( ) ,
1064
+ Err ( e) => e. assert_contains (
1095
1065
"The component transitively contains 2 Wasm linear memories, which exceeds the \
1096
- configured maximum of 1"
1066
+ configured maximum of 1",
1097
1067
) ,
1098
1068
}
1099
1069
@@ -1133,10 +1103,9 @@ fn component_tables_limit() -> Result<()> {
1133
1103
"# ,
1134
1104
) {
1135
1105
Ok ( _) => panic ! ( "should have hit limit" ) ,
1136
- Err ( e) => assert_eq ! (
1137
- e. to_string( ) ,
1106
+ Err ( e) => e. assert_contains (
1138
1107
"The component transitively contains 2 tables, which exceeds the \
1139
- configured maximum of 1"
1108
+ configured maximum of 1",
1140
1109
) ,
1141
1110
}
1142
1111
@@ -1281,13 +1250,9 @@ fn shared_memory_unsupported() -> Result<()> {
1281
1250
"# ,
1282
1251
)
1283
1252
. unwrap_err ( ) ;
1284
- let err = err. to_string ( ) ;
1285
- assert ! (
1286
- err. contains(
1287
- "memory index 0 is shared which is not supported \
1288
- in the pooling allocator"
1289
- ) ,
1290
- "bad error: {err}"
1253
+ err. assert_contains (
1254
+ "memory index 0 is shared which is not supported \
1255
+ in the pooling allocator",
1291
1256
) ;
1292
1257
Ok ( ( ) )
1293
1258
}
0 commit comments