From 0e3dee5b2c71b8d27ed820dfa14b4d4510c9d6df Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Sun, 13 Feb 2022 20:56:22 -0800 Subject: [PATCH 1/7] dac interface performance test Signed-off-by: zhangyalei --- .../test/unittest/common/hdf_dac_test.cpp | 11 ++++++ test/unittest/platform/common/dac_test.c | 36 +++++++++++++++++++ test/unittest/platform/common/dac_test.h | 1 + 3 files changed, 48 insertions(+) diff --git a/support/platform/test/unittest/common/hdf_dac_test.cpp b/support/platform/test/unittest/common/hdf_dac_test.cpp index b148a5a5..07cb7673 100644 --- a/support/platform/test/unittest/common/hdf_dac_test.cpp +++ b/support/platform/test/unittest/common/hdf_dac_test.cpp @@ -92,3 +92,14 @@ HWTEST_F(HdfLiteDacTest, DacTestReliability001, TestSize.Level1) EXPECT_EQ(0, DacTestExecute(DAC_TEST_CMD_RELIABILITY)); printf("%s: exit!\n", __func__); } + +/** + * @tc.name: DacIfPerformanceTest001 + * @tc.desc: dac user if performance test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HdfLiteDacTest, DacIfPerformanceTest001, TestSize.Level1) +{ + EXPECT_EQ(0, DacTestExecute(DAC_TEST_CMD_IF_PERFORMANCE)); +} diff --git a/test/unittest/platform/common/dac_test.c b/test/unittest/platform/common/dac_test.c index c3528bbb..37cb5a3a 100644 --- a/test/unittest/platform/common/dac_test.c +++ b/test/unittest/platform/common/dac_test.c @@ -213,6 +213,41 @@ int32_t DacTestReliability(void) return HDF_SUCCESS; } +static int32_t DacIfPerformanceTest(void) +{ +#ifdef __LITEOS__ + // liteos the accuracy of the obtained time is too large and inaccurate. + return HDF_SUCCESS; +#endif + + uint64_t startMs; + uint64_t endMs; + uint64_t useTime; /*ms*/ + struct DacTester *tester = NULL; + int32_t ret; + uint32_t val; + + val = 0; + tester = DacTesterGet(); + if (tester == NULL || tester->handle == NULL) { + HDF_LOGE("%s: get tester failed", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + startMs = OsalGetSysTimeMs(); + ret = DacWrite(tester->handle, tester->config.channel, val); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: write value failed:%u, ret:%d", __func__, val, ret); + return HDF_ERR_IO; + } + endMs = OsalGetSysTimeMs(); + + useTime = endMs - startMs; + HDF_LOGE("----->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 DacTestEntry { int cmd; int32_t (*func)(void); @@ -222,6 +257,7 @@ static struct DacTestEntry g_entry[] = { { DAC_TEST_CMD_WRITE, DacTestWrite, "DacTestWrite" }, { DAC_TEST_CMD_MULTI_THREAD, DacTestMultiThread, "DacTestMultiThread" }, { DAC_TEST_CMD_RELIABILITY, DacTestReliability, "DacTestReliability" }, + { DAC_TEST_CMD_IF_PERFORMANCE, DacIfPerformanceTest, "DacIfPerformanceTest" }, }; int32_t DacTestExecute(int cmd) diff --git a/test/unittest/platform/common/dac_test.h b/test/unittest/platform/common/dac_test.h index 4e25d2f0..40df8e06 100644 --- a/test/unittest/platform/common/dac_test.h +++ b/test/unittest/platform/common/dac_test.h @@ -34,6 +34,7 @@ enum DacTestCmd { DAC_TEST_CMD_WRITE = 0, DAC_TEST_CMD_MULTI_THREAD, DAC_TEST_CMD_RELIABILITY, + DAC_TEST_CMD_IF_PERFORMANCE, DAC_TEST_CMD_MAX, }; From 1ce5c2155aa4eee8be56da482a6b1038aa5d624f Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Mon, 14 Feb 2022 02:08:01 -0800 Subject: [PATCH 2/7] dac interface performance test Signed-off-by: zhangyalei --- test/unittest/platform/common/dac_test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unittest/platform/common/dac_test.c b/test/unittest/platform/common/dac_test.c index 37cb5a3a..f7fcac6c 100644 --- a/test/unittest/platform/common/dac_test.c +++ b/test/unittest/platform/common/dac_test.c @@ -90,6 +90,16 @@ struct DacTester *DacTesterGet(void) return &tester; } +static void DacTesterPut(struct DacTester *tester) +{ + if (tester == NULL) { + HDF_LOGE("%s: tester is NULL", __func__); + return; + } + DacClose(tester->handle); + tester->handle = NULL; +} + int32_t DacTestWrite(void) { struct DacTester *tester = NULL; @@ -110,6 +120,7 @@ int32_t DacTestWrite(void) return HDF_ERR_IO; } } + DacTesterPut(tester); return HDF_SUCCESS; } @@ -138,6 +149,7 @@ static int DacTestThreadFunc(void *param) } *((int32_t *)param) = 1; + DacTesterPut(tester); return val; } @@ -210,6 +222,7 @@ int32_t DacTestReliability(void) (void)DacWrite(NULL, tester->config.channel, val); // invalid channel (void)DacWrite(tester->handle, tester->config.maxChannel + 1, val); + DacTesterPut(tester); return HDF_SUCCESS; } @@ -245,6 +258,7 @@ static int32_t DacIfPerformanceTest(void) useTime = endMs - startMs; HDF_LOGE("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n", startMs, endMs, useTime, useTime < 1 ? true : false ); + DacTesterPut(tester); return HDF_SUCCESS; } From 76b7c94c3b4585145d48c43c40f2574e3a7bd007 Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Mon, 14 Feb 2022 23:29:00 -0800 Subject: [PATCH 3/7] dac performance test Signed-off-by: zhangyalei --- test/unittest/platform/common/dac_test.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/unittest/platform/common/dac_test.c b/test/unittest/platform/common/dac_test.c index f7fcac6c..d96ddb8b 100644 --- a/test/unittest/platform/common/dac_test.c +++ b/test/unittest/platform/common/dac_test.c @@ -120,7 +120,6 @@ int32_t DacTestWrite(void) return HDF_ERR_IO; } } - DacTesterPut(tester); return HDF_SUCCESS; } @@ -149,7 +148,6 @@ static int DacTestThreadFunc(void *param) } *((int32_t *)param) = 1; - DacTesterPut(tester); return val; } @@ -222,7 +220,6 @@ int32_t DacTestReliability(void) (void)DacWrite(NULL, tester->config.channel, val); // invalid channel (void)DacWrite(tester->handle, tester->config.maxChannel + 1, val); - DacTesterPut(tester); return HDF_SUCCESS; } @@ -256,9 +253,8 @@ static int32_t DacIfPerformanceTest(void) endMs = OsalGetSysTimeMs(); useTime = endMs - startMs; - HDF_LOGE("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n", + HDF_LOGI("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n", startMs, endMs, useTime, useTime < 1 ? true : false ); - DacTesterPut(tester); return HDF_SUCCESS; } @@ -295,5 +291,6 @@ int32_t DacTestExecute(int cmd) __EXIT__: HDF_LOGE("[%s][======cmd:%d====ret:%d======]", __func__, cmd, ret); + DacTesterPut(DacTesterGet()); return ret; } From dcebd4a8c4a537ef641833faf710d53be445b91e Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Tue, 15 Feb 2022 18:41:08 -0800 Subject: [PATCH 4/7] dac performance test Signed-off-by: zhangyalei --- test/unittest/platform/common/dac_test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unittest/platform/common/dac_test.c b/test/unittest/platform/common/dac_test.c index d96ddb8b..015d059c 100644 --- a/test/unittest/platform/common/dac_test.c +++ b/test/unittest/platform/common/dac_test.c @@ -289,8 +289,12 @@ int32_t DacTestExecute(int cmd) break; } + // At last test case. + if (cmd == DAC_TEST_CMD_IF_PERFORMANCE) { + DacTesterPut(DacTesterGet()); + } + __EXIT__: HDF_LOGE("[%s][======cmd:%d====ret:%d======]", __func__, cmd, ret); - DacTesterPut(DacTesterGet()); return ret; } From 5a5b85ca1938e5796c45701d267015987d0e9bd3 Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Wed, 16 Feb 2022 03:01:40 -0800 Subject: [PATCH 5/7] dac performance test Signed-off-by: zhangyalei --- test/unittest/platform/common/dac_test.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/unittest/platform/common/dac_test.c b/test/unittest/platform/common/dac_test.c index 015d059c..98de3e5a 100644 --- a/test/unittest/platform/common/dac_test.c +++ b/test/unittest/platform/common/dac_test.c @@ -71,11 +71,7 @@ struct DacTester *DacTesterGet(void) { int32_t ret; static struct DacTester tester; - static bool hasInit = false; - if (hasInit) { - return &tester; - } ret = DacTestGetConfig(&tester.config); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: write config failed:%d", __func__, ret); @@ -86,7 +82,6 @@ struct DacTester *DacTesterGet(void) HDF_LOGE("%s: open dac device:%u failed", __func__, tester.config.devNum); return NULL; } - hasInit = true; return &tester; } @@ -121,6 +116,7 @@ int32_t DacTestWrite(void) } } + DacTesterPut(tester); return HDF_SUCCESS; } @@ -148,6 +144,7 @@ static int DacTestThreadFunc(void *param) } *((int32_t *)param) = 1; + DacTesterPut(tester); return val; } @@ -220,6 +217,7 @@ int32_t DacTestReliability(void) (void)DacWrite(NULL, tester->config.channel, val); // invalid channel (void)DacWrite(tester->handle, tester->config.maxChannel + 1, val); + DacTesterPut(tester); return HDF_SUCCESS; } @@ -255,6 +253,7 @@ static int32_t DacIfPerformanceTest(void) 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 ); + DacTesterPut(tester); return HDF_SUCCESS; } @@ -289,11 +288,6 @@ int32_t DacTestExecute(int cmd) break; } - // At last test case. - if (cmd == DAC_TEST_CMD_IF_PERFORMANCE) { - DacTesterPut(DacTesterGet()); - } - __EXIT__: HDF_LOGE("[%s][======cmd:%d====ret:%d======]", __func__, cmd, ret); return ret; From d9114b3b9699e1d23fed9d236398285f7e7d4c08 Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Wed, 16 Feb 2022 18:16:23 -0800 Subject: [PATCH 6/7] dac performance test Signed-off-by: zhangyalei --- test/unittest/platform/common/dac_test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unittest/platform/common/dac_test.c b/test/unittest/platform/common/dac_test.c index 98de3e5a..0a33a1c5 100644 --- a/test/unittest/platform/common/dac_test.c +++ b/test/unittest/platform/common/dac_test.c @@ -112,6 +112,7 @@ int32_t DacTestWrite(void) ret = DacWrite(tester->handle, tester->config.channel, value[i]); if (ret != HDF_SUCCESS || value[i] >= (1U << tester->config.dataWidth)) { HDF_LOGE("%s: write value failed:%u, ret:%d", __func__, value[i], ret); + DacTesterPut(tester); return HDF_ERR_IO; } } @@ -139,6 +140,7 @@ static int DacTestThreadFunc(void *param) if (ret != HDF_SUCCESS) { HDF_LOGE("%s: DacWrite failed, ret:%d", __func__, ret); *((int32_t *)param) = 1; + DacTesterPut(tester); return HDF_ERR_IO; } } @@ -246,6 +248,7 @@ static int32_t DacIfPerformanceTest(void) ret = DacWrite(tester->handle, tester->config.channel, val); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: write value failed:%u, ret:%d", __func__, val, ret); + DacTesterPut(tester); return HDF_ERR_IO; } endMs = OsalGetSysTimeMs(); From a363c53375ee7ad1233dac832c10ef3c5eb290fe Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Wed, 16 Feb 2022 22:14:06 -0800 Subject: [PATCH 7/7] dac performance test Signed-off-by: zhangyalei --- test/unittest/platform/common/dac_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/platform/common/dac_test.c b/test/unittest/platform/common/dac_test.c index 0a33a1c5..81dee7b3 100644 --- a/test/unittest/platform/common/dac_test.c +++ b/test/unittest/platform/common/dac_test.c @@ -110,7 +110,7 @@ int32_t DacTestWrite(void) for (i = 0; i < TEST_DAC_VAL_NUM; i++) { value[i] = i; ret = DacWrite(tester->handle, tester->config.channel, value[i]); - if (ret != HDF_SUCCESS || value[i] >= (1U << tester->config.dataWidth)) { + if (ret != HDF_SUCCESS) { HDF_LOGE("%s: write value failed:%u, ret:%d", __func__, value[i], ret); DacTesterPut(tester); return HDF_ERR_IO;