diff --git a/interfaces/native/light/test/unittest/light_agent_test.cpp b/interfaces/native/light/test/unittest/light_agent_test.cpp index 88d8846c238e698df2600a63d867b14110c498ac..bf528a28b89ae68e1a09e6861f02e0bfadddfb03 100755 --- a/interfaces/native/light/test/unittest/light_agent_test.cpp +++ b/interfaces/native/light/test/unittest/light_agent_test.cpp @@ -14,7 +14,7 @@ */ #include -#include +#include #include "light_agent.h" #include "sensors_errors.h" @@ -25,7 +25,8 @@ using namespace testing::ext; using namespace OHOS::HiviewDFX; namespace { - constexpr HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "LightAgentTest" }; +constexpr int32_t TIME_WAIT_FOR_OP = 2; +constexpr HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "LightAgentTest" }; } // namespace class LightAgentTest : public testing::Test { @@ -127,7 +128,7 @@ HWTEST_F(LightAgentTest, StartLightTest_003, TestSize.Level1) animation.onTime = 50; animation.offTime = 50; int32_t ret = TurnOn(lightId_, color, animation); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); ASSERT_EQ(ret, 0); } } @@ -243,7 +244,7 @@ HWTEST_F(LightAgentTest, StartLightTest_008, TestSize.Level1) animation.onTime = 2; animation.offTime = 2; int32_t ret = TurnOn(lightId_, color, animation); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); ASSERT_EQ(ret, 0); } } diff --git a/interfaces/native/vibrator/test/unittest/vibrator_agent_test.cpp b/interfaces/native/vibrator/test/unittest/vibrator_agent_test.cpp index ba4ab76ae7f639ef32a62d8d7d8307e3d0fa96ba..5e1a50c6b43667806cbc04902a701063f539b782 100755 --- a/interfaces/native/vibrator/test/unittest/vibrator_agent_test.cpp +++ b/interfaces/native/vibrator/test/unittest/vibrator_agent_test.cpp @@ -32,6 +32,7 @@ using namespace Security::AccessToken; using Security::AccessToken::AccessTokenID; namespace { +constexpr int32_t TIME_WAIT_FOR_OP = 2; const std::string PHONE_TYPE = "phone"; std::string g_deviceType; constexpr HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "VibratorAgentTest" }; @@ -254,10 +255,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_001, TestSize.Level1) ASSERT_EQ(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_002, TestSize.Level1) @@ -272,10 +274,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_002, TestSize.Level1) ASSERT_EQ(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_003, TestSize.Level1) @@ -294,10 +297,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_003, TestSize.Level1) ASSERT_NE(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_004, TestSize.Level1) @@ -316,10 +320,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_004, TestSize.Level1) ASSERT_NE(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_005, TestSize.Level1) @@ -338,10 +343,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_005, TestSize.Level1) ASSERT_EQ(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_006, TestSize.Level1) @@ -360,10 +366,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_006, TestSize.Level1) ASSERT_NE(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_007, TestSize.Level1) @@ -382,10 +389,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_007, TestSize.Level1) ASSERT_EQ(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_008, TestSize.Level1) @@ -404,10 +412,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_008, TestSize.Level1) ASSERT_NE(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_009, TestSize.Level1) @@ -426,10 +435,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_009, TestSize.Level1) ASSERT_EQ(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_010, TestSize.Level1) @@ -448,10 +458,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_010, TestSize.Level1) ASSERT_NE(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_011, TestSize.Level1) @@ -470,10 +481,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_011, TestSize.Level1) ASSERT_EQ(ret, 0); } close(fd); - sleep(5); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_012, TestSize.Level1) @@ -488,10 +500,11 @@ HWTEST_F(VibratorAgentTest, PlayVibratorCustom_012, TestSize.Level1) ASSERT_EQ(ret, 0); } close(fd); - sleep(7); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } else { ASSERT_EQ(0, 0); } + Cancel(); } HWTEST_F(VibratorAgentTest, PlayVibratorCustom_013, TestSize.Level1)