@@ -30,6 +30,46 @@ INSTANTIATE_TEST_SUITE_P(WasmEngines, TestVm, testing::ValuesIn(getWasmEngines()
30
30
return info.param ;
31
31
});
32
32
33
+ TEST_P (TestVm, Init) {
34
+ std::chrono::time_point<std::chrono::steady_clock> time2;
35
+
36
+ auto time1 = std::chrono::steady_clock::now ();
37
+ if (engine_ == " v8" ) {
38
+ #if defined(PROXY_WASM_HOST_ENGINE_V8)
39
+ EXPECT_TRUE (proxy_wasm::initV8Engine ());
40
+ time2 = std::chrono::steady_clock::now ();
41
+ EXPECT_TRUE (proxy_wasm::initV8Engine ());
42
+ #endif
43
+ } else if (engine_ == " wamr" ) {
44
+ #if defined(PROXY_WASM_HOST_ENGINE_WAMR)
45
+ EXPECT_TRUE (proxy_wasm::initWamrEngine ());
46
+ time2 = std::chrono::steady_clock::now ();
47
+ EXPECT_TRUE (proxy_wasm::initWamrEngine ());
48
+ #endif
49
+ } else if (engine_ == " wasmtime" ) {
50
+ #if defined(PROXY_WASM_HOST_ENGINE_WASMTIME)
51
+ EXPECT_TRUE (proxy_wasm::initWasmtimeEngine ());
52
+ time2 = std::chrono::steady_clock::now ();
53
+ EXPECT_TRUE (proxy_wasm::initWasmtimeEngine ());
54
+ #endif
55
+ } else {
56
+ return ;
57
+ }
58
+ auto time3 = std::chrono::steady_clock::now ();
59
+
60
+ auto cold = std::chrono::duration_cast<std::chrono::nanoseconds>(time2 - time1).count ();
61
+ auto warm = std::chrono::duration_cast<std::chrono::nanoseconds>(time3 - time2).count ();
62
+
63
+ std::cout << " \" cold\" engine time: " << cold << " ns" << std::endl;
64
+ std::cout << " \" warm\" engine time: " << warm << " ns" << std::endl;
65
+
66
+ // Verify that getting a "warm" engine takes less than 10us.
67
+ EXPECT_LE (warm, 10000 );
68
+
69
+ // Verify that getting a "warm" engine takes at least 50x less time than getting a "cold" one.
70
+ EXPECT_LE (warm * 50 , cold);
71
+ }
72
+
33
73
TEST_P (TestVm, Basic) {
34
74
if (engine_ == " wasmedge" ) {
35
75
EXPECT_EQ (vm_->cloneable (), proxy_wasm::Cloneable::NotCloneable);
0 commit comments