@@ -7,10 +7,13 @@ use std::path::Path;
77use std:: sync:: Arc ;
88use tempfile:: TempDir ;
99
10- pub fn wasm_test < P : AsRef < Path > > ( wasm_file : P ) -> Result < Arc < DlModule > , Error > {
10+ pub fn wasm_test < P : AsRef < Path > > (
11+ wasm_file : P ,
12+ icount_option : bool ,
13+ ) -> Result < Arc < DlModule > , Error > {
1114 let workdir = TempDir :: new ( ) . expect ( "create working directory" ) ;
1215
13- let native_build = Lucetc :: new ( wasm_file) . with_count_instructions ( true ) ;
16+ let native_build = Lucetc :: new ( wasm_file) . with_count_instructions ( icount_option ) ;
1417
1518 let so_file = workdir. path ( ) . join ( "out.so" ) ;
1619
@@ -21,9 +24,8 @@ pub fn wasm_test<P: AsRef<Path>>(wasm_file: P) -> Result<Arc<DlModule>, Error> {
2124 Ok ( dlmodule)
2225}
2326
24- #[ test]
25- pub fn check_instruction_counts ( ) {
26- let files: Vec < DirEntry > = std:: fs:: read_dir ( "./tests/instruction_counting" )
27+ pub fn get_instruction_count_test_files ( ) -> Vec < DirEntry > {
28+ std:: fs:: read_dir ( "./tests/instruction_counting" )
2729 . expect ( "can iterate test files" )
2830 . map ( |ent| {
2931 let ent = ent. expect ( "can get test files" ) ;
@@ -33,7 +35,12 @@ pub fn check_instruction_counts() {
3335 ) ;
3436 ent
3537 } )
36- . collect ( ) ;
38+ . collect ( )
39+ }
40+
41+ #[ test]
42+ pub fn check_instruction_count_off ( ) {
43+ let files: Vec < DirEntry > = get_instruction_count_test_files ( ) ;
3744
3845 assert ! (
3946 files. len( ) > 0 ,
@@ -42,7 +49,8 @@ pub fn check_instruction_counts() {
4249
4350 files. par_iter ( ) . for_each ( |ent| {
4451 let wasm_path = ent. path ( ) ;
45- let module = wasm_test ( & wasm_path) . expect ( "can load module" ) ;
52+ let do_not_instrument = false ;
53+ let module = wasm_test ( & wasm_path, do_not_instrument) . expect ( "can load module" ) ;
4654
4755 let region = MmapRegion :: create ( 1 , & Limits :: default ( ) ) . expect ( "region can be created" ) ;
4856
@@ -53,6 +61,37 @@ pub fn check_instruction_counts() {
5361 inst. run ( "test_function" , & [ ] ) . expect ( "instance runs" ) ;
5462
5563 let instruction_count = inst. get_instruction_count ( ) ;
64+ if instruction_count. is_some ( ) {
65+ panic ! ( "instruction count instrumentation was not expected from instance" ) ;
66+ }
67+ } ) ;
68+ }
69+
70+ #[ test]
71+ pub fn check_instruction_count ( ) {
72+ let files: Vec < DirEntry > = get_instruction_count_test_files ( ) ;
73+
74+ assert ! (
75+ files. len( ) > 0 ,
76+ "there are no test cases in the `instruction_counting` directory"
77+ ) ;
78+
79+ files. par_iter ( ) . for_each ( |ent| {
80+ let wasm_path = ent. path ( ) ;
81+ let do_instrument = true ;
82+ let module = wasm_test ( & wasm_path, do_instrument) . expect ( "can load instrumented module" ) ;
83+
84+ let region = MmapRegion :: create ( 1 , & Limits :: default ( ) ) . expect ( "region can be created" ) ;
85+
86+ let mut inst = region
87+ . new_instance ( module)
88+ . expect ( "instance can be created" ) ;
89+
90+ inst. run ( "test_function" , & [ ] ) . expect ( "instance runs" ) ;
91+
92+ let instruction_count = inst
93+ . get_instruction_count ( )
94+ . expect ( "instruction count expected from instance" ) ;
5695
5796 assert_eq ! (
5897 instruction_count,
0 commit comments