devicedebug基于错误码打印错误信息

Signed-off-by: 王达 <wangda20@huawei.com>
This commit is contained in:
王达 2024-11-16 15:03:10 +08:00
parent 62acf5459f
commit fceed2dc74
4 changed files with 35 additions and 8 deletions

View File

@ -57,6 +57,21 @@ APPSPAWN_STATIC char* DeviceDebugJsonStringGeneral(int pid, const char *op, cJSO
return jsonString; return jsonString;
} }
APPSPAWN_STATIC void DevicedebugKillRetDeal(int result, int pid)
{
switch (result) {
case APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST:
printf("devicedebug: kill: %d: No such app process\r\n", pid);
break;
case APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE:
printf("devicedebug: kill: process: %d is not debuggable app\r\n", pid);
break;
default:
printf("devicedebug: process: %d kill unsuccess, please check the hilog for the cause\r\n", pid);
break;
}
}
APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal) APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal)
{ {
cJSON *args = cJSON_CreateObject(); cJSON *args = cJSON_CreateObject();
@ -106,7 +121,7 @@ APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal)
} }
if (result.result != 0) { if (result.result != 0) {
DEVICEDEBUG_LOGE("devicedebug appspawn kill process unsuccess, result=%{public}d", result.result); DevicedebugKillRetDeal(result.result, pid);
return result.result; return result.result;
} }

View File

@ -1530,12 +1530,12 @@ APPSPAWN_STATIC int AppspawpnDevicedebugKill(int pid, cJSON *args)
AppSpawnedProcess *appInfo = GetSpawnedProcess(pid); AppSpawnedProcess *appInfo = GetSpawnedProcess(pid);
if (appInfo == NULL) { if (appInfo == NULL) {
APPSPAWN_LOGE("appspawn devicedebug get app info unsuccess, pid=%{public}d", pid); APPSPAWN_LOGE("appspawn devicedebug get app info unsuccess, pid=%{public}d", pid);
return -1; return APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST;
} }
if (!appInfo->isDebuggable) { if (!appInfo->isDebuggable) {
APPSPAWN_LOGE("appspawn devicedebug process is not debuggable, pid=%{public}d", pid); APPSPAWN_LOGE("appspawn devicedebug process is not debuggable, pid=%{public}d", pid);
return -1; return APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE;
} }
APPSPAWN_LOGI("appspawn devicedebug debugable=%{public}d, pid=%{public}d, signal=%{public}d", APPSPAWN_LOGI("appspawn devicedebug debugable=%{public}d, pid=%{public}d, signal=%{public}d",

View File

@ -552,7 +552,6 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_008, TestSize.Level0)
HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0) HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0)
{ {
int ret = 0; int ret = 0;
char pid[16];
AppSpawnClientHandle clientHandle = nullptr; AppSpawnClientHandle clientHandle = nullptr;
AppSpawnResult result = {}; AppSpawnResult result = {};
do { do {
@ -572,18 +571,28 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0)
AppSpawnReqMsgHandle reqHandle2; AppSpawnReqMsgHandle reqHandle2;
ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle2); ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle2);
ASSERT_GT(sprintf_s(pid, 16, "%d", app->pid), 0); cJSON *args = cJSON_CreateObject();
AppSpawnReqMsgAddStringInfo(reqHandle2, "signal", "-9"); ASSERT_NE(args, nullptr);
AppSpawnReqMsgAddStringInfo(reqHandle2, "pid", pid); cJSON_AddNumberToObject(args, "signal", 9);
cJSON *root = cJSON_CreateObject();
ASSERT_NE(root, nullptr);
cJSON_AddNumberToObject(root, "app", app->pid);
cJSON_AddStringToObject(root, "op", "kill");
cJSON_AddItemToObject(root, "args", args);
char *jsonString = cJSON_Print(root);
cJSON_Delete(root);
ret = AppSpawnReqMsgAddExtInfo(reqHandle2, "devicedebug", (uint8_t *)jsonString, strlen(jsonString) + 1);
ASSERT_EQ(ret, 0);
ret = AppSpawnClientSendMsg(clientHandle, reqHandle2, &result); ret = AppSpawnClientSendMsg(clientHandle, reqHandle2, &result);
AppSpawnClientDestroy(clientHandle); AppSpawnClientDestroy(clientHandle);
free(jsonString);
APPSPAWN_CHECK(ret == 0 && result.result == 0, break, "Failed to send msg ret:%{public}d, result:%{public}d", APPSPAWN_CHECK(ret == 0 && result.result == 0, break, "Failed to send msg ret:%{public}d, result:%{public}d",
ret, result.result); ret, result.result);
ASSERT_EQ(kill(app->pid, SIGKILL), 0); ASSERT_EQ(kill(app->pid, SIGKILL), 0);
} while (0); } while (0);
ASSERT_EQ(ret, 0); ASSERT_EQ(ret, 0);
ASSERT_EQ(result.result, -1); ASSERT_EQ(result.result, APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE);
} }
HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0) HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0)

View File

@ -131,6 +131,9 @@ typedef enum {
APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL, APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL,
APPSPAWN_SANDBOX_ERROR_SET_PERMISSION_FLAG_FAIL, APPSPAWN_SANDBOX_ERROR_SET_PERMISSION_FLAG_FAIL,
APPSPAWN_NODE_EXIST, APPSPAWN_NODE_EXIST,
/* devicedebug errno */
APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST,
APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE,
} AppSpawnErrorCode; } AppSpawnErrorCode;
uint64_t DiffTime(const struct timespec *startTime, const struct timespec *endTime); uint64_t DiffTime(const struct timespec *startTime, const struct timespec *endTime);