Add UT & Changelog

Signed-off-by: hufeng <hufeng20@huawei.com>
Change-Id: I6c37eb1c333046f5025ac7c4c6863298ad0fad44
This commit is contained in:
hufeng 2024-04-07 17:52:06 +08:00
parent 1a173e4ea4
commit 3d471cd326
4 changed files with 220 additions and 1 deletions

View File

@ -1186,4 +1186,193 @@ HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_020, TestSize.Level1)
auto success = AsmEmitter::EmitPrograms(filename, progs, true);
EXPECT_TRUE(success);
}
/**
* @tc.name: assembly_emitter_test_021
* @tc.desc: Verify the AsmEmitter::EmitPrograms function with different API version.
* @tc.type: FUNC
* @tc.require: issueNumber
*/
HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_021, TestSize.Level1)
{
Parser p;
auto source = R"(
.function any foo(any a0) <noimpl>
)";
auto res = p.Parse(source);
EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE);
std::vector<Program *> progs;
progs.push_back(&res.Value());
// api 11
{
std::string descriptor;
const std::string filename_api11 = "source_021_api11.abc";
auto is_emitted = AsmEmitter::EmitPrograms(filename_api11, progs, false, 11);
EXPECT_TRUE(is_emitted);
auto pf = panda_file::OpenPandaFile(filename_api11);
EXPECT_NE(pf, nullptr);
auto class_id = pf->GetClassId(GetTypeDescriptor("_GLOBAL", &descriptor));
EXPECT_TRUE(class_id.IsValid());
panda_file::ClassDataAccessor cda(*pf, class_id);
EXPECT_FALSE(cda.GetSourceLang());
const auto tagged = panda_file::Type(panda_file::Type::TypeId::TAGGED);
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
EXPECT_NE(mda.GetProtoIdx(), panda_file::INVALID_INDEX_16);
panda_file::ProtoDataAccessor pda(*pf, mda.GetProtoId());
EXPECT_EQ(tagged, pda.GetReturnType());
EXPECT_EQ(1u, pda.GetNumArgs());
EXPECT_EQ(tagged, pda.GetArgType(0));
});
}
// api 12
{
std::string descriptor;
const std::string filename_api12 = "source_021_api12.abc";
auto is_emitted = AsmEmitter::EmitPrograms(filename_api12, progs, false, 12);
EXPECT_TRUE(is_emitted);
auto pf = panda_file::OpenPandaFile(filename_api12);
EXPECT_NE(pf, nullptr);
auto class_id = pf->GetClassId(GetTypeDescriptor("_GLOBAL", &descriptor));
EXPECT_TRUE(class_id.IsValid());
panda_file::ClassDataAccessor cda(*pf, class_id);
EXPECT_FALSE(cda.GetSourceLang());
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
EXPECT_EQ(mda.GetProtoIdx(), panda_file::INVALID_INDEX_16);
});
}
}
/**
* @tc.name: assembly_emitter_test_022
* @tc.desc: Verify the AsmEmitter::Emit function with different API version.
* @tc.type: FUNC
* @tc.require: issueNumber
*/
HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_022, TestSize.Level1)
{
Parser p;
auto source = R"(
.function any foo(any a0) <noimpl>
)";
auto res = p.Parse(source);
EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE);
// api 11
{
std::string descriptor;
const std::string filename_api11 = "source_022_api11.abc";
auto writer = panda_file::FileWriter(filename_api11);
auto is_emitted = AsmEmitter::Emit(&writer, res.Value(), nullptr, nullptr, false, nullptr, 11);
EXPECT_TRUE(is_emitted);
auto pf = panda_file::OpenPandaFile(filename_api11);
EXPECT_NE(pf, nullptr);
auto class_id = pf->GetClassId(GetTypeDescriptor("_GLOBAL", &descriptor));
EXPECT_TRUE(class_id.IsValid());
panda_file::ClassDataAccessor cda(*pf, class_id);
EXPECT_FALSE(cda.GetSourceLang());
const auto tagged = panda_file::Type(panda_file::Type::TypeId::TAGGED);
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
EXPECT_NE(mda.GetProtoIdx(), panda_file::INVALID_INDEX_16);
panda_file::ProtoDataAccessor pda(*pf, mda.GetProtoId());
EXPECT_EQ(tagged, pda.GetReturnType());
EXPECT_EQ(1u, pda.GetNumArgs());
EXPECT_EQ(tagged, pda.GetArgType(0));
});
}
// api 12
{
std::string descriptor;
const std::string filename_api12 = "source_022_api12.abc";
auto writer = panda_file::FileWriter(filename_api12);
auto is_emitted = AsmEmitter::Emit(&writer, res.Value(), nullptr, nullptr, false, nullptr, 12);
EXPECT_TRUE(is_emitted);
auto pf = panda_file::OpenPandaFile(filename_api12);
EXPECT_NE(pf, nullptr);
auto class_id = pf->GetClassId(GetTypeDescriptor("_GLOBAL", &descriptor));
EXPECT_TRUE(class_id.IsValid());
panda_file::ClassDataAccessor cda(*pf, class_id);
EXPECT_FALSE(cda.GetSourceLang());
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
EXPECT_EQ(mda.GetProtoIdx(), panda_file::INVALID_INDEX_16);
});
}
}
/**
* @tc.name: assembly_emitter_test_023
* @tc.desc: Verify the AsmEmitter::Emit function with different API version.
* @tc.type: FUNC
* @tc.require: issueNumber
*/
HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_023, TestSize.Level1)
{
Parser p;
auto source = R"(
.function any foo(any a0) <noimpl>
)";
auto res = p.Parse(source);
EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE);
// api 11
{
std::string descriptor;
auto pf = AsmEmitter::Emit(res.Value(), nullptr, 11);
EXPECT_NE(pf, nullptr);
auto class_id = pf->GetClassId(GetTypeDescriptor("_GLOBAL", &descriptor));
EXPECT_TRUE(class_id.IsValid());
panda_file::ClassDataAccessor cda(*pf, class_id);
EXPECT_FALSE(cda.GetSourceLang());
const auto tagged = panda_file::Type(panda_file::Type::TypeId::TAGGED);
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
EXPECT_NE(mda.GetProtoIdx(), panda_file::INVALID_INDEX_16);
panda_file::ProtoDataAccessor pda(*pf, mda.GetProtoId());
EXPECT_EQ(tagged, pda.GetReturnType());
EXPECT_EQ(1u, pda.GetNumArgs());
EXPECT_EQ(tagged, pda.GetArgType(0));
});
}
// api 12
{
std::string descriptor;
auto pf = AsmEmitter::Emit(res.Value(), nullptr, 12);
EXPECT_NE(pf, nullptr);
auto class_id = pf->GetClassId(GetTypeDescriptor("_GLOBAL", &descriptor));
EXPECT_TRUE(class_id.IsValid());
panda_file::ClassDataAccessor cda(*pf, class_id);
EXPECT_FALSE(cda.GetSourceLang());
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
EXPECT_EQ(mda.GetProtoIdx(), panda_file::INVALID_INDEX_16);
});
}
}
}

