Improve tests regarding imported namespaces and chained calls in C++

llvm-svn: 245505
This commit is contained in:
Paul Herman 2015-08-19 21:23:01 +00:00
parent 4e3ee1e548
commit 493bb398e7
4 changed files with 86 additions and 231 deletions

View File

@ -3,16 +3,15 @@ from lldbtest import *
import lldbutil
class TestCppChainedCalls(TestBase):
mydir = TestBase.compute_mydir(__file__)
@skipUnlessDarwin
@dsym_test
def test_with_dsym_and_run_command(self):
self.buildDsym()
self.check()
@expectedFailureGcc
@dwarf_test
def test_with_dwarf_and_run_command(self):
self.buildDwarf()
@ -26,18 +25,18 @@ class TestCppChainedCalls(TestBase):
src_file = "main.cpp"
src_file_spec = lldb.SBFileSpec(src_file)
self.assertTrue(src_file_spec.IsValid(), "Main source file")
# Get the path of the executable
cwd = os.getcwd()
cwd = self.get_process_working_directory()
exe_file = "a.out"
exe_path = os.path.join(cwd, exe_file)
# Load the executable
target = self.dbg.CreateTarget(exe_path)
self.assertTrue(target.IsValid(), VALID_TARGET)
# Break on main function
main_breakpoint = target.BreakpointCreateBySourceRegex("Break here", src_file_spec)
main_breakpoint = target.BreakpointCreateBySourceRegex("break here", src_file_spec)
self.assertTrue(main_breakpoint.IsValid() and main_breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT)
# Launch the process
@ -50,43 +49,39 @@ class TestCppChainedCalls(TestBase):
self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED)
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
# Get frame for current thread
# Get frame for current thread
frame = thread.GetSelectedFrame()
# Test chained calls
test_result = frame.EvaluateExpression("g(f(12345))")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 12345, "g(f(12345)) = 12345")
test_result = frame.EvaluateExpression("get(set(true))")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "true", "get(set(true)) = true")
test_result = frame.EvaluateExpression("q(p()).a")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 12345678, "q(p()).a = 12345678")
test_result = frame.EvaluateExpression("get(set(false))")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(set(false)) = false")
test_result = frame.EvaluateExpression("(p() + r()).a")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 22345678, "(p() + r()).a = 22345678")
test_result = frame.EvaluateExpression("get(t & f)")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(t & f) = false")
test_result = frame.EvaluateExpression("q(p() + r()).a")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 22345678, "q(p() + r()).a = 22345678")
test_result = frame.EvaluateExpression("get(f & t)")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(f & t) = false")
test_result = frame.EvaluateExpression("g(f(6700) + f(89))")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 6789, "g(f(6700) + f(89)) = 6789")
test_result = frame.EvaluateExpression("get(t & t)")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "true", "get(t & t) = true")
test_result = frame.EvaluateExpression("g(f(g(f(300) + f(40))) + f(5))")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 345, "g(f(g(f(300) + f(40))) + f(5)) = 345")
test_result = frame.EvaluateExpression("get(f & f)")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(f & f) = false")
test_result = frame.EvaluateExpression("getb(makeb(), 789)")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 789, "getb(makeb(), 789) = 789")
test_result = frame.EvaluateExpression("get(t & f)")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(t & f) = false")
test_result = frame.EvaluateExpression("(*c).a")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 5678, "(*c).a = 5678")
test_result = frame.EvaluateExpression("get(f) && get(t)")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(f) && get(t) = false")
test_result = frame.EvaluateExpression("(*c + *c).a")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 11356, "(*c + *c).a = 11356")
test_result = frame.EvaluateExpression("q(*c + *c).a")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 11356, "q(*c + *c).a = 11356")
test_result = frame.EvaluateExpression("make_int().get_type()")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "INT", "make_int().get_type() = \"INT\"")
test_result = frame.EvaluateExpression("get(f) && get(f)")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(f) && get(t) = false")
test_result = frame.EvaluateExpression("get(t) && get(t)")
self.assertTrue(test_result.IsValid() and test_result.GetValue() == "true", "get(t) && get(t) = true")
if __name__ == '__main__':
import atexit

View File

@ -1,186 +1,33 @@
class S
{
class Bool {
public:
S () { }
S (S &obj);
Bool operator&(const Bool other)
{
Bool result;
result.value = value && other.value;
return result;
}
S operator+ (const S &s);
int a;
bool value;
};
S::S (S &obj)
bool get(Bool object)
{
a = obj.a;
return object.value;
}
S
S::operator+ (const S &s)
Bool set(bool value)
{
S res;
res.a = a + s.a;
return res;
Bool result;
result.value = value;
return result;
}
S
f (int i)
int main()
{
S s;
s.a = i;
return s;
}
int
g (const S &s)
{
return s.a;
}
class A
{
public:
A operator+ (const A &);
int a;
};
A
A::operator+ (const A &obj)
{
A n;
n.a = a + obj.a;
return n;
}
A
p ()
{
A a;
a.a = 12345678;
return a;
}
A
r ()
{
A a;
a.a = 10000000;
return a;
}
A
q (const A &a)
{
return a;
}
class B
{
public:
int b[1024];
};
B
makeb ()
{
B b;
int i;
for (i = 0; i < 1024; i++)
b.b[i] = i;
return b;
}
int
getb (const B &b, int i)
{
return b.b[i];
}
class C
{
public:
C ();
~C ();
A operator* ();
A *a_ptr;
};
C::C ()
{
a_ptr = new A;
a_ptr->a = 5678;
}
C::~C ()
{
delete a_ptr;
}
A
C::operator* ()
{
return *a_ptr;
}
#define TYPE_INDEX 1
enum type
{
INT,
CHAR
};
union U
{
public:
U (type t);
type get_type ();
int a;
char c;
type tp[2];
};
U::U (type t)
{
tp[TYPE_INDEX] = t;
}
U
make_int ()
{
return U (INT);
}
U
make_char ()
{
return U (CHAR);
}
type
U::get_type ()
{
return tp[TYPE_INDEX];
}
int
main ()
{
int i = g(f(0));
A a = q(p() + r());
B b = makeb ();
C c;
return i + getb(b, 0); /* Break here */
Bool t = set(true);
Bool f = set(false);
get(t);
get(f);
get(t & f);
return 0; // break here
}

View File

@ -34,7 +34,7 @@ class TestCppNsImport(TestBase):
self.assertTrue(src_file_spec.IsValid(), "Main source file")
# Get the path of the executable
cwd = os.getcwd()
cwd = self.get_process_working_directory()
exe_file = "a.out"
exe_path = os.path.join(cwd, exe_file)
@ -43,13 +43,13 @@ class TestCppNsImport(TestBase):
self.assertTrue(target.IsValid(), VALID_TARGET)
# Break on main function
main_breakpoint = target.BreakpointCreateByName("main")
self.assertTrue(main_breakpoint.IsValid() and main_breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT)
break_0 = target.BreakpointCreateBySourceRegex("// break 0", src_file_spec)
self.assertTrue(break_0.IsValid() and break_0.GetNumLocations() >= 1, VALID_BREAKPOINT)
# Launch the process
args = None
env = None
process = target.LaunchSimple(args, env, self.get_process_working_directory())
process = target.LaunchSimple(args, env, cwd)
self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
# Get the thread of the process
@ -60,14 +60,18 @@ class TestCppNsImport(TestBase):
frame = thread.GetSelectedFrame()
# Test imported namespaces
test_result = frame.EvaluateExpression("x")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 11, "x = 11")
test_result = frame.EvaluateExpression("n")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 1, "n = 1")
test_result = frame.EvaluateExpression("xx")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 22, "xx = 22")
test_result = frame.EvaluateExpression("N::n")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 1, "N::n = 1")
test_result = frame.EvaluateExpression("nested")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 3, "nested = 3")
test_result = frame.EvaluateExpression("anon")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 2, "anon = 2")
test_result = frame.EvaluateExpression("xxx")
self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 33, "xxx = 33")
if __name__ == '__main__':
import atexit

View File

@ -1,19 +1,28 @@
namespace A {
int x = 11;
namespace {
int xx = 22;
namespace N
{
int n;
}
namespace
{
int anon;
}
namespace Nested
{
namespace
{
int nested;
}
}
using namespace A;
using namespace N;
using namespace Nested;
namespace {
int xxx = 33;
};
int main() {
x;
xx;
xxx;
return 0;
int main()
{
n = 1;
anon = 2;
nested = 3;
return 0; // break 0
}