Skip to content

Commit b6d7865

Browse files
authored
Merge branch 'main' into canonical_path
2 parents 00bccb8 + 52edf4b commit b6d7865

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+822
-10
lines changed

ci/spectest-zkasm.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ set -eux
55

66
./ci/test-zkasm.sh "cranelift/zkasm_data/spectest/i32"
77
./ci/test-zkasm.sh "cranelift/zkasm_data/spectest/i64"
8+
./ci/test-zkasm.sh "cranelift/zkasm_data/spectest/conversions"

cranelift/filetests/src/test_zkasm.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ mod tests {
193193

194194
// This function asserts that none of tests generated from
195195
// spectest has been changed.
196-
fn check_spectests(bitness: i32) -> Result<(), Error> {
197-
let spectests_path = &format!("../../tests/spec_testsuite/i{bitness}.wast");
196+
fn check_spectests(name: &str) -> Result<(), Error> {
197+
let spectests_path = &format!("../../tests/spec_testsuite/{name}.wast");
198198
let file_content = read_to_string(spectests_path)?;
199199
let re = Regex::new(
200-
r#"\(assert_return \(invoke \"(\w+)\"\s*((?:\([^\)]+\)\s*)+)\)\s*\(([^\)]+)\)\)"#,
200+
r#"\(assert_return \(invoke \"([.\w]+)\"\s*((?:\([^\)]+\)\s*)+)\)\s*\(([^\)]+)\)\)"#,
201201
)
202202
.unwrap();
203203
let mut test_counters = HashMap::new();
@@ -206,6 +206,19 @@ mod tests {
206206
let arguments = &cap[2];
207207
let expected_result = &cap[3];
208208
let assert_type = &expected_result[0..3];
209+
// It seems like wast have different nan type comparing to our wat parser,
210+
// I faced wat parser error parsing generated tests with nan.
211+
// So, just skip fp tests for now.
212+
let mut is_float = false;
213+
for i in 0..4 {
214+
if cap[i].contains("f32.") || cap[i].contains("f64") {
215+
is_float = true;
216+
continue;
217+
}
218+
}
219+
if is_float {
220+
continue;
221+
}
209222
let count = test_counters.entry(function_name.to_string()).or_insert(0);
210223
*count += 1;
211224
let mut testcase = String::new();
@@ -217,13 +230,23 @@ mod tests {
217230
.replace("(", "")
218231
.replace(")", "")
219232
));
220-
testcase.push_str(&format!("\ti{bitness}.{}\n", function_name));
233+
let function_type = if arguments.contains("i64") {
234+
"i64"
235+
} else {
236+
"i32"
237+
};
238+
let func_types = ["i32.", "i64."];
239+
if func_types.iter().any(|&pat| function_name.contains(pat)) {
240+
testcase.push_str(&format!("\t{}\n", function_name));
241+
} else {
242+
testcase.push_str(&format!("\t{function_type}.{}\n", function_name));
243+
}
221244
testcase.push_str(&format!(
222245
"\t{}\n\tcall $assert_eq)\n (start $main))\n",
223246
expected_result.trim()
224247
));
225248
let file_name = format!(
226-
"../../zkasm_data/spectest/i{bitness}/{}_{}.wat",
249+
"../../zkasm_data/spectest/{name}/{}_{}.wat",
227250
function_name, count
228251
);
229252
let expected_test = expect_test::expect_file![file_name];
@@ -264,15 +287,16 @@ mod tests {
264287
println!("Failed {failures} tests out of {count}");
265288
}
266289

267-
fn run_spectests_with_bitness(bitness: i32) {
268-
check_spectests(bitness).unwrap();
269-
test_wat_in_directory(Path::new(&format!("../zkasm_data/spectest/i{bitness}/")));
290+
fn run_spectest(name: &str) {
291+
check_spectests(name).unwrap();
292+
test_wat_in_directory(Path::new(&format!("../zkasm_data/spectest/{name}/")));
270293
}
271294

272295
#[test]
273296
fn run_spectests() {
274-
run_spectests_with_bitness(32);
275-
run_spectests_with_bitness(64);
297+
run_spectest("i32");
298+
run_spectest("i64");
299+
run_spectest("conversions");
276300
}
277301

278302
macro_rules! testcases {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
two_power:
2+
0x1n => B :JMP(RR) ;2**0
3+
0x2n => B :JMP(RR) ;2**1
4+
0x4n => B :JMP(RR) ;2**2
5+
0x8n => B :JMP(RR) ;2**3
6+
0x10n => B :JMP(RR) ;2**4
7+
0x20n => B :JMP(RR) ;2**5
8+
0x40n => B :JMP(RR) ;2**6
9+
0x80n => B :JMP(RR) ;2**7
10+
0x100n => B :JMP(RR) ;2**8
11+
0x200n => B :JMP(RR) ;2**9
12+
0x400n => B :JMP(RR) ;2**10
13+
0x800n => B :JMP(RR) ;2**11
14+
0x1000n => B :JMP(RR) ;2**12
15+
0x2000n => B :JMP(RR) ;2**13
16+
0x4000n => B :JMP(RR) ;2**14
17+
0x8000n => B :JMP(RR) ;2**15
18+
0x10000n => B :JMP(RR) ;2**16
19+
0x20000n => B :JMP(RR) ;2**17
20+
0x40000n => B :JMP(RR) ;2**18
21+
0x80000n => B :JMP(RR) ;2**19
22+
0x100000n => B :JMP(RR) ;2**20
23+
0x200000n => B :JMP(RR) ;2**21
24+
0x400000n => B :JMP(RR) ;2**22
25+
0x800000n => B :JMP(RR) ;2**23
26+
0x1000000n => B :JMP(RR) ;2**24
27+
0x2000000n => B :JMP(RR) ;2**25
28+
0x4000000n => B :JMP(RR) ;2**26
29+
0x8000000n => B :JMP(RR) ;2**27
30+
0x10000000n => B :JMP(RR) ;2**28
31+
0x20000000n => B :JMP(RR) ;2**29
32+
0x40000000n => B :JMP(RR) ;2**30
33+
0x80000000n => B :JMP(RR) ;2**31
34+
0x100000000n => B :JMP(RR) ;2**32
35+
0x200000000n => B :JMP(RR) ;2**33
36+
0x400000000n => B :JMP(RR) ;2**34
37+
0x800000000n => B :JMP(RR) ;2**35
38+
0x1000000000n => B :JMP(RR) ;2**36
39+
0x2000000000n => B :JMP(RR) ;2**37
40+
0x4000000000n => B :JMP(RR) ;2**38
41+
0x8000000000n => B :JMP(RR) ;2**39
42+
0x10000000000n => B :JMP(RR) ;2**40
43+
0x20000000000n => B :JMP(RR) ;2**41
44+
0x40000000000n => B :JMP(RR) ;2**42
45+
0x80000000000n => B :JMP(RR) ;2**43
46+
0x100000000000n => B :JMP(RR) ;2**44
47+
0x200000000000n => B :JMP(RR) ;2**45
48+
0x400000000000n => B :JMP(RR) ;2**46
49+
0x800000000000n => B :JMP(RR) ;2**47
50+
0x1000000000000n => B :JMP(RR) ;2**48
51+
0x2000000000000n => B :JMP(RR) ;2**49
52+
0x4000000000000n => B :JMP(RR) ;2**50
53+
0x8000000000000n => B :JMP(RR) ;2**51
54+
0x10000000000000n => B :JMP(RR) ;2**52
55+
0x20000000000000n => B :JMP(RR) ;2**53
56+
0x40000000000000n => B :JMP(RR) ;2**54
57+
0x80000000000000n => B :JMP(RR) ;2**55
58+
0x100000000000000n => B :JMP(RR) ;2**56
59+
0x200000000000000n => B :JMP(RR) ;2**57
60+
0x400000000000000n => B :JMP(RR) ;2**58
61+
0x800000000000000n => B :JMP(RR) ;2**59
62+
0x1000000000000000n => B :JMP(RR) ;2**60
63+
0x2000000000000000n => B :JMP(RR) ;2**61
64+
0x4000000000000000n => B :JMP(RR) ;2**62
65+
0x8000000000000000n => B :JMP(RR) ;2**63
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
start:
2+
zkPC + 2 => RR
3+
:JMP(function_1)
4+
:JMP(finalizeExecution)
5+
function_1:
6+
SP + 1 => SP
7+
RR :MSTORE(SP - 1)
8+
SP + 2 => SP
9+
B :MSTORE(SP - 1)
10+
18446744073709551615n => A
11+
18446744069414584320n => B
12+
B :ASSERT
13+
$ => B :MLOAD(SP - 1)
14+
SP - 2 => SP
15+
$ => RR :MLOAD(SP - 1)
16+
SP - 1 => SP
17+
:JMP(RR)
18+
finalizeExecution:
19+
${beforeLast()} :JMPN(finalizeExecution)
20+
:JMP(start)
21+
INCLUDE "helpers/2-exp.zkasm"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
start:
2+
zkPC + 2 => RR
3+
:JMP(function_1)
4+
:JMP(finalizeExecution)
5+
function_1:
6+
SP + 1 => SP
7+
RR :MSTORE(SP - 1)
8+
SP + 2 => SP
9+
B :MSTORE(SP - 1)
10+
4294967295n => A
11+
18446744069414584320n => B
12+
B :ASSERT
13+
$ => B :MLOAD(SP - 1)
14+
SP - 2 => SP
15+
$ => RR :MLOAD(SP - 1)
16+
SP - 1 => SP
17+
:JMP(RR)
18+
finalizeExecution:
19+
${beforeLast()} :JMPN(finalizeExecution)
20+
:JMP(start)
21+
INCLUDE "helpers/2-exp.zkasm"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
start:
2+
zkPC + 2 => RR
3+
:JMP(function_1)
4+
:JMP(finalizeExecution)
5+
function_1:
6+
SP + 1 => SP
7+
RR :MSTORE(SP - 1)
8+
SP + 2 => SP
9+
B :MSTORE(SP - 1)
10+
4294967296n => A
11+
0n => B
12+
B :ASSERT
13+
$ => B :MLOAD(SP - 1)
14+
SP - 2 => SP
15+
$ => RR :MLOAD(SP - 1)
16+
SP - 1 => SP
17+
:JMP(RR)
18+
finalizeExecution:
19+
${beforeLast()} :JMPN(finalizeExecution)
20+
:JMP(start)
21+
INCLUDE "helpers/2-exp.zkasm"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
start:
2+
zkPC + 2 => RR
3+
:JMP(function_1)
4+
:JMP(finalizeExecution)
5+
function_1:
6+
SP + 1 => SP
7+
RR :MSTORE(SP - 1)
8+
SP + 2 => SP
9+
B :MSTORE(SP - 1)
10+
4294967297n => A
11+
4294967296n => B
12+
B :ASSERT
13+
$ => B :MLOAD(SP - 1)
14+
SP - 2 => SP
15+
$ => RR :MLOAD(SP - 1)
16+
SP - 1 => SP
17+
:JMP(RR)
18+
finalizeExecution:
19+
${beforeLast()} :JMPN(finalizeExecution)
20+
:JMP(start)
21+
INCLUDE "helpers/2-exp.zkasm"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
start:
2+
zkPC + 2 => RR
3+
:JMP(function_1)
4+
:JMP(finalizeExecution)
5+
function_1:
6+
SP + 1 => SP
7+
RR :MSTORE(SP - 1)
8+
SP + 2 => SP
9+
B :MSTORE(SP - 1)
10+
18446744073709451616n => A
11+
18446314576979951616n => B
12+
B :ASSERT
13+
$ => B :MLOAD(SP - 1)
14+
SP - 2 => SP
15+
$ => RR :MLOAD(SP - 1)
16+
SP - 1 => SP
17+
:JMP(RR)
18+
finalizeExecution:
19+
${beforeLast()} :JMPN(finalizeExecution)
20+
:JMP(start)
21+
INCLUDE "helpers/2-exp.zkasm"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
start:
2+
zkPC + 2 => RR
3+
:JMP(function_1)
4+
:JMP(finalizeExecution)
5+
function_1:
6+
SP + 1 => SP
7+
RR :MSTORE(SP - 1)
8+
SP + 2 => SP
9+
B :MSTORE(SP - 1)
10+
2147483648n => A
11+
9223372036854775808n => B
12+
B :ASSERT
13+
$ => B :MLOAD(SP - 1)
14+
SP - 2 => SP
15+
$ => RR :MLOAD(SP - 1)
16+
SP - 1 => SP
17+
:JMP(RR)
18+
finalizeExecution:
19+
${beforeLast()} :JMPN(finalizeExecution)
20+
:JMP(start)
21+
INCLUDE "helpers/2-exp.zkasm"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
start:
2+
zkPC + 2 => RR
3+
:JMP(function_1)
4+
:JMP(finalizeExecution)
5+
function_1:
6+
SP + 1 => SP
7+
RR :MSTORE(SP - 1)
8+
SP + 2 => SP
9+
B :MSTORE(SP - 1)
10+
18446744071562067967n => A
11+
9223372032559808512n => B
12+
B :ASSERT
13+
$ => B :MLOAD(SP - 1)
14+
SP - 2 => SP
15+
$ => RR :MLOAD(SP - 1)
16+
SP - 1 => SP
17+
:JMP(RR)
18+
finalizeExecution:
19+
${beforeLast()} :JMPN(finalizeExecution)
20+
:JMP(start)
21+
INCLUDE "helpers/2-exp.zkasm"

0 commit comments

Comments
 (0)