View File

@ -0,0 +1,22 @@
# 2024-04-08-file_format-changelog
This document describes change log with the following modifications:
* Version
* Proto
* IndexHeader
File format with this changes is incompatible with version <=12.0.0.0 of Runtime.
## Version
1. We update the version to 12.0.1.0
## Proto
1. We delete ProtoItem's data from file format from version 12.0.1.0.
2. We invalid the [proto_idx] field by setting [0xffff] in Method from version 12.0.1.0.
## IndexHeader
1. We delete the corresponding [field_idx_off] offsets-array from file format from version 12.0.1.0.
2. We invalid the [field_idx_size] & [field_idx_off] by setting [0xffffffff] in IndexHeader from version 12.0.1.0.
3. We delete the corresponding [proto_idx_off] offsets-array from file format from version 12.0.1.0.
4. We invalid the [proto_idx_size] & [proto_idx_off] by setting [0xffffffff] in IndexHeader from version 12.0.1.0.

View File

@ -480,7 +480,7 @@ void TestProtos(size_t n)
constexpr size_t ELEM_PER16 = 16 / ELEM_WIDTH;
// Write panda file to memory
ItemContainer::SetApi(11);
ItemContainer container;
ClassItem *class_item = container.GetOrCreateClassItem("A");
@ -565,6 +565,14 @@ void TestProtos(size_t n)
});
}
HWTEST(ItemContainer, TestProtos, testing::ext::TestSize.Level0)
{
TestProtos(0);
TestProtos(1);
TestProtos(2);
TestProtos(7);
}
HWTEST(ItemContainer, TestDebugInfo, testing::ext::TestSize.Level0)
{
// Write panda file to memory