diff --git a/lldb/include/lldb/Utility/Timer.h b/lldb/include/lldb/Utility/Timer.h index d046861cc30f0a110aa9831cc277384c6a860a20..04573c8caa1660eaaa956c3cb8aa187473fcce83 100644 --- a/lldb/include/lldb/Utility/Timer.h +++ b/lldb/include/lldb/Utility/Timer.h @@ -76,8 +76,7 @@ private: const Timer &operator=(const Timer &) = delete; }; // OHOS_LOCAL begin -namespace LLDBPerformanceTagName -{ +namespace LLDBPerformanceTagName { const char *const TAG_DYNAMICLOADER = "LLDB_Performance_DynamicLoader"; const char *const TAG_BREAKPOINTS = "LLDB_Performance_Breakpoints"; const char *const TAG_CONNECTION = "LLDB_Performance_Connection"; diff --git a/lldb/test/API/lldb_time_test/LLDB_time_test_manual.md b/lldb/test/API/lldb_time_test/LLDB_time_test_manual.md index d34327a2567d28905e0dfcdb5d669999dec5b9c3..4cef302d2957e338a8a7ba6f994f4f7c1b1bbc99 100644 --- a/lldb/test/API/lldb_time_test/LLDB_time_test_manual.md +++ b/lldb/test/API/lldb_time_test/LLDB_time_test_manual.md @@ -70,6 +70,6 @@ For example: ##### Report: -After the test script has been executed, reports are generated in the report folder located in the same directory as each test case. +After executing the test script, reports are generated in the report directory, which is located in the same directory where the test script is run. +For example: `lldb_time_test/report/lldb_time_test/attach/test_attach_to_process_with_id_api/report.csv` -For example: `lldb_time_test/attach/report/test_attach_to_process_with_name_api.csv` diff --git a/lldb/test/API/lldb_time_test/TimeTestBase.py b/lldb/test/API/lldb_time_test/TimeTestBase.py index 11ce4f97f9d3d8482a32fc5f020534509b5843e5..77c8ef78cdcf1f7697bdde334048c0197a9d241b 100644 --- a/lldb/test/API/lldb_time_test/TimeTestBase.py +++ b/lldb/test/API/lldb_time_test/TimeTestBase.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,17 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -from lldbsuite.test.lldbtest import TestBase -import shutil -import json -import lldb import csv +import json import os +import shutil +from pathlib import Path + +import lldb + +from lldbsuite.test.lldbtest import TestBase class LogTagTime: - def __init__(self, id=None, value=0, expect=None, msg=None): - self.id = id + def __init__(self, name=None, value=0, expect=None, msg=None): + self.name = name self.value = value self.expect = expect self.msg = msg @@ -36,6 +41,7 @@ class TimeTestBase(TestBase): results = list() def setUp(self): + self.hdc_path = os.environ.get("HDC") # Remove cache run_with_cache = eval(os.environ.get("RUN_WITH_CACHE", "TRUE")) cache = os.path.join(os.path.expanduser("~"), ".lldb", "module_cache") @@ -43,10 +49,6 @@ class TimeTestBase(TestBase): lldb.SBModule.GarbageCollectAllocatedModules() shutil.rmtree(cache, True) TestBase.setUp(self) - - self.log = "%s.log" % self._testMethodName - self.report = "%s_report.csv" % self._testMethodName - # Set log and report self.set_log_and_report() # Log enable lldb performance -T @@ -61,18 +63,33 @@ class TimeTestBase(TestBase): os.remove(self.log) TestBase.tearDown(self) + def _create_dir_if_not_existent(self, dirPath: Path): + if dirPath.exists() and not dirPath.is_dir(): + raise RuntimeException(f"'{report_dir}' exits and is not a directory") + elif not dirPath.exists(): + dirPath.mkdir(parents=True) + + def _remove_file_if_existent(self, filePath: Path): + if not filePath.exists(): + return + if not filePath.is_file(): + raise RuntimeException( + f"'{filePath}' is expected to be a file, but it is not" + ) + filePath.unlink() + def set_log_and_report(self): - # Set log and report\ - default_report_dir = os.path.join(os.getcwd(), "report") - self.report = os.path.join(default_report_dir, self.report) - self.log = os.path.join(default_report_dir, self.log) - if not os.path.exists(default_report_dir): - os.mkdir(default_report_dir) + # Set log and report + report_dir = Path(os.getcwd(), "report") + working_dir = os.environ.get("OH_LLDB_TEST_DIR", report_dir) + if working_dir: + report_dir = Path(working_dir, "report", self.mydir, self._testMethodName) + self._create_dir_if_not_existent(report_dir) + self.report = report_dir / "report.csv" + self.log = report_dir / "lldb.log" self.reset_time_test_suite() - if os.path.exists(self.log): - os.remove(self.log) - self.log_file_write = open(self.log, "w") - sbf = lldb.SBFile(self.log_file_write.fileno(), "w", False) + self.log_file_write = os.open(self.log, os.O_CREAT | os.O_RDWR, 0o664) + sbf = lldb.SBFile(self.log_file_write, "w", False) self.dbg.SetOutputFile(sbf) def init_benchmark(self, benchmark_json): @@ -107,7 +124,7 @@ class TimeTestBase(TestBase): self.dbg.GetErrorFile().Flush() self.assertTrue(ret.Succeeded()) self.dump_timers_log = ret.GetOutput() - self.log_file_write.write(self.dump_timers_log) + os.write(self.log_file_write, self.dump_timers_log.encode()) def lldb_assert(self, expr, msg=""): """Check that the expression is true.""" @@ -122,7 +139,8 @@ class TimeTestBase(TestBase): percentage = total_time / benchmark_time if percentage < benchmark_range[0] or percentage > benchmark_range[1]: output_msg = ( - "LLDBTestTotalTime: actual time: %.9f, benchmark time: %.9f, range: %.2f%%~%.2f%%, actual percentage: %.2f%%" + """LLDBTestTotalTime: actual time: %.9f, benchmark time: %.9f, """ + """benchmark range: %.2f%%~%.2f%%, actual percentage: %.2f%%.""" % ( total_time, benchmark_time, @@ -158,7 +176,7 @@ class TimeTestBase(TestBase): end_decimal = None tags = [start, end] for tag in tags: - with open(self.log, "r+") as fo: + with open(self.log, "r") as fo: for line in fo.readlines(): line = line.strip() num = line.find(tag) @@ -195,26 +213,27 @@ class TimeTestBase(TestBase): rows = list() headers = ["tag", "actual time", "benchmark", "range", "actual percentage"] for result in self.results: - benchmark_time = benchmark.get(result.id).get("benchmark") - range = benchmark.get(result.id).get("range") + benchmark_time = benchmark.get(result.name).get("benchmark") + benchmark_range = benchmark.get(result.name).get("range") percentage = result.value / benchmark_time * 100 rows.append( [ - result.id, + result.name, "%.9f" % result.value, benchmark_time, - "[%.2f%%, %.2f%%]" % (range[0] * 100, range[1] * 100), + "[%.2f%%, %.2f%%]" + % (benchmark_range[0] * 100, benchmark_range[1] * 100), "%.2f%%" % percentage, ] ) - with open(self.report, "w", newline="") as f: - f_csv = csv.writer(f) - f_csv.writerow(headers) - f_csv.writerows(rows) + report_fd = os.open(self.report, os.O_CREAT | os.O_RDWR, 0o664) + report_csvfile = os.fdopen(report_fd, "w") + f_csv = csv.writer(report_csvfile) + f_csv.writerow(headers) + f_csv.writerows(rows) + report_csvfile.close() def reset_time_test_suite(self): - if os.path.exists(self.report): - os.remove(self.report) - if os.path.exists(self.log): - os.remove(self.log) + self._remove_file_if_existent(self.report) + self._remove_file_if_existent(self.log) self.results.clear() diff --git a/lldb/test/API/lldb_time_test/attach/Makefile b/lldb/test/API/lldb_time_test/attach/Makefile deleted file mode 100644 index 58f6da16656d17852b3e61c31e3a32640c80b38a..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/attach/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2023 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. -C_SOURCES := attach.c - -include Makefile.rules diff --git a/lldb/test/API/lldb_time_test/attach/Makefile b/lldb/test/API/lldb_time_test/attach/Makefile new file mode 120000 index 0000000000000000000000000000000000000000..c48a845d5e29c72caf2f676ea7732b0978d1966d --- /dev/null +++ b/lldb/test/API/lldb_time_test/attach/Makefile @@ -0,0 +1 @@ +../../python_api/hello_world/Makefile \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/attach/TestAttachAPI.py b/lldb/test/API/lldb_time_test/attach/TestAttachAPI.py index 984710a7b2fcc3187e4f44a1fe775c854590aca9..80aa32b6a5d08f4fe92866b802a25bcedaa7602d 100644 --- a/lldb/test/API/lldb_time_test/attach/TestAttachAPI.py +++ b/lldb/test/API/lldb_time_test/attach/TestAttachAPI.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,9 +15,10 @@ # limitations under the License. import lldb -from lldbsuite.test.decorators import skipOnOpenHarmonyCI, skipIf -from lldb_time_test.TimeTestBase import TimeTestBase + +from lldbsuite.test.decorators import skipIf, skipOnOpenHarmonyCI from lldbsuite.test import lldbutil +from lldb_time_test.TimeTestBase import TimeTestBase class TestAttachAPI(TimeTestBase): @@ -56,7 +59,7 @@ class TestAttachAPI(TimeTestBase): # Destroy process lldb.remote_platform.Kill(popen.pid) - self.lldb_assert_total_time("Attach Start", "CompleteAttach end") + self.lldb_assert_total_time("Attach start", "CompleteAttach end") @skipOnOpenHarmonyCI @skipIf(remote=False) @@ -87,4 +90,4 @@ class TestAttachAPI(TimeTestBase): # Destroy process lldb.remote_platform.Kill(popen.pid) - self.lldb_assert_total_time("Attach Start", "CompleteAttach end") + self.lldb_assert_total_time("Attach start", "CompleteAttach end") diff --git a/lldb/test/API/lldb_time_test/attach/attach.c b/lldb/test/API/lldb_time_test/attach/attach.c deleted file mode 100644 index c527eb237fd951385869ca42821f77e09099c500..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/attach/attach.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2023 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 -#ifdef _MSC_VER -#include -#define sleep(x) Sleep((x)*1000) -#else -#include -#endif - -int main(int argc, char const *argv[]) { - printf("Hello world.\n"); // Set break point at this line. - if (argc == 1) - return 1; - - // Create the synchronization token. - FILE *f; - if (f = fopen(argv[1], "wx")) { - fputs("\n", f); - fflush(f); - fclose(f); - } else - return 1; - - // Waiting to be attached by the debugger, otherwise. - while (1) - sleep(1); // Waiting to be attached... -} diff --git a/lldb/test/API/lldb_time_test/attach/main.c b/lldb/test/API/lldb_time_test/attach/main.c new file mode 120000 index 0000000000000000000000000000000000000000..056e2e1862f991b730edd4e4ca1fdc8c976d2914 --- /dev/null +++ b/lldb/test/API/lldb_time_test/attach/main.c @@ -0,0 +1 @@ +../../python_api/hello_world/main.c \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/attach_hap/TestAttachToHap.py b/lldb/test/API/lldb_time_test/attach_hap/TestAttachToHap.py index 4d5f6ac1ac779ccfb6bc1d29f404f078ec8b1691..f79603cdf31eeefa9050df1686f0bbccbd6519f9 100644 --- a/lldb/test/API/lldb_time_test/attach_hap/TestAttachToHap.py +++ b/lldb/test/API/lldb_time_test/attach_hap/TestAttachToHap.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,11 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import subprocess -import lldb import os +import subprocess + +from lldbsuite.test.decorators import skipIf, skipOnOpenHarmonyCI, skipUnlessPlatform from lldb_time_test.TimeTestBase import TimeTestBase -from lldbsuite.test.decorators import skipOnOpenHarmonyCI, skipIf, skipUnlessPlatform class TestAttachHap(TimeTestBase): @@ -27,7 +29,7 @@ class TestAttachHap(TimeTestBase): TimeTestBase.setUp(self) # Init benchmark JSON file self.init_benchmark("benchmark_usb.json") - self.package_name = "com.hw.lldbperformancetestapp" + self.package_name = "com.myapplication" @skipOnOpenHarmonyCI @skipIf(remote=False) @@ -36,25 +38,25 @@ class TestAttachHap(TimeTestBase): # install app hap_path = os.path.join(os.path.dirname(__file__), "entry-default-signed.hap") subprocess.run( - ["hdc", "install", "-r", hap_path], + [self.hdc_path, "install", "-r", hap_path], stdout=subprocess.PIPE, ) # start hap subprocess.run( [ - "hdc", + self.hdc_path, "shell", "aa", "start", "-a", - "%s.MainAbility" % self.package_name, + "EntryAbility", "-b", self.package_name, ], stdout=subprocess.PIPE, ) ret = subprocess.run( - ["hdc", "shell", "pidof", self.package_name], + [self.hdc_path, "shell", "pidof", self.package_name], stdout=subprocess.PIPE, ) pid = int(ret.stdout.decode("utf-8").strip()) @@ -65,4 +67,4 @@ class TestAttachHap(TimeTestBase): # Attach hap process by pid self.handle_cmd("attach -p %s" % str(pid)) - self.lldb_assert_total_time("Attach Start", "CompleteAttach end") + self.lldb_assert_total_time("Attach start", "CompleteAttach end") diff --git a/lldb/test/API/lldb_time_test/attach_hap/entry-default-signed.hap b/lldb/test/API/lldb_time_test/attach_hap/entry-default-signed.hap index 2b68e22c6451fe277c77d985c1ada028b667d236..16d3ec51f3e5a3bc519c7bc1969d2836e820d07a 100644 Binary files a/lldb/test/API/lldb_time_test/attach_hap/entry-default-signed.hap and b/lldb/test/API/lldb_time_test/attach_hap/entry-default-signed.hap differ diff --git a/lldb/test/API/lldb_time_test/frame_variable/Makefile b/lldb/test/API/lldb_time_test/frame_variable/Makefile deleted file mode 100644 index 9da91e2beba2b388e3feb129675efa9f37bb7431..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/frame_variable/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2023 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. -C_SOURCES := frame_variable.c - -include Makefile.rules diff --git a/lldb/test/API/lldb_time_test/frame_variable/Makefile b/lldb/test/API/lldb_time_test/frame_variable/Makefile new file mode 120000 index 0000000000000000000000000000000000000000..1125e4387a0bd93195d800a3ab7a09d4924d0d5a --- /dev/null +++ b/lldb/test/API/lldb_time_test/frame_variable/Makefile @@ -0,0 +1 @@ +../../python_api/frame/get-variables/Makefile \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/frame_variable/TestFrameVariable.py b/lldb/test/API/lldb_time_test/frame_variable/TestFrameVariable.py index ce74cda06544138b1eadf00339aa56836a18581a..b0fe3ea422026f9c56d78eb08a2cdae1e5de5f8a 100644 --- a/lldb/test/API/lldb_time_test/frame_variable/TestFrameVariable.py +++ b/lldb/test/API/lldb_time_test/frame_variable/TestFrameVariable.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,15 +15,16 @@ # limitations under the License. import lldb -from lldb_time_test.TimeTestBase import TimeTestBase -from lldbsuite.test import lldbutil + +from lldbsuite.test.decorators import skipIf, skipOnOpenHarmonyCI from lldbsuite.test.lldbtest import line_number -from lldbsuite.test.decorators import skipOnOpenHarmonyCI, skipIf +from lldbsuite.test import lldbutil +from lldb_time_test.TimeTestBase import TimeTestBase -def get_names_from_vars(vars): +def get_names_from_vars(variables): names = list() - value_list = vars.splitlines() + value_list = variables.splitlines() for value in value_list: start = value.find(")") + 2 end = value.find("=") - 1 @@ -40,9 +43,9 @@ class TestFrameVariable(TimeTestBase): # Init benchmark JSON file self.init_benchmark("benchmark_usb.json") - def verify_variable_names(self, description, vars, names): + def verify_variable_names(self, description, variables, names): copy_names = list(names) - actual_names = get_names_from_vars(vars) + actual_names = get_names_from_vars(variables) for name in actual_names: if name in copy_names: copy_names.remove(name) @@ -66,9 +69,9 @@ class TestFrameVariable(TimeTestBase): self.lldb_assert(target, "target is not valid") # Set breakpoint - line = line_number("frame_variable.c", "// breakpoint 1") - breakpoint = target.BreakpointCreateByLocation("frame_variable.c", line) - self.lldb_assert(breakpoint.GetNumLocations() >= 1, "process is not valid") + line = line_number("main.c", "// breakpoint 3") + bk = target.BreakpointCreateByLocation("main.c", line) + self.lldb_assert(bk.GetNumLocations() >= 1, "process is not valid") process = target.LaunchSimple( None, None, lldb.remote_platform.GetWorkingDirectory() @@ -76,10 +79,10 @@ class TestFrameVariable(TimeTestBase): self.lldb_assert(process and process.IsValid(), "process is not valid") threads = lldbutil.get_threads_stopped_at_breakpoint_id( - process, breakpoint.GetID() + process, bk.GetID() ) self.lldb_assert( - len(threads) == 1, "There should be a thread stopped at breakpoint 1" + len(threads) == 1, "There should be a thread stopped at breakpoint 3" ) thread = threads[0] self.lldb_assert(thread.IsValid(), "Thread must be valid") @@ -92,18 +95,18 @@ class TestFrameVariable(TimeTestBase): # Log timers reset self.handle_cmd("log timers reset") # Frame variable - vars = self.handle_cmd("frame variable") + variables = self.handle_cmd("frame variable") # Verify if we ask for arguments and locals that we got what we expect desc = "arguments + locals" names = arg_names + local_names count = len(names) self.lldb_assert( - len(vars.splitlines()) == count, + len(variables.splitlines()) == count, "There should be %i %s (%s) but we are reporting %i (%s)" - % (count, desc, names, len(vars.splitlines()), get_names_from_vars(vars)), + % (count, desc, names, len(variables.splitlines()), get_names_from_vars(variables)), ) - self.verify_variable_names("check names of %s" % (desc), vars, names) + self.verify_variable_names("check names of %s" % (desc), variables, names) self.lldb_assert_total_time( "HandleCommand: frame variable", "Completed frame variable." diff --git a/lldb/test/API/lldb_time_test/frame_variable/frame_variable.c b/lldb/test/API/lldb_time_test/frame_variable/frame_variable.c deleted file mode 100644 index 3270202ab0d1b05bde227f4025e3076fae21c9b4..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/frame_variable/frame_variable.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2023 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 - -int g_global_var = 123; -static int g_static_var = 123; - -int main(int argc, char const *argv[]) { - static int static_var = 123; - g_static_var = 123; - int i = 0; - for (i = 0; i < 1; ++i) { - int j = i * 2; - printf("i = %i, j = %i\n", i, j); - { - int k = i * j * 3; - printf("i = %i, j = %i\n", i, j); // breakpoint 1 - } - } - return 0; -} diff --git a/lldb/test/API/lldb_time_test/frame_variable/main.c b/lldb/test/API/lldb_time_test/frame_variable/main.c new file mode 120000 index 0000000000000000000000000000000000000000..d1fe8e686935295f5e63f7e0af2d1d7825a4fabc --- /dev/null +++ b/lldb/test/API/lldb_time_test/frame_variable/main.c @@ -0,0 +1 @@ +../../python_api/frame/get-variables/main.c \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/register_read/Makefile b/lldb/test/API/lldb_time_test/register_read/Makefile deleted file mode 100644 index a35d13edb812545dea705be929d7df33718181b1..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/register_read/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (C) 2023 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. -CXX_SOURCES ?= register_read.cpp - -DEBUG_INFO_FLAG := -g - -include Makefile.rules \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/register_read/Makefile b/lldb/test/API/lldb_time_test/register_read/Makefile new file mode 120000 index 0000000000000000000000000000000000000000..91bc871b28ff46e5a50a81fac94dff2313c4d90a --- /dev/null +++ b/lldb/test/API/lldb_time_test/register_read/Makefile @@ -0,0 +1 @@ +../../python_api/lldbutil/iter/Makefile \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/register_read/TestRegisterRead.py b/lldb/test/API/lldb_time_test/register_read/TestRegisterRead.py index 4a0fd76ebc625617567e126d774c7d60cb3dd5fd..7e761b8c378a44548d23dd9b2b31d689c4ec7682 100644 --- a/lldb/test/API/lldb_time_test/register_read/TestRegisterRead.py +++ b/lldb/test/API/lldb_time_test/register_read/TestRegisterRead.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,9 +15,10 @@ # limitations under the License. import lldb -from lldb_time_test.TimeTestBase import TimeTestBase + +from lldbsuite.test.decorators import skipIf, skipOnOpenHarmonyCI from lldbsuite.test.lldbtest import line_number -from lldbsuite.test.decorators import skipOnOpenHarmonyCI, skipIf +from lldb_time_test.TimeTestBase import TimeTestBase class TestRegisterRead(TimeTestBase): @@ -29,7 +32,7 @@ class TestRegisterRead(TimeTestBase): self.init_benchmark("benchmark_usb.json") # Find the line number to break inside main(). - self.line = line_number("register_read.cpp", "// Set break point at this line.") + self.line = line_number("main.cpp", "// Set break point at this line.") @skipOnOpenHarmonyCI @skipIf(remote=False) @@ -42,8 +45,8 @@ class TestRegisterRead(TimeTestBase): target = self.dbg.CreateTarget(exe) self.lldb_assert(target, "target is not valid") - breakpoint = target.BreakpointCreateByLocation("register_read.cpp", self.line) - self.lldb_assert(breakpoint, "breakpoint is not valid") + bk = target.BreakpointCreateByLocation("main.cpp", self.line) + self.lldb_assert(bk, "breakpoint is not valid") # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( diff --git a/lldb/test/API/lldb_time_test/register_read/main.cpp b/lldb/test/API/lldb_time_test/register_read/main.cpp new file mode 120000 index 0000000000000000000000000000000000000000..bd609a2bf2ca016579ad65e45ddd571c60b01dcd --- /dev/null +++ b/lldb/test/API/lldb_time_test/register_read/main.cpp @@ -0,0 +1 @@ +../../python_api/lldbutil/iter/main.cpp \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/register_read/register_read.cpp b/lldb/test/API/lldb_time_test/register_read/register_read.cpp deleted file mode 100644 index eef31242f72acb3dbb1f2e94cba27afcb5141d78..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/register_read/register_read.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2023 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 -#include -#include - -#include -#include -#include -#include - -std::thread g_thread_1; -std::thread g_thread_2; -std::thread g_thread_3; -std::mutex g_mask_mutex; - -enum MaskAction { eGet, eAssign, eClearBits }; - -uint32_t mask_access(MaskAction action, uint32_t mask = 0); - -uint32_t mask_access(MaskAction action, uint32_t mask) { - static uint32_t g_mask = 0; - - std::lock_guard lock(g_mask_mutex); - switch (action) { - case eGet: - break; - - case eAssign: - g_mask |= mask; - break; - - case eClearBits: - g_mask &= ~mask; - break; - } - return g_mask; -} - -void *thread_func(void *arg) { - uint32_t thread_index = *((uint32_t *)arg); - uint32_t thread_mask = (1u << (thread_index)); - printf("%s (thread index = %u) starting...\n", __FUNCTION__, thread_index); - - std::default_random_engine generator; - std::uniform_int_distribution distribution(0, 3000000); - - while (mask_access(eGet) & thread_mask) { - // random micro second sleep from zero to 3 seconds - int usec = distribution(generator); - printf("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, - thread_index, usec); - - std::chrono::microseconds duration(usec); - std::this_thread::sleep_for(duration); - printf("%s (thread = %u) after usleep ...\n", __FUNCTION__, - thread_index); // Set break point at this line. - } - printf("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); - return NULL; -} - -int main(int argc, char const *argv[]) { - uint32_t thread_index_1 = 1; - uint32_t thread_index_2 = 2; - uint32_t thread_index_3 = 3; - uint32_t thread_mask_1 = (1u << thread_index_1); - uint32_t thread_mask_2 = (1u << thread_index_2); - uint32_t thread_mask_3 = (1u << thread_index_3); - - // Make a mask that will keep all threads alive - mask_access(eAssign, - thread_mask_1 | thread_mask_2 | thread_mask_3); // And that line. - - // Create 3 threads - g_thread_1 = std::thread(thread_func, (void *)&thread_index_1); - g_thread_2 = std::thread(thread_func, (void *)&thread_index_2); - g_thread_3 = std::thread(thread_func, (void *)&thread_index_3); - - char line[64]; - while (mask_access(eGet) != 0) { - printf("Enter thread index to kill or ENTER for all:\n"); - fflush(stdout); - // Kill threads by index, or ENTER for all threads - - if (fgets(line, sizeof(line), stdin)) { - if (line[0] == '\n' || line[0] == '\r' || line[0] == '\0') { - printf("Exiting all threads...\n"); - break; - } - int32_t index = strtoul(line, NULL, 0); - switch (index) { - case 1: - mask_access(eClearBits, thread_mask_1); - break; - case 2: - mask_access(eClearBits, thread_mask_2); - break; - case 3: - mask_access(eClearBits, thread_mask_3); - break; - } - continue; - } - - break; - } - - // Clear all thread bits to they all exit - mask_access(eClearBits, UINT32_MAX); - - // Join all of our threads - g_thread_1.join(); - g_thread_2.join(); - g_thread_3.join(); - - return 0; -} diff --git a/lldb/test/API/lldb_time_test/run_lldb_time_test.sh b/lldb/test/API/lldb_time_test/run_lldb_time_test.sh index 3d64f7e4584598d9d864765584ddbddf12c9bfe3..7fc6ad325250325cda9315be6e9c6c07fd5533bb 100755 --- a/lldb/test/API/lldb_time_test/run_lldb_time_test.sh +++ b/lldb/test/API/lldb_time_test/run_lldb_time_test.sh @@ -37,24 +37,24 @@ while [[ $# -ge 1 ]]; do done if [ -z $HDC ] || [ -z $LLVM_PROJECT_DIR ] || [ -z $TEST_WITH_CACHE ]; then - echo "$0: Require options: [-hdc-path VALUE] [-llvm-path VALUE] [-use-module-cache VALUE]." + echo "$0: Require options: [-hdc-path VALUE] [-llvm-root VALUE] [-use-module-cache VALUE]." exit 1 fi LLVM_BUILD_PREFIX="${LLVM_PROJECT_DIR}/out" -LLVM_BUILD_LINUX_X86_PREFIX="${LLVM_BUILD_PREFIX}/llvm_make" +LLVM_BUILD_LINUX_X86_PREFIX="${LLVM_BUILD_PREFIX}/llvm-install" LLVM_BUILD_LINUX_X86_BIN="${LLVM_BUILD_LINUX_X86_PREFIX}/bin" LLDB_TEST_PATH="${LLVM_PROJECT_DIR}/toolchain/llvm-project/lldb/test/API/lldb_time_test/" LLDB_API_DOTEST="${LLVM_PROJECT_DIR}/toolchain/llvm-project/lldb/test/API/dotest.py" LLDB_TEST_ROOT=${PWD} - -SYSROOT="${LLVM_BUILD_PREFIX}/sysroot" +export OH_LLDB_TEST_DIR=${PWD} LLDB_API_DOTEST_ARCH="arm" -CONFIG="${LLDB_TEST_ROOT}/arm-linux-ohos.cfg" TARGET="arm-linux-ohos" +CONFIG="${LLDB_TEST_ROOT}/${TARGET}.cfg" CONFIG_OPT="--config ${CONFIG}" +SYSROOT="${LLVM_BUILD_PREFIX}/sysroot/${TARGET}" REMOTE_PLATFORM_WORKDIR="/data/local/tmp/lldb_time_test" LLDB_SERVER_BINARY_RELATIVE_TO_TOOLCHAIN_PATH="${LLVM_BUILD_PREFIX}/lib/lldb-server-${TARGET}/bin/lldb-server" @@ -63,9 +63,9 @@ LLDB_API_REMOTE_PLATFORM_NAME_OHOS="remote-ohos" LLDB_API_REMOTE_PLATFORM_URL_STRING_OHOS="connect://:${LLDB_SERVER_PORT_OHOS}" if [ ! -f ${CONFIG} ]; then - echo -e "--target=${LLDB_API_DOTEST_ARCH}-linux-ohos" >>${CONFIG} + echo -e "-target ${LLDB_API_DOTEST_ARCH}-linux-ohos" >> ${CONFIG} echo -e "--sysroot ${SYSROOT}" >>${CONFIG} - echo -e "--static" >>${CONFIG} + echo -e "-static-libstdc++" >> ${CONFIG} fi OHOS_DEVICE_SERIAL="$(${HDC} list targets)" @@ -127,6 +127,7 @@ ${python_exe} \ --lldb-libs-dir ${LD_LIBRARY_PATH} \ --llvm-tools-dir ${LLVM_BUILD_LINUX_X86_BIN} \ --env RUN_WITH_CACHE=${TEST_WITH_CACHE} \ + --env HDC=${HDC} \ ${LLDB_TEST_PATH} kill ${hdc_lldb_server_pid} diff --git a/lldb/test/API/lldb_time_test/step/Makefile b/lldb/test/API/lldb_time_test/step/Makefile deleted file mode 100644 index 7a616d4feda41e166e4f9f1049e48f1b959e96a8..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/step/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (C) 2023 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. -CXX_SOURCES ?= step.cpp - -DEBUG_INFO_FLAG := -g - -include Makefile.rules \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/step/Makefile b/lldb/test/API/lldb_time_test/step/Makefile new file mode 120000 index 0000000000000000000000000000000000000000..06cefd2af6bea0f0d826b69cabeab05fa25de84b --- /dev/null +++ b/lldb/test/API/lldb_time_test/step/Makefile @@ -0,0 +1 @@ +../../python_api/thread/Makefile \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/step/TestStepIn.py b/lldb/test/API/lldb_time_test/step/TestStepIn.py index 279df89a1f23b9031c58750dab17b7d733fe7a8f..2c9ce7563cd524b153b429e5d173a7628c7181e6 100644 --- a/lldb/test/API/lldb_time_test/step/TestStepIn.py +++ b/lldb/test/API/lldb_time_test/step/TestStepIn.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +15,11 @@ # limitations under the License. import lldb -from lldb_time_test.TimeTestBase import TimeTestBase -from lldbsuite.test import lldbutil + +from lldbsuite.test.decorators import skipIf, skipOnOpenHarmonyCI from lldbsuite.test.lldbtest import line_number -from lldbsuite.test.decorators import skipOnOpenHarmonyCI, skipIf +from lldbsuite.test import lldbutil +from lldb_time_test.TimeTestBase import TimeTestBase class TestStepIn(TimeTestBase): @@ -29,14 +32,14 @@ class TestStepIn(TimeTestBase): # Init benchmark JSON file self.init_benchmark("benchmark_usb.json") - # Find the line numbers within step.cpp for test_step_in_function_c(). + # Find the line numbers within main2.cpp for test_step_in_function_c(). self.step_in_c = line_number( - "step.cpp", "// breakpoint for thread step-in function c." + "main2.cpp", "int rc = c(val);" ) self.function_c = line_number( - "step.cpp", "// target location for thread step-in function c." + "main2.cpp", "return val + 3;" ) - # We'll use the test method name as the exe_name for executable compiled from step.cpp. + # We'll use the test method name as the exe_name for executable compiled from main2.cpp. self.exe_name = self._testMethodName @skipOnOpenHarmonyCI @@ -44,7 +47,7 @@ class TestStepIn(TimeTestBase): def test_step_in_function_c(self): """Test 'thread step-in' to step in function c().""" # We build a different executable than the default build() does. - d = {"CXX_SOURCES": "step.cpp", "EXE": self.exe_name} + d = {"CXX_SOURCES": "main2.cpp", "EXE": self.exe_name} self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) self.step_in_function_c() @@ -55,8 +58,8 @@ class TestStepIn(TimeTestBase): target = self.dbg.CreateTarget(exe) self.lldb_assert(target, "target is not valid") - breakpoint = target.BreakpointCreateByLocation("step.cpp", self.step_in_c) - self.lldb_assert(breakpoint, "breakpoint is not valid") + bk = target.BreakpointCreateByLocation("main2.cpp", self.step_in_c) + self.lldb_assert(bk, "breakpoint is not valid") # Launch the process, and do not stop at the entry point. process = target.LaunchSimple( @@ -67,13 +70,13 @@ class TestStepIn(TimeTestBase): self.lldb_assert( thread.IsValid(), "There should be a thread stopped due to breakpoint" ) - frame0 = thread.GetFrameAtIndex(0) - lineEntry = frame0.GetLineEntry() + thread_frame = thread.GetFrameAtIndex(0) + line_entry = thread_frame.GetLineEntry() self.lldb_assert( - lineEntry.GetLine() == self.step_in_c, + line_entry.GetLine() == self.step_in_c, "Thread didn't stop at the correct source line number where we expect.", ) - target.BreakpointDelete(breakpoint.GetID()) + target.BreakpointDelete(bk.GetID()) # Log timers reset self.handle_cmd("log timers reset") diff --git a/lldb/test/API/lldb_time_test/step/TestStepOut.py b/lldb/test/API/lldb_time_test/step/TestStepOut.py index a9e390c923de07bd92457bb18856710fa3e6154f..0580155cae03b6f379fb601cbc3f6fc6d27136c3 100644 --- a/lldb/test/API/lldb_time_test/step/TestStepOut.py +++ b/lldb/test/API/lldb_time_test/step/TestStepOut.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +15,10 @@ # limitations under the License. import lldb -from lldb_time_test.TimeTestBase import TimeTestBase -from lldbsuite.test import lldbutil +from lldbsuite.test.decorators import skipIf, skipOnOpenHarmonyCI from lldbsuite.test.lldbtest import line_number -from lldbsuite.test.decorators import skipOnOpenHarmonyCI, skipIf +from lldbsuite.test import lldbutil +from lldb_time_test.TimeTestBase import TimeTestBase class TestStepOut(TimeTestBase): @@ -29,11 +31,11 @@ class TestStepOut(TimeTestBase): # Init benchmark JSON file self.init_benchmark("benchmark_usb.json") - # Find the line numbers within step.cpp for step_out(). + # Find the line numbers within main2.cpp for step_out(). self.step_in_c = line_number( - "step.cpp", "// breakpoint for thread step-in function c." + "main2.cpp", "int rc = c(val);" ) - # We'll use the test method name as the exe_name for executable compiled from step.cpp. + # We'll use the test method name as the exe_name for executable compiled from main2.cpp. self.exe_name = self._testMethodName @skipOnOpenHarmonyCI @@ -41,7 +43,7 @@ class TestStepOut(TimeTestBase): def test_step_out_of_function_c(self): """Test 'thread step-out' to step out of function c().""" # We build a different executable than the default build() does. - d = {"CXX_SOURCES": "step.cpp", "EXE": self.exe_name} + d = {"CXX_SOURCES": "main2.cpp", "EXE": self.exe_name} self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) self.step_out_of_function_c() @@ -52,8 +54,8 @@ class TestStepOut(TimeTestBase): target = self.dbg.CreateTarget(exe) self.lldb_assert(target, "target is not valid") - breakpoint = target.BreakpointCreateByName("c") - self.lldb_assert(breakpoint, "breakpoint is not valid") + bk = target.BreakpointCreateByName("c") + self.lldb_assert(bk, "breakpoint is not valid") # Launch the process, and do not stop at the entry point. process = target.LaunchSimple( @@ -64,7 +66,7 @@ class TestStepOut(TimeTestBase): self.lldb_assert( thread.IsValid(), "There should be a thread stopped due to breakpoint" ) - target.BreakpointDelete(breakpoint.GetID()) + target.BreakpointDelete(bk.GetID()) # Log timers reset self.handle_cmd("log timers reset") diff --git a/lldb/test/API/lldb_time_test/step/TestStepOver.py b/lldb/test/API/lldb_time_test/step/TestStepOver.py index c8d477c79f743a269d58fe3ec200473969cb581c..a41df5d403dbc810f14f6ac8d5647d79d4ea29e4 100644 --- a/lldb/test/API/lldb_time_test/step/TestStepOver.py +++ b/lldb/test/API/lldb_time_test/step/TestStepOver.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +15,11 @@ # limitations under the License. import lldb -from lldb_time_test.TimeTestBase import TimeTestBase -from lldbsuite.test import lldbutil -from lldbsuite.test.lldbtest import line_number + from lldbsuite.test.decorators import skipOnOpenHarmonyCI, skipIf +from lldbsuite.test.lldbtest import line_number +from lldbsuite.test import lldbutil +from lldb_time_test.TimeTestBase import TimeTestBase class TestStepOver(TimeTestBase): @@ -28,15 +31,15 @@ class TestStepOver(TimeTestBase): self.init_benchmark("benchmark_usb.json") - # Find the line numbers within step.cpp for step_over() + # Find the line numbers within main2.cpp for step_over() self.step_over_breakpoint = line_number( - "step.cpp", "// breakpoint for thread step-over." + "main2.cpp", "// thread step-out of malloc into function b." ) self.step_over_target = line_number( - "step.cpp", "// target location for thread step-over." + "main2.cpp", "if (!ptr)" ) - # We'll use the test method name as the exe_name for executable compiled from step.cpp. + # We'll use the test method name as the exe_name for executable compiled from main2.cpp. self.exe_name = self._testMethodName @skipOnOpenHarmonyCI @@ -44,7 +47,7 @@ class TestStepOver(TimeTestBase): def test_step_over(self): """Test 'thread step-over'.""" # We build a different executable than the default build() does. - d = {"CXX_SOURCES": "step.cpp", "EXE": self.exe_name} + d = {"CXX_SOURCES": "main2.cpp", "EXE": self.exe_name} self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) self.step_over() @@ -55,10 +58,10 @@ class TestStepOver(TimeTestBase): target = self.dbg.CreateTarget(exe) self.lldb_assert(target, "target is not valid") - breakpoint = target.BreakpointCreateByLocation( - "step.cpp", self.step_over_breakpoint + bk = target.BreakpointCreateByLocation( + "main2.cpp", self.step_over_breakpoint ) - self.lldb_assert(breakpoint, "breakpoint is not valid") + self.lldb_assert(bk, "breakpoint is not valid") # Launch the process, and do not stop at the entry point. process = target.LaunchSimple( @@ -75,10 +78,10 @@ class TestStepOver(TimeTestBase): ) # Frame #0 should be on self.step_over_breakpoint. - frame0 = thread.GetFrameAtIndex(0) - lineEntry = frame0.GetLineEntry() + thread_frame = thread.GetFrameAtIndex(0) + line_entry = thread_frame.GetLineEntry() self.lldb_assert( - lineEntry.GetLine() == self.step_over_breakpoint, + line_entry.GetLine() == self.step_over_breakpoint, "Thread didn't stop at the correct source line number where we expect.", ) @@ -87,15 +90,15 @@ class TestStepOver(TimeTestBase): # Thread step-over self.handle_cmd("thread step-over") - # Verify that we are stopped at the correct source line number in step.cpp. - frame0 = thread.GetFrameAtIndex(0) - lineEntry = frame0.GetLineEntry() + # Verify that we are stopped at the correct source line number in main2.cpp. + thread_frame = thread.GetFrameAtIndex(0) + line_entry = thread_frame.GetLineEntry() self.lldb_assert( thread.GetStopReason() == lldb.eStopReasonPlanComplete, "Thread stop reason didn't meet expectations", ) self.lldb_assert( - lineEntry.GetLine() == self.step_over_target, + line_entry.GetLine() == self.step_over_target, "Thread didn't stop at the correct source line number where we expect.", ) diff --git a/lldb/test/API/lldb_time_test/step/main2.cpp b/lldb/test/API/lldb_time_test/step/main2.cpp new file mode 120000 index 0000000000000000000000000000000000000000..90a713887080d60bf362d53586352f12945a5504 --- /dev/null +++ b/lldb/test/API/lldb_time_test/step/main2.cpp @@ -0,0 +1 @@ +../../python_api/thread/main2.cpp \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/step/step.cpp b/lldb/test/API/lldb_time_test/step/step.cpp deleted file mode 100644 index 62bfdde3f9da2ce8e18867bbf362c9f546500dfb..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/step/step.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2023 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 -#include - -int a(int); -int b(int); -int c(int); - -int a(int val) { - if (val <= 1) - return b(val); - else if (val >= 3) - return c(val); - - return val; -} - -int b(int val) { - int rc = c(val); // breakpoint for thread step-in function c. - void *ptr = malloc(1024); // breakpoint for thread step-over. - if (!ptr) // target location for thread step-over. - return -1; - else - printf("ptr=%p\n", ptr); - return rc; -} - -int c(int val) { - return val + 3; // target location for thread step-in function c. -} - -int main(int argc, char const *argv[]) { - int A1 = a(1); - printf("a(1) returns %d\n", A1); - - int B2 = b(2); - printf("b(2) returns %d\n", B2); - - int A3 = a(3); - printf("a(3) returns %d\n", A3); - - return 0; -} diff --git a/lldb/test/API/lldb_time_test/thread_backtrace/Makefile b/lldb/test/API/lldb_time_test/thread_backtrace/Makefile deleted file mode 100644 index 941041939b7623ca8f89a331632515a682a4be48..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/thread_backtrace/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (C) 2023 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. -CXX_SOURCES ?= thread_backtrace.cpp - -DEBUG_INFO_FLAG := -g - -include Makefile.rules \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/thread_backtrace/Makefile b/lldb/test/API/lldb_time_test/thread_backtrace/Makefile new file mode 120000 index 0000000000000000000000000000000000000000..06cefd2af6bea0f0d826b69cabeab05fa25de84b --- /dev/null +++ b/lldb/test/API/lldb_time_test/thread_backtrace/Makefile @@ -0,0 +1 @@ +../../python_api/thread/Makefile \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/thread_backtrace/TestThreadBacktrace.py b/lldb/test/API/lldb_time_test/thread_backtrace/TestThreadBacktrace.py index b43b405203ccf8cec88419079b1953ddbf3d3693..4f75c0fa4886cfb8645244d8fef40c02b1469a8d 100644 --- a/lldb/test/API/lldb_time_test/thread_backtrace/TestThreadBacktrace.py +++ b/lldb/test/API/lldb_time_test/thread_backtrace/TestThreadBacktrace.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (C) 2023 Huawei Device Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +15,11 @@ # limitations under the License. import lldb -from lldb_time_test.TimeTestBase import TimeTestBase -from lldbsuite.test import lldbutil + +from lldbsuite.test.decorators import skipIf, skipOnOpenHarmonyCI from lldbsuite.test.lldbtest import line_number -from lldbsuite.test.decorators import skipOnOpenHarmonyCI, skipIf +from lldbsuite.test import lldbutil +from lldb_time_test.TimeTestBase import TimeTestBase class TestBacktrace(TimeTestBase): @@ -29,12 +32,13 @@ class TestBacktrace(TimeTestBase): # Init benchmark JSON file self.init_benchmark("benchmark_usb.json") - # Find the line numbers within thread_backtrace.cpp for thread_backtrace. + # Find the line numbers within main2.cpp for thread_backtrace. self.backtrace_breakpoint = line_number( - "thread_backtrace.cpp", "// breakpoint for thread backtrace." + "main2.cpp", "// thread step-out of malloc into function b." ) - # We'll use the test method name as the exe_name for executable compiled from thread_backtrace.cpp. + # We'll use the test method name as the exe_name + # for executable compiled from main2.cpp. self.exe_name = self._testMethodName @skipOnOpenHarmonyCI @@ -42,7 +46,7 @@ class TestBacktrace(TimeTestBase): def test_thread_backtrace(self): """Test 'thread backtrace'.""" # We build a different executable than the default build() does. - d = {"CXX_SOURCES": "thread_backtrace.cpp", "EXE": self.exe_name} + d = {"CXX_SOURCES": "main2.cpp", "EXE": self.exe_name} self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) self.thread_backtrace() @@ -53,10 +57,10 @@ class TestBacktrace(TimeTestBase): target = self.dbg.CreateTarget(exe) self.lldb_assert(target, "target is not valid") - breakpoint = target.BreakpointCreateByLocation( - "thread_backtrace.cpp", self.backtrace_breakpoint + bk = target.BreakpointCreateByLocation( + "main2.cpp", self.backtrace_breakpoint ) - self.lldb_assert(breakpoint, "breakpoint is not valid") + self.lldb_assert(bk, "breakpoint is not valid") # Launch the process, and do stop at breakpoint. process = target.LaunchSimple( @@ -72,11 +76,11 @@ class TestBacktrace(TimeTestBase): "There should be a thread stopped due to breakpoint condition", ) - # Verify that we are stopped at the correct source line number in thread_backtrace.cpp. - frame0 = thread.GetFrameAtIndex(0) - lineEntry = frame0.GetLineEntry() + # Verify that we are stopped at the correct source line number in main2.cpp. + thread_frame = thread.GetFrameAtIndex(0) + line_entry = thread_frame.GetLineEntry() self.lldb_assert( - lineEntry.GetLine() == self.backtrace_breakpoint, + line_entry.GetLine() == self.backtrace_breakpoint, "Thread didn't stop at the correct source line number where we expect.", ) diff --git a/lldb/test/API/lldb_time_test/thread_backtrace/main2.cpp b/lldb/test/API/lldb_time_test/thread_backtrace/main2.cpp new file mode 120000 index 0000000000000000000000000000000000000000..90a713887080d60bf362d53586352f12945a5504 --- /dev/null +++ b/lldb/test/API/lldb_time_test/thread_backtrace/main2.cpp @@ -0,0 +1 @@ +../../python_api/thread/main2.cpp \ No newline at end of file diff --git a/lldb/test/API/lldb_time_test/thread_backtrace/thread_backtrace.cpp b/lldb/test/API/lldb_time_test/thread_backtrace/thread_backtrace.cpp deleted file mode 100644 index 5c57ef37e50020bcdba5b41f7be3a11df95b9ad0..0000000000000000000000000000000000000000 --- a/lldb/test/API/lldb_time_test/thread_backtrace/thread_backtrace.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2023 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 -#include - -int a(int); -int b(int); -int c(int); - -int a(int val) { - if (val <= 1) - return b(val); - else if (val >= 3) - return c(val); - - return val; -} - -int b(int val) { - int rc = c(val); - void *ptr = malloc(1024); // breakpoint for thread backtrace. - if (!ptr) - return -1; - else - printf("ptr=%p\n", ptr); - return rc; -} - -int c(int val) { return val + 3; } - -int main(int argc, char const *argv[]) { - int A1 = a(1); - printf("a(1) returns %d\n", A1); - - int B2 = b(2); - printf("b(2) returns %d\n", B2); - - int A3 = a(3); - printf("a(3) returns %d\n", A3); - - return 0; -} diff --git a/lldb/test/API/test_linker/TestLinkerLaunch.py b/lldb/test/API/test_linker/TestLinkerLaunch.py index e968bd951d874a6562dc64491dd7855a212e1c0f..b9a73727a8db41161bb0cbf0ee5179cf8cf1670c 100644 --- a/lldb/test/API/test_linker/TestLinkerLaunch.py +++ b/lldb/test/API/test_linker/TestLinkerLaunch.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3.10 +# -*- coding: utf-8 -*- # Copyright (c) 2023 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. @@ -19,12 +21,15 @@ a remote-ohos connection, will skip on CI or remote = false. import subprocess import sys +import os import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * + +from lldbsuite.test.decorators import skipIf, skipUnlessPlatform +from lldbsuite.test.lldbtest import TestBase, PROCESS_IS_VALID, BREAKPOINT_HIT_ONCE from lldbsuite.test import lldbutil + class LaunchLinker(TestBase): NO_DEBUG_INFO_TESTCASE = True @@ -47,10 +52,10 @@ class LaunchLinker(TestBase): """Create target, breakpoint, launch a process, and then kill it.""" target = self.dbg.CreateTarget(self.exe) - breakpoint = target.BreakpointCreateByName("__dls2b") + bkpt_dls2b = target.BreakpointCreateByName("__dls2b") # The default state after breakpoint creation should be enabled. self.assertTrue( - breakpoint.IsEnabled(), "Breakpoint should be enabled after creation" + bkpt_dls2b.IsEnabled(), "Breakpoint should be enabled after creation" ) process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) @@ -59,7 +64,7 @@ class LaunchLinker(TestBase): self.assertIsNotNone(thread) # The breakpoint should have a hit count of 1. - self.assertEqual(breakpoint.GetHitCount(), 1, BREAKPOINT_HIT_ONCE) + self.assertEqual(bkpt_dls2b.GetHitCount(), 1, BREAKPOINT_HIT_ONCE) # Destroy process before TestBase.tearDown() self.dbg.GetSelectedTarget().GetProcess().Destroy() @@ -70,10 +75,10 @@ class LaunchLinker(TestBase): """Create target, breakpoint, launch a process, and then kill it.""" target = self.dbg.CreateTarget(self.exe) - breakpoint = target.BreakpointCreateByName("printf") + bkpt_printf = target.BreakpointCreateByName("printf") # The default state after breakpoint creation should be enabled. self.assertTrue( - breakpoint.IsEnabled(), "Breakpoint should be enabled after creation" + bkpt_printf.IsEnabled(), "Breakpoint should be enabled after creation" ) process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) @@ -82,7 +87,7 @@ class LaunchLinker(TestBase): self.assertIsNotNone(thread) # The breakpoint should have a hit count of 1. - self.assertEqual(breakpoint.GetHitCount(), 1, BREAKPOINT_HIT_ONCE) + self.assertEqual(bkpt_printf.GetHitCount(), 1, BREAKPOINT_HIT_ONCE) # Destroy process before TestBase.tearDown() self.dbg.GetSelectedTarget().GetProcess().Destroy() diff --git a/lldb/test/API/test_linker/main.c b/lldb/test/API/test_linker/main.c index f404bb69b769e7c3d3d3587d27ba6c99479bdb79..f93b92476b5a379cd2df9853f7e6fb1677e1b48a 100644 --- a/lldb/test/API/test_linker/main.c +++ b/lldb/test/API/test_linker/main.c @@ -15,8 +15,8 @@ #include -int main () +int main() { - printf("test musl/linker!\n"); - return 0; + printf("test musl/linker!\n"); + return 0; }