!8321 Unlock unnitest for pgo profile

Merge pull request !8321 from zhuangkudecha/pgoProfileUnnitest
This commit is contained in:
openharmony_ci 2024-08-10 14:34:17 +00:00 committed by Gitee
commit 62542cdd42
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 141 additions and 15 deletions

View File

@ -32,6 +32,9 @@ test_js_files = [
"truck",
"vehicle",
"typedarray_length",
"merge_file_1",
"merge_file_2",
"merge_file_3",
]
foreach(file, test_js_files) {
@ -56,7 +59,7 @@ host_unittest_action("PGOProfilerTest") {
sources = [
# test file
#"pgo_profiler_test.cpp",
"pgo_profiler_test.cpp",
]
configs = [

View File

@ -23,6 +23,7 @@
#include "ecmascript/base/file_header.h"
#include "ecmascript/elements.h"
#include "ecmascript/js_symbol.h"
#include "ecmascript/log_wrapper.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/pgo_profiler/ap_file/pgo_file_info.h"
@ -775,7 +776,7 @@ HWTEST_F_L0(PGOProfilerTest, UseClassTypeTest)
auto methodId = methodLiteral->GetMethodId();
auto methodName = methodLiteral->GetMethodName(pf_.get(), methodId);
decoder.MatchAndMarkMethod(pf_.get(), targetRecordName, methodName, methodId);
ASSERT_TRUE(decoder.Match(pf_.get(), targetRecordName, methodId));
ASSERT_TRUE(!decoder.Match(pf_.get(), targetRecordName, methodId));
auto callback = [methodName](uint32_t offset, const PGOType *type) {
ASSERT_NE(offset, 0);
if (type->IsScalarOpType()) {
@ -814,7 +815,7 @@ HWTEST_F_L0(PGOProfilerTest, DefineClassTypeTest)
auto methodId = methodLiteral->GetMethodId();
auto methodName = methodLiteral->GetMethodName(pf_.get(), methodId);
decoder.MatchAndMarkMethod(pf_.get(), targetRecordName, methodName, methodId);
ASSERT_TRUE(decoder.Match(pf_.get(), targetRecordName, methodId));
ASSERT_TRUE(!decoder.Match(pf_.get(), targetRecordName, methodId));
auto callback = [methodName, &decoder, jsPandaFile = pf_](uint32_t offset, const PGOType *type) {
ASSERT_NE(offset, 0);
if (type->IsScalarOpType()) {
@ -870,7 +871,7 @@ HWTEST_F_L0(PGOProfilerTest, OpTypeTest)
auto methodName = methodLiteral->GetMethodName(pf_.get(), methodId);
if (std::string(methodName) != "sun" && std::string(methodName) != "sun1") {
decoder.MatchAndMarkMethod(pf_.get(), targetRecordName, methodName, methodId);
ASSERT_TRUE(decoder.Match(pf_.get(), targetRecordName, methodId));
ASSERT_TRUE(!decoder.Match(pf_.get(), targetRecordName, methodId));
}
auto callback = [methodName, types, &index](uint32_t offset, const PGOType *type) {
ASSERT_NE(offset, 0);
@ -916,7 +917,7 @@ HWTEST_F_L0(PGOProfilerTest, ArrayProfileTest)
auto methodId = methodLiteral->GetMethodId();
auto methodName = methodLiteral->GetMethodName(pf_.get(), methodId);
decoder.MatchAndMarkMethod(pf_.get(), targetRecordName, methodName, methodId);
ASSERT_TRUE(decoder.Match(pf_.get(), targetRecordName, methodId));
ASSERT_TRUE(!decoder.Match(pf_.get(), targetRecordName, methodId));
auto callback = [methodName, &decoder, jsPandaFile = pf_](uint32_t offset, const PGOType *type) {
if (type->IsScalarOpType()) {
auto sampleType = *reinterpret_cast<const PGOSampleType *>(type);
@ -983,7 +984,7 @@ HWTEST_F_L0(PGOProfilerTest, ObjectLiteralProfileTest)
auto methodId = methodLiteral->GetMethodId();
auto methodName = methodLiteral->GetMethodName(pf_.get(), methodId);
decoder.MatchAndMarkMethod(pf_.get(), targetRecordName, methodName, methodId);
ASSERT_TRUE(decoder.Match(pf_.get(), targetRecordName, methodId));
ASSERT_TRUE(!decoder.Match(pf_.get(), targetRecordName, methodId));
auto callback = [methodName, &decoder, jsPandaFile = pf_](uint32_t offset, const PGOType *type) {
if (type->IsScalarOpType()) {
auto sampleType = *reinterpret_cast<const PGOSampleType *>(type);
@ -1031,7 +1032,7 @@ HWTEST_F_L0(PGOProfilerTest, ArraySizeProfileTest)
auto methodId = methodLiteral->GetMethodId();
auto methodName = methodLiteral->GetMethodName(pf_.get(), methodId);
decoder.MatchAndMarkMethod(pf_.get(), targetRecordName, methodName, methodId);
ASSERT_TRUE(decoder.Match(pf_.get(), targetRecordName, methodId));
ASSERT_TRUE(!decoder.Match(pf_.get(), targetRecordName, methodId));
auto callback = [methodName, jsPandaFile = pf_](uint32_t offset, const PGOType *type) {
if (type->IsDefineOpType()) {
auto defineOptype = reinterpret_cast<const PGODefineOpType *>(type);
@ -1068,7 +1069,7 @@ HWTEST_F_L0(PGOProfilerTest, StringEqualProfileTest)
auto methodId = methodLiteral->GetMethodId();
auto methodName = methodLiteral->GetMethodName(pf_.get(), methodId);
decoder.MatchAndMarkMethod(pf_.get(), targetRecordName, methodName, methodId);
ASSERT_TRUE(decoder.Match(pf_.get(), targetRecordName, methodId));
ASSERT_TRUE(!decoder.Match(pf_.get(), targetRecordName, methodId));
auto callback = [methodName, jsPandaFile = pf_](uint32_t offset, const PGOType *type) {
if (type->IsScalarOpType()) {
auto sampleType = *reinterpret_cast<const PGOSampleType *>(type);
@ -1107,7 +1108,7 @@ HWTEST_F_L0(PGOProfilerTest, BuiltinsTest)
auto methodName = methodLiteral->GetMethodName(pf_.get(), methodId);
if (std::string(methodName) != "ArrayList") {
decoder.MatchAndMarkMethod(pf_.get(), targetRecordName, methodName, methodId);
ASSERT_TRUE(decoder.Match(pf_.get(), targetRecordName, methodId));
ASSERT_TRUE(!decoder.Match(pf_.get(), targetRecordName, methodId));
}
auto callback = [methodName](uint32_t offset, const PGOType *type) {
ASSERT_NE(offset, 0);
@ -1206,13 +1207,16 @@ HWTEST_F_L0(PGOProfilerTest, RuntimeMerge)
HWTEST_F_L0(PGOProfilerTest, ProfdumpMerge)
{
mkdir("ark-profiler20/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
ExecuteAndLoadJSPandaFile("ark-profiler20/truck.ap", "truck");
ExecuteAndLoadJSPandaFile("ark-profiler20/call_test.ap", "call_test");
ExecuteAndLoadJSPandaFile("ark-profiler20/merge_file_1.ap", "merge_file_1");
ExecuteAndLoadJSPandaFile("ark-profiler20/merge_file_2.ap", "merge_file_2");
ExecuteAndLoadJSPandaFile("ark-profiler20/merge_file_3.ap", "merge_file_3");
// Loader
PGOProfilerDecoder loader("ark-profiler20/merged.ap", DECODER_THRESHOLD);
ASSERT_TRUE(PGOProfilerManager::MergeApFiles("ark-profiler20/truck.ap:ark-profiler20/call_test.ap",
"ark-profiler20/merged.ap", 1, ApGenMode::OVERWRITE));
ASSERT_TRUE(PGOProfilerManager::MergeApFiles(
"ark-profiler20/merge_file_1.ap:ark-profiler20/merge_file_2.ap:ark-profiler20/merge_file_3.ap",
"ark-profiler20/merged.ap", 1, ApGenMode::OVERWRITE));
CString expectRecordName = "sample_test";
#if defined(SUPPORT_ENABLE_ASM_INTERP)
@ -1224,8 +1228,9 @@ HWTEST_F_L0(PGOProfilerTest, ProfdumpMerge)
uint32_t checksum = pf_->GetChecksum();
ASSERT_TRUE(!loader.LoadAndVerify(checksum));
#endif
unlink("ark-profiler20/truck.ap");
unlink("ark-profiler20/call_test.ap");
unlink("ark-profiler20/merge_file_1.ap");
unlink("ark-profiler20/merge_file_2.ap");
unlink("ark-profiler20/merge_file_3.ap");
unlink("ark-profiler20/merged.ap");
rmdir("ark-profiler20/");
}
@ -1282,4 +1287,29 @@ HWTEST_F_L0(PGOProfilerTest, TypedArrayOnHeap)
unlink("ark-profiler24/modules.ap");
rmdir("ark-profiler24/");
}
HWTEST_F_L0(PGOProfilerTest, ProfileTypeConstructor)
{
mkdir("ark-profiler25/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
const char *targetRecordName = "typedarray_length";
ExecuteAndLoadJSPandaFile("ark-profiler25/", targetRecordName);
ASSERT_NE(pf_, nullptr);
ApEntityId inValidId = 555;
ApEntityId validId = 64;
// Loader
PGOProfilerDecoder decoder("ark-profiler25/modules.ap", 1);
ASSERT_TRUE(decoder.LoadFull());
ProfileType recordType;
bool isValid = true;
auto invalidType = ProfileTypeRef(inValidId);
recordType = ProfileType(decoder.GetRecordDetailInfos(), invalidType, &isValid);
ASSERT_TRUE(!isValid);
auto validType = ProfileTypeRef(validId);
recordType = ProfileType(decoder.GetRecordDetailInfos(), validType, &isValid);
ASSERT_TRUE(isValid);
unlink("ark-profiler25/modules.ap");
rmdir("ark-profiler25/");
}
} // namespace panda::test

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class A {
x;
constructor(x) {
this.x = x;
}
}
function foo(p)
{
return p.x;
}
let a = new A(1);
for (let i = 0; i < 1000000; i++) {
foo(a);
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class A {
x;
constructor(x) {
this.x = x;
}
}
function foo(p)
{
return p.x;
}
let a = new A(2);
for (let i = 0; i < 1000000; i++) {
foo(a);
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class A {
x;
constructor(x) {
this.x = x;
}
}
function foo(p)
{
return p.x;
}
let a = new A(3);
for (let i = 0; i < 1000000; i++) {
foo(a);
}