forked from OSchip/llvm-project
Add a sample_test directory with simple starter
test cases for standard and "inline" tests. llvm-svn: 296669
This commit is contained in:
parent
0a4703b5ec
commit
96b2530f52
|
@ -54,6 +54,10 @@ o subdirectories of 'test'
|
|||
C/C++/ObjC source files; they were created to house the Python test case which
|
||||
does not involve lldb reading in an executable file at all.
|
||||
|
||||
The sample_test directory contains examples of both a full and an "inline"
|
||||
testcase that run a process to a breakpoint and check a local variable. These
|
||||
are convenient starting points for adding new tests.
|
||||
|
||||
o make directory
|
||||
|
||||
Contains Makefile.rules, which can be utilized by test cases to write Makefile
|
||||
|
@ -158,6 +162,9 @@ o Writing test cases:
|
|||
from the command in the command return object, and all the part where you are driving the
|
||||
debugger to the point you want to test will be more robust.
|
||||
|
||||
The sample_test directory contains a standard and an "inline" test that are good starting
|
||||
points for writing a new test.
|
||||
|
||||
o Attaching in test cases:
|
||||
|
||||
If you need to attach to inferiors in your tests, you must make sure the inferior calls
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
LEVEL = ../make
|
||||
|
||||
C_SOURCES := main.c
|
||||
CFLAGS_EXTRAS += -std=c99
|
||||
|
||||
include $(LEVEL)/Makefile.rules
|
|
@ -0,0 +1,6 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from lldbsuite.test import lldbinline
|
||||
|
||||
lldbinline.MakeInlineTest(
|
||||
__file__, globals(), None)
|
|
@ -0,0 +1,71 @@
|
|||
"""
|
||||
Sample test that runs a process to a source regexp breakpoint.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import lldb
|
||||
import lldbsuite.test.lldbutil as lldbutil
|
||||
from lldbsuite.test.lldbtest import *
|
||||
|
||||
|
||||
class SampleTestTestCase(TestBase):
|
||||
|
||||
mydir = TestBase.compute_mydir(__file__)
|
||||
|
||||
NO_DEBUG_INFO_TESTCASE = True
|
||||
|
||||
def test_sample(self):
|
||||
"""A sample test example that drives a debug session to a breakpoint."""
|
||||
self.build()
|
||||
self.sample_test()
|
||||
|
||||
def setUp(self):
|
||||
# Call super's setUp().
|
||||
TestBase.setUp(self)
|
||||
|
||||
def sample_test(self):
|
||||
"""A sample test example that drives a debug session to a breakpoint."""
|
||||
exe = os.path.join(os.getcwd(), "a.out")
|
||||
|
||||
# Create a target by the debugger.
|
||||
target = self.dbg.CreateTarget(exe)
|
||||
self.assertTrue(target, VALID_TARGET)
|
||||
|
||||
# Now create a breakpoint in main.c at the source matching
|
||||
# "Set a breakpoint here"
|
||||
breakpoint = target.BreakpointCreateBySourceRegex(
|
||||
"Set a breakpoint here", lldb.SBFileSpec("main.c"))
|
||||
self.assertTrue(breakpoint and
|
||||
breakpoint.GetNumLocations() >= 1,
|
||||
VALID_BREAKPOINT)
|
||||
|
||||
error = lldb.SBError()
|
||||
# This is the launch info. If you want to launch with arguments or
|
||||
# environment variables, add them using SetArguments or
|
||||
# SetEnvironmentEntries
|
||||
|
||||
launch_info = lldb.SBLaunchInfo(None)
|
||||
process = target.Launch(launch_info, error)
|
||||
self.assertTrue(process, PROCESS_IS_VALID)
|
||||
|
||||
# Did we hit our breakpoint?
|
||||
from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
|
||||
threads = get_threads_stopped_at_breakpoint(process, breakpoint)
|
||||
self.assertTrue(
|
||||
len(threads) == 1,
|
||||
"There should be a thread stopped at our breakpoint")
|
||||
|
||||
# The hit count for the breakpoint should be 1.
|
||||
self.assertTrue(breakpoint.GetHitCount() == 1)
|
||||
|
||||
frame = threads[0].GetFrameAtIndex(0)
|
||||
test_var = frame.FindVariable("test_var")
|
||||
self.assertTrue(test_var.GetError().Success(), "Failed to fetch test_var")
|
||||
test_value = test_var.GetValueAsUnsigned()
|
||||
self.assertEqual(test_value, 10, "Got the right value for test_var")
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int test_var = 10;
|
||||
printf ("Set a breakpoint here: %d.\n", test_var);
|
||||
//% test_var = self.frame().FindVariable("test_var")
|
||||
//% test_value = test_var.GetValueAsUnsigned()
|
||||
//% self.assertTrue(test_var.GetError().Success(), "Failed to fetch test_var")
|
||||
//% self.assertEqual(test_value, 10, "Failed to get the right value for test_var")
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue