[Lldb-commits] [lldb] r245505 - Improve tests regarding imported namespaces and chained calls in C++
Paul Herman via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 19 14:23:01 PDT 2015
Author: paulherman
Date: Wed Aug 19 16:23:01 2015
New Revision: 245505
URL: http://llvm.org/viewvc/llvm-project?rev=245505&view=rev
Log:
Improve tests regarding imported namespaces and chained calls in C++
Modified:
lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py
lldb/trunk/test/lang/cpp/chained-calls/main.cpp
lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py
lldb/trunk/test/lang/cpp/nsimport/main.cpp
Modified: lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py?rev=245505&r1=245504&r2=245505&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py (original)
+++ lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py Wed Aug 19 16:23:01 2015
@@ -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("q(p()).a")
- self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 12345678, "q(p()).a = 12345678")
- test_result = frame.EvaluateExpression("(p() + r()).a")
- self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 22345678, "(p() + r()).a = 22345678")
+ # Test chained calls
+ 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() + r()).a")
- self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 22345678, "q(p() + r()).a = 22345678")
+ 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("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 & f)")
+ self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(t & f) = false")
- 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 & t)")
+ self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(f & t) = 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 & t)")
+ self.assertTrue(test_result.IsValid() and test_result.GetValue() == "true", "get(t & t) = true")
- 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 & f)")
+ self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(f & f) = 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("get(t & f)")
+ self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(t & f) = false")
- 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("get(f) && get(t)")
+ self.assertTrue(test_result.IsValid() and test_result.GetValue() == "false", "get(f) && get(t) = false")
- 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
Modified: lldb/trunk/test/lang/cpp/chained-calls/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/chained-calls/main.cpp?rev=245505&r1=245504&r2=245505&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/chained-calls/main.cpp (original)
+++ lldb/trunk/test/lang/cpp/chained-calls/main.cpp Wed Aug 19 16:23:01 2015
@@ -1,186 +1,33 @@
-class S
-{
-public:
- S () { }
- S (S &obj);
-
- S operator+ (const S &s);
-
- int a;
-};
-
-S::S (S &obj)
-{
- a = obj.a;
-}
-
-S
-S::operator+ (const S &s)
-{
- S res;
-
- res.a = a + s.a;
-
- return res;
-}
-
-S
-f (int i)
-{
- 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
-{
+class Bool {
public:
- U (type t);
- type get_type ();
+ Bool operator&(const Bool other)
+ {
+ Bool result;
+ result.value = value && other.value;
+ return result;
+ }
- int a;
- char c;
- type tp[2];
+ bool value;
};
-U::U (type t)
-{
- tp[TYPE_INDEX] = t;
-}
-
-U
-make_int ()
+bool get(Bool object)
{
- return U (INT);
+ return object.value;
}
-U
-make_char ()
+Bool set(bool value)
{
- return U (CHAR);
+ Bool result;
+ result.value = value;
+ return result;
}
-type
-U::get_type ()
+int main()
{
- 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
}
Modified: lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py?rev=245505&r1=245504&r2=245505&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py (original)
+++ lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py Wed Aug 19 16:23:01 2015
@@ -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
Modified: lldb/trunk/test/lang/cpp/nsimport/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/nsimport/main.cpp?rev=245505&r1=245504&r2=245505&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/nsimport/main.cpp (original)
+++ lldb/trunk/test/lang/cpp/nsimport/main.cpp Wed Aug 19 16:23:01 2015
@@ -1,19 +1,28 @@
-namespace A {
- int x = 11;
- namespace {
- int xx = 22;
- }
+namespace N
+{
+ int n;
+}
+
+namespace
+{
+ int anon;
}
-using namespace A;
+namespace Nested
+{
+ namespace
+ {
+ int nested;
+ }
+}
-namespace {
- int xxx = 33;
-};
+using namespace N;
+using namespace Nested;
-int main() {
- x;
- xx;
- xxx;
- return 0;
+int main()
+{
+ n = 1;
+ anon = 2;
+ nested = 3;
+ return 0; // break 0
}
More information about the lldb-commits
mailing list