mirror of
https://gitee.com/openharmony/arkcompiler_runtime_core
synced 2024-12-12 17:07:03 +00:00
!287 Add TDD test cases
Merge pull request !287 from dakeQI/1123master_tdd
This commit is contained in:
commit
0aee28d359
36
BUILD.gn
36
BUILD.gn
@ -314,24 +314,24 @@ if (!ark_standalone_build) {
|
||||
deps += [ "$ark_root/libark_defect_scan_aux/tests/unittest:defect_scan_aux_unittest(${host_toolchain})" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group("runtime_core_unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"$ark_root/libpandabase/tests:unittest",
|
||||
"$ark_root/libpandafile/tests:unittest",
|
||||
"$ark_root/libziparchive/tests:unittest",
|
||||
"$ark_root/runtime/tests:unittest",
|
||||
]
|
||||
}
|
||||
group("runtime_core_unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"$ark_root/libpandabase/tests:unittest",
|
||||
"$ark_root/libpandafile/tests:unittest",
|
||||
"$ark_root/libziparchive/tests:unittest",
|
||||
"$ark_root/runtime/tests:unittest",
|
||||
]
|
||||
}
|
||||
|
||||
group("runtime_core_host_unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"$ark_root/libpandabase/tests:host_unittest",
|
||||
"$ark_root/libpandafile/tests:host_unittest",
|
||||
"$ark_root/libziparchive/tests:host_unittest",
|
||||
"$ark_root/runtime/tests:host_unittest",
|
||||
]
|
||||
group("runtime_core_host_unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"$ark_root/libpandabase/tests:host_unittest",
|
||||
"$ark_root/libpandafile/tests:host_unittest",
|
||||
"$ark_root/libziparchive/tests:host_unittest",
|
||||
"$ark_root/runtime/tests:host_unittest",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ void RegEncoder::InsertSpillsForDynInputsInst(compiler::Inst *inst)
|
||||
RegContentVec spill_vec(GetGraph()->GetLocalAllocator()->Adapter()); // spill_vec is used to handle callrange
|
||||
|
||||
auto nargs = inst->GetInputsCount() - (inst->RequireState() ? 1 : 0);
|
||||
auto start = 0;
|
||||
size_t start = 0;
|
||||
bool range = IsIntrinsicRange(inst) || (nargs - start > MAX_NUM_NON_RANGE_ARGS && CanHoldRange(inst));
|
||||
|
||||
compiler::Register temp = range ? range_temps_start_ : 0;
|
||||
|
@ -19,11 +19,12 @@ host_unittest_action("LibPandaBaseTest") {
|
||||
|
||||
sources = [
|
||||
"arch_test.cpp",
|
||||
"arena_allocator_test.cpp",
|
||||
"base_mem_stats_test.cpp",
|
||||
"base_thread_test.cpp",
|
||||
"bit_vector_test.cpp",
|
||||
"cframe_layout_test.cpp",
|
||||
"code_allocator_test.cpp",
|
||||
"dfx_test.cpp",
|
||||
"error_test.cpp",
|
||||
"json_parser_test.cpp",
|
||||
"math_helpers_test.cpp",
|
||||
|
@ -169,7 +169,7 @@ private:
|
||||
std::string str_value_;
|
||||
};
|
||||
|
||||
TEST_F(ArenaAllocatorTest, AllocateTest)
|
||||
HWTEST_F(ArenaAllocatorTest, AllocateTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
void *addr;
|
||||
void *tmp;
|
||||
@ -196,7 +196,7 @@ TEST_F(ArenaAllocatorTest, AllocateTest)
|
||||
ASSERT_EQ(tmp = aa.Alloc(DEFAULT_ARENA_SIZE + maxAlignDrift + 1), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, AllocateVectorTest)
|
||||
HWTEST_F(ArenaAllocatorTest, AllocateVectorTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
constexpr size_t SIZE = 2048;
|
||||
constexpr size_t SMALL_MAGIC_CONSTANT = 3;
|
||||
@ -217,7 +217,7 @@ TEST_F(ArenaAllocatorTest, AllocateVectorTest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, AllocateVectorWithComplexTypeTest)
|
||||
HWTEST_F(ArenaAllocatorTest, AllocateVectorWithComplexTypeTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
constexpr size_t SIZE = 512;
|
||||
constexpr size_t MAGIC_CONSTANT_1 = std::numeric_limits<size_t>::max() / (SIZE + 2);
|
||||
@ -293,7 +293,7 @@ TEST_F(ArenaAllocatorTest, AllocateVectorWithComplexTypeTest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, AllocateDequeWithComplexTypeTest)
|
||||
HWTEST_F(ArenaAllocatorTest, AllocateDequeWithComplexTypeTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
constexpr size_t SIZE = 2048;
|
||||
constexpr size_t MAGIC_CONSTANT_1 = std::numeric_limits<size_t>::max() / (SIZE + 2);
|
||||
@ -370,7 +370,7 @@ TEST_F(ArenaAllocatorTest, AllocateDequeWithComplexTypeTest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, LongRandomTest)
|
||||
HWTEST_F(ArenaAllocatorTest, LongRandomTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
constexpr size_t SIZE = 3250000;
|
||||
constexpr size_t HALF_SIZE = SIZE >> 1;
|
||||
@ -438,7 +438,7 @@ TEST_F(ArenaAllocatorTest, LongRandomTest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, LogAlignmentSmallSizesTest)
|
||||
HWTEST_F(ArenaAllocatorTest, LogAlignmentSmallSizesTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
constexpr size_t MAX_SMALL_SIZE = 32;
|
||||
|
||||
@ -457,7 +457,7 @@ TEST_F(ArenaAllocatorTest, LogAlignmentSmallSizesTest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, LogAlignmentBigSizeTest)
|
||||
HWTEST_F(ArenaAllocatorTest, LogAlignmentBigSizeTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
constexpr size_t SIZE = 0.3_KB;
|
||||
ArenaAllocator aa(SpaceType::SPACE_TYPE_INTERNAL);
|
||||
@ -473,37 +473,37 @@ TEST_F(ArenaAllocatorTest, LogAlignmentBigSizeTest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, ArrayUINT16AlignmentTest)
|
||||
HWTEST_F(ArenaAllocatorTest, ArrayUINT16AlignmentTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
AllocateWithAlignment<uint16_t>();
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, ArrayUINT32AlignmentTest)
|
||||
HWTEST_F(ArenaAllocatorTest, ArrayUINT32AlignmentTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
AllocateWithAlignment<uint32_t>();
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, ArrayUINT64AlignmentTest)
|
||||
HWTEST_F(ArenaAllocatorTest, ArrayUINT64AlignmentTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
AllocateWithAlignment<uint64_t>();
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, ArrayUINT16WithDiffAlignmentTest)
|
||||
HWTEST_F(ArenaAllocatorTest, ArrayUINT16WithDiffAlignmentTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
AllocateWithDiffAlignment<uint16_t>();
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, ArrayUINT32WithDiffAlignmentTest)
|
||||
HWTEST_F(ArenaAllocatorTest, ArrayUINT32WithDiffAlignmentTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
AllocateWithDiffAlignment<uint32_t>();
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, ArrayUINT64WithDiffAlignmentTest)
|
||||
HWTEST_F(ArenaAllocatorTest, ArrayUINT64WithDiffAlignmentTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
AllocateWithDiffAlignment<uint64_t>();
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, FunctionNewTest)
|
||||
HWTEST_F(ArenaAllocatorTest, FunctionNewTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ArenaAllocator aa(SpaceType::SPACE_TYPE_INTERNAL);
|
||||
std::array<ComplexClass *, ARRAY_SIZE> arr;
|
||||
@ -538,26 +538,7 @@ TEST_F(ArenaAllocatorTest, FunctionNewTest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, ResizeTest)
|
||||
{
|
||||
ArenaAllocator aa(SpaceType::SPACE_TYPE_INTERNAL);
|
||||
static constexpr size_t alloc_count = 1000;
|
||||
static constexpr size_t init_val = 0xdeadbeef;
|
||||
void *tmp;
|
||||
size_t *first_var = aa.New<size_t>(init_val);
|
||||
{
|
||||
size_t init_size = aa.GetAllocatedSize();
|
||||
for (size_t i = 0; i < alloc_count; i++) {
|
||||
tmp = aa.Alloc(sizeof(size_t));
|
||||
}
|
||||
EXPECT_DEATH(aa.Resize(aa.GetAllocatedSize() + 1), "");
|
||||
aa.Resize(init_size);
|
||||
ASSERT_EQ(aa.GetAllocatedSize(), init_size);
|
||||
}
|
||||
ASSERT_EQ(*first_var, init_val);
|
||||
}
|
||||
|
||||
TEST_F(ArenaAllocatorTest, ResizeWrapperTest)
|
||||
HWTEST_F(ArenaAllocatorTest, ResizeWrapperTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
static constexpr size_t VECTOR_SIZE = 1000;
|
||||
ArenaAllocator aa(SpaceType::SPACE_TYPE_INTERNAL);
|
||||
@ -569,7 +550,7 @@ TEST_F(ArenaAllocatorTest, ResizeWrapperTest)
|
||||
vector.push_back(i);
|
||||
}
|
||||
}
|
||||
ASSERT(old_size == aa.GetAllocatedSize());
|
||||
ASSERT_TRUE(old_size == aa.GetAllocatedSize());
|
||||
}
|
||||
|
||||
} // namespace panda
|
||||
|
@ -76,4 +76,26 @@ HWTEST_F(BaseMemStatsTest, AllocationsOverAllocator, testing::ext::TestSize.Leve
|
||||
ASSERT_EQ(sizeof(buff1), stats.GetFootprint(SpaceType::SPACE_TYPE_CODE));
|
||||
}
|
||||
|
||||
HWTEST_F(BaseMemStatsTest, HeapAllocateTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
BaseMemStats stats;
|
||||
stats.RecordAllocateRaw(1U, SpaceType::SPACE_TYPE_CODE);
|
||||
ASSERT_EQ(stats.GetAllocated(SpaceType::SPACE_TYPE_CODE), 1U);
|
||||
|
||||
stats.RecordAllocateRaw(2U, SpaceType::SPACE_TYPE_OBJECT);
|
||||
ASSERT_EQ(stats.GetAllocated(SpaceType::SPACE_TYPE_OBJECT), 2U);
|
||||
|
||||
stats.RecordAllocateRaw(3U, SpaceType::SPACE_TYPE_HUMONGOUS_OBJECT);
|
||||
ASSERT_EQ(stats.GetAllocated(SpaceType::SPACE_TYPE_HUMONGOUS_OBJECT), 3U);
|
||||
|
||||
stats.RecordFreeRaw(4U, SpaceType::SPACE_TYPE_CODE);
|
||||
ASSERT_EQ(stats.GetFreed(SpaceType::SPACE_TYPE_CODE), 4U);
|
||||
|
||||
stats.RecordFreeRaw(5U, SpaceType::SPACE_TYPE_OBJECT);
|
||||
ASSERT_EQ(stats.GetFreed(SpaceType::SPACE_TYPE_OBJECT), 5U);
|
||||
|
||||
ASSERT_EQ(5U, stats.GetAllocatedHeap());
|
||||
ASSERT_EQ(5U, stats.GetFreedHeap());
|
||||
}
|
||||
|
||||
} // namespace panda
|
||||
|
41
libpandabase/tests/cframe_layout_test.cpp
Normal file
41
libpandabase/tests/cframe_layout_test.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 <gtest/gtest.h>
|
||||
|
||||
#include "libpandabase/utils/bit_field.h"
|
||||
#include "libpandabase/utils/cframe_layout.h"
|
||||
|
||||
namespace panda::test {
|
||||
|
||||
HWTEST(CFrameLayoutTest, AlignSpillCountTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
CFrameLayout cfl1(Arch::AARCH64, 4U);
|
||||
ASSERT_EQ(cfl1.GetSpillsCount(), 5U);
|
||||
|
||||
CFrameLayout cfl2(Arch::X86_64, 0U);
|
||||
ASSERT_EQ(cfl2.GetSpillsCount(), 0U);
|
||||
|
||||
CFrameLayout cfl3(Arch::AARCH32, 2U);
|
||||
ASSERT_EQ(cfl3.GetSpillsCount(), 7U);
|
||||
|
||||
CFrameLayout cfl4(Arch::AARCH32, 1U);
|
||||
ASSERT_EQ(cfl4.GetSpillsCount(), 5U);
|
||||
|
||||
CFrameLayout cfl5(Arch::X86, 5U);
|
||||
ASSERT_EQ(cfl5.GetSpillsCount(), 5U);
|
||||
}
|
||||
|
||||
} // namespace panda::test
|
@ -58,6 +58,8 @@ HWTEST(JsonParser, ParsePrimitive, testing::ext::TestSize.Level0)
|
||||
|
||||
ASSERT_NE(obj.GetValue<JsonObject::StringT>("key_1"), nullptr);
|
||||
ASSERT_EQ(*obj.GetValue<JsonObject::StringT>("key_1"), "\"key_1\"\\. value\n");
|
||||
|
||||
ASSERT_EQ(obj.GetValue<JsonObject::StringT>("key_2"), nullptr);
|
||||
}
|
||||
|
||||
HWTEST(JsonParser, Arrays, testing::ext::TestSize.Level0)
|
||||
|
@ -42,6 +42,7 @@ HWTEST(libpandargs, TestAPI, testing::ext::TestSize.Level0)
|
||||
PandArg<uint64_t> paur64("ruint64", ref_def_uint64, "uint64 argument with range", 0, 100000000000);
|
||||
|
||||
PandArgParser pa_parser;
|
||||
EXPECT_FALSE(pa_parser.Add(nullptr));
|
||||
EXPECT_TRUE(pa_parser.Add(&pab));
|
||||
EXPECT_TRUE(pa_parser.Add(&pai));
|
||||
EXPECT_TRUE(pa_parser.Add(&pad));
|
||||
@ -152,6 +153,13 @@ HWTEST(libpandargs, TestAPI, testing::ext::TestSize.Level0)
|
||||
EXPECT_EQ(pa_parser.GetTailSize(), 0U);
|
||||
}
|
||||
|
||||
{
|
||||
ASSERT_EQ(pa_parser.GetTailSize(), 0U);
|
||||
ASSERT_FALSE(pa_parser.PushBackTail(nullptr));
|
||||
ASSERT_EQ(pa_parser.GetTailSize(), 0U);
|
||||
ASSERT_FALSE(pa_parser.PopBackTail());
|
||||
}
|
||||
|
||||
// expect help string formed right
|
||||
{
|
||||
std::string ref_string = "--" + pab.GetName() + ": " + pab.GetDesc() + "\n";
|
||||
@ -928,4 +936,28 @@ HWTEST(libpandargs, CompoundArgs, testing::ext::TestSize.Level0)
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST(libpandargs, GetHelpString, testing::ext::TestSize.Level0)
|
||||
{
|
||||
PandArg<bool> pab("bool", false, "Sample boolean argument");
|
||||
PandArg<int> pai("int", 0, "Sample integer argument");
|
||||
PandArg<std::string> t_pas("tail_string", "arg", "Sample tail string argument");
|
||||
PandArgCompound pac("compound", "Sample compound argument", {&pab, &pai});
|
||||
|
||||
PandArgParser pa_parser;
|
||||
ASSERT_TRUE(pa_parser.Add(&pab));
|
||||
ASSERT_TRUE(pa_parser.Add(&pai));
|
||||
ASSERT_TRUE(pa_parser.PushBackTail(&t_pas));
|
||||
ASSERT_TRUE(pa_parser.Add(&pac));
|
||||
|
||||
std::string ref_string = "--" + pab.GetName() + ": " + pab.GetDesc() + "\n";
|
||||
ref_string += "--" + pac.GetName() + ": " + pac.GetDesc() + "\n";
|
||||
ref_string += " Sub arguments:\n";
|
||||
ref_string += " " + pab.GetName() + ": " + pab.GetDesc() + "\n";
|
||||
ref_string += " " + pai.GetName() + ": " + pai.GetDesc() + "\n";
|
||||
ref_string += "--" + pai.GetName() + ": " + pai.GetDesc() + "\n";
|
||||
ref_string += "Tail arguments:\n";
|
||||
ref_string += t_pas.GetName() + ": " + t_pas.GetDesc() + "\n";
|
||||
ASSERT_EQ(pa_parser.GetHelpString(), ref_string);
|
||||
}
|
||||
|
||||
} // namespace panda::test
|
||||
|
@ -155,6 +155,8 @@ HWTEST_F(PoolMapTest, TwoConsistentPoolsTest, testing::ext::TestSize.Level0)
|
||||
// Therefore it must return a pointer to the first pool byte.
|
||||
CheckRandomPoolAddress(second_pool, SECOND_SPACE_TYPE, SECOND_ALLOCATOR_TYPE, SECOND_POOL_ADDR);
|
||||
|
||||
ASSERT_FALSE(IsEmptyPoolMap());
|
||||
|
||||
// Check that we remove elements from pool map correctly
|
||||
RemovePoolFromMap(first_pool);
|
||||
RemovePoolFromMap(second_pool);
|
||||
|
@ -86,4 +86,16 @@ HWTEST(RegMask, Base, testing::ext::TestSize.Level0)
|
||||
TestDistance(mask, 31, 5, 0);
|
||||
}
|
||||
|
||||
HWTEST(RegMask, SetAndDumpTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
RegMask mask(MakeMask(1, 2, 3));
|
||||
ASSERT_EQ(mask.GetValue(), 14U);
|
||||
|
||||
mask.Set(1U, false);
|
||||
ASSERT_EQ(mask.GetValue(), 12U);
|
||||
|
||||
mask.Set(5U, true);
|
||||
ASSERT_EQ(mask.GetValue(), 44U);
|
||||
}
|
||||
|
||||
} // namespace panda::test
|
@ -91,4 +91,23 @@ HWTEST(MemoryTest, RoundMemoryConverterTest, testing::ext::TestSize.Level0)
|
||||
ASSERT_EQ(MemoryConverter(11'121'092), ValueUnit(10.606, "MB"));
|
||||
}
|
||||
|
||||
HWTEST(TypeConverterTest, OperatorEqualTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const uint64_t number_zero = 0UL;
|
||||
const uint64_t number_one = 1UL;
|
||||
ASSERT_TRUE(ValueUnit(10.27, "MB") == ValueUnit(10.27, "MB"));
|
||||
ASSERT_FALSE(ValueUnit(10.27, "MB") == ValueUnit(10.27, "KB"));
|
||||
ASSERT_TRUE(ValueUnit(number_zero, "MB") == ValueUnit(number_zero, "MB"));
|
||||
ASSERT_FALSE(ValueUnit(number_zero, "MB") == ValueUnit(number_zero, "GB"));
|
||||
ASSERT_FALSE(ValueUnit(number_one, "MB") == ValueUnit(number_one, "KB"));
|
||||
}
|
||||
|
||||
HWTEST(TypeConverterTest, ValueConverterTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const uint64_t number = 10UL;
|
||||
ASSERT_EQ(ValueConverter(11'119'272, ValueType::VALUE_TYPE_TIME), ValueUnit(11.119, "ms"));
|
||||
ASSERT_EQ(ValueConverter(11'119'272, ValueType::VALUE_TYPE_MEMORY), ValueUnit(10.604, "MB"));
|
||||
ASSERT_EQ(ValueConverter(number, ValueType::VALUE_TYPE_OBJECT), ValueUnit(number, ""));
|
||||
}
|
||||
|
||||
} // namespace panda::helpers::test
|
||||
|
@ -389,4 +389,34 @@ HWTEST(Utf, CompareUtf8ToUtf8, testing::ext::TestSize.Level0)
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST(Utf, IsMUtf8OnlySingleBytes, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const std::vector<uint8_t> v1 {0x02, 0x00};
|
||||
EXPECT_TRUE(IsMUtf8OnlySingleBytes(v1.data()));
|
||||
|
||||
const std::vector<uint8_t> v2 {0x90, 0x00};
|
||||
EXPECT_FALSE(IsMUtf8OnlySingleBytes(v2.data()));
|
||||
}
|
||||
|
||||
HWTEST(Utf, IsValidModifiedUTF8, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const std::vector<uint8_t> v1 {0x31, 0x00};
|
||||
EXPECT_TRUE(IsValidModifiedUTF8(v1.data()));
|
||||
|
||||
const std::vector<uint8_t> v2 {0x9f};
|
||||
EXPECT_FALSE(IsValidModifiedUTF8(v2.data()));
|
||||
|
||||
const std::vector<uint8_t> v3 {0xf7};
|
||||
EXPECT_FALSE(IsValidModifiedUTF8(v3.data()));
|
||||
|
||||
const std::vector<uint8_t> v4 {0xe0};
|
||||
EXPECT_FALSE(IsValidModifiedUTF8(v4.data()));
|
||||
|
||||
const std::vector<uint8_t> v5 {0xd4};
|
||||
EXPECT_FALSE(IsValidModifiedUTF8(v5.data()));
|
||||
|
||||
const std::vector<uint8_t> v6 {0x11, 0x31, 0x00};
|
||||
EXPECT_TRUE(IsValidModifiedUTF8(v6.data()));
|
||||
}
|
||||
|
||||
} // namespace panda::utf::test
|
||||
|
@ -238,7 +238,7 @@ bool JsonObject::Parser::GetBool()
|
||||
bool JsonObject::Parser::GetValue()
|
||||
{
|
||||
auto symbol = PeekSymbol();
|
||||
size_t pos_start = istream_.tellg();
|
||||
size_t pos_start = static_cast<size_t>(istream_.tellg());
|
||||
bool res = false;
|
||||
switch (symbol) {
|
||||
case 't':
|
||||
@ -283,7 +283,7 @@ bool JsonObject::Parser::GetValue()
|
||||
}
|
||||
|
||||
// Save source string of parsed value:
|
||||
size_t pos_end = istream_.tellg();
|
||||
size_t pos_end = static_cast<size_t>(istream_.tellg());
|
||||
if (pos_end == static_cast<size_t>(-1)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -18,7 +18,10 @@ host_unittest_action("LibPandaFileTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"debug_info_extractor_test.cpp",
|
||||
"file_format_version_test.cpp",
|
||||
"file_item_container_test.cpp",
|
||||
"file_items_test.cpp",
|
||||
"file_test.cpp",
|
||||
]
|
||||
|
||||
@ -34,6 +37,7 @@ host_unittest_action("LibPandaFileTest") {
|
||||
deps = [
|
||||
"$ark_root/assembler:libarkassembler_static",
|
||||
"$ark_root/libpandafile:libarkfile_static",
|
||||
"//third_party/googletest:gmock_main",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ public:
|
||||
std::unique_ptr<const panda_file::File> ExtractorTest::u_file {nullptr};
|
||||
std::vector<uint8_t> ExtractorTest::file_data;
|
||||
|
||||
TEST_F(ExtractorTest, DebugInfoTest)
|
||||
HWTEST_F(ExtractorTest, DebugInfoTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const panda_file::File *pf = u_file.get();
|
||||
ASSERT_TRUE(pf != nullptr);
|
||||
@ -341,14 +341,14 @@ TEST_F(ExtractorTest, DebugInfoTest)
|
||||
ASSERT_EQ(source_location.line, 5U);
|
||||
|
||||
auto vars = GetLocalVariableInfoWrapper(extractor, method_id, 4);
|
||||
EXPECT_EQ(vars.size(), 2);
|
||||
EXPECT_EQ(vars.size(), 2U);
|
||||
ASSERT_EQ(vars[0].name, "local_1");
|
||||
ASSERT_EQ(vars[0].type, "I");
|
||||
ASSERT_EQ(vars[1].name, "local_2");
|
||||
ASSERT_EQ(vars[1].type, "I");
|
||||
}
|
||||
|
||||
TEST_F(ExtractorTest, DebugInfoTestStaticWithRefArg)
|
||||
HWTEST_F(ExtractorTest, DebugInfoTestStaticWithRefArg, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const panda_file::File *pf = u_file.get();
|
||||
ASSERT_TRUE(pf != nullptr);
|
||||
@ -360,10 +360,10 @@ TEST_F(ExtractorTest, DebugInfoTestStaticWithRefArg)
|
||||
ASSERT_TRUE(method_id.IsValid());
|
||||
|
||||
auto vars = GetLocalVariableInfoWrapper(extractor, method_id, 14);
|
||||
EXPECT_EQ(vars.size(), 0);
|
||||
EXPECT_EQ(vars.size(), 0U);
|
||||
}
|
||||
|
||||
TEST_F(ExtractorTest, DebugInfoTestNonStaticWithRefArg)
|
||||
HWTEST_F(ExtractorTest, DebugInfoTestNonStaticWithRefArg, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const panda_file::File *pf = u_file.get();
|
||||
ASSERT_TRUE(pf != nullptr);
|
||||
@ -375,10 +375,10 @@ TEST_F(ExtractorTest, DebugInfoTestNonStaticWithRefArg)
|
||||
ASSERT_TRUE(method_id.IsValid());
|
||||
|
||||
auto vars = GetLocalVariableInfoWrapper(extractor, method_id, 16);
|
||||
EXPECT_EQ(vars.size(), 0);
|
||||
EXPECT_EQ(vars.size(), 0U);
|
||||
}
|
||||
|
||||
TEST_F(ExtractorTest, DebugInfoTestColumnNumber)
|
||||
HWTEST_F(ExtractorTest, DebugInfoTestColumnNumber, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const panda_file::File *pf = u_file.get();
|
||||
ASSERT_TRUE(pf != nullptr);
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
namespace panda::panda_file::test {
|
||||
|
||||
TEST(ItemContainer, DeduplicationTest)
|
||||
HWTEST(ItemContainer, DeduplicationTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ItemContainer container;
|
||||
|
||||
@ -71,7 +71,7 @@ TEST(ItemContainer, DeduplicationTest)
|
||||
EXPECT_NE(double_item, float_item);
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestFileOpen)
|
||||
HWTEST(ItemContainer, TestFileOpen, testing::ext::TestSize.Level0)
|
||||
{
|
||||
using panda::os::file::Mode;
|
||||
using panda::os::file::Open;
|
||||
@ -88,7 +88,7 @@ TEST(ItemContainer, TestFileOpen)
|
||||
EXPECT_NE(File::Open(file_name), nullptr);
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestFileFormatVersionTooOld)
|
||||
HWTEST(ItemContainer, TestFileFormatVersionTooOld, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const std::string file_name = "test_file_format_version_too_old.abc";
|
||||
{
|
||||
@ -96,7 +96,10 @@ TEST(ItemContainer, TestFileFormatVersionTooOld)
|
||||
auto writer = FileWriter(file_name);
|
||||
|
||||
File::Header header;
|
||||
memset(&header, 0, sizeof(header));
|
||||
errno_t res = memset_s(&header, sizeof(header), 0, sizeof(header));
|
||||
if (res != EOK) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
header.magic = File::MAGIC;
|
||||
|
||||
auto old = std::array<uint8_t, File::VERSION_SIZE>(minVersion);
|
||||
@ -113,7 +116,7 @@ TEST(ItemContainer, TestFileFormatVersionTooOld)
|
||||
EXPECT_EQ(File::Open(file_name), nullptr);
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestFileFormatVersionTooNew)
|
||||
HWTEST(ItemContainer, TestFileFormatVersionTooNew, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const std::string file_name = "test_file_format_version_too_new.abc";
|
||||
{
|
||||
@ -121,13 +124,12 @@ TEST(ItemContainer, TestFileFormatVersionTooNew)
|
||||
auto writer = FileWriter(file_name);
|
||||
|
||||
File::Header header;
|
||||
memset(&header, 0, sizeof(header));
|
||||
errno_t res = memset_s(&header, sizeof(header), 0, sizeof(header));
|
||||
if (res != EOK) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
header.magic = File::MAGIC;
|
||||
|
||||
auto new_ = std::array<uint8_t, File::VERSION_SIZE>(minVersion);
|
||||
++new_[3];
|
||||
|
||||
header.version = new_;
|
||||
header.version = {0, 0, 0, 4};
|
||||
header.file_size = sizeof(File::Header);
|
||||
|
||||
for (uint8_t b : Span<uint8_t>(reinterpret_cast<uint8_t *>(&header), sizeof(header))) {
|
||||
@ -138,7 +140,7 @@ TEST(ItemContainer, TestFileFormatVersionTooNew)
|
||||
EXPECT_EQ(File::Open(file_name), nullptr);
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestFileFormatVersionValid)
|
||||
HWTEST(ItemContainer, TestFileFormatVersionValid, testing::ext::TestSize.Level0)
|
||||
{
|
||||
const std::string file_name = "test_file_format_version_valid.abc";
|
||||
{
|
||||
@ -146,7 +148,10 @@ TEST(ItemContainer, TestFileFormatVersionValid)
|
||||
auto writer = FileWriter(file_name);
|
||||
|
||||
File::Header header;
|
||||
memset(&header, 0, sizeof(header));
|
||||
errno_t res = memset_s(&header, sizeof(header), 0, sizeof(header));
|
||||
if (res != EOK) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
header.magic = File::MAGIC;
|
||||
header.version = {0, 0, 0, 2};
|
||||
header.file_size = sizeof(File::Header);
|
||||
@ -166,7 +171,7 @@ static std::unique_ptr<const File> GetPandaFile(std::vector<uint8_t> &data)
|
||||
return File::OpenFromMemory(std::move(ptr));
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestClasses)
|
||||
HWTEST(ItemContainer, TestClasses, testing::ext::TestSize.Level0)
|
||||
{
|
||||
// Write panda file to memory
|
||||
|
||||
@ -236,7 +241,7 @@ TEST(ItemContainer, TestClasses)
|
||||
|
||||
ASSERT_NE(panda_file, nullptr);
|
||||
|
||||
EXPECT_THAT(panda_file->GetHeader()->version, ::testing::ElementsAre(0, 0, 0, 2));
|
||||
EXPECT_THAT(panda_file->GetHeader()->version, ::testing::ElementsAre(0, 0, 0, 3));
|
||||
EXPECT_EQ(panda_file->GetHeader()->file_size, mem_writer.GetData().size());
|
||||
EXPECT_EQ(panda_file->GetHeader()->foreign_off, 0U);
|
||||
EXPECT_EQ(panda_file->GetHeader()->foreign_size, 0U);
|
||||
@ -337,7 +342,7 @@ TEST(ItemContainer, TestClasses)
|
||||
EXPECT_EQ(empty_class_data_accessor.GetSize(), empty_class_item->GetSize());
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestMethods)
|
||||
HWTEST(ItemContainer, TestMethods, testing::ext::TestSize.Level0)
|
||||
{
|
||||
// Write panda file to memory
|
||||
|
||||
@ -503,7 +508,7 @@ void TestProtos(size_t n)
|
||||
});
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestProtos)
|
||||
HWTEST(ItemContainer, TestProtos, testing::ext::TestSize.Level0)
|
||||
{
|
||||
TestProtos(0);
|
||||
TestProtos(1);
|
||||
@ -511,7 +516,7 @@ TEST(ItemContainer, TestProtos)
|
||||
TestProtos(7);
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestDebugInfo)
|
||||
HWTEST(ItemContainer, TestDebugInfo, testing::ext::TestSize.Level0)
|
||||
{
|
||||
// Write panda file to memory
|
||||
|
||||
@ -612,7 +617,7 @@ TEST(ItemContainer, TestDebugInfo)
|
||||
});
|
||||
}
|
||||
|
||||
TEST(ItemContainer, ForeignItems)
|
||||
HWTEST(ItemContainer, ForeignItems, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ItemContainer container;
|
||||
|
||||
@ -667,7 +672,7 @@ TEST(ItemContainer, ForeignItems)
|
||||
EXPECT_TRUE(field_data_accessor.IsExternal());
|
||||
}
|
||||
|
||||
TEST(ItemContainer, EmptyContainerChecksum)
|
||||
HWTEST(ItemContainer, EmptyContainerChecksum, testing::ext::TestSize.Level0)
|
||||
{
|
||||
using panda::os::file::Mode;
|
||||
using panda::os::file::Open;
|
||||
@ -679,12 +684,12 @@ TEST(ItemContainer, EmptyContainerChecksum)
|
||||
auto writer = FileWriter(file_name);
|
||||
|
||||
// Initial value of adler32
|
||||
EXPECT_EQ(writer.GetChecksum(), 1);
|
||||
EXPECT_EQ(writer.GetChecksum(), 1U);
|
||||
ASSERT_TRUE(container.Write(&writer));
|
||||
|
||||
// At least header was written so the checksum should be changed
|
||||
auto container_checksum = writer.GetChecksum();
|
||||
EXPECT_NE(container_checksum, 1);
|
||||
EXPECT_NE(container_checksum, 1U);
|
||||
|
||||
// Read panda file from disk
|
||||
auto file = File::Open(file_name);
|
||||
@ -696,7 +701,7 @@ TEST(ItemContainer, EmptyContainerChecksum)
|
||||
EXPECT_EQ(file->GetHeader()->checksum, checksum);
|
||||
}
|
||||
|
||||
TEST(ItemContainer, ContainerChecksum)
|
||||
HWTEST(ItemContainer, ContainerChecksum, testing::ext::TestSize.Level0)
|
||||
{
|
||||
using panda::os::file::Mode;
|
||||
using panda::os::file::Open;
|
||||
@ -734,7 +739,7 @@ TEST(ItemContainer, ContainerChecksum)
|
||||
EXPECT_EQ(file->GetHeader()->checksum, checksum);
|
||||
}
|
||||
|
||||
TEST(ItemContainer, TestProfileGuidedRelayout)
|
||||
HWTEST(ItemContainer, TestProfileGuidedRelayout, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ItemContainer container;
|
||||
|
||||
@ -924,7 +929,7 @@ TEST(ItemContainer, TestProfileGuidedRelayout)
|
||||
EXPECT_EQ(item, items.end());
|
||||
}
|
||||
|
||||
TEST(ItemContainer, GettersTest)
|
||||
HWTEST(ItemContainer, GettersTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ItemContainer container;
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
namespace panda::panda_file::test {
|
||||
|
||||
TEST(LineNumberProgramItem, EmitSpecialOpcode)
|
||||
HWTEST(LineNumberProgramItem, EmitSpecialOpcode, testing::ext::TestSize.Level0)
|
||||
{
|
||||
LineNumberProgramItem item;
|
||||
|
||||
@ -51,4 +51,17 @@ TEST(LineNumberProgramItem, EmitSpecialOpcode)
|
||||
EXPECT_EQ(writer.GetData(), data);
|
||||
}
|
||||
|
||||
HWTEST(LineNumberProgramItem, LanguageFromAndToString, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ASSERT_EQ(LanguageFromString("not ECMAScript"), static_cast<SourceLang>(1U));
|
||||
ASSERT_STREQ(LanguageToString(SourceLang::ECMASCRIPT), "ECMAScript");
|
||||
ASSERT_STREQ(LanguageToString(SourceLang::PANDA_ASSEMBLY), "PandaAssembly");
|
||||
}
|
||||
|
||||
HWTEST(LineNumberProgramItem, GetStringClassDescriptor, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ASSERT_STREQ(GetStringClassDescriptor(SourceLang::ECMASCRIPT), "Lpanda/JSString;");
|
||||
ASSERT_STREQ(GetStringClassDescriptor(SourceLang::PANDA_ASSEMBLY), "Lpanda/String;");
|
||||
}
|
||||
|
||||
} // namespace panda::panda_file::test
|
||||
|
Loading…
Reference in New Issue
Block a user