From 3e823b63f75e452f535e7898c881471451f690e1 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 22 Mar 2023 11:27:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E6=94=B9=E7=94=A8=E4=BE=8B=E8=B6=85?= =?UTF-8?q?=E9=95=BFsleep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- .../light/test/unittest/light_agent_test.cpp | 9 +++-- .../test/unittest/vibrator_agent_test.cpp | 37 +++++++++++++------ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/interfaces/native/light/test/unittest/light_agent_test.cpp b/interfaces/native/light/test/unittest/light_agent_test.cpp index 88d8846..bf528a2 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 ba4ab76..5e1a50c 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) -- Gitee