From 3bc96ec3519fee7ad7bb5a0ee3e886ad3aae94e8 Mon Sep 17 00:00:00 2001 From: Sergei Shadrin Date: Thu, 8 Dec 2022 15:05:49 +0000 Subject: [PATCH] Add test - read source file from debug info Change-Id: Id19bce62edc14af72f2aa1e1328f1476783b72f0 Signed-off-by: Sergei Shadrin --- tests/runtime/tooling/CMakeLists.txt | 34 ++++++++++++++++ .../runtime/tooling/ets/BitopsBitwiseAnd.ets | 32 +++++++++++++++ tests/runtime/tooling/test_debug_info.cpp | 40 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 tests/runtime/tooling/ets/BitopsBitwiseAnd.ets create mode 100644 tests/runtime/tooling/test_debug_info.cpp diff --git a/tests/runtime/tooling/CMakeLists.txt b/tests/runtime/tooling/CMakeLists.txt index 5133ffa7a..efb8bd87e 100644 --- a/tests/runtime/tooling/CMakeLists.txt +++ b/tests/runtime/tooling/CMakeLists.txt @@ -56,3 +56,37 @@ add_gtests( arkruntime_ecmascript_options_test options_test/options_test.cpp ) + +panda_add_gtest( + NO_CORES + NAME debug_info_tests_ecma + SOURCES + test_debug_info.cpp + LIBRARIES + arkfile arkruntime + INCLUDE_DIRS + ${PANDA_ROOT} + SANITIZERS + ${PANDA_SANITIZERS_LIST} +) +add_dependencies(debug_info_tests_ecma arkstdlib) +target_compile_definitions(debug_info_tests_ecma + PRIVATE TEST_FILE="${CMAKE_CURRENT_BINARY_DIR}/ets/BitopsBitwiseAnd.abc" +) + +# test that stdlib is generated successfully with debug info +add_custom_target(es2panda_build_ets_stdlib +COMMAND echo "Build ets stdlib with debug info: plugins/ets/stdlib/std/" +COMMAND ${PANDA_RUN_PREFIX} $ --opt-level=0 --debug-info --gen-stdlib=true + --extension=ets --stdlib=${CMAKE_SOURCE_DIR}/plugins/ets/stdlib/std/ + ${CMAKE_CURRENT_SOURCE_DIR}/ets/BitopsBitwiseAnd.ets --output ${CMAKE_CURRENT_BINARY_DIR}/etsstdlib.abc +) + +add_custom_target(es2panda_convert_ets +COMMAND echo "Convert ets: ets/BitopsBitwiseAnd.ets to ets/BitopsBitwiseAnd.abc" +COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/ets/" +COMMAND ${PANDA_RUN_PREFIX} $ --opt-level=0 --debug-info --gen-stdlib=false + --extension=ets --stdlib=${CMAKE_SOURCE_DIR}/plugins/ets/stdlib/std/ + ${CMAKE_CURRENT_SOURCE_DIR}/ets/BitopsBitwiseAnd.ets --output ${CMAKE_CURRENT_BINARY_DIR}/ets/BitopsBitwiseAnd.abc +) +add_dependencies(debug_info_tests_ecma_gtests es2panda_convert_ets es2panda_build_ets_stdlib) diff --git a/tests/runtime/tooling/ets/BitopsBitwiseAnd.ets b/tests/runtime/tooling/ets/BitopsBitwiseAnd.ets new file mode 100644 index 000000000..c6b7e22fb --- /dev/null +++ b/tests/runtime/tooling/ets/BitopsBitwiseAnd.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + + +export class BitopsBitwiseAnd { + n: int = 600000; + static const expected: long = 0; + + public run(): void { + let bitwiseAndValue: long = 4294967296; + for (let i: int = 0; i < this.n; i++) { + bitwiseAndValue = bitwiseAndValue & i; + } + if (bitwiseAndValue != this.expected) { + //System.err.println("ERROR: bad result: expected " + expected + " but got " + bitwiseAndValue); + //System.exit(-1); + } + } +} + diff --git a/tests/runtime/tooling/test_debug_info.cpp b/tests/runtime/tooling/test_debug_info.cpp new file mode 100644 index 000000000..6cbd729ab --- /dev/null +++ b/tests/runtime/tooling/test_debug_info.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021-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 "debug_info_extractor.h" +#include "file.h" +#include "gtest/gtest.h" +#include "os/filesystem.h" + +namespace panda::test { + +class DebugInfoTest : public testing::Test { +public: + void SetUp() override {} + + void TearDown() override {} +}; + +TEST_F(DebugInfoTest, GetSourceFile) +{ + auto file = panda_file::OpenPandaFile(TEST_FILE); + panda_file::DebugInfoExtractor extractor(file.get()); + auto methods = extractor.GetMethodIdList(); + ASSERT_FALSE(methods.empty()); + auto source_file_path = extractor.GetSourceFile(methods[0]); + ASSERT_TRUE(os::IsFileExists(source_file_path)); +} + +} // namespace panda::test -- Gitee