diff --git a/ecmascript/pgo_profiler/tests/BUILD.gn b/ecmascript/pgo_profiler/tests/BUILD.gn index 8d473fd1b3..20f9a668ec 100644 --- a/ecmascript/pgo_profiler/tests/BUILD.gn +++ b/ecmascript/pgo_profiler/tests/BUILD.gn @@ -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 = [ diff --git a/ecmascript/pgo_profiler/tests/pgo_profiler_test.cpp b/ecmascript/pgo_profiler/tests/pgo_profiler_test.cpp index d55b367232..e49b53d54e 100644 --- a/ecmascript/pgo_profiler/tests/pgo_profiler_test.cpp +++ b/ecmascript/pgo_profiler/tests/pgo_profiler_test.cpp @@ -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(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(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(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(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 diff --git a/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_1.js b/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_1.js new file mode 100644 index 0000000000..fe84d01251 --- /dev/null +++ b/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_1.js @@ -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); +} \ No newline at end of file diff --git a/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_2.js b/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_2.js new file mode 100644 index 0000000000..b8bcfc27cb --- /dev/null +++ b/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_2.js @@ -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); +} \ No newline at end of file diff --git a/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_3.js b/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_3.js new file mode 100644 index 0000000000..5a4fd40b4d --- /dev/null +++ b/ecmascript/pgo_profiler/tests/pgo_test_case/merge_file_3.js @@ -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); +}