diff options
Diffstat (limited to 'lldb/test/expression_command/timeout')
-rw-r--r-- | lldb/test/expression_command/timeout/Makefile | 5 | ||||
-rw-r--r-- | lldb/test/expression_command/timeout/TestCallWithTimeout.py | 94 | ||||
-rw-r--r-- | lldb/test/expression_command/timeout/wait-a-while.c | 41 |
3 files changed, 140 insertions, 0 deletions
diff --git a/lldb/test/expression_command/timeout/Makefile b/lldb/test/expression_command/timeout/Makefile new file mode 100644 index 00000000000..1cd67828bd7 --- /dev/null +++ b/lldb/test/expression_command/timeout/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := wait-a-while.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/expression_command/timeout/TestCallWithTimeout.py b/lldb/test/expression_command/timeout/TestCallWithTimeout.py new file mode 100644 index 00000000000..fb9b7d04002 --- /dev/null +++ b/lldb/test/expression_command/timeout/TestCallWithTimeout.py @@ -0,0 +1,94 @@ +""" +Test calling a function that waits a while, and make sure the timeout option to expr works. +""" + +import unittest2 +import lldb +import lldbutil +from lldbtest import * + +class ExprCommandWithTimeoutsTestCase(TestBase): + + mydir = os.path.join("expression_command", "timeout") + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "wait-a-while.c" + self.main_source_spec = lldb.SBFileSpec (self.main_source) + + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @dsym_test + def test_with_dsym(self): + """Test calling std::String member function.""" + self.buildDsym() + self.call_function() + + @dwarf_test + def test_with_dwarf(self): + """Test calling std::String member function.""" + self.buildDsym() + self.call_function() + + def call_function(self): + """Test calling function with timeout.""" + exe_name = "a.out" + exe = os.path.join(os.getcwd(), exe_name) + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + breakpoint = target.BreakpointCreateBySourceRegex('stop here in main.',self.main_source_spec) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + self.runCmd("breakpoint list") + + # Launch the process, and do not stop at the entry point. + process = target.LaunchSimple(None, None, os.getcwd()) + + self.assertTrue(process, PROCESS_IS_VALID) + + # Frame #0 should be on self.step_out_of_malloc. + threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) + + self.assertTrue(len(threads) == 1) + thread = threads[0] + + # First set the timeout too short, and make sure we fail. + options = lldb.SBExpressionOptions() + options.SetTimeoutUsec(100) + options.SetUnwindOnError(True) + + frame = thread.GetFrameAtIndex(0) + + value = frame.EvaluateExpression ("wait_a_while (10000)", options) + self.assertTrue (value.IsValid()) + self.assertTrue (value.GetError().Success() == False) + + # Now do the same thing with the command line command, and make sure it works too. + interp = self.dbg.GetCommandInterpreter() + + result = lldb.SBCommandReturnObject() + return_value = interp.HandleCommand ("expr -t 100 -u true -- wait_a_while(10000)", result) + self.assertTrue (return_value == lldb.eReturnStatusFailed) + + # Okay, now do it again with long enough time outs: + + options.SetTimeoutUsec(1000000) + value = frame.EvaluateExpression ("wait_a_while (1000)", options) + self.assertTrue(value.IsValid()) + self.assertTrue (value.GetError().Success() == True) + + # Now do the same thingwith the command line command, and make sure it works too. + interp = self.dbg.GetCommandInterpreter() + + result = lldb.SBCommandReturnObject() + return_value = interp.HandleCommand ("expr -t 1000000 -u true -- wait_a_while(1000)", result) + self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/expression_command/timeout/wait-a-while.c b/lldb/test/expression_command/timeout/wait-a-while.c new file mode 100644 index 00000000000..f3475fc3ff2 --- /dev/null +++ b/lldb/test/expression_command/timeout/wait-a-while.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <unistd.h> +#include <sys/time.h> +#include <stdint.h> + +int +wait_a_while (useconds_t interval) +{ + int num_times = 0; + int return_value = 1; + + struct timeval start_time; + gettimeofday(&start_time, NULL); + uint64_t target = start_time.tv_sec * 1000000 + start_time.tv_usec + interval; + + while (1) + { + num_times++; + return_value = usleep (interval); + if (return_value != 0) + { + struct timeval now; + gettimeofday(&now, NULL); + interval = target - now.tv_sec * 1000000 + now.tv_usec; + } + else + break; + } + return num_times; +} + +int +main (int argc, char **argv) +{ + printf ("stop here in main.\n"); + int num_times = wait_a_while (argc * 1000); + printf ("Done, took %d times.\n", num_times); + + return 0; + +} |