LiteOS_M轻量系统XTS测试ActsSamgrTes用例内存优化
·
简介
ActsSamgrTes测试用例代码中部分使用malloc申请的内存在测试结束后未释放,若设备内存紧张,修改后在进行XTS测试时可减少约500kb的动态运行内存。
社区修改PR: https://gitcode.com/openharmony/xts_acts/pull/37674
修改
在sendrequest_func_test.c、sendresponse_func_test.c、sendsharerequest_func_test.c、taskpool_sharedtask_func_test.c、taskpool_singletask_func_test.c、taskpool_specifiedtask_func_test.c 这些文件的测试用例中存在申请内存,在测试后为释放的数据。
以下testSendRequest0010测试为例:
LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0010, Function | MediumTest | Level1)
{
DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502");
if (demoApi == NULL) {
TEST_FAIL();
}
Request request = {.msgId = MSG_RT, .msgValue = 0};
char *body = "I wanna async call good result!";
request.len = (int16)(strlen(body) + 1);
request.data = malloc(request.len); // 此处使用malloc申请内存,但在测试结束后未释放
if (request.data == NULL) {
TEST_FAIL();
}
strcpy_s(request.data, request.len, body);
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503");
if (iUnknown == NULL) {
TEST_FAIL();
}
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
feature->featureCalledCount = 0;
int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, NULL);
TEST_ASSERT_EQUAL_INT(result == 0, TRUE);
osDelay(OPER_INTERVAL);
TEST_ASSERT_EQUAL_INT(feature->featureCalledCount == 1, TRUE);
TEST_ASSERT_EQUAL_INT(strcmp(feature->latestRequest, body), 0);
free(request.data); // 添加释放操作
request.data = NULL; // 添加置空操作
ReleaseIUnknown(demoApi);
}
更多推荐

所有评论(0)