33module Wasmtime
44 RSpec . describe Engine do
55 describe ".new" do
6- it ( "accepts a config Hash" ) { Engine . new ( consume_fuel : true ) }
7- it ( "accepts no config" ) { Engine . new }
8- it ( "accepts nil config" ) { Engine . new ( nil ) }
9- it "rejects non-hash config" do
10- expect { Engine . new ( 1 ) } . to raise_error ( TypeError )
11- end
12- it "rejects unknown options" do
13- expect { Engine . new ( nope : 1 ) } . to raise_error ( ArgumentError , "Unknown option: :nope" )
14- end
15- it "rejects multiple args" do
16- expect { Engine . new ( 1 , 2 ) } . to raise_error ( ArgumentError )
17- end
18-
19- # bool & numeric options
20- [
21- [ :debug_info , true ] ,
22- [ :wasm_backtrace_details , true ] ,
23- [ :native_unwind_info , true ] ,
24- [ :consume_fuel , true ] ,
25- [ :epoch_interruption , true ] ,
26- [ :max_wasm_stack , 400 , true ] ,
27- [ :wasm_threads , true ] ,
28- [ :wasm_multi_memory , true ] ,
29- [ :wasm_memory64 , true ] ,
30- [ :parallel_compilation , true ] ,
31- [ :wasm_reference_types , true ] ,
32- [ :async_stack_zeroing , true ]
33- ] . each do |option , valid , invalid = nil |
34- it "supports #{ option } " do
35- Engine . new ( option => valid )
36- expect { Engine . new ( option => invalid ) } . to raise_error ( TypeError , /#{ option } / ) if invalid
37- end
38- end
39-
406 profiler_options = [ :none ]
417 profiler_options . push ( :jitdump , :vtune ) if Gem ::Platform . local . os == "linux"
428
@@ -52,67 +18,6 @@ module Wasmtime
5218 . to raise_error ( ArgumentError , /invalid :#{ option } .*:nope/ )
5319 end
5420 end
55-
56- it "supports allocation_strategy config" do
57- expect ( Engine . new ( allocation_strategy : :pooling ) ) . to be_a ( Engine )
58- expect ( Engine . new ( allocation_strategy : :on_demand ) ) . to be_a ( Engine )
59- expect ( Engine . new ( allocation_strategy : PoolingAllocationConfig . new ) ) . to be_a ( Engine )
60- expect { Engine . new ( allocation_strategy : :nope ) } . to raise_error ( ArgumentError , /invalid instance allocation strategy: :nope/ )
61- end
62-
63- it "supports target options" do
64- expect { Engine . new ( target : "x86_64-unknown-linux-gnu" ) } . not_to raise_error
65- expect { Engine . new ( target : "nope" ) } . to raise_error ( ArgumentError , /Unrecognized architecture/ )
66- end
67- end
68-
69- describe ".precompile_module" do
70- it "returns a String" do
71- serialized = engine . precompile_module ( "(module)" )
72- expect ( serialized ) . to be_instance_of ( String )
73- end
74-
75- it "can be used by Module.deserialize" do
76- serialized = engine . precompile_module ( "(module)" )
77- mod = Module . deserialize ( engine , serialized )
78- expect ( mod ) . to be_instance_of ( Wasmtime ::Module )
79- end
80- end
81-
82- describe ".precompile_component" do
83- it "returns a String" do
84- serialized = engine . precompile_component ( "(component)" )
85- expect ( serialized ) . to be_instance_of ( String )
86- end
87-
88- it "can be used by Component.deserialize" do
89- serialized = engine . precompile_component ( "(component)" )
90- component = Component ::Component . deserialize ( engine , serialized )
91- expect ( component ) . to be_instance_of ( Component ::Component )
92- end
93- end
94-
95- describe "#precompile_compatibility_key" do
96- it "is the same amongst similar engines" do
97- engine_one = Engine . new ( target : "x86_64-unknown-linux-gnu" , parallel_compilation : true )
98- engine_two = Engine . new ( target : "x86_64-unknown-linux-gnu" , parallel_compilation : false )
99-
100- expect ( engine_one . precompile_compatibility_key ) . to eq ( engine_two . precompile_compatibility_key )
101- end
102-
103- it "is different amongst different engines" do
104- engine_one = Engine . new ( target : "x86_64-unknown-linux-gnu" )
105- engine_two = Engine . new ( target : "arm64-apple-darwin" )
106-
107- expect ( engine_one . precompile_compatibility_key ) . not_to eq ( engine_two . precompile_compatibility_key )
108- end
109-
110- it "freezes and caches the result to avoid repeated allocation" do
111- engine = Engine . new ( target : "x86_64-unknown-linux-gnu" )
112-
113- expect ( engine . precompile_compatibility_key ) . to be_frozen
114- expect ( engine . precompile_compatibility_key . object_id ) . to eq ( engine . precompile_compatibility_key . object_id )
115- end
11621 end
11722 end
11823end
0 commit comments