add mac UT support

Signed-off-by: fangting <fangting12@huawei.com>
This commit is contained in:
fangting 2023-12-20 17:26:40 +08:00
parent 5e45e80ab1
commit e719aea4d9
15 changed files with 92 additions and 73 deletions

View File

@ -32,7 +32,6 @@ group("ark_js_packages") {
"ecmascript/pgo_profiler/prof_dump:profdump",
]
}
}
group("ark_js_host_windows_tools_packages") {
@ -69,7 +68,6 @@ group("ark_js_host_linux_tools_packages") {
deps = []
deps += [
"ecmascript/js_vm:ark_js_context(${host_toolchain})",
"ecmascript/js_vm:ark_js_vm(${host_toolchain})",
"ecmascript/quick_fix:quick_fix(${host_toolchain})",
]
@ -299,13 +297,7 @@ config("ark_jsruntime_common_config") {
]
if (use_musl) {
defines += [
"PANDA_USE_MUSL",
"ECMASCRIPT_SUPPORT_CPUPROFILER",
"ECMASCRIPT_SUPPORT_HEAPPROFILER",
"ECMASCRIPT_SUPPORT_HEAPSAMPLING",
"ECMASCRIPT_SUPPORT_SNAPSHOT",
]
defines += [ "PANDA_USE_MUSL" ]
}
if (build_public_version) {
@ -480,7 +472,7 @@ config("ark_jsruntime_common_config") {
defines += [ "ENABLE_EXCEPTION_BACKTRACE" ]
if (use_musl && (current_cpu == "arm" || current_cpu == "arm64") &&
!is_mingw && target_os != "ios" && !is_asan) {
!is_mac && !is_mingw && target_os != "ios" && !is_asan) {
defines += [ "HOOK_ENABLE" ]
}
}
@ -516,8 +508,9 @@ config("ecma_test_config") {
if (enable_leak_check || is_asan) {
defines = [ "ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK" ]
}
ldflags = [ "-Wl,-rpath=\$ORIGIN/" ]
if (!is_mac) {
ldflags = [ "-Wl,-rpath=\$ORIGIN/" ]
}
if (!ark_standalone_build) {
ldflags += [ "-Wl,--lto-O0" ]
@ -855,7 +848,7 @@ ecma_debugger_source = [
]
ecma_profiler_source = [ "ecmascript/napi/dfx_jsnapi.cpp" ]
if (!is_mingw && target_os != "ios") {
if (!is_mingw && !is_mac && target_os != "ios") {
if (ark_compile_mode == "debug") {
ecma_profiler_source += [
"ecmascript/dfx/cpu_profiler/cpu_profiler.cpp",

View File

@ -605,7 +605,25 @@ group("host_unittest") {
deps -= [
":BuiltinsInternational_001_TestAction",
":BuiltinsInternational_002_TestAction",
":BuiltinsNaturalTestAction",
":BuiltinsInternational_003_TestAction",
":BuiltinsInternational_004_TestAction",
":BuiltinsInternational_005_TestAction",
":BuiltinsInternational_006_TestAction",
":BuiltinsInternational_007_TestAction",
":BuiltinsInternational_008_TestAction",
":BuiltinsInternational_009_TestAction",
":BuiltinsInternational_010_TestAction",
":BuiltinsInternational_011_TestAction",
":BuiltinsInternational_012_TestAction",
":BuiltinsInternational_013_TestAction",
":BuiltinsInternational_014_TestAction",
":BuiltinsInternational_015_TestAction",
":BuiltinsNatural_001_TestAction",
":BuiltinsNatural_002_TestAction",
":BuiltinsNatural_003_TestAction",
":BuiltinsNatural_004_TestAction",
":BuiltinsNatural_005_TestAction",
":BuiltinsNatural_006_TestAction",
]
}
}

View File

@ -165,10 +165,10 @@ using Address = uintptr_t;
#define STATIC_ASSERT_EQ_ARCH64(a, b) static_assert(true)
#endif
#if defined(PANDA_TARGET_WINDOWS) || defined(PANDA_TARGET_IOS)
#define WIN_OR_IOS_PLATFORM true
#if defined(PANDA_TARGET_WINDOWS) || defined(PANDA_TARGET_MACOS) || defined(PANDA_TARGET_IOS)
#define WIN_OR_MAC_OR_IOS_PLATFORM true
#else
#define WIN_OR_IOS_PLATFORM false
#define WIN_OR_MAC_OR_IOS_PLATFORM false
#endif
#define ECMASCRIPT_ENABLE_VALUE_SERIALIZER 1

View File

@ -88,7 +88,7 @@ bool AOTFileManager::LoadAnFile(const std::string &fileName)
bool AOTFileManager::LoadAiFile([[maybe_unused]] const std::string &filename)
{
Snapshot snapshot(vm_);
#if !WIN_OR_IOS_PLATFORM
#if !WIN_OR_MAC_OR_IOS_PLATFORM
return snapshot.Deserialize(SnapshotType::AI, filename.c_str());
#else
return true;

View File

@ -68,11 +68,7 @@ void CpuProfiler::StartCpuProfilerForInfo()
isProfiling_ = false;
return;
}
#ifdef PANDA_TARGET_MACOS
tid_ = static_cast<pthread_t>(pthread_self());
#else
tid_ = static_cast<pthread_t>(syscall(SYS_gettid));
#endif
{
LockHolder lock(synchronizationMutex_);
profilerMap_[tid_] = vm_;
@ -134,11 +130,7 @@ void CpuProfiler::StartCpuProfilerForFile(const std::string &fileName)
isProfiling_ = false;
return;
}
#ifdef PANDA_TARGET_MACOS
tid_ = static_cast<pthread_t>(pthread_self());
#else
tid_ = static_cast<pthread_t>(syscall(SYS_gettid));
#endif
{
LockHolder lock(synchronizationMutex_);
profilerMap_[tid_] = vm_;
@ -248,7 +240,6 @@ void CpuProfiler::SetProfileStart(uint64_t nowTimeStamp)
struct CurrentProcessInfo currentProcessInfo = {0};
GetCurrentProcessInfo(currentProcessInfo);
std::string data = "";
#ifndef PANDA_TARGET_MACOS
data = "[{\"args\":{\"data\":{\"frames\":[{\"processId\":" + std::to_string(currentProcessInfo.pid) + "}]"
+ ",\"persistentIds\":true}},\"cat\":\"disabled-by-default-devtools.timeline\","
+ "\"name\":\"TracingStartedInBrowser\",\"ph\":\"I\",\"pid\":"
@ -263,25 +254,6 @@ void CpuProfiler::SetProfileStart(uint64_t nowTimeStamp)
+ std::to_string(currentProcessInfo.tid) + ",\"ts\":"
+ std::to_string(ts) + ",\"tts\":" + std::to_string(currentProcessInfo.tts)
+ "},\n";
#else
int sp = static_cast<int>(getpid());
auto st = reinterpret_cast<uint64_t>(pthread_self());
data = "[{\"args\":{\"data\":{\"frames\":[{\"processId\":" + std::to_string(sp) + "}]"
+ ",\"persistentIds\":true}},\"cat\":\"disabled-by-default-devtools.timeline\","
+ "\"name\":\"TracingStartedInBrowser\",\"ph\":\"I\",\"pid\":"
+ std::to_string(sp) + ",\"s\":\"t\",\"tid\":"
+ std::to_string(st) + ",\"ts\":"
+ std::to_string(ts) + ",\"tts\":178460227},\n";
ts = SamplingProcessor::GetMicrosecondsTimeStamp();
data += "{\"args\":{\"data\":{\"startTime\":" + std::to_string(nowTimeStamp) + "}},"
+ "\"cat\":\"disabled-by-default-ark.cpu_profiler\",\"id\":\"0x2\","
+ "\"name\":\"Profile\",\"ph\":\"P\",\"pid\":"
+ std::to_string(sp) + ",\"tid\":"
+ std::to_string(st) + ",\"ts\":"
+ std::to_string(ts) + ",\"tts\":" + std::to_string(currentProcessInfo.tts)
+ "},\n";
#endif
generator_->SetStartsampleData(data);
}
@ -289,11 +261,7 @@ void CpuProfiler::GetCurrentProcessInfo(struct CurrentProcessInfo &currentProces
{
currentProcessInfo.nowTimeStamp = SamplingProcessor::GetMicrosecondsTimeStamp();
currentProcessInfo.pid = getpid();
#ifdef PANDA_TARGET_MACOS
if (pthread_self()) {
#else
if (syscall(SYS_gettid) == -1) {
#endif
LOG_FULL(FATAL) << "syscall failed";
UNREACHABLE();
}
@ -420,11 +388,7 @@ void CpuProfiler::GetStackSignalHandler(int signal, [[maybe_unused]] siginfo_t *
JSThread *thread = nullptr;
{
LockHolder lock(synchronizationMutex_);
#ifdef PANDA_TARGET_MACOS
pthread_t tid = static_cast<pthread_t>(pthread_self());
#else
pthread_t tid = static_cast<pthread_t>(syscall(SYS_gettid));
#endif
const EcmaVM *vm = profilerMap_[tid];
if (vm == nullptr) {
LOG_ECMA(ERROR) << "CpuProfiler GetStackSignalHandler vm is nullptr";
@ -464,10 +428,10 @@ void CpuProfiler::GetStackSignalHandler(int signal, [[maybe_unused]] siginfo_t *
[[maybe_unused]] mcontext_t &mcontext = ucontext->uc_mcontext;
[[maybe_unused]] void *fp = nullptr;
[[maybe_unused]] void *sp = nullptr;
#if !defined(PANDA_TARGET_MACOS) && defined(PANDA_TARGET_AMD64)
#if defined(PANDA_TARGET_AMD64)
fp = reinterpret_cast<void*>(mcontext.gregs[REG_RBP]);
sp = reinterpret_cast<void*>(mcontext.gregs[REG_RSP]);
#elif !defined(PANDA_TARGET_MACOS) && defined(PANDA_TARGET_ARM64)
#elif defined(PANDA_TARGET_ARM64)
fp = reinterpret_cast<void*>(mcontext.regs[29]); // FP is an alias for x29.
sp = reinterpret_cast<void*>(mcontext.sp);
#else
@ -540,9 +504,9 @@ uint64_t CpuProfiler::GetPcFromContext(void *context)
[[maybe_unused]] ucontext_t *ucontext = reinterpret_cast<ucontext_t*>(context);
[[maybe_unused]] mcontext_t &mcontext = ucontext->uc_mcontext;
uint64_t pc = 0;
#if !defined(PANDA_TARGET_MACOS) && defined(PANDA_TARGET_AMD64)
#if defined(PANDA_TARGET_AMD64)
pc = static_cast<uint64_t>(mcontext.gregs[REG_RIP]);
#elif !defined(PANDA_TARGET_MACOS) && defined(PANDA_TARGET_ARM64)
#elif defined(PANDA_TARGET_ARM64)
pc = static_cast<uint64_t>(mcontext.pc);
#else
LOG_FULL(FATAL) << "AsmInterpreter does not currently support other platforms, please run on x64 and arm64";

View File

@ -150,7 +150,9 @@ group("host_unittest") {
deps -= [
":HProfTestAction",
":HeapSamplingTestAction",
":HeapTrackerTestAction",
":HeapTrackerFirstTestAction",
":HeapTrackerSecondTestAction",
":HeapTrackerThirdTestAction",
]
}
}

View File

@ -38,7 +38,7 @@
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
#include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
#endif
#if !WIN_OR_IOS_PLATFORM
#if !WIN_OR_MAC_OR_IOS_PLATFORM
#include "ecmascript/dfx/hprof/heap_profiler.h"
#include "ecmascript/dfx/hprof/heap_profiler_interface.h"
#endif
@ -534,7 +534,7 @@ void EcmaVM::Iterate(const RootVisitor &v, const RootRangeVisitor &rv)
{
rv(Root::ROOT_VM, ObjectSlot(ToUintPtr(&internalNativeMethods_.front())),
ObjectSlot(ToUintPtr(&internalNativeMethods_.back()) + JSTaggedValue::TaggedTypeSize()));
if (!WIN_OR_IOS_PLATFORM) {
if (!WIN_OR_MAC_OR_IOS_PLATFORM) {
snapshotEnv_->Iterate(v);
}
pgoProfiler_->Iterate(v);

View File

@ -59,7 +59,7 @@ class SnapshotEnv;
class SnapshotSerialize;
class SnapshotProcessor;
using PGOProfiler = pgo::PGOProfiler;
#if !WIN_OR_IOS_PLATFORM
#if !WIN_OR_MAC_OR_IOS_PLATFORM
class HeapProfilerInterface;
class HeapProfiler;
#endif
@ -579,7 +579,7 @@ private:
tooling::JsDebuggerManager *debuggerManager_ {nullptr};
// merge abc
bool isBundlePack_ {true}; // isBundle means app compile mode is JSBundle
#if !WIN_OR_IOS_PLATFORM
#if !WIN_OR_MAC_OR_IOS_PLATFORM
HeapProfilerInterface *heapProfile_ {nullptr};
#endif
CString assetPath_;

View File

@ -473,7 +473,7 @@ public:
bool EnableSnapshotDeserialize() const
{
if (WIN_OR_IOS_PLATFORM) {
if (WIN_OR_MAC_OR_IOS_PLATFORM) {
return false;
}

View File

@ -41,7 +41,7 @@
#include "ecmascript/mem/gc_stats.h"
#include "ecmascript/ecma_string_table.h"
#include "ecmascript/runtime_call_id.h"
#if !WIN_OR_IOS_PLATFORM
#if !WIN_OR_MAC_OR_IOS_PLATFORM
#include "ecmascript/dfx/hprof/heap_profiler_interface.h"
#include "ecmascript/dfx/hprof/heap_profiler.h"
#endif

View File

@ -32,7 +32,7 @@ class EcmaVM;
class FullGC;
class HeapRegionAllocator;
class HeapTracker;
#if !WIN_OR_IOS_PLATFORM
#if !WIN_OR_MAC_OR_IOS_PLATFORM
class HeapProfilerInterface;
class HeapProfiler;
#endif

View File

@ -3615,7 +3615,7 @@ void JSNApi::InitializeIcuData(const JSRuntimeOptions &options)
{
std::string icuPath = options.GetIcuDataPath();
if (icuPath == "default") {
#if !WIN_OR_IOS_PLATFORM && !defined(PANDA_TARGET_LINUX)
#if !WIN_OR_MAC_OR_IOS_PLATFORM && !defined(PANDA_TARGET_LINUX)
SetHwIcuDirectory();
#endif
} else {

View File

@ -29,11 +29,6 @@ MemMap PageMap(size_t size, int prot, size_t alignment)
ASSERT(size == AlignUp(size, PageSize()));
ASSERT(alignment == AlignUp(alignment, PageSize()));
size_t allocSize = size + alignment;
#ifdef PANDA_TARGET_MACOS
if(prot == PAGE_PROT_EXEC_READWRITE){
prot = 5;
}
#endif
void *result = mmap(nullptr, allocSize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (reinterpret_cast<intptr_t>(result) == -1) {
LOG_ECMA(FATAL) << "mmap failed with error code:" << strerror(errno);

View File

@ -1444,6 +1444,50 @@ group("host_unittest") {
":EcmaVm_001_TestAction",
":EcmaVm_002_TestAction",
":EcmaVm_003_TestAction",
":EcmaVm_004_TestAction",
":EcmaVm_005_TestAction",
":EcmaVm_006_TestAction",
":EcmaVm_007_TestAction",
":EcmaVm_008_TestAction",
":EcmaVm_009_TestAction",
":EcmaVm_010_TestAction",
":EcmaVm_011_TestAction",
":EcmaVm_012_TestAction",
":EcmaVm_013_TestAction",
":EcmaVm_014_TestAction",
":EcmaVm_015_TestAction",
":EcmaVm_016_TestAction",
":EcmaVm_017_TestAction",
":EcmaVm_018_TestAction",
":EcmaVm_019_TestAction",
":EcmaVm_020_TestAction",
":EcmaVm_021_TestAction",
":EcmaVm_022_TestAction",
":EcmaVm_023_TestAction",
":EcmaVm_024_TestAction",
":EcmaVm_025_TestAction",
":EcmaVm_026_TestAction",
":EcmaVm_027_TestAction",
":EcmaVm_028_TestAction",
":EcmaVm_029_TestAction",
":EcmaVm_030_TestAction",
":EcmaVm_031_TestAction",
":EcmaVm_032_TestAction",
":EcmaVm_033_TestAction",
":EcmaVm_034_TestAction",
":EcmaVm_035_TestAction",
":EcmaVm_036_TestAction",
":EcmaVm_037_TestAction",
":EcmaVm_038_TestAction",
":EcmaVm_039_TestAction",
":EcmaVm_040_TestAction",
":EcmaVm_041_TestAction",
":EcmaVm_042_TestAction",
":EcmaVm_043_TestAction",
":EcmaVm_044_TestAction",
":EcmaVm_045_TestAction",
":EcmaVm_046_TestAction",
":EcmaVm_047_TestAction",
]
}
}

View File

@ -1661,7 +1661,10 @@ template("host_quickfix_test_action") {
script = "//arkcompiler/ets_runtime/script/run_ark_executable.py"
quickfix_options = " --merge-abc true --asm-interpreter=false"
quickfix_options = " --merge-abc true "
if (is_mac) {
quickfix_optios = " --merge-abc true --asm-interpreter=false"
}
args = [
"--script-file",