Codecheck fixes

Issue: #IAE151

Testing: tests benchmarks

Signed-off-by: Sizov Nikita <sizov.nikita@huawei.com>
This commit is contained in:
Sizov Nikita 2024-07-19 19:00:51 +03:00
parent 0425c3bb1c
commit 92b4d149a1
7 changed files with 109 additions and 79 deletions

View File

@ -43,11 +43,11 @@ enum class EtsNapiException {
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define RETURN_NULL_IF_NULL(ptr) \
do { \
{ \
if ((ptr) == nullptr) { \
return nullptr; \
} \
} while (false);
}
class ManagedCodeAccessor {
public:

View File

@ -65,9 +65,9 @@ def write_snippet_line(line, space_len, ets_file, ts_file=None):
def write_code_meta(expect_cte, frontend_status, expect_subset, file):
file.write("// " + expect_cte + "\n")
file.write("// " + frontend_status + "\n")
file.write("// " + expect_subset + "\n")
file.write("//" + expect_cte + "\n")
file.write("//" + frontend_status + "\n")
file.write("//" + expect_subset + "\n")
def write_snippet(rst_lines, snippet_name, snippet_meta, previous_snippet_name, frontend_statuses):

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -93,7 +93,7 @@ TEST_F(EffectiveTypeTest, TestGetStaticMethod)
{
ets_class testClass = env->FindClass("EffectiveTypes");
ASSERT_NE(testClass, nullptr);
std::array<EtsNativeMethod, 4> native_methods {
std::array<EtsNativeMethod, 4U> native_methods {
EtsNativeMethod {"foo", "I:I", reinterpret_cast<void *>(effective_types_foo_I)},
EtsNativeMethod {"foo", "D:I", reinterpret_cast<void *>(effective_types_foo_D)},
EtsNativeMethod {"foo", ":D", reinterpret_cast<void *>(effective_types_foo)},

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -145,6 +145,18 @@ static void AssertPrimitiveContainerClassRoot(EtsClassLinker *classLinker, EtsCl
ASSERT_EQ(klass->GetBase(), classLinker->GetClassRoot(EtsClassRoot::OBJECT));
}
static void AssertPrimitiveClassRoots(EtsClassLinker *classLinker)
{
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::BOOLEAN);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::BYTE);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::SHORT);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::CHAR);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::INT);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::LONG);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::FLOAT);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::DOUBLE);
}
TEST_F(EtsVMTest, InitTest)
{
auto runtime = Runtime::GetCurrent();
@ -167,14 +179,7 @@ TEST_F(EtsVMTest, InitTest)
AssertCompoundContainerClassRoot(classLinker, EtsClassRoot::STRING_ARRAY);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::BOOLEAN);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::BYTE);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::SHORT);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::CHAR);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::INT);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::LONG);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::FLOAT);
AssertPrimitiveClassRoot(classLinker, EtsClassRoot::DOUBLE);
AssertPrimitiveClassRoots(classLinker);
AssertPrimitiveContainerClassRoot(classLinker, EtsClassRoot::BOOLEAN_ARRAY);
AssertPrimitiveContainerClassRoot(classLinker, EtsClassRoot::BYTE_ARRAY);

View File

