Skip to content

Commit 9d8058e

Browse files
authored
[lldb][test] Move std::function from libcxx to generic directory (#147701)
This just moves the test from `libcxx` to `generic`. There are currently no `std::function` formatters for libstdc++ so I didn't add a test-case for it. Split out from llvm/llvm-project#146740
1 parent 2fc6c73 commit 9d8058e

File tree

4 files changed

+55
-63
lines changed

4 files changed

+55
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
CXX_SOURCES := main.cpp
2-
CXXFLAGS_EXTRAS := -std=c++11
3-
USE_LIBCPP := 1
42

53
include Makefile.rules

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py renamed to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/function/TestDataFormatterStdFunction.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
Test lldb data formatter subsystem.
33
"""
44

5-
65
import lldb
76
from lldbsuite.test.decorators import *
87
from lldbsuite.test.lldbtest import *
98
from lldbsuite.test import lldbutil
109

1110

12-
class LibCxxFunctionTestCase(TestBase):
11+
class StdFunctionTestCase(TestBase):
1312
# Run frame var for a variable twice. Verify we do not hit the cache
1413
# the first time but do the second time.
1514
def run_frame_var_check_cache_use(
@@ -34,10 +33,8 @@ def run_frame_var_check_cache_use(
3433
substrs=["lldb_private::CompileUnit::FindFunction"],
3534
)
3635

37-
@add_test_categories(["libc++"])
38-
def test(self):
39-
"""Test that std::function as defined by libc++ is correctly printed by LLDB"""
40-
self.build()
36+
def do_test(self):
37+
"""Test that std::function is correctly printed by LLDB"""
4138
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
4239

4340
bkpt = self.target().FindBreakpointByID(
@@ -56,20 +53,20 @@ def test(self):
5653
)
5754

5855
self.run_frame_var_check_cache_use(
59-
"foo2_f", "Lambda in File main.cpp at Line 22"
56+
"foo2_f", "Lambda in File main.cpp at Line 16"
6057
)
6158

6259
lldbutil.continue_to_breakpoint(self.process(), bkpt)
6360

6461
self.run_frame_var_check_cache_use(
65-
"add_num2_f", "Lambda in File main.cpp at Line 13"
62+
"add_num2_f", "Lambda in File main.cpp at Line 9"
6663
)
6764

6865
lldbutil.continue_to_breakpoint(self.process(), bkpt)
6966

70-
self.run_frame_var_check_cache_use("f2", "Lambda in File main.cpp at Line 35")
67+
self.run_frame_var_check_cache_use("f2", "Lambda in File main.cpp at Line 26")
7168
self.run_frame_var_check_cache_use(
72-
"f3", "Lambda in File main.cpp at Line 39", True
69+
"f3", "Lambda in File main.cpp at Line 30", True
7370
)
7471
# TODO reenable this case when std::function formatter supports
7572
# general callable object case.
@@ -82,3 +79,8 @@ def test(self):
8279
self.expect(
8380
"frame variable f5", substrs=["f5 = Function = Bar::add_num(int) const"]
8481
)
82+
83+
@add_test_categories(["libc++"])
84+
def test_libcxx(self):
85+
self.build(dictionary={"USE_LIBCPP": 1})
86+
self.do_test()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <functional>
2+
3+
int foo(int x, int y) { return x + y - 1; }
4+
5+
struct Bar {
6+
int operator()() { return 66; }
7+
int add_num(int i) const { return i + 3; }
8+
int add_num2(int i) {
9+
std::function<int(int)> add_num2_f = [](int x) { return x + 1; };
10+
11+
return add_num2_f(i); // Set break point at this line.
12+
}
13+
};
14+
15+
int foo2() {
16+
auto f = [](int x) { return x + 1; };
17+
18+
std::function<int(int)> foo2_f = f;
19+
20+
return foo2_f(10); // Set break point at this line.
21+
}
22+
23+
int main(int argc, char *argv[]) {
24+
int acc = 42;
25+
std::function<int(int, int)> f1 = foo;
26+
std::function<int(int)> f2 = [acc, f1](int x) -> int {
27+
return x + f1(acc, x);
28+
};
29+
30+
auto f = [](int x, int y) { return x + y; };
31+
auto g = [](int x, int y) { return x * y; };
32+
std::function<int(int, int)> f3 = argc % 2 ? f : g;
33+
34+
Bar bar1;
35+
std::function<int()> f4(bar1);
36+
std::function<int(const Bar &, int)> f5 = &Bar::add_num;
37+
38+
int foo2_result = foo2();
39+
int bar_add_num2_result = bar1.add_num2(10);
40+
41+
return f1(acc, acc) + f2(acc) + f3(acc + 1, acc + 2) + f4() +
42+
f5(bar1, 10); // Set break point at this line.
43+
}

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)