From 33f9bb46eec14d6adec2ec16eab408de0b68fe94 Mon Sep 17 00:00:00 2001 From: s00442234 Date: Sat, 12 Feb 2022 14:59:31 +0800 Subject: [PATCH] Feat:Add pwm/watchdog/timer user interface performance test unittest Signed-off-by: s00442234 --- .../test/unittest/common/hdf_pwm_test.cpp | 11 +++++++ .../test/unittest/common/hdf_timer_test.cpp | 11 +++++++ .../unittest/common/hdf_watchdog_test.cpp | 10 +++++++ test/unittest/platform/common/pwm_test.c | 26 +++++++++++++++++ test/unittest/platform/common/pwm_test.h | 1 + test/unittest/platform/common/timer_test.c | 29 ++++++++++++++++++- test/unittest/platform/common/timer_test.h | 2 ++ test/unittest/platform/common/watchdog_test.c | 26 +++++++++++++++++ test/unittest/platform/common/watchdog_test.h | 11 +++---- 9 files changed, 121 insertions(+), 6 deletions(-) diff --git a/support/platform/test/unittest/common/hdf_pwm_test.cpp b/support/platform/test/unittest/common/hdf_pwm_test.cpp index 663b4dd2..52b0648d 100644 --- a/support/platform/test/unittest/common/hdf_pwm_test.cpp +++ b/support/platform/test/unittest/common/hdf_pwm_test.cpp @@ -122,3 +122,14 @@ HWTEST_F(HdfLitePwmTest, PwmDisableTest001, TestSize.Level1) EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); EXPECT_EQ(0, PwmTestExecute(PWM_DISABLE_TEST)); } + +/** + * @tc.name: PwmIfPerformanceTest001 + * @tc.desc: pwm user if performance test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HdfLitePwmTest, PwmIfPerformanceTest001, TestSize.Level1) +{ + EXPECT_EQ(0, PwmTestExecute(PWM_IF_PERFORMANCE_TEST)); +} diff --git a/support/platform/test/unittest/common/hdf_timer_test.cpp b/support/platform/test/unittest/common/hdf_timer_test.cpp index 91c64250..9d051162 100755 --- a/support/platform/test/unittest/common/hdf_timer_test.cpp +++ b/support/platform/test/unittest/common/hdf_timer_test.cpp @@ -135,3 +135,14 @@ HWTEST_F(HdfLiteTimerTest, TimerTestReliability001, TestSize.Level1) EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); EXPECT_EQ(0, TimerTestExecute(TIMER_RELIABILITY_TEST)); } + +/** + * @tc.name: TimerTestIfPerformance001 + * @tc.desc: timer user if performance test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfLiteTimerTest, TimerTestIfPerformance001, TestSize.Level1) +{ + EXPECT_EQ(0, TimerTestExecute(TIMER_IF_PERFORMANCE_TEST)); +} diff --git a/support/platform/test/unittest/common/hdf_watchdog_test.cpp b/support/platform/test/unittest/common/hdf_watchdog_test.cpp index dd881a53..df8c1767 100644 --- a/support/platform/test/unittest/common/hdf_watchdog_test.cpp +++ b/support/platform/test/unittest/common/hdf_watchdog_test.cpp @@ -97,3 +97,13 @@ HWTEST_F(HdfLiteWatchdogTest, HdfLiteWatchdogTestReliability001, TestSize.Level1 EXPECT_EQ(0, WatchdogTestExecute(WATCHDOG_TEST_RELIABILITY)); } +/** + * @tc.name: HdfLiteWatchdogTestIfPerformance001 + * @tc.desc: watchdog user if performance test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HdfLiteWatchdogTest, HdfLiteWatchdogTestIfPerformance001, TestSize.Level1) +{ + EXPECT_EQ(0, WatchdogTestExecute(WATCHDOG_IF_PERFORMANCE_TEST)); +} diff --git a/test/unittest/platform/common/pwm_test.c b/test/unittest/platform/common/pwm_test.c index 0c0ab625..ef18ecd9 100644 --- a/test/unittest/platform/common/pwm_test.c +++ b/test/unittest/platform/common/pwm_test.c @@ -327,6 +327,31 @@ static int32_t PwmReliabilityTest(struct PwmTester *tester) return HDF_SUCCESS; } +static int32_t PwmIfPerformanceTest(struct PwmTester *tester) +{ +#ifdef __LITEOS__ + // liteos the accuracy of the obtained time is too large and inaccurate. + if (tester == NULL) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +#endif + + struct PwmConfig cfg = {0}; + uint64_t startMs; + uint64_t endMs; + uint64_t useTime; /*ms*/ + + startMs = OsalGetSysTimeMs(); + PwmGetConfig(tester->handle, &cfg); + endMs = OsalGetSysTimeMs(); + + useTime = endMs - startMs; + HDF_LOGI("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n", + startMs, endMs, useTime, useTime < 1 ? true : false ); + return HDF_SUCCESS; +} + struct PwmTestEntry { int cmd; int32_t (*func)(struct PwmTester *tester); @@ -340,6 +365,7 @@ static struct PwmTestEntry g_entry[] = { { PWM_DISABLE_TEST, PwmDisableTest }, { PWM_SET_GET_CONFIG_TEST, PwmSetGetConfigTest }, { PWM_RELIABILITY_TEST, PwmReliabilityTest }, + { PWM_IF_PERFORMANCE_TEST, PwmIfPerformanceTest }, }; int32_t PwmTestExecute(int cmd) diff --git a/test/unittest/platform/common/pwm_test.h b/test/unittest/platform/common/pwm_test.h index 0c0383bb..00dc1630 100644 --- a/test/unittest/platform/common/pwm_test.h +++ b/test/unittest/platform/common/pwm_test.h @@ -25,6 +25,7 @@ enum PwmTestCmd { PWM_DISABLE_TEST, PWM_SET_GET_CONFIG_TEST, PWM_RELIABILITY_TEST, + PWM_IF_PERFORMANCE_TEST, PWM_TEST_CMD_MAX, }; diff --git a/test/unittest/platform/common/timer_test.c b/test/unittest/platform/common/timer_test.c index 0efca903..4169d256 100755 --- a/test/unittest/platform/common/timer_test.c +++ b/test/unittest/platform/common/timer_test.c @@ -338,6 +338,32 @@ struct TimerTest *TimerTestGet(void) return &tester; } +static int32_t TimerIfPerformanceTest(struct TimerTest *test) +{ +#ifdef __LITEOS__ + // liteos the accuracy of the obtained time is too large and inaccurate. + if (test == NULL) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +#endif + + uint64_t startMs; + uint64_t endMs; + uint64_t useTime; /*ms*/ + uint32_t uSecond; + bool isPeriod; + + startMs = OsalGetSysTimeMs(); + HwTimerGet(test->handle, &uSecond, &isPeriod); + endMs = OsalGetSysTimeMs(); + + useTime = endMs - startMs; + HDF_LOGI("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n", + startMs, endMs, useTime, useTime < 1 ? true : false ); + return HDF_SUCCESS; +} + static struct TimerTestFunc g_timerTestFunc[] = { {TIMER_TEST_SET, TimerSetTest}, {TIMER_TEST_SETONCE, TimerSetOnceTest}, @@ -346,6 +372,7 @@ static struct TimerTestFunc g_timerTestFunc[] = { {TIMER_TEST_STOP, TimerStopTest}, {TIMER_MULTI_THREAD_TEST, TimerTestMultiThread}, {TIMER_RELIABILITY_TEST, TimerTestReliability}, + {TIMER_IF_PERFORMANCE_TEST, TimerIfPerformanceTest}, }; int32_t TimerTestExecute(int cmd) @@ -353,7 +380,7 @@ int32_t TimerTestExecute(int cmd) uint32_t i; int32_t ret = HDF_ERR_NOT_SUPPORT; - if (cmd > TIMER_RELIABILITY_TEST) { + if (cmd > TIMER_TEST_MAX_CMD) { HDF_LOGE("%s: invalid cmd:%d", __func__, cmd); return HDF_ERR_NOT_SUPPORT; } diff --git a/test/unittest/platform/common/timer_test.h b/test/unittest/platform/common/timer_test.h index ba8ff0de..04e40c58 100755 --- a/test/unittest/platform/common/timer_test.h +++ b/test/unittest/platform/common/timer_test.h @@ -24,6 +24,8 @@ enum TimerTestCmd { TIMER_TEST_STOP, TIMER_MULTI_THREAD_TEST, TIMER_RELIABILITY_TEST, + TIMER_IF_PERFORMANCE_TEST, + TIMER_TEST_MAX_CMD, }; #define TIMER_TEST_STACK_SIZE (1024 * 100) diff --git a/test/unittest/platform/common/watchdog_test.c b/test/unittest/platform/common/watchdog_test.c index 46134299..4bbe380c 100644 --- a/test/unittest/platform/common/watchdog_test.c +++ b/test/unittest/platform/common/watchdog_test.c @@ -257,12 +257,38 @@ static int32_t TestCaseWatchdogReliability(struct WatchdogTester *tester) return HDF_SUCCESS; } +static int32_t TestCaseWatchdogIfPerformanceTest(struct WatchdogTester *tester) +{ +#ifdef __LITEOS__ + // liteos the accuracy of the obtained time is too large and inaccurate. + if (tester == NULL) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +#endif + + uint32_t timeoutGet = 0; + uint64_t startMs; + uint64_t endMs; + uint64_t useTime; /*ms*/ + + startMs = OsalGetSysTimeMs(); + WatchdogGetTimeout(tester->handle, &timeoutGet); + endMs = OsalGetSysTimeMs(); + + useTime = endMs - startMs; + HDF_LOGI("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n", + startMs, endMs, useTime, useTime < 1 ? true : false ); + return HDF_SUCCESS; +} + static struct WatchdogTestEntry g_entry[] = { { WATCHDOG_TEST_SET_GET_TIMEOUT, TestCaseWatchdogSetGetTimeout}, { WATCHDOG_TEST_START_STOP, TestCaseWatchdogStartStop}, { WATCHDOG_TEST_FEED, TestCaseWatchdogFeed}, { WATCHDOG_TEST_RELIABILITY, TestCaseWatchdogReliability}, { WATCHDOG_TEST_BARK, TestCaseWatchdogBark}, + { WATCHDOG_IF_PERFORMANCE_TEST, TestCaseWatchdogIfPerformanceTest}, }; int32_t WatchdogTestExecute(int cmd) diff --git a/test/unittest/platform/common/watchdog_test.h b/test/unittest/platform/common/watchdog_test.h index 29372e48..64c2fcaa 100644 --- a/test/unittest/platform/common/watchdog_test.h +++ b/test/unittest/platform/common/watchdog_test.h @@ -17,11 +17,12 @@ extern "C" { enum WatchdogTestCmd { WATCHDOG_TEST_SET_GET_TIMEOUT = 0, - WATCHDOG_TEST_START_STOP = 1, - WATCHDOG_TEST_FEED = 2, - WATCHDOG_TEST_RELIABILITY = 3, - WATCHDOG_TEST_BARK = 4, - WATCHDOG_TEST_MAX = 5, + WATCHDOG_TEST_START_STOP, + WATCHDOG_TEST_FEED, + WATCHDOG_TEST_RELIABILITY, + WATCHDOG_TEST_BARK, + WATCHDOG_IF_PERFORMANCE_TEST, + WATCHDOG_TEST_MAX, }; struct WatchdogTestConfig {