@ -25,6 +25,48 @@
namespace ark::ets::test {
namespace {
void InSamePackagePrologue()
{
{
const char *source = R"(
.language eTS
.record Test {}
)";
EtsClass *klass = GetTestClass(source, "LTest;");
ASSERT_NE(klass, nullptr);
EtsArray *array1 = EtsObjectArray::Create(klass, 1000U);
EtsArray *array2 = EtsFloatArray::Create(1000U);
ASSERT_NE(array1, nullptr);
ASSERT_NE(array2, nullptr);
EtsClass *klass1 = array1->GetClass();
EtsClass *klass2 = array2->GetClass();
ASSERT_NE(klass1, nullptr);
ASSERT_NE(klass2, nullptr);
ASSERT_TRUE(klass1->IsInSamePackage(klass2));
}
{
EtsArray *array1 = EtsFloatArray::Create(1000U);
EtsArray *array2 = EtsIntArray::Create(1000U);
ASSERT_NE(array1, nullptr);
ASSERT_NE(array2, nullptr);
EtsClass *klass1 = array1->GetClass();
EtsClass *klass2 = array2->GetClass();
ASSERT_NE(klass1, nullptr);
ASSERT_NE(klass2, nullptr);
ASSERT_TRUE(klass1->IsInSamePackage(klass2));
}
}
} // namespace
class EtsClassTest : public testing::Test {
public:
EtsClassTest()
@ -668,40 +710,8 @@ TEST_F(EtsClassTest, IsInSamePackage)
ASSERT_FALSE(EtsClass::IsInSamePackage("LA/B;", "LA/B/C;"));
ASSERT_FALSE(EtsClass::IsInSamePackage("LA/B/C;", "LA/B;"));
{
const char *source = R"(
.language eTS
.record Test {}
)";
InSamePackagePrologue();
EtsClass *klass = GetTestClass(source, "LTest;");
ASSERT_NE(klass, nullptr);
EtsArray *array1 = EtsObjectArray::Create(klass, 1000);
EtsArray *array2 = EtsFloatArray::Create(1000);
ASSERT_NE(array1, nullptr);
ASSERT_NE(array2, nullptr);
EtsClass *klass1 = array1->GetClass();
EtsClass *klass2 = array2->GetClass();
ASSERT_NE(klass1, nullptr);
ASSERT_NE(klass2, nullptr);
ASSERT_TRUE(klass1->IsInSamePackage(klass2));
}
{
EtsArray *array1 = EtsFloatArray::Create(1000);
EtsArray *array2 = EtsIntArray::Create(1000);
ASSERT_NE(array1, nullptr);
ASSERT_NE(array2, nullptr);
EtsClass *klass1 = array1->GetClass();
EtsClass *klass2 = array2->GetClass();
ASSERT_NE(klass1, nullptr);
ASSERT_NE(klass2, nullptr);
ASSERT_TRUE(klass1->IsInSamePackage(klass2));
}
{
const char *source = R"(
.language eTS

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -21,31 +21,8 @@
namespace ark::ets::test {
// NOTE(a.urakov): move initialization to a common internal objects testing base class
class EtsMethodSignatureTest : public testing::Test {
public:
EtsMethodSignatureTest()
{
RuntimeOptions options;
options.SetShouldLoadBootPandaFiles(false);
options.SetShouldInitializeIntrinsics(false);
options.SetCompilerEnableJit(false);
options.SetGcType("epsilon");
options.SetLoadRuntimes({"ets"});
Runtime::Create(options);
}
~EtsMethodSignatureTest() override
{
Runtime::Destroy();
}
NO_COPY_SEMANTIC(EtsMethodSignatureTest);
NO_MOVE_SEMANTIC(EtsMethodSignatureTest);
};
TEST_F(EtsMethodSignatureTest, MethodSignature)
namespace {
void MethodSignaturePrologue()
{
EtsMethodSignature minimal(":V");
EXPECT_EQ(minimal.GetProto(), Method::Proto(
@ -74,6 +51,38 @@ TEST_F(EtsMethodSignatureTest, MethodSignature)
panda_file::Type {panda_file::Type::TypeId::F64},
},
Method::Proto::RefTypeVector {}));
}
} // namespace
// NOTE(a.urakov): move initialization to a common internal objects testing base class
class EtsMethodSignatureTest : public testing::Test {
public:
EtsMethodSignatureTest()
{
RuntimeOptions options;
options.SetShouldLoadBootPandaFiles(false);
options.SetShouldInitializeIntrinsics(false);
options.SetCompilerEnableJit(false);
options.SetGcType("epsilon");
options.SetLoadRuntimes({"ets"});
Runtime::Create(options);
}
~EtsMethodSignatureTest() override
{
Runtime::Destroy();
}
NO_COPY_SEMANTIC(EtsMethodSignatureTest);
NO_MOVE_SEMANTIC(EtsMethodSignatureTest);
};
TEST_F(EtsMethodSignatureTest, MethodSignature)
{
MethodSignaturePrologue();
EtsMethodSignature arrays("SB[J[Lstd/core/String;I:LT;");
EXPECT_EQ(arrays.GetProto(), Method::Proto(
Method::Proto::ShortyVector {

View File

@ -98,8 +98,9 @@ class EtsBenchmarksRunner:
self.aot_opts = aot_opts
def dump_output_to_file(self, pipe, file_ext):
dumpfile = open(os.path.join(self.host_output_dir,
self.current_bench_name, f"test.{file_ext}"), "w")
dumpfile = os.fdopen(os.open(os.path.join(self.host_output_dir,
self.current_bench_name, f"test.{file_ext}"),
os.O_RDWR|os.O_CREAT, 0o755), "w")
dumpfile.write(pipe.decode('ascii'))
dumpfile.close()
@ -170,8 +171,13 @@ class EtsBenchmarksRunner:
self.host_output_dir, self.current_bench_name)
tmp_asm_file_path = os.path.join(current_output_dir, "test.pa")
os.system(f"mkdir -p {current_output_dir}")
open(tmp_asm_file_path, "w").write(open(self.wrapper_asm_filepath, "r").read() +
open(base_asm_file_path, "r").read())
fd_read = os.open(self.wrapper_asm_filepath, os.O_RDONLY, 0o755)
fd_read_two = os.open(base_asm_file_path, os.O_RDONLY, 0o755)
file_to_read = os.fdopen(fd_read, "r")
file_to_read_two = os.fdopen(fd_read_two, "r")
os.fdopen(os.open(tmp_asm_file_path, os.O_WRONLY | os.O_CREAT, 0o755), "w").write(file_to_read.read() +
file_to_read_two.read())
if self.is_device:
device_current_output_dir = os.path.join(
self.device_output_dir, self.current_bench_name)