[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 https://github.com/llvm/llvm-project/pull/146740
This commit is contained in:
parent
2fc6c73b39
commit
9d8058e3b8
@ -1,5 +1,3 @@
|
|||||||
CXX_SOURCES := main.cpp
|
CXX_SOURCES := main.cpp
|
||||||
CXXFLAGS_EXTRAS := -std=c++11
|
|
||||||
USE_LIBCPP := 1
|
|
||||||
|
|
||||||
include Makefile.rules
|
include Makefile.rules
|
@ -2,14 +2,13 @@
|
|||||||
Test lldb data formatter subsystem.
|
Test lldb data formatter subsystem.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import lldb
|
import lldb
|
||||||
from lldbsuite.test.decorators import *
|
from lldbsuite.test.decorators import *
|
||||||
from lldbsuite.test.lldbtest import *
|
from lldbsuite.test.lldbtest import *
|
||||||
from lldbsuite.test import lldbutil
|
from lldbsuite.test import lldbutil
|
||||||
|
|
||||||
|
|
||||||
class LibCxxFunctionTestCase(TestBase):
|
class StdFunctionTestCase(TestBase):
|
||||||
# Run frame var for a variable twice. Verify we do not hit the cache
|
# Run frame var for a variable twice. Verify we do not hit the cache
|
||||||
# the first time but do the second time.
|
# the first time but do the second time.
|
||||||
def run_frame_var_check_cache_use(
|
def run_frame_var_check_cache_use(
|
||||||
@ -34,10 +33,8 @@ class LibCxxFunctionTestCase(TestBase):
|
|||||||
substrs=["lldb_private::CompileUnit::FindFunction"],
|
substrs=["lldb_private::CompileUnit::FindFunction"],
|
||||||
)
|
)
|
||||||
|
|
||||||
@add_test_categories(["libc++"])
|
def do_test(self):
|
||||||
def test(self):
|
"""Test that std::function is correctly printed by LLDB"""
|
||||||
"""Test that std::function as defined by libc++ is correctly printed by LLDB"""
|
|
||||||
self.build()
|
|
||||||
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
|
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
|
||||||
|
|
||||||
bkpt = self.target().FindBreakpointByID(
|
bkpt = self.target().FindBreakpointByID(
|
||||||
@ -56,20 +53,20 @@ class LibCxxFunctionTestCase(TestBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.run_frame_var_check_cache_use(
|
self.run_frame_var_check_cache_use(
|
||||||
"foo2_f", "Lambda in File main.cpp at Line 22"
|
"foo2_f", "Lambda in File main.cpp at Line 16"
|
||||||
)
|
)
|
||||||
|
|
||||||
lldbutil.continue_to_breakpoint(self.process(), bkpt)
|
lldbutil.continue_to_breakpoint(self.process(), bkpt)
|
||||||
|
|
||||||
self.run_frame_var_check_cache_use(
|
self.run_frame_var_check_cache_use(
|
||||||
"add_num2_f", "Lambda in File main.cpp at Line 13"
|
"add_num2_f", "Lambda in File main.cpp at Line 9"
|
||||||
)
|
)
|
||||||
|
|
||||||
lldbutil.continue_to_breakpoint(self.process(), bkpt)
|
lldbutil.continue_to_breakpoint(self.process(), bkpt)
|
||||||
|
|
||||||
self.run_frame_var_check_cache_use("f2", "Lambda in File main.cpp at Line 35")
|
self.run_frame_var_check_cache_use("f2", "Lambda in File main.cpp at Line 26")
|
||||||
self.run_frame_var_check_cache_use(
|
self.run_frame_var_check_cache_use(
|
||||||
"f3", "Lambda in File main.cpp at Line 39", True
|
"f3", "Lambda in File main.cpp at Line 30", True
|
||||||
)
|
)
|
||||||
# TODO reenable this case when std::function formatter supports
|
# TODO reenable this case when std::function formatter supports
|
||||||
# general callable object case.
|
# general callable object case.
|
||||||
@ -82,3 +79,8 @@ class LibCxxFunctionTestCase(TestBase):
|
|||||||
self.expect(
|
self.expect(
|
||||||
"frame variable f5", substrs=["f5 = Function = Bar::add_num(int) const"]
|
"frame variable f5", substrs=["f5 = Function = Bar::add_num(int) const"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@add_test_categories(["libc++"])
|
||||||
|
def test_libcxx(self):
|
||||||
|
self.build(dictionary={"USE_LIBCPP": 1})
|
||||||
|
self.do_test()
|
@ -0,0 +1,43 @@
|
|||||||
|
#include <functional>
|
||||||
|
|
||||||
|
int foo(int x, int y) { return x + y - 1; }
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
int operator()() { return 66; }
|
||||||
|
int add_num(int i) const { return i + 3; }
|
||||||
|
int add_num2(int i) {
|
||||||
|
std::function<int(int)> add_num2_f = [](int x) { return x + 1; };
|
||||||
|
|
||||||
|
return add_num2_f(i); // Set break point at this line.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int foo2() {
|
||||||
|
auto f = [](int x) { return x + 1; };
|
||||||
|
|
||||||
|
std::function<int(int)> foo2_f = f;
|
||||||
|
|
||||||
|
return foo2_f(10); // Set break point at this line.
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
int acc = 42;
|
||||||
|
std::function<int(int, int)> f1 = foo;
|
||||||
|
std::function<int(int)> f2 = [acc, f1](int x) -> int {
|
||||||
|
return x + f1(acc, x);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto f = [](int x, int y) { return x + y; };
|
||||||
|
auto g = [](int x, int y) { return x * y; };
|
||||||
|
std::function<int(int, int)> f3 = argc % 2 ? f : g;
|
||||||
|
|
||||||
|
Bar bar1;
|
||||||
|
std::function<int()> f4(bar1);
|
||||||
|
std::function<int(const Bar &, int)> f5 = &Bar::add_num;
|
||||||
|
|
||||||
|
int foo2_result = foo2();
|
||||||
|
int bar_add_num2_result = bar1.add_num2(10);
|
||||||
|
|
||||||
|
return f1(acc, acc) + f2(acc) + f3(acc + 1, acc + 2) + f4() +
|
||||||
|
f5(bar1, 10); // Set break point at this line.
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
#include <functional>
|
|
||||||
|
|
||||||
int foo(int x, int y) {
|
|
||||||
return x + y - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Bar {
|
|
||||||
int operator()() {
|
|
||||||
return 66 ;
|
|
||||||
}
|
|
||||||
int add_num(int i) const { return i + 3 ; }
|
|
||||||
int add_num2(int i) {
|
|
||||||
std::function<int (int)> add_num2_f = [](int x) {
|
|
||||||
return x+1;
|
|
||||||
};
|
|
||||||
|
|
||||||
return add_num2_f(i); // Set break point at this line.
|
|
||||||
}
|
|
||||||
} ;
|
|
||||||
|
|
||||||
int foo2() {
|
|
||||||
auto f = [](int x) {
|
|
||||||
return x+1;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::function<int (int)> foo2_f = f;
|
|
||||||
|
|
||||||
return foo2_f(10); // Set break point at this line.
|
|
||||||
}
|
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int acc = 42;
|
|
||||||
std::function<int (int,int)> f1 = foo;
|
|
||||||
std::function<int (int)> f2 = [acc,f1] (int x) -> int {
|
|
||||||
return x+f1(acc,x);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto f = [](int x, int y) { return x + y; };
|
|
||||||
auto g = [](int x, int y) { return x * y; } ;
|
|
||||||
std::function<int (int,int)> f3 = argc %2 ? f : g ;
|
|
||||||
|
|
||||||
Bar bar1 ;
|
|
||||||
std::function<int ()> f4( bar1 ) ;
|
|
||||||
std::function<int (const Bar&, int)> f5 = &Bar::add_num;
|
|
||||||
|
|
||||||
int foo2_result = foo2();
|
|
||||||
int bar_add_num2_result = bar1.add_num2(10);
|
|
||||||
|
|
||||||
return f1(acc,acc) + f2(acc) + f3(acc+1,acc+2) + f4() + f5(bar1, 10); // Set break point at this line.
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user