Skip to content

Commit b98726e

Browse files
authored
test: use the correct wasm profile (#2061)
And update the integer overflow tests to match. It also gives us better test coverage of panics/traps. And update the oom test to make sure we don't optimize away the allocations.
1 parent a0f85fa commit b98726e

File tree

4 files changed

+163
-103
lines changed

4 files changed

+163
-103
lines changed

Cargo.toml

+5-12
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,13 @@ fvm_integration_tests = { path = "testing/integration", version = "~4.4.1" }
8787
fvm_gas_calibration_shared = { path = "testing/calibration/shared" }
8888
fvm_test_actors = { path = "testing/test_actors" }
8989

90-
[profile.actor]
91-
inherits = "release"
92-
panic = "abort"
93-
overflow-checks = true
94-
lto = true
95-
opt-level = "z"
96-
#strip = true
97-
90+
# Same as in the built-in actors repo
9891
[profile.wasm]
9992
inherits = "release"
100-
panic = "abort"
101-
overflow-checks = false
102-
lto = true
103-
opt-level = "z"
93+
panic = "unwind"
94+
overflow-checks = true
95+
lto = "thin"
96+
opt-level = 3
10497
strip = true
10598
codegen-units = 1
10699
incremental = false

testing/integration/tests/fil_integer_overflow.rs

+144-88
Original file line numberDiff line numberDiff line change
@@ -60,94 +60,150 @@ fn integer_overflow() {
6060
// Instantiate machine
6161
tester.instantiate_machine(DummyExterns).unwrap();
6262

63-
// Params setup
63+
// X is the target value.
6464
let x: i64 = 10000000000;
65-
let params = RawBytes::serialize(x).unwrap();
66-
67-
// Send message to set
68-
let message = Message {
69-
from: sender.1,
70-
to: actor_address,
71-
gas_limit: 1000000000,
72-
method_num: 1,
73-
params,
74-
..Message::default()
75-
};
76-
77-
// Set inner state value
78-
let res = tester
79-
.executor
80-
.as_mut()
81-
.unwrap()
82-
.execute_message(message, ApplyKind::Explicit, 100)
83-
.unwrap();
84-
85-
assert_eq!(
86-
ExitCode::OK,
87-
res.msg_receipt.exit_code,
88-
"{}",
89-
res.failure_info.unwrap()
90-
);
91-
92-
// Read inner state value
93-
let message = Message {
94-
from: sender.1,
95-
to: actor_address,
96-
gas_limit: 1000000000,
97-
method_num: 3,
98-
sequence: 1,
99-
..Message::default()
100-
};
101-
102-
let res = tester
103-
.executor
104-
.as_mut()
105-
.unwrap()
106-
.execute_message(message, ApplyKind::Explicit, 100)
107-
.unwrap();
108-
109-
let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();
110-
111-
assert_eq!(current_state_value, x);
112-
113-
// Overflow inner state integer
114-
let message = Message {
115-
from: sender.1,
116-
to: actor_address,
117-
gas_limit: 1000000000,
118-
method_num: 2,
119-
sequence: 2,
120-
..Message::default()
121-
};
122-
123-
// Set inner state value
124-
tester
125-
.executor
126-
.as_mut()
127-
.unwrap()
128-
.execute_message(message, ApplyKind::Explicit, 100)
129-
.unwrap();
130-
131-
// Read inner state value
132-
let message = Message {
133-
from: sender.1,
134-
to: actor_address,
135-
gas_limit: 1000000000,
136-
method_num: 3,
137-
sequence: 3,
138-
..Message::default()
139-
};
140-
141-
let res = tester
142-
.executor
143-
.unwrap()
144-
.execute_message(message, ApplyKind::Explicit, 100)
145-
.unwrap();
146-
147-
let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();
148-
149-
// Check overflow
150-
let overflow_value: i64 = -5340232216128654848;
15165

152-
assert_eq!(current_state_value, overflow_value);
66+
{
67+
// Params setup
68+
let params = RawBytes::serialize(x).unwrap();
69+
70+
// Send message to set
71+
let message = Message {
72+
from: sender.1,
73+
to: actor_address,
74+
gas_limit: 1000000000,
75+
method_num: 1,
76+
params,
77+
..Message::default()
78+
};
79+
80+
// Set inner state value
81+
let res = tester
82+
.executor
83+
.as_mut()
84+
.unwrap()
85+
.execute_message(message, ApplyKind::Explicit, 100)
86+
.unwrap();
87+
88+
assert_eq!(
89+
ExitCode::OK,
90+
res.msg_receipt.exit_code,
91+
"{}",
92+
res.failure_info.unwrap()
93+
);
94+
95+
// Read inner state value
96+
let message = Message {
97+
from: sender.1,
98+
to: actor_address,
99+
gas_limit: 1000000000,
100+
method_num: 3,
101+
sequence: 1,
102+
..Message::default()
103+
};
104+
105+
let res = tester
106+
.executor
107+
.as_mut()
108+
.unwrap()
109+
.execute_message(message, ApplyKind::Explicit, 100)
110+
.unwrap();
111+
assert!(res.msg_receipt.exit_code.is_success());
112+
113+
let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();
114+
115+
assert_eq!(current_state_value, x);
116+
}
117+
118+
{
119+
// Overflow inner state integer with checked overflows.
120+
let message = Message {
121+
from: sender.1,
122+
to: actor_address,
123+
gas_limit: 1000000000,
124+
method_num: 4,
125+
sequence: 2,
126+
..Message::default()
127+
};
128+
129+
let res = tester
130+
.executor
131+
.as_mut()
132+
.unwrap()
133+
.execute_message(message, ApplyKind::Explicit, 100)
134+
.unwrap();
135+
assert_eq!(ExitCode::SYS_ILLEGAL_INSTRUCTION, res.msg_receipt.exit_code);
136+
137+
// Read inner state value
138+
let message = Message {
139+
from: sender.1,
140+
to: actor_address,
141+
gas_limit: 1000000000,
142+
method_num: 3,
143+
sequence: 3,
144+
..Message::default()
145+
};
146+
147+
let res = tester
148+
.executor
149+
.as_mut()
150+
.unwrap()
151+
.execute_message(message, ApplyKind::Explicit, 100)
152+
.unwrap();
153+
assert!(res.msg_receipt.exit_code.is_success());
154+
155+
let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();
156+
assert_eq!(current_state_value, x);
157+
}
158+
159+
{
160+
// Overflow inner state integer with wrapping.
161+
let message = Message {
162+
from: sender.1,
163+
to: actor_address,
164+
gas_limit: 1000000000,
165+
method_num: 2,
166+
sequence: 4,
167+
..Message::default()
168+
};
169+
170+
// Set inner state value
171+
let res = tester
172+
.executor
173+
.as_mut()
174+
.unwrap()
175+
.execute_message(message, ApplyKind::Explicit, 100)
176+
.unwrap();
177+
assert_eq!(
178+
ExitCode::OK,
179+
res.msg_receipt.exit_code,
180+
"{}",
181+
res.failure_info.unwrap()
182+
);
183+
184+
// Read inner state value
185+
let message = Message {
186+
from: sender.1,
187+
to: actor_address,
188+
gas_limit: 1000000000,
189+
method_num: 3,
190+
sequence: 5,
191+
..Message::default()
192+
};
193+
194+
let res = tester
195+
.executor
196+
.as_mut()
197+
.unwrap()
198+
.execute_message(message, ApplyKind::Explicit, 100)
199+
.unwrap();
200+
assert!(res.msg_receipt.exit_code.is_success());
201+
202+
let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();
203+
204+
// Check overflow
205+
let overflow_value: i64 = -5340232216128654848;
206+
207+
assert_eq!(current_state_value, overflow_value);
208+
}
153209
}

testing/test_actors/actors/fil-integer-overflow-actor/src/actor/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ pub fn invoke(params_pointer: u32) -> u32 {
8686

8787
None
8888
}
89-
// Overflow value
89+
// Overflow value, wrapping
9090
2 => {
9191
let mut state = State::load();
9292

93-
state.value = (state.value >> 1i64) * (state.value + 1);
93+
state.value = (state.value >> 1i64).wrapping_mul(state.value.wrapping_add(1));
9494
state.save();
9595

9696
None
@@ -109,6 +109,15 @@ pub fn invoke(params_pointer: u32) -> u32 {
109109
}
110110
}
111111
}
112+
// Overflow value, default
113+
4 => {
114+
let mut state = State::load();
115+
116+
state.value = (state.value >> 1i64) * (state.value + 1);
117+
state.save();
118+
119+
None
120+
}
112121
_ => abort(
113122
ExitCode::USR_UNHANDLED_MESSAGE.value(),
114123
Some("unrecognized method"),

testing/test_actors/actors/fil-oom-actor/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fn allocate_one() {
4848
let cap = mem.len();
4949
mem.resize(2 * cap, 0);
5050
}
51+
std::hint::black_box(mem);
5152
}
5253

5354
// Allocate many small chunks until OOm
@@ -59,10 +60,11 @@ fn allocate_many() {
5960
chunk.resize(1024 * 1024, 0);
6061
chunks.push(chunk);
6162
}
63+
std::hint::black_box(chunks);
6264
}
6365

6466
#[cfg(target_arch = "wasm32")]
6567
fn allocate_some() {
6668
// 64 WASM pages
67-
let _ = Vec::<u8>::with_capacity(64 * 65536);
69+
std::hint::black_box(Vec::<u8>::with_capacity(64 * 65536));
6870
}

0 commit comments

Comments
 (0)