mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 18:20:04 +00:00
Fix find device crash
Set read end symbol when getting runtime info Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAQWSU Signed-off-by: wangyuxin <wangyuxin53@huawei.com> Change-Id: I0954e2c2c8381767f91903d4f606a9ddd501999e
This commit is contained in:
parent
fa4a5954f7
commit
c408186a1f
@ -348,7 +348,7 @@ protected:
|
|||||||
GetRuntimeInfoByPath(lines, realOutPath.c_str(), soBuildId);
|
GetRuntimeInfoByPath(lines, realOutPath.c_str(), soBuildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetRuntimeInfo(const char *realOutPath, char lines[][BUFFER_SIZE], int length) const
|
virtual void SetRuntimeInfo(const char *realOutPath, char lines[][BUFFER_SIZE], int length) const
|
||||||
{
|
{
|
||||||
int fd = open(realOutPath, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
int fd = open(realOutPath, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
@ -374,7 +374,7 @@ protected:
|
|||||||
char *token;
|
char *token;
|
||||||
ssize_t bytesRead;
|
ssize_t bytesRead;
|
||||||
int lineCount = 0;
|
int lineCount = 0;
|
||||||
while ((bytesRead = read(fd, buffer, BUFFER_SIZE)) > 0) {
|
while ((bytesRead = read(fd, buffer, BUFFER_SIZE - 1)) > 0) {
|
||||||
token = strtok_r(buffer, "\n", &saveptr);
|
token = strtok_r(buffer, "\n", &saveptr);
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
if (strcmp(GetInfoFromBuffer(token, RUNTIME_INDEX_BUILDID), soBuildId) == 0 &&
|
if (strcmp(GetInfoFromBuffer(token, RUNTIME_INDEX_BUILDID), soBuildId) == 0 &&
|
||||||
|
@ -131,4 +131,25 @@ HWTEST_F_L0(CrashTest, BuildCompileRuntimeInfo)
|
|||||||
unlink(sanboxRealPath);
|
unlink(sanboxRealPath);
|
||||||
rmdir(MockAotRuntimeInfo::SANBOX_DIR);
|
rmdir(MockAotRuntimeInfo::SANBOX_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HWTEST_F_L0(CrashTest, CrashGetRuntimeInfoByPath)
|
||||||
|
{
|
||||||
|
char timestamp[ohos::AotRuntimeInfo::TIME_STAMP_SIZE];
|
||||||
|
char soBuildId[NAME_MAX];
|
||||||
|
ohos::AotRuntimeInfo *runtimeInfo = new MockAotRuntimeInfo(true);
|
||||||
|
|
||||||
|
runtimeInfo->GetMicrosecondsTimeStamp(timestamp, ohos::AotRuntimeInfo::TIME_STAMP_SIZE);
|
||||||
|
runtimeInfo->GetRuntimeBuildId(soBuildId, NAME_MAX);
|
||||||
|
char sanboxRealPath[PATH_MAX];
|
||||||
|
mkdir(MockAotRuntimeInfo::SANBOX_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
|
std::ofstream file(sanboxRealPath);
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
runtimeInfo->GetCrashSandBoxRealPath(sanboxRealPath, NAME_MAX);
|
||||||
|
runtimeInfo->BuildCrashRuntimeInfo(ecmascript::ohos::RuntimeInfoType::AOT_CRASH);
|
||||||
|
runtimeInfo->CollectCrashSum();
|
||||||
|
|
||||||
|
unlink(sanboxRealPath);
|
||||||
|
rmdir(MockAotRuntimeInfo::SANBOX_DIR);
|
||||||
|
}
|
||||||
} // namespace panda::test
|
} // namespace panda::test
|
@ -57,4 +57,25 @@ bool MockAotRuntimeInfo::BuildRuntimeInfoPart(char *runtimeInfoPart, const char
|
|||||||
{
|
{
|
||||||
return ecmascript::ohos::AotRuntimeInfo::BuildRuntimeInfoPart(runtimeInfoPart, soBuildId, timestamp, type);
|
return ecmascript::ohos::AotRuntimeInfo::BuildRuntimeInfoPart(runtimeInfoPart, soBuildId, timestamp, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MockAotRuntimeInfo::SetRuntimeInfo(const char *realOutPath, char lines[][BUFFER_SIZE], int length) const
|
||||||
|
{
|
||||||
|
int fd = open(realOutPath, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
|
if (fd == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < length && lines[i] != NULL; i++) {
|
||||||
|
if (lines[i][0] != '\0') {
|
||||||
|
write(fd, lines[i], strlen(lines[i]));
|
||||||
|
if (IsRuntimeInfoCrashTest()) {
|
||||||
|
char buffer[BUFFER_SIZE];
|
||||||
|
memset_s(buffer, BUFFER_SIZE, 'a', BUFFER_SIZE);
|
||||||
|
write(fd, buffer, strlen(buffer));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
write(fd, "\n", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -23,8 +23,8 @@ class MockAotRuntimeInfo : public ecmascript::ohos::AotRuntimeInfo {
|
|||||||
public:
|
public:
|
||||||
static constexpr const char *SANBOX_DIR = "ohos-crash-test";
|
static constexpr const char *SANBOX_DIR = "ohos-crash-test";
|
||||||
static constexpr const char *AOT_RUNTIME_INFO = "aot_runtime_info.log";
|
static constexpr const char *AOT_RUNTIME_INFO = "aot_runtime_info.log";
|
||||||
|
|
||||||
MockAotRuntimeInfo();
|
MockAotRuntimeInfo();
|
||||||
|
MockAotRuntimeInfo(bool isRuntimeInfoCrashTest) : isRuntimeInfoCrashTest_(isRuntimeInfoCrashTest) {}
|
||||||
~MockAotRuntimeInfo();
|
~MockAotRuntimeInfo();
|
||||||
|
|
||||||
bool GetRuntimeBuildId(char *buildId, int length) const override;
|
bool GetRuntimeBuildId(char *buildId, int length) const override;
|
||||||
@ -33,7 +33,15 @@ public:
|
|||||||
|
|
||||||
bool BuildRuntimeInfoPart(char *runtimeInfoPart, const char *soBuildId, const char *timestamp,
|
bool BuildRuntimeInfoPart(char *runtimeInfoPart, const char *soBuildId, const char *timestamp,
|
||||||
ecmascript::ohos::RuntimeInfoType type) const;
|
ecmascript::ohos::RuntimeInfoType type) const;
|
||||||
void SetRuntimeInfo(const char *realOutPath, char lines[][BUFFER_SIZE], int length) const;
|
void SetRuntimeInfo(const char *realOutPath, char lines[][BUFFER_SIZE], int length) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool IsRuntimeInfoCrashTest() const
|
||||||
|
{
|
||||||
|
return isRuntimeInfoCrashTest_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isRuntimeInfoCrashTest_ = false;
|
||||||
};
|
};
|
||||||
}; // namespace panda::test
|
}; // namespace panda::test
|
||||||
#endif // MOCK_ECMASCRIPT_AOT_RUNTIME_INFO_H
|
#endif // MOCK_ECMASCRIPT_AOT_RUNTIME_INFO_H
|
||||||
|
Loading…
Reference in New Issue
Block a user