From 92b4d149a1d284eaa334d765c5a2fee33bc85c8e Mon Sep 17 00:00:00 2001 From: Sizov Nikita Date: Fri, 19 Jul 2024 19:00:51 +0300 Subject: [PATCH] Codecheck fixes Issue: #IAE151 Testing: tests benchmarks Signed-off-by: Sizov Nikita --- .../ets/runtime/napi/ets_scoped_objects_fix.h | 4 +- .../plugins/ets/snippet_verifier/verify.py | 6 +- .../ets/tests/mock/effective_types_test.cpp | 4 +- .../plugins/ets/tests/runtime/ets_vm_test.cpp | 23 +++--- .../tests/runtime/types/ets_class_test.cpp | 76 +++++++++++-------- .../types/ets_method_signature_test.cpp | 61 ++++++++------- .../micro-benchmarks/run_micro_benchmarks.py | 14 +++- 7 files changed, 109 insertions(+), 79 deletions(-) diff --git a/static_core/plugins/ets/runtime/napi/ets_scoped_objects_fix.h b/static_core/plugins/ets/runtime/napi/ets_scoped_objects_fix.h index 490fc529c3..afe1e37df3 100644 --- a/static_core/plugins/ets/runtime/napi/ets_scoped_objects_fix.h +++ b/static_core/plugins/ets/runtime/napi/ets_scoped_objects_fix.h @@ -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: diff --git a/static_core/plugins/ets/snippet_verifier/verify.py b/static_core/plugins/ets/snippet_verifier/verify.py index 7403b8d9ff..be2d4dab0c 100755 --- a/static_core/plugins/ets/snippet_verifier/verify.py +++ b/static_core/plugins/ets/snippet_verifier/verify.py @@ -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): diff --git a/static_core/plugins/ets/tests/mock/effective_types_test.cpp b/static_core/plugins/ets/tests/mock/effective_types_test.cpp index 0eeb127753..a58fef0bef 100644 --- a/static_core/plugins/ets/tests/mock/effective_types_test.cpp +++ b/static_core/plugins/ets/tests/mock/effective_types_test.cpp @@ -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 native_methods { + std::array native_methods { EtsNativeMethod {"foo", "I:I", reinterpret_cast(effective_types_foo_I)}, EtsNativeMethod {"foo", "D:I", reinterpret_cast(effective_types_foo_D)}, EtsNativeMethod {"foo", ":D", reinterpret_cast(effective_types_foo)}, diff --git a/static_core/plugins/ets/tests/runtime/ets_vm_test.cpp b/static_core/plugins/ets/tests/runtime/ets_vm_test.cpp index 6c072eec44..f4073ec899 100644 --- a/static_core/plugins/ets/tests/runtime/ets_vm_test.cpp +++ b/static_core/plugins/ets/tests/runtime/ets_vm_test.cpp @@ -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); diff --git a/static_core/plugins/ets/tests/runtime/types/ets_class_test.cpp b/static_core/plugins/ets/tests/runtime/types/ets_class_test.cpp index 843df54fe7..eec4f1c722 100644 --- a/static_core/plugins/ets/tests/runtime/types/ets_class_test.cpp +++ b/static_core/plugins/ets/tests/runtime/types/ets_class_test.cpp @@ -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 diff --git a/static_core/plugins/ets/tests/runtime/types/ets_method_signature_test.cpp b/static_core/plugins/ets/tests/runtime/types/ets_method_signature_test.cpp index 17297d03dd..516ebb443c 100644 --- a/static_core/plugins/ets/tests/runtime/types/ets_method_signature_test.cpp +++ b/static_core/plugins/ets/tests/runtime/types/ets_method_signature_test.cpp @@ -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 { diff --git a/static_core/plugins/ets/tests/scripts/micro-benchmarks/run_micro_benchmarks.py b/static_core/plugins/ets/tests/scripts/micro-benchmarks/run_micro_benchmarks.py index 5a4183e49d..d4db5ba609 100644 --- a/static_core/plugins/ets/tests/scripts/micro-benchmarks/run_micro_benchmarks.py +++ b/static_core/plugins/ets/tests/scripts/micro-benchmarks/run_micro_benchmarks.py @@ -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)