@@ -2,181 +2,102 @@ use ckb_vm::machine::VERSION3;
22use ckb_vm:: { DefaultMachineRunner , Error , ISA_B , ISA_CFI , ISA_IMC , ISA_MOP } ;
33pub mod machine_build;
44
5- fn run_int ( path : & str ) -> Result < i8 , Error > {
5+ fn run ( path : & str ) -> Result < i8 , Error > {
66 let mut machine =
77 machine_build:: int ( path, vec ! [ ] , VERSION3 , ISA_IMC | ISA_B | ISA_MOP | ISA_CFI ) ;
8- machine. run ( )
9- }
8+ let ret = machine. run ( ) ;
109
11- #[ cfg( has_asm) ]
12- fn run_asm ( path : & str ) -> Result < i8 , Error > {
13- let mut machine =
14- machine_build:: asm ( path, vec ! [ ] , VERSION3 , ISA_IMC | ISA_B | ISA_MOP | ISA_CFI ) ;
15- machine. run ( )
10+ #[ cfg( has_asm) ]
11+ {
12+ let mut machine_asm =
13+ machine_build:: asm ( path, vec ! [ ] , VERSION3 , ISA_IMC | ISA_B | ISA_MOP | ISA_CFI ) ;
14+ let ret_asm = machine_asm. run ( ) ;
15+ assert_eq ! ( ret, ret_asm, "Interpreter and ASM results should match" ) ;
16+ }
17+
18+ ret
1619}
1720
1821#[ test]
1922pub fn test_simple_instructions_64 ( ) {
20- let ret = run_int ( "tests/programs/simple64" ) ;
23+ let ret = run ( "tests/programs/simple64" ) ;
2124 assert ! ( ret. is_ok( ) ) ;
22-
23- #[ cfg( has_asm) ]
24- {
25- let ret_asm = run_asm ( "tests/programs/simple64" ) ;
26- assert ! ( ret_asm. is_ok( ) ) ;
27- }
2825}
2926
3027#[ test]
3128pub fn test_cfi_ss_success ( ) {
32- let ret = run_int ( "tests/programs/cfi_ss_success" ) ;
33- assert ! ( ret. is_ok( ) ) ;
34- assert_eq ! ( ret. unwrap( ) , 0 ) ;
35-
36- #[ cfg( has_asm) ]
37- {
38- let ret_asm = run_asm ( "tests/programs/cfi_ss_success" ) ;
39- assert ! ( ret_asm. is_ok( ) ) ;
40- assert_eq ! ( ret_asm. unwrap( ) , 0 ) ;
41- }
29+ let ret = run ( "tests/programs/cfi_ss_success" ) ;
30+ assert_eq ! ( ret, Ok ( 0 ) ) ;
4231}
4332
4433#[ test]
4534pub fn test_cfi_ss_not_active ( ) {
46- let ret = run_int ( "tests/programs/cfi_ss_not_active" ) ;
47- assert ! ( ret. is_ok( ) ) ;
48- assert_eq ! ( ret. unwrap( ) , 0 ) ;
49-
50- #[ cfg( has_asm) ]
51- {
52- let ret_asm = run_asm ( "tests/programs/cfi_ss_not_active" ) ;
53- assert ! ( ret_asm. is_ok( ) ) ;
54- assert_eq ! ( ret_asm. unwrap( ) , 0 ) ;
55- }
35+ let ret = run ( "tests/programs/cfi_ss_not_active" ) ;
36+ assert_eq ! ( ret, Ok ( 0 ) ) ;
5637}
5738
5839#[ test]
5940pub fn test_cfi_ss_stack_downto_zero ( ) {
60- let ret = run_int ( "tests/programs/cfi_ss_stack_downto_zero" ) ;
41+ let ret = run ( "tests/programs/cfi_ss_stack_downto_zero" ) ;
6142 assert ! ( ret. is_err( ) ) ;
62-
63- #[ cfg( has_asm) ]
64- {
65- let ret_asm = run_asm ( "tests/programs/cfi_ss_stack_downto_zero" ) ;
66- assert ! ( ret_asm. is_err( ) ) ;
67- }
43+ assert ! ( matches!( ret, Err ( Error :: ShadowStackOutOfStack ) ) ) ;
6844}
6945
7046#[ test]
7147pub fn test_cfi_ss_stack_full ( ) {
72- let ret = run_int ( "tests/programs/cfi_ss_stack_full" ) ;
73- assert ! ( ret. is_ok( ) ) ;
74- assert_eq ! ( ret. unwrap( ) , 0 ) ;
75-
76- #[ cfg( has_asm) ]
77- {
78- let ret_asm = run_asm ( "tests/programs/cfi_ss_stack_full" ) ;
79- assert ! ( ret_asm. is_ok( ) ) ;
80- assert_eq ! ( ret_asm. unwrap( ) , 0 ) ;
81- }
48+ let ret = run ( "tests/programs/cfi_ss_stack_full" ) ;
49+ assert_eq ! ( ret, Ok ( 0 ) ) ;
8250}
8351
8452#[ test]
8553pub fn test_cfi_lpad_unlabeled ( ) {
86- let ret = run_int ( "tests/programs/cfi_lpad_unlabeled" ) ;
87- assert ! ( ret. is_ok( ) ) ;
88- assert_eq ! ( ret. unwrap( ) , 0 ) ;
89-
90- #[ cfg( has_asm) ]
91- {
92- let ret_asm = run_asm ( "tests/programs/cfi_lpad_unlabeled" ) ;
93- assert ! ( ret_asm. is_ok( ) ) ;
94- assert_eq ! ( ret_asm. unwrap( ) , 0 ) ;
95- }
54+ let ret = run ( "tests/programs/cfi_lpad_unlabeled" ) ;
55+ assert_eq ! ( ret, Ok ( 0 ) ) ;
9656}
9757
9858#[ test]
9959pub fn test_cfi_lpad_not_active ( ) {
100- let ret = run_int ( "tests/programs/cfi_lpad_not_active" ) ;
101- assert ! ( ret. is_ok( ) ) ;
102- assert_eq ! ( ret. unwrap( ) , 0 ) ;
103-
104- #[ cfg( has_asm) ]
105- {
106- let ret_asm = run_asm ( "tests/programs/cfi_lpad_not_active" ) ;
107- assert ! ( ret_asm. is_ok( ) ) ;
108- assert_eq ! ( ret_asm. unwrap( ) , 0 ) ;
109- }
60+ let ret = run ( "tests/programs/cfi_lpad_not_active" ) ;
61+ assert_eq ! ( ret, Ok ( 0 ) ) ;
11062}
11163
11264#[ test]
11365pub fn test_cfi_lpad_unlabeled_failed ( ) {
114- let ret = run_int ( "tests/programs/cfi_lpad_unlabeled_failed" ) ;
66+ let ret = run ( "tests/programs/cfi_lpad_unlabeled_failed" ) ;
11567 assert ! ( ret. is_err( ) ) ;
116-
117- #[ cfg( has_asm) ]
118- {
119- let ret_asm = run_asm ( "tests/programs/cfi_lpad_unlabeled_failed" ) ;
120- assert ! ( ret_asm. is_err( ) ) ;
121- }
68+ assert ! ( matches!( ret, Err ( Error :: ShadowStackNotLpad ) ) ) ;
12269}
12370
12471#[ test]
12572pub fn test_cfi_lpad_func_sig ( ) {
126- let ret = run_int ( "tests/programs/cfi_lpad_func_sig" ) ;
73+ let ret = run ( "tests/programs/cfi_lpad_func_sig" ) ;
12774 assert ! ( ret. is_ok( ) ) ;
128-
129- #[ cfg( has_asm) ]
130- {
131- let ret_asm = run_asm ( "tests/programs/cfi_lpad_func_sig" ) ;
132- assert ! ( ret_asm. is_ok( ) ) ;
133- }
13475}
13576
13677#[ test]
13778pub fn test_cfi_lpad_func_sig_zero ( ) {
138- let ret = run_int ( "tests/programs/cfi_lpad_func_sig_zero" ) ;
79+ let ret = run ( "tests/programs/cfi_lpad_func_sig_zero" ) ;
13980 assert ! ( ret. is_ok( ) ) ;
140-
141- #[ cfg( has_asm) ]
142- {
143- let ret_asm = run_asm ( "tests/programs/cfi_lpad_func_sig_zero" ) ;
144- assert ! ( ret_asm. is_ok( ) ) ;
145- }
14681}
14782
14883#[ test]
14984pub fn test_cfi_lpad_func_sig_failed ( ) {
150- let ret = run_int ( "tests/programs/cfi_lpad_func_sig_failed" ) ;
85+ let ret = run ( "tests/programs/cfi_lpad_func_sig_failed" ) ;
15186 assert ! ( ret. is_err( ) ) ;
152-
153- #[ cfg( has_asm) ]
154- {
155- let ret_asm = run_asm ( "tests/programs/cfi_lpad_func_sig_failed" ) ;
156- assert ! ( ret_asm. is_err( ) ) ;
157- }
87+ assert ! ( matches!( ret, Err ( Error :: ShadowStackLabelWrong ) ) ) ;
15888}
15989
16090#[ test]
16191pub fn test_cfi_ss_only_pop ( ) {
162- let ret = run_int ( "tests/programs/cfi_ss_only_pop" ) ;
92+ let ret = run ( "tests/programs/cfi_ss_only_pop" ) ;
93+ print ! ( "err {:?}" , ret) ;
16394 assert ! ( ret. is_err( ) ) ;
164-
165- #[ cfg( has_asm) ]
166- {
167- let ret_asm = run_asm ( "tests/programs/cfi_ss_only_pop" ) ;
168- assert ! ( ret_asm. is_err( ) ) ;
169- }
95+ assert ! ( matches!( ret, Err ( Error :: ShadowStackOutOfStack ) ) ) ;
17096}
17197
17298#[ test]
17399pub fn test_cfi_ss_popchk_failed ( ) {
174- let ret = run_int ( "tests/programs/cfi_ss_popchk_failed" ) ;
100+ let ret = run ( "tests/programs/cfi_ss_popchk_failed" ) ;
175101 assert ! ( ret. is_err( ) ) ;
176-
177- #[ cfg( has_asm) ]
178- {
179- let ret_asm = run_asm ( "tests/programs/cfi_ss_popchk_failed" ) ;
180- assert ! ( ret_asm. is_err( ) ) ;
181- }
102+ assert ! ( matches!( ret, Err ( Error :: ShadowStackValueWrong ) ) ) ;
182103}
0 commit comments