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..81dee7b3 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,10 +82,19 @@ struct DacTester *DacTesterGet(void) HDF_LOGE("%s: open dac device:%u failed", __func__, tester.config.devNum); return NULL; } - hasInit = true; 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; @@ -105,12 +110,14 @@ 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; } } + DacTesterPut(tester); return HDF_SUCCESS; } @@ -133,11 +140,13 @@ 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; } } *((int32_t *)param) = 1; + DacTesterPut(tester); return val; } @@ -210,6 +219,44 @@ 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; +} + +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); + DacTesterPut(tester); + return HDF_ERR_IO; + } + 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 ); + DacTesterPut(tester); return HDF_SUCCESS; } @@ -222,6 +269,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, };