mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-07-21 03:35:25 -04:00
!622 Add dac user interface performance test unittest
Merge pull request !622 from 张亚雷/master
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user