mirror of
https://gitee.com/openharmony/arkcompiler_runtime_core
synced 2024-11-23 06:40:32 +00:00
!2855 [abckit] Implement some of missing cpp api + mock api refactor
Merge pull request !2855 from Nazarov Konstantin/abckit-cpp-api-1-alyupa-cherry-pick
This commit is contained in:
commit
b58dfb771f
@ -16,6 +16,7 @@ import("//arkcompiler/runtime_core/libabckit/abckit_config.gni")
|
||||
|
||||
config("abckit_config") {
|
||||
cflags_cc = [ "-std=c++17" ]
|
||||
cflags_c = [ "-std=c99" ]
|
||||
|
||||
cflags = [
|
||||
"-pedantic",
|
||||
@ -62,6 +63,12 @@ config("abckit_config") {
|
||||
configs = [ sdk_libc_secshared_config ]
|
||||
}
|
||||
|
||||
config("abckit_mock_config") {
|
||||
defines = [ "ABCKIT_ENABLE_MOCK_IMPLEMENTATION" ]
|
||||
|
||||
configs = [ ":abckit_config" ]
|
||||
}
|
||||
|
||||
group("abckit_packages") {
|
||||
if (abckit_enable) {
|
||||
deps = [
|
||||
@ -78,7 +85,7 @@ group("abckit_tests") {
|
||||
":abckit_documentation",
|
||||
":abckit_status",
|
||||
"tests:abckit_gtests_action",
|
||||
"tests:abckit_gtests_mock_action",
|
||||
"tests:abckit_mock_gtests_action",
|
||||
"tests/canary:abckit_canary",
|
||||
]
|
||||
}
|
||||
|
@ -41,7 +41,9 @@ public:
|
||||
BasicBlock GetSuccByIdx(int idx) const;
|
||||
std::vector<BasicBlock> GetSuccs() const;
|
||||
BasicBlock &AddInstFront(const Instruction &inst);
|
||||
BasicBlock &AddInstBack(const Instruction &inst);
|
||||
std::vector<Instruction> GetInstructions() const;
|
||||
Instruction GetFirstInst() const;
|
||||
|
||||
protected:
|
||||
const ApiConfig *GetApiConfig() const override
|
||||
|
@ -69,6 +69,14 @@ inline std::vector<Instruction> BasicBlock::GetInstructions() const
|
||||
return insts;
|
||||
}
|
||||
|
||||
inline Instruction BasicBlock::GetFirstInst() const
|
||||
{
|
||||
auto *conf = GetApiConfig();
|
||||
auto *inst = conf->cGapi_->bbGetFirstInst(GetView());
|
||||
CheckError(conf);
|
||||
return Instruction(inst, conf);
|
||||
}
|
||||
|
||||
inline BasicBlock &BasicBlock::AddInstFront(const Instruction &inst)
|
||||
{
|
||||
GetApiConfig()->cGapi_->bbAddInstFront(GetView(), inst.GetView());
|
||||
@ -76,6 +84,13 @@ inline BasicBlock &BasicBlock::AddInstFront(const Instruction &inst)
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BasicBlock &BasicBlock::AddInstBack(const Instruction &inst)
|
||||
{
|
||||
GetApiConfig()->cGapi_->bbAddInstBack(GetView(), inst.GetView());
|
||||
CheckError(GetApiConfig());
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace abckit
|
||||
|
||||
#endif // CPP_ABCKIT_BASIC_BLOCK_H
|
||||
|
@ -117,7 +117,6 @@ public:
|
||||
|
||||
protected:
|
||||
explicit ApiConfig(std::unique_ptr<IErrorHandler> eh)
|
||||
#ifndef ABCKIT_TEST_ENABLE_MOCK
|
||||
: cApi_(AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cIapi_(AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cMapi_(AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
@ -127,17 +126,6 @@ protected:
|
||||
cDynapi_(AbckitGetIsaApiDynamicImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cStatapi_(AbckitGetIsaApiStaticImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
eh_(std::move(eh)) {};
|
||||
#else
|
||||
: cApi_(AbckitGetMockApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cIapi_(AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cMapi_(AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cArktsIapi_(AbckitGetArktsInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cArktsMapi_(AbckitGetArktsModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cGapi_(AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cDynapi_(AbckitGetIsaApiDynamicImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
cStatapi_(AbckitGetIsaApiStaticImpl(ABCKIT_VERSION_RELEASE_1_0_0)),
|
||||
eh_(std::move(eh)) {};
|
||||
#endif
|
||||
|
||||
private:
|
||||
// NOTE(nsizov): make getters for these pointers
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "../base_classes.h"
|
||||
#include "./function.h"
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace abckit::core {
|
||||
@ -28,6 +29,7 @@ class Class : public View<AbckitCoreClass *> {
|
||||
// We restrict constructors in order to prevent C/C++ API mix-up by user.
|
||||
friend class Module;
|
||||
friend class Namespace;
|
||||
friend class Function;
|
||||
|
||||
public:
|
||||
Class(const Class &other) = default;
|
||||
@ -36,8 +38,10 @@ public:
|
||||
Class &operator=(Class &&other) = default;
|
||||
~Class() override = default;
|
||||
|
||||
std::string_view GetName() const;
|
||||
std::vector<core::Function> GetAllMethods() const;
|
||||
std::vector<core::Annotation> GetAnnotations() const;
|
||||
void EnumerateMethods(const std::function<bool(core::Function)> &cb) const;
|
||||
|
||||
// Core API's.
|
||||
// ...
|
||||
|
@ -20,6 +20,16 @@
|
||||
|
||||
namespace abckit::core {
|
||||
|
||||
inline std::string_view Class::GetName() const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
AbckitString *cString = conf->cIapi_->classGetName(GetView());
|
||||
CheckError(conf);
|
||||
std::string_view view = conf->cIapi_->abckitStringToString(cString);
|
||||
CheckError(conf);
|
||||
return view;
|
||||
}
|
||||
|
||||
// CC-OFFNXT(G.FUD.06) perf critical
|
||||
inline std::vector<core::Function> Class::GetAllMethods() const
|
||||
{
|
||||
@ -62,6 +72,21 @@ inline std::vector<core::Annotation> Class::GetAnnotations() const
|
||||
return anns;
|
||||
}
|
||||
|
||||
// CC-OFFNXT(G.FUD.06) perf critical
|
||||
inline void Class::EnumerateMethods(const std::function<bool(core::Function)> &cb) const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
using EnumerateData = std::pair<const std::function<bool(core::Function)> &, const ApiConfig *>;
|
||||
EnumerateData enumerateData(cb, conf);
|
||||
|
||||
conf->cIapi_->classEnumerateMethods(GetView(), &enumerateData, [](AbckitCoreFunction *method, void *data) {
|
||||
const std::function<bool(core::Function)> &callback = static_cast<EnumerateData *>(data)->first;
|
||||
auto *config = static_cast<EnumerateData *>(data)->second;
|
||||
return callback(core::Function(method, config));
|
||||
});
|
||||
CheckError(conf);
|
||||
}
|
||||
|
||||
} // namespace abckit::core
|
||||
|
||||
#endif // CPP_ABCKIT_CORE_CLASS_IMPL_H
|
||||
|
@ -30,6 +30,7 @@ class Function : public View<AbckitCoreFunction *> {
|
||||
// We restrict constructors in order to prevent C/C++ API mix-up by user.
|
||||
friend class core::Class;
|
||||
friend class core::Module;
|
||||
friend class abckit::Instruction;
|
||||
|
||||
public:
|
||||
Function(const Function &other) = default;
|
||||
@ -45,7 +46,8 @@ public:
|
||||
bool IsStatic() const;
|
||||
|
||||
// Core API's.
|
||||
// ...
|
||||
core::Module GetModule() const;
|
||||
core::Class GetParentClass() const;
|
||||
|
||||
private:
|
||||
Function(AbckitCoreFunction *func, const ApiConfig *conf) : View(func), conf_(conf) {};
|
||||
|
@ -17,6 +17,8 @@
|
||||
#define CPP_ABCKIT_CORE_FUNCTION_IMPL_H
|
||||
|
||||
#include "./function.h"
|
||||
#include "./class.h"
|
||||
#include "./module.h"
|
||||
|
||||
namespace abckit::core {
|
||||
|
||||
@ -74,6 +76,22 @@ inline bool Function::IsStatic() const
|
||||
return result;
|
||||
}
|
||||
|
||||
inline core::Module Function::GetModule() const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
AbckitCoreModule *module = conf->cIapi_->functionGetModule(GetView());
|
||||
CheckError(conf);
|
||||
return core::Module(module, conf_);
|
||||
}
|
||||
|
||||
inline core::Class Function::GetParentClass() const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
AbckitCoreClass *klass = conf->cIapi_->functionGetParentClass(GetView());
|
||||
CheckError(conf);
|
||||
return core::Class(klass, conf_);
|
||||
}
|
||||
|
||||
} // namespace abckit::core
|
||||
|
||||
#endif // CPP_ABCKIT_CORE_FUNCTION_IMPL_H
|
||||
|
@ -28,6 +28,7 @@ class ImportDescriptor : public View<AbckitCoreImportDescriptor *> {
|
||||
friend class abckit::File;
|
||||
friend class abckit::core::Module;
|
||||
friend class abckit::arkts::Module;
|
||||
friend class abckit::DynamicIsa;
|
||||
|
||||
public:
|
||||
ImportDescriptor(const ImportDescriptor &other) = default;
|
||||
@ -39,7 +40,7 @@ public:
|
||||
std::string_view GetName() const;
|
||||
|
||||
// Core API's.
|
||||
// ...
|
||||
core::Module GetImportedModule() const;
|
||||
|
||||
private:
|
||||
ImportDescriptor(AbckitCoreImportDescriptor *module, const ApiConfig *conf) : View(module), conf_(conf) {};
|
||||
|
@ -17,6 +17,8 @@
|
||||
#define CPP_ABCKIT_CORE_IMPORT_DESCRIPTOR_IMPL_H
|
||||
|
||||
#include "./import_descriptor.h"
|
||||
#include "./function.h"
|
||||
#include "./module.h"
|
||||
|
||||
namespace abckit::core {
|
||||
|
||||
@ -29,6 +31,13 @@ inline std::string_view ImportDescriptor::GetName() const
|
||||
return name;
|
||||
}
|
||||
|
||||
inline core::Module ImportDescriptor::GetImportedModule() const
|
||||
{
|
||||
AbckitCoreModule *module = GetApiConfig()->cIapi_->importDescriptorGetImportedModule(GetView());
|
||||
CheckError(GetApiConfig());
|
||||
return core::Module(module, conf_);
|
||||
}
|
||||
|
||||
} // namespace abckit::core
|
||||
|
||||
#endif // CPP_ABCKIT_CORE_IMPORT_DESCRIPTOR_IMPL_H
|
||||
|
@ -28,6 +28,8 @@ class Module : public View<AbckitCoreModule *> {
|
||||
// To access private constructor.
|
||||
// We restrict constructors in order to prevent C/C++ API mix-up by user.
|
||||
friend class abckit::File;
|
||||
friend class abckit::core::Function;
|
||||
friend class abckit::core::ImportDescriptor;
|
||||
|
||||
public:
|
||||
Module(const Module &other) = default;
|
||||
@ -36,12 +38,16 @@ public:
|
||||
Module &operator=(Module &&other) = default;
|
||||
~Module() override = default;
|
||||
|
||||
std::string_view GetName() const;
|
||||
std::vector<core::Class> GetClasses() const;
|
||||
std::vector<core::Function> GetTopLevelFunctions() const;
|
||||
std::vector<core::AnnotationInterface> GetAnnotationInterfaces() const;
|
||||
std::vector<core::Namespace> GetNamespaces() const;
|
||||
std::vector<core::ImportDescriptor> GetImports() const;
|
||||
std::vector<core::ExportDescriptor> GetExports() const;
|
||||
void EnumerateTopLevelFunctions(const std::function<bool(core::Function)> &cb) const;
|
||||
void EnumerateClasses(const std::function<bool(core::Class)> &cb) const;
|
||||
void EnumerateImports(const std::function<bool(core::ImportDescriptor)> &cb) const;
|
||||
|
||||
// Core API's.
|
||||
// ...
|
||||
|
@ -26,6 +26,16 @@
|
||||
|
||||
namespace abckit::core {
|
||||
|
||||
inline std::string_view Module::GetName() const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
AbckitString *cString = conf->cIapi_->moduleGetName(GetView());
|
||||
CheckError(conf);
|
||||
std::string_view view = conf->cIapi_->abckitStringToString(cString);
|
||||
CheckError(conf);
|
||||
return view;
|
||||
}
|
||||
|
||||
inline std::vector<core::Class> Module::GetClasses() const
|
||||
{
|
||||
std::vector<core::Class> classes;
|
||||
@ -92,6 +102,48 @@ inline std::vector<core::ExportDescriptor> Module::GetExports() const
|
||||
return exports;
|
||||
}
|
||||
|
||||
inline void Module::EnumerateTopLevelFunctions(const std::function<bool(core::Function)> &cb) const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
using EnumerateData = std::pair<const std::function<bool(core::Function)> &, const ApiConfig *>;
|
||||
EnumerateData enumerateData(cb, GetApiConfig());
|
||||
|
||||
conf->cIapi_->moduleEnumerateTopLevelFunctions(GetView(), &enumerateData, [](AbckitCoreFunction *func, void *data) {
|
||||
const std::function<bool(core::Function)> &callback = static_cast<EnumerateData *>(data)->first;
|
||||
auto *config = static_cast<EnumerateData *>(data)->second;
|
||||
return callback(core::Function(func, config));
|
||||
});
|
||||
CheckError(conf);
|
||||
}
|
||||
|
||||
inline void Module::EnumerateClasses(const std::function<bool(core::Class)> &cb) const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
using EnumerateData = std::pair<const std::function<bool(core::Class)> &, const ApiConfig *>;
|
||||
EnumerateData enumerateData(cb, GetApiConfig());
|
||||
|
||||
conf->cIapi_->moduleEnumerateClasses(GetView(), &enumerateData, [](AbckitCoreClass *klass, void *data) {
|
||||
const std::function<bool(core::Class)> &callback = static_cast<EnumerateData *>(data)->first;
|
||||
auto *config = static_cast<EnumerateData *>(data)->second;
|
||||
return callback(core::Class(klass, config));
|
||||
});
|
||||
CheckError(conf);
|
||||
}
|
||||
|
||||
inline void Module::EnumerateImports(const std::function<bool(core::ImportDescriptor)> &cb) const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
using EnumerateData = std::pair<const std::function<bool(core::ImportDescriptor)> &, const ApiConfig *>;
|
||||
EnumerateData enumerateData(cb, GetApiConfig());
|
||||
|
||||
conf->cIapi_->moduleEnumerateImports(GetView(), &enumerateData, [](AbckitCoreImportDescriptor *func, void *data) {
|
||||
const std::function<bool(core::ImportDescriptor)> &callback = static_cast<EnumerateData *>(data)->first;
|
||||
auto *config = static_cast<EnumerateData *>(data)->second;
|
||||
return callback(core::ImportDescriptor(func, config));
|
||||
});
|
||||
CheckError(conf);
|
||||
}
|
||||
|
||||
} // namespace abckit::core
|
||||
|
||||
#endif // CPP_ABCKIT_CORE_MODULE_IMPL_H
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
Instruction CreateCallArg1(const Instruction &acc, const Instruction &input0) &&;
|
||||
|
||||
// Other dynamic API methods declarations
|
||||
core::ImportDescriptor GetImportDescriptor(const Instruction &inst);
|
||||
|
||||
private:
|
||||
explicit DynamicIsa(const Graph &graph) : graph_(graph) {};
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "./dynamic_isa.h"
|
||||
#include "./instruction.h"
|
||||
#include "./graph.h"
|
||||
#include "./core/import_descriptor.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -56,6 +57,14 @@ inline Instruction DynamicIsa::CreateLoadString(const std::string &str) &&
|
||||
return Instruction(abcLoadstring, conf);
|
||||
}
|
||||
|
||||
inline core::ImportDescriptor DynamicIsa::GetImportDescriptor(const Instruction &inst)
|
||||
{
|
||||
auto *conf = graph_.GetApiConfig();
|
||||
AbckitCoreImportDescriptor *id = conf->cDynapi_->iGetImportDescriptor(inst.GetView());
|
||||
CheckError(conf);
|
||||
return core::ImportDescriptor(id, conf);
|
||||
}
|
||||
|
||||
} // namespace abckit
|
||||
|
||||
#endif // CPP_ABCKIT_DYNAMIC_ISA_IMPL_H
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "./core/module.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@ -57,11 +58,7 @@ public:
|
||||
File(File &&file) = delete;
|
||||
File &operator=(File &&file) = delete;
|
||||
File(const std::string &path, std::unique_ptr<IErrorHandler> eh)
|
||||
#ifndef ABCKIT_TEST_ENABLE_MOCK
|
||||
: Resource(AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)->openAbc(path.c_str())), conf_(std::move(eh))
|
||||
#else
|
||||
: Resource(AbckitGetMockApiImpl(ABCKIT_VERSION_RELEASE_1_0_0)->openAbc(path.c_str())), conf_(std::move(eh))
|
||||
#endif
|
||||
{
|
||||
CheckError(&conf_);
|
||||
SetDeleter(std::make_unique<FileDeleter>(&conf_, *this));
|
||||
@ -123,6 +120,7 @@ public:
|
||||
std::vector<core::Module> GetModules() const;
|
||||
// Returns all functions in a file (consider to delete for mainenace reasons)
|
||||
std::vector<core::Function> GetAllFunctions() const;
|
||||
void EnumerateModules(const std::function<bool(core::Module)> &cb) const;
|
||||
|
||||
// Other API.
|
||||
|
||||
|
@ -75,6 +75,22 @@ inline abckit::LiteralArray File::CreateLiteralArray(const std::vector<abckit::L
|
||||
return abckit::LiteralArray(litaIml, GetApiConfig());
|
||||
}
|
||||
|
||||
inline void File::EnumerateModules(const std::function<bool(core::Module)> &cb) const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
|
||||
using EnumerateData = std::pair<const std::function<bool(core::Module)> &, const ApiConfig *>;
|
||||
EnumerateData enumerateData(cb, conf);
|
||||
|
||||
conf->cIapi_->fileEnumerateModules(GetResource(), &enumerateData, [](AbckitCoreModule *module, void *data) {
|
||||
const std::function<bool(core::Module)> &callback = static_cast<EnumerateData *>(data)->first;
|
||||
auto *config = static_cast<EnumerateData *>(data)->second;
|
||||
return callback(core::Module(module, config));
|
||||
});
|
||||
|
||||
CheckError(conf);
|
||||
}
|
||||
|
||||
} // namespace abckit
|
||||
|
||||
#endif // CPP_ABCKIT_FILE_IMPL_H
|
||||
|
@ -38,6 +38,9 @@ public:
|
||||
Instruction &InsertBefore(const Instruction &inst);
|
||||
AbckitIsaApiDynamicOpcode GetOpcodeDyn() const;
|
||||
AbckitIsaApiStaticOpcode GetOpcodeStat() const;
|
||||
std::string_view GetString() const;
|
||||
Instruction GetNext() const;
|
||||
core::Function GetFunction() const;
|
||||
|
||||
protected:
|
||||
const ApiConfig *GetApiConfig() const override
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define CPP_ABCKIT_INSTRUCTION_IMPL_H
|
||||
|
||||
#include "./instruction.h"
|
||||
#include "./core/function.h"
|
||||
|
||||
namespace abckit {
|
||||
|
||||
@ -52,6 +53,32 @@ inline AbckitIsaApiStaticOpcode Instruction::GetOpcodeStat() const
|
||||
return opc;
|
||||
}
|
||||
|
||||
inline std::string_view Instruction::GetString() const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
AbckitString *cString = conf->cGapi_->iGetString(GetView());
|
||||
CheckError(conf);
|
||||
std::string_view view = conf->cIapi_->abckitStringToString(cString);
|
||||
CheckError(conf);
|
||||
return view;
|
||||
}
|
||||
|
||||
inline Instruction Instruction::GetNext() const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
AbckitInst *inst = conf->cGapi_->iGetNext(GetView());
|
||||
CheckError(conf);
|
||||
return Instruction(inst, conf);
|
||||
}
|
||||
|
||||
inline core::Function Instruction::GetFunction() const
|
||||
{
|
||||
const ApiConfig *conf = GetApiConfig();
|
||||
AbckitCoreFunction *func = conf->cGapi_->iGetFunction(GetView());
|
||||
CheckError(conf);
|
||||
return core::Function(func, conf);
|
||||
}
|
||||
|
||||
} // namespace abckit
|
||||
|
||||
#endif // CPP_ABCKIT_INSTRUCTION_IMPL_H
|
||||
|
@ -49,52 +49,72 @@ group("libabckit_header_deps") {
|
||||
deps = [ ":abckit_options_gen_h" ]
|
||||
}
|
||||
|
||||
ohos_source_set("libabckit_source_set") {
|
||||
sources = [
|
||||
"abckit_impl.cpp",
|
||||
"helpers_common.cpp",
|
||||
"ir_impl.cpp",
|
||||
"ir_interface_impl.cpp",
|
||||
"isa_dynamic_impl.cpp",
|
||||
"isa_dynamic_impl_instr_1.cpp",
|
||||
"isa_dynamic_impl_instr_2.cpp",
|
||||
"isa_static_impl.cpp",
|
||||
"metadata_arkts_inspect_impl.cpp",
|
||||
"metadata_arkts_modify_impl.cpp",
|
||||
"metadata_inspect_impl.cpp",
|
||||
"metadata_js_inspect_impl.cpp",
|
||||
"metadata_js_modify_impl.cpp",
|
||||
"metadata_modify_impl.cpp",
|
||||
"statuses_impl.cpp",
|
||||
]
|
||||
libabckit_sources = [
|
||||
"abckit_impl.cpp",
|
||||
"helpers_common.cpp",
|
||||
"ir_impl.cpp",
|
||||
"ir_interface_impl.cpp",
|
||||
"isa_dynamic_impl.cpp",
|
||||
"isa_dynamic_impl_instr_1.cpp",
|
||||
"isa_dynamic_impl_instr_2.cpp",
|
||||
"isa_static_impl.cpp",
|
||||
"metadata_arkts_inspect_impl.cpp",
|
||||
"metadata_arkts_modify_impl.cpp",
|
||||
"metadata_inspect_impl.cpp",
|
||||
"metadata_js_inspect_impl.cpp",
|
||||
"metadata_js_modify_impl.cpp",
|
||||
"metadata_modify_impl.cpp",
|
||||
"statuses_impl.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"$ark_root_dynamic",
|
||||
"$ark_root_dynamic/libpandabase",
|
||||
"$target_gen_dir/src",
|
||||
]
|
||||
libabckit_include_dirs = [
|
||||
"$ark_root_dynamic",
|
||||
"$ark_root_dynamic/libpandabase",
|
||||
"$target_gen_dir/src",
|
||||
]
|
||||
|
||||
libabckit_deps = [ ":libabckit_header_deps" ]
|
||||
|
||||
ohos_source_set("libabckit_source_set") {
|
||||
sources = libabckit_sources
|
||||
|
||||
include_dirs = libabckit_include_dirs
|
||||
|
||||
configs = [ "$abckit_root:abckit_config" ]
|
||||
|
||||
deps = [ ":libabckit_header_deps" ]
|
||||
deps = libabckit_deps
|
||||
|
||||
part_name = "runtime_core"
|
||||
subsystem_name = "arkcompiler"
|
||||
}
|
||||
|
||||
ohos_source_set("libabckit_source_set_mock") {
|
||||
sources = libabckit_sources
|
||||
|
||||
include_dirs = libabckit_include_dirs
|
||||
|
||||
configs = [ "$abckit_root:abckit_mock_config" ]
|
||||
|
||||
deps = libabckit_deps
|
||||
|
||||
part_name = "runtime_core"
|
||||
subsystem_name = "arkcompiler"
|
||||
}
|
||||
|
||||
libabckit_so_deps = [
|
||||
"adapter_dynamic:abckit_adapter_dynamic_source_set",
|
||||
"adapter_static:abckit_adapter_static_source_set",
|
||||
"codegen:abckit_codegen_dynamic_source_set",
|
||||
"codegen:abckit_codegen_static_source_set",
|
||||
"irbuilder_dynamic:abckit_ir_builder_dynamic_source_set",
|
||||
"mem_manager:abckit_mem_manager_source_set",
|
||||
"wrappers:abckit_abcfile_wrapper_source_set",
|
||||
"wrappers:abckit_pandasm_wrapper_source_set",
|
||||
]
|
||||
|
||||
ohos_shared_library("libabckit") {
|
||||
deps = [
|
||||
":libabckit_header_deps",
|
||||
":libabckit_source_set",
|
||||
"adapter_dynamic:abckit_adapter_dynamic_source_set",
|
||||
"adapter_static:abckit_adapter_static_source_set",
|
||||
"codegen:abckit_codegen_dynamic_source_set",
|
||||
"codegen:abckit_codegen_static_source_set",
|
||||
"irbuilder_dynamic:abckit_ir_builder_dynamic_source_set",
|
||||
"mem_manager:abckit_mem_manager_source_set",
|
||||
"wrappers:abckit_abcfile_wrapper_source_set",
|
||||
"wrappers:abckit_pandasm_wrapper_source_set",
|
||||
]
|
||||
deps = libabckit_so_deps
|
||||
deps += [ ":libabckit_source_set" ]
|
||||
|
||||
configs = [ "$abckit_root:abckit_config" ]
|
||||
|
||||
@ -111,3 +131,17 @@ ohos_shared_library("libabckit") {
|
||||
part_name = "runtime_core"
|
||||
subsystem_name = "arkcompiler"
|
||||
}
|
||||
|
||||
ohos_source_set("libabckit_mock") {
|
||||
deps = libabckit_so_deps
|
||||
deps += [ ":libabckit_source_set_mock" ]
|
||||
|
||||
configs = [ "$abckit_root:abckit_mock_config" ]
|
||||
|
||||
if (is_linux) {
|
||||
libs = [ "stdc++fs" ]
|
||||
}
|
||||
|
||||
part_name = "runtime_core"
|
||||
subsystem_name = "arkcompiler"
|
||||
}
|
||||
|
@ -150,8 +150,15 @@ AbckitApi g_impl = {
|
||||
|
||||
} // namespace libabckit
|
||||
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
#include "./mock/abckit_mock.h"
|
||||
#endif
|
||||
|
||||
extern "C" AbckitApi const *AbckitGetApiImpl(AbckitApiVersion version)
|
||||
{
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
return AbckitGetMockApiImpl(version);
|
||||
#endif
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::g_impl;
|
||||
|
@ -916,8 +916,15 @@ AbckitGraphApi g_graphApiImpl = {
|
||||
|
||||
} // namespace libabckit
|
||||
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
#include "./mock/abckit_mock.h"
|
||||
#endif
|
||||
|
||||
extern "C" AbckitGraphApi const *AbckitGetGraphApiImpl(AbckitApiVersion version)
|
||||
{
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
// return mock api
|
||||
#endif
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::g_graphApiImpl;
|
||||
|
@ -230,8 +230,15 @@ AbckitIsaApiDynamic g_isaApiDynamicImpl = {
|
||||
|
||||
} // namespace libabckit
|
||||
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
#include "./mock/abckit_mock.h"
|
||||
#endif
|
||||
|
||||
extern "C" AbckitIsaApiDynamic const *AbckitGetIsaApiDynamicImpl(AbckitApiVersion version)
|
||||
{
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
// return mock api
|
||||
#endif
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::g_isaApiDynamicImpl;
|
||||
|
@ -889,8 +889,15 @@ AbckitIsaApiStatic g_isaApiStaticImpl = {
|
||||
|
||||
} // namespace libabckit
|
||||
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
#include "./mock/abckit_mock.h"
|
||||
#endif
|
||||
|
||||
extern "C" AbckitIsaApiStatic const *AbckitGetIsaApiStaticImpl(AbckitApiVersion version)
|
||||
{
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
// return mock api
|
||||
#endif
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::g_isaApiStaticImpl;
|
||||
|
@ -587,8 +587,15 @@ void ArkTSAnnotationInterfaceEnumerateFields(AbckitCoreAnnotationInterface *ai,
|
||||
|
||||
} // namespace libabckit
|
||||
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
#include "./mock/abckit_mock.h"
|
||||
#endif
|
||||
|
||||
extern "C" AbckitArktsInspectApi const *AbckitGetArktsInspectApiImpl(AbckitApiVersion version)
|
||||
{
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
// return mock api
|
||||
#endif
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::g_arktsInspectApiImpl;
|
||||
|
@ -435,8 +435,15 @@ AbckitArktsModifyApi g_arktsModifyApiImpl = {
|
||||
|
||||
} // namespace libabckit
|
||||
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
#include "./mock/abckit_mock.h"
|
||||
#endif
|
||||
|
||||
extern "C" AbckitArktsModifyApi const *AbckitGetArktsModifyApiImpl(AbckitApiVersion version)
|
||||
{
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
// return mock api
|
||||
#endif
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::g_arktsModifyApiImpl;
|
||||
|
@ -1438,8 +1438,15 @@ AbckitInspectApi g_inspectApiImpl = {
|
||||
|
||||
} // namespace libabckit
|
||||
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
#include "./mock/abckit_mock.h"
|
||||
#endif
|
||||
|
||||
extern "C" AbckitInspectApi const *AbckitGetInspectApiImpl(AbckitApiVersion version)
|
||||
{
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
// return mock api
|
||||
#endif
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::g_inspectApiImpl;
|
||||
|
@ -464,8 +464,15 @@ AbckitModifyApi g_modifyApiImpl = {
|
||||
|
||||
} // namespace libabckit
|
||||
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
#include "./mock/abckit_mock.h"
|
||||
#endif
|
||||
|
||||
extern "C" AbckitModifyApi const *AbckitGetModifyApiImpl(AbckitApiVersion version)
|
||||
{
|
||||
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
|
||||
// return mock api
|
||||
#endif
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::g_modifyApiImpl;
|
||||
|
29
libabckit/src/mock/abckit_mock.h
Normal file
29
libabckit/src/mock/abckit_mock.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ABCKIT_IMPL_MOCK
|
||||
#define ABCKIT_IMPL_MOCK
|
||||
|
||||
#include <string>
|
||||
#include <queue>
|
||||
|
||||
#include "../../include/c/abckit.h"
|
||||
|
||||
// CC-OFFNXT(G.NAM.01) false positive
|
||||
extern std::queue<std::string> g_calledFuncs;
|
||||
|
||||
AbckitApi const *AbckitGetMockApiImpl(AbckitApiVersion version);
|
||||
|
||||
#endif
|
@ -16,12 +16,6 @@
|
||||
#ifndef ABCKIT_MOCK_GLOBAL_VALUES
|
||||
#define ABCKIT_MOCK_GLOBAL_VALUES
|
||||
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "libpandabase/macros.h"
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
#define DEFAULT_PATH "abckit.abc"
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
@ -89,17 +83,4 @@
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
|
||||
#define DEFAULT_FILE_VERSION ((AbckitFileVersion)0xdead0022)
|
||||
|
||||
// CC-OFFNXT(G.NAM.03) false positive
|
||||
static std::queue<std::string> g_calledFuncs;
|
||||
|
||||
inline bool CheckMockedApi(const std::string &apiName)
|
||||
{
|
||||
if (g_calledFuncs.empty()) {
|
||||
return false;
|
||||
}
|
||||
auto apiStr = std::move(g_calledFuncs.front());
|
||||
g_calledFuncs.pop();
|
||||
return apiStr == apiName;
|
||||
}
|
||||
|
||||
#endif // ABCKIT_MOCK_GLOBAL_VALUES
|
@ -403,6 +403,28 @@ template("libabckit_host_unittest_action") {
|
||||
}
|
||||
}
|
||||
|
||||
libabckit_host_unittest_action("abckit_mock_gtests") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
# mock infrastructure
|
||||
"mock/abckit_api_mock.cpp",
|
||||
"mock/check_mock.cpp",
|
||||
|
||||
#mock tests
|
||||
"mock/tests/cpp_mock_file.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"$abckit_root",
|
||||
"$abckit_root/src",
|
||||
]
|
||||
|
||||
configs = [ "$abckit_root:abckit_mock_config" ]
|
||||
|
||||
deps = [ "$abckit_root/src:libabckit_mock" ]
|
||||
}
|
||||
|
||||
libabckit_host_unittest_action("abckit_gtests") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
@ -629,53 +651,6 @@ libabckit_host_unittest_action("abckit_gtests") {
|
||||
]
|
||||
}
|
||||
|
||||
libabckit_host_unittest_action("abckit_gtests_mock") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [ "cpp/tests/cpp_test_mock/cpp_mock_file.cpp" ]
|
||||
|
||||
include_dirs = [
|
||||
"$ark_root_dynamic",
|
||||
"$abckit_root",
|
||||
"$abckit_root/include",
|
||||
"$abckit_root/src",
|
||||
"$abckit_root/tests",
|
||||
]
|
||||
|
||||
configs = [ "$abckit_root:abckit_config" ]
|
||||
|
||||
deps = [
|
||||
":abckit_ets_vm_helpers",
|
||||
":abckit_js_vm_helpers",
|
||||
"$abckit_root/src:libabckit",
|
||||
]
|
||||
|
||||
foreach(file, test_js_files) {
|
||||
deps += [ ":gen_${file}_abc" ]
|
||||
}
|
||||
|
||||
foreach(file, test_ts_files) {
|
||||
deps += [ ":gen_${file}_abc" ]
|
||||
}
|
||||
|
||||
foreach(file, test_ets_files) {
|
||||
deps += [ ":gen_${file}_abc" ]
|
||||
}
|
||||
|
||||
if (is_ohos && is_standard_system) {
|
||||
test_abc_dir = "/data/test"
|
||||
} else {
|
||||
test_abc_dir = rebase_path(target_out_dir)
|
||||
}
|
||||
|
||||
test_js_dir = rebase_path(test_js_path)
|
||||
|
||||
defines = [
|
||||
"ABCKIT_ABC_DIR=\"${test_abc_dir}/\"",
|
||||
"ABCKIT_TEST_DIR=\"${test_js_dir}\"",
|
||||
]
|
||||
}
|
||||
|
||||
group("libabckit_stress_tests_package") {
|
||||
deps = [
|
||||
"$abckit_root/abckit:abckit(${host_toolchain})",
|
||||
|
@ -13,20 +13,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ABCKIT_IMPL_MOCK
|
||||
#define ABCKIT_IMPL_MOCK
|
||||
#include "mock/abckit_mock.h"
|
||||
#include "mock/mock_values.h"
|
||||
|
||||
#include "mock_global_values.h"
|
||||
#include "include/c/metadata_core.h"
|
||||
#include "include/c/statuses.h"
|
||||
#include "include/c/abckit.h"
|
||||
|
||||
#include "../../src/ir_impl.h"
|
||||
#include "../../include/c/metadata_core.h"
|
||||
#include "../../include/c/statuses.h"
|
||||
#include "../../src/logger.h"
|
||||
#include "../../src/metadata_inspect_impl.h"
|
||||
|
||||
#include "../../include/c/abckit.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace libabckit::mock {
|
||||
@ -35,33 +28,32 @@ namespace libabckit::mock {
|
||||
|
||||
inline AbckitStatus getLastError()
|
||||
{
|
||||
LIBABCKIT_IMPLEMENTED;
|
||||
return libabckit::statuses::GetLastError();
|
||||
return ABCKIT_STATUS_NO_ERROR;
|
||||
}
|
||||
|
||||
inline AbckitFile *openAbc(const char *path)
|
||||
{
|
||||
g_calledFuncs.push(LIBABCKIT_FUNC_NAME);
|
||||
g_calledFuncs.push(__func__);
|
||||
EXPECT_TRUE(strncmp(path, DEFAULT_PATH, sizeof(DEFAULT_PATH)) == 0);
|
||||
return DEFAULT_FILE;
|
||||
}
|
||||
|
||||
inline void writeAbc(AbckitFile *file, const char *path)
|
||||
{
|
||||
g_calledFuncs.push(LIBABCKIT_FUNC_NAME);
|
||||
g_calledFuncs.push(__func__);
|
||||
EXPECT_TRUE(strncmp(path, DEFAULT_PATH, sizeof(DEFAULT_PATH)) == 0);
|
||||
EXPECT_TRUE(file == DEFAULT_FILE);
|
||||
}
|
||||
|
||||
inline void closeFile(AbckitFile *file)
|
||||
{
|
||||
g_calledFuncs.push(LIBABCKIT_FUNC_NAME);
|
||||
g_calledFuncs.push(__func__);
|
||||
EXPECT_TRUE(file == DEFAULT_FILE);
|
||||
}
|
||||
|
||||
inline void destroyGraph(AbckitGraph *graph)
|
||||
{
|
||||
g_calledFuncs.push(LIBABCKIT_FUNC_NAME);
|
||||
g_calledFuncs.push(__func__);
|
||||
EXPECT_TRUE(graph == DEFAULT_GRAPH);
|
||||
}
|
||||
|
||||
@ -83,24 +75,16 @@ static AbckitApi g_impl = {
|
||||
writeAbc,
|
||||
closeFile,
|
||||
|
||||
// // ========================================
|
||||
// // IR API entrypoints
|
||||
// // ========================================
|
||||
// ========================================
|
||||
// IR API entrypoints
|
||||
// ========================================
|
||||
|
||||
destroyGraph,
|
||||
};
|
||||
|
||||
} // namespace libabckit::mock
|
||||
|
||||
inline extern AbckitApi const *AbckitGetMockApiImpl(AbckitApiVersion version)
|
||||
AbckitApi const *AbckitGetMockApiImpl([[maybe_unused]] AbckitApiVersion version)
|
||||
{
|
||||
switch (version) {
|
||||
case ABCKIT_VERSION_RELEASE_1_0_0:
|
||||
return &libabckit::mock::g_impl;
|
||||
default:
|
||||
libabckit::statuses::SetLastError(ABCKIT_STATUS_UNKNOWN_API_VERSION);
|
||||
return nullptr;
|
||||
}
|
||||
return &libabckit::mock::g_impl;
|
||||
}
|
||||
|
||||
#endif
|
31
libabckit/tests/mock/check_mock.cpp
Normal file
31
libabckit/tests/mock/check_mock.cpp
Normal 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.
|
||||
*/
|
||||
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
||||
#include "./check_mock.h"
|
||||
|
||||
std::queue<std::string> g_calledFuncs;
|
||||
|
||||
bool CheckMockedApi(const std::string &apiName)
|
||||
{
|
||||
if (g_calledFuncs.empty()) {
|
||||
return false;
|
||||
}
|
||||
auto apiStr = std::move(g_calledFuncs.front());
|
||||
g_calledFuncs.pop();
|
||||
return apiStr == apiName;
|
||||
}
|
@ -13,10 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ABCKIT_MOCK_C_API
|
||||
#define ABCKIT_MOCK_C_API
|
||||
#ifndef ABCKIT_CHECK_MOCK
|
||||
#define ABCKIT_CHECK_MOCK
|
||||
|
||||
#include "mock_global_values.h"
|
||||
#include "abckit_impl_mock.h"
|
||||
#include <string>
|
||||
|
||||
#endif // ABCKIT_MOCK_C_API
|
||||
bool CheckMockedApi(const std::string &apiName);
|
||||
|
||||
#endif
|
@ -13,18 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define ABCKIT_TEST_ENABLE_MOCK
|
||||
|
||||
#include "libabckit/include/cpp/abckit_cpp.h"
|
||||
|
||||
#include "helpers/helpers_runtime.h"
|
||||
#include "helpers/helpers.h"
|
||||
#include "libabckit/include/c/isa/isa_dynamic.h"
|
||||
#include "libabckit/src/include_v2/c/isa/isa_static.h"
|
||||
#include "libabckit/include/c/metadata_core.h"
|
||||
#include "include/cpp/abckit_cpp.h"
|
||||
#include "../check_mock.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace libabckit::test {
|
||||
|
||||
@ -35,11 +27,11 @@ TEST_F(LibAbcKitCppMockTest, CppTestMockFile)
|
||||
{
|
||||
{
|
||||
abckit::File file("abckit.abc");
|
||||
ASSERT(CheckMockedApi("openAbc"));
|
||||
ASSERT_TRUE(CheckMockedApi("openAbc"));
|
||||
file.WriteAbc("abckit.abc");
|
||||
ASSERT(CheckMockedApi("writeAbc"));
|
||||
ASSERT_TRUE(CheckMockedApi("writeAbc"));
|
||||
}
|
||||
ASSERT(CheckMockedApi("closeFile"));
|
||||
ASSERT_TRUE(CheckMockedApi("closeFile"));
|
||||
}
|
||||
|
||||
} // namespace libabckit::test
|
Loading…
Reference in New Issue
Block a user