summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile7
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py75
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp42
3 files changed, 124 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile
new file mode 100644
index 00000000000..a6ea665ef63
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../../../../make
+
+CXX_SOURCES := main.cpp
+
+USE_LIBCPP := 1
+include $(LEVEL)/Makefile.rules
+CXXFLAGS += -std=c++17
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py
new file mode 100644
index 00000000000..7826305931d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py
@@ -0,0 +1,75 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class LibcxxOptionalDataFormatterTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @add_test_categories(["libc++"])
+ ## We are skipping clang version less that 5.0 since this test requires -std=c++17
+ @skipIf(oslist=no_match(["macosx"]), compiler="clang", compiler_version=['<', '5.0'])
+ ## We are skipping gcc version less that 5.1 since this test requires -std=c++17
+ @skipIf(compiler="gcc", compiler_version=['<', '5.1'])
+
+ def test_with_run_command(self):
+ """Test that that file and class static variables display correctly."""
+ self.build()
+ self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
+
+ bkpt = self.target().FindBreakpointByID(
+ lldbutil.run_break_set_by_source_regexp(
+ self, "break here"))
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs=['stopped',
+ 'stop reason = breakpoint'])
+
+ self.runCmd( "frame variable has_optional" )
+
+ output = self.res.GetOutput()
+
+ ## The variable has_optional tells us if the test program
+ ## detected we have a sufficient libc++ version to support optional
+ ## false means we do not and therefore should skip the test
+ if output.find("(bool) has_optional = false") != -1 :
+ self.skipTest( "Optional not supported" )
+
+ lldbutil.continue_to_breakpoint(self.process(), bkpt)
+
+ self.expect("frame variable number_not_engaged",
+ substrs=['Has Value=false'])
+
+ self.expect("frame variable number_engaged",
+ substrs=['Has Value=true',
+ 'Value = 42',
+ '}'])
+
+ self.expect("frame var numbers",
+ substrs=['(optional_int_vect) numbers = Has Value=true {',
+ 'Value = size=4 {',
+ '[0] = 1',
+ '[1] = 2',
+ '[2] = 3',
+ '[3] = 4',
+ '}',
+ '}'])
+
+ self.expect("frame var ostring",
+ substrs=['(optional_string) ostring = Has Value=true {',
+ 'Value = "hello"',
+ '}'])
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp
new file mode 100644
index 00000000000..16bb98c6105
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp
@@ -0,0 +1,42 @@
+#include <cstdio>
+#include <string>
+#include <vector>
+
+// If we have libc++ 4.0 or greater we should have <optional>
+// According to libc++ C++1z status page https://libcxx.llvm.org/cxx1z_status.html
+#if _LIBCPP_VERSION >= 4000
+#include <optional>
+#define HAVE_OPTIONAL 1
+#else
+#define HAVE_OPTIONAL 0
+#endif
+
+
+int main()
+{
+ bool has_optional = HAVE_OPTIONAL ;
+
+ printf( "%d\n", has_optional ) ; // break here
+
+#if HAVE_OPTIONAL == 1
+ using int_vect = std::vector<int> ;
+ using optional_int = std::optional<int> ;
+ using optional_int_vect = std::optional<int_vect> ;
+ using optional_string = std::optional<std::string> ;
+
+ optional_int number_not_engaged ;
+ optional_int number_engaged = 42 ;
+
+ printf( "%d\n", *number_engaged) ;
+
+ optional_int_vect numbers{{1,2,3,4}} ;
+
+ printf( "%d %d\n", numbers.value()[0], numbers.value()[1] ) ;
+
+ optional_string ostring = "hello" ;
+
+ printf( "%s\n", ostring->c_str() ) ;
+#endif
+
+ return 0; // break here
+}
OpenPOWER on IntegriCloud