@@ -30,6 +30,54 @@ INSTANTIATE_TEST_SUITE_P(WasmEngines, TestVm, testing::ValuesIn(getWasmEngines()
3030 return info.param ;
3131 });
3232
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+ // Default warm time in nanoseconds.
67+ int warm_time_ns_limit = 10000 ;
68+
69+ #if defined(__linux__) && defined(__s390x__)
70+ // Linux 390x is significantly slower, so we use a more lenient limit.
71+ warm_time_ns_limit = 75000 ;
72+ #endif
73+
74+ // Verify that getting a "warm" engine takes less than 10us.
75+ EXPECT_LE (warm, warm_time_ns_limit);
76+
77+ // Verify that getting a "warm" engine takes at least 50x less time than getting a "cold" one.
78+ EXPECT_LE (warm * 50 , cold);
79+ }
80+
3381TEST_P (TestVm, Basic) {
3482 if (engine_ == " wasmedge" ) {
3583 EXPECT_EQ (vm_->cloneable (), proxy_wasm::Cloneable::NotCloneable);
0 commit comments