forked from OSchip/llvm-project
Add a test script for exercising the "taregt create", "target list", and "target select" commands.
llvm-svn: 129717
This commit is contained in:
parent
b2545fbc2a
commit
1ee61a7f3b
|
@ -300,6 +300,7 @@ public:
|
|||
{
|
||||
strm.PutCString ("No targets.\n");
|
||||
}
|
||||
result.SetStatus (eReturnStatusSuccessFinishResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -355,6 +356,7 @@ public:
|
|||
target_list.SetSelectedTarget (target_sp.get());
|
||||
bool show_stopped_process_status = false;
|
||||
DumpTargetList (target_list, show_stopped_process_status, strm);
|
||||
result.SetStatus (eReturnStatusSuccessFinishResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -546,6 +546,9 @@ class TestBase(unittest2.TestCase):
|
|||
# These are for customized teardown cleanup.
|
||||
self.dict = None
|
||||
self.doTearDownCleanup = False
|
||||
# And in rare cases where there are multiple teardown cleanups.
|
||||
self.dicts = []
|
||||
self.doTearDownCleanups = False
|
||||
|
||||
# Create a string buffer to record the session info, to be dumped into a
|
||||
# test case specific file if test failure is encountered.
|
||||
|
@ -644,6 +647,11 @@ class TestBase(unittest2.TestCase):
|
|||
self.dict = dictionary
|
||||
self.doTearDownCleanup = True
|
||||
|
||||
def addTearDownCleanup(self, dictionary):
|
||||
"""Add a cleanup action at tearDown() time with a dictinary"""
|
||||
self.dicts.append(dictionary)
|
||||
self.doTearDownCleanups = True
|
||||
|
||||
def addTearDownHook(self, hook):
|
||||
"""
|
||||
Add a function to be run during tearDown() time.
|
||||
|
@ -686,7 +694,15 @@ class TestBase(unittest2.TestCase):
|
|||
if doCleanup and self.doTearDownCleanup:
|
||||
module = __import__(sys.platform)
|
||||
if not module.cleanup(self, dictionary=self.dict):
|
||||
raise Exception("Don't know how to do cleanup")
|
||||
raise Exception("Don't know how to do cleanup with dictionary: " + self.dict)
|
||||
|
||||
# In rare cases where there are multiple teardown cleanups added.
|
||||
if doCleanup and self.doTearDownCleanups:
|
||||
module = __import__(sys.platform)
|
||||
if self.dicts:
|
||||
for dict in reversed(self.dicts):
|
||||
if not module.cleanup(self, dictionary=dict):
|
||||
raise Exception("Don't know how to do cleanup with dictionary: " + dict)
|
||||
|
||||
# Decide whether to dump the session info.
|
||||
self.dumpSessionInfo()
|
||||
|
|
|
@ -38,7 +38,7 @@ CXXFLAGS +=$(CFLAGS)
|
|||
LD = $(CC)
|
||||
LDFLAGS ?= $(CFLAGS)
|
||||
OBJECTS =
|
||||
EXE = a.out
|
||||
EXE ?= a.out
|
||||
DSYM = $(EXE).dSYM
|
||||
|
||||
# Function that returns the counterpart C++ compiler, given $(CC) as arg.
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
LEVEL = ../make
|
||||
|
||||
# Example:
|
||||
#
|
||||
# C_SOURCES := b.c
|
||||
# EXE := b.out
|
||||
|
||||
include $(LEVEL)/Makefile.rules
|
|
@ -0,0 +1,95 @@
|
|||
"""
|
||||
Test some target commands: create, list, select.
|
||||
"""
|
||||
|
||||
import unittest2
|
||||
import lldb
|
||||
import sys
|
||||
from lldbtest import *
|
||||
|
||||
class targetCommandTestCase(TestBase):
|
||||
|
||||
mydir = "target"
|
||||
|
||||
def setUp(self):
|
||||
# Call super's setUp().
|
||||
TestBase.setUp(self)
|
||||
# Find the line numbers for our breakpoints.
|
||||
self.line_b = line_number('b.c', '// Set break point at this line.')
|
||||
self.line_c = line_number('c.c', '// Set break point at this line.')
|
||||
|
||||
def test_target_command_with_dwarf(self):
|
||||
"""Test some target commands: create, list, select."""
|
||||
da = {'C_SOURCES': 'a.c', 'EXE': 'a.out'}
|
||||
self.buildDefault(dictionary=da)
|
||||
self.addTearDownCleanup(dictionary=da)
|
||||
|
||||
db = {'C_SOURCES': 'b.c', 'EXE': 'b.out'}
|
||||
self.buildDefault(dictionary=db)
|
||||
self.addTearDownCleanup(dictionary=db)
|
||||
|
||||
dc = {'C_SOURCES': 'c.c', 'EXE': 'c.out'}
|
||||
self.buildDefault(dictionary=dc)
|
||||
self.addTearDownCleanup(dictionary=dc)
|
||||
|
||||
self.do_target_command()
|
||||
|
||||
def do_target_command(self):
|
||||
"""Exercise 'target create', 'target list', 'target select' commands."""
|
||||
exe_a = os.path.join(os.getcwd(), "a.out")
|
||||
exe_b = os.path.join(os.getcwd(), "b.out")
|
||||
exe_c = os.path.join(os.getcwd(), "c.out")
|
||||
|
||||
self.runCmd("target list")
|
||||
output = self.res.GetOutput()
|
||||
if output.startswith("No targets"):
|
||||
# We start from index 0.
|
||||
base = 0
|
||||
else:
|
||||
# Find the largest index of the existing list.
|
||||
import re
|
||||
pattern = re.compile("target #(\d+):")
|
||||
for line in reversed(output.split(os.linesep)):
|
||||
match = pattern.search(line)
|
||||
if match:
|
||||
# We will start from (index + 1) ....
|
||||
base = int(match.group(1), 10) + 1
|
||||
#print "base is:", base
|
||||
break;
|
||||
|
||||
self.runCmd("target create " + exe_a, CURRENT_EXECUTABLE_SET)
|
||||
self.runCmd("run", RUN_SUCCEEDED)
|
||||
|
||||
self.runCmd("target create " + exe_b, CURRENT_EXECUTABLE_SET)
|
||||
self.runCmd("breakpoint set -f %s -l %d" % ('b.c', self.line_b),
|
||||
BREAKPOINT_CREATED)
|
||||
self.runCmd("run", RUN_SUCCEEDED)
|
||||
|
||||
self.runCmd("target create " + exe_c, CURRENT_EXECUTABLE_SET)
|
||||
self.runCmd("breakpoint set -f %s -l %d" % ('c.c', self.line_c),
|
||||
BREAKPOINT_CREATED)
|
||||
self.runCmd("run", RUN_SUCCEEDED)
|
||||
|
||||
self.runCmd("target list")
|
||||
|
||||
self.runCmd("target select %d" % base)
|
||||
self.runCmd("thread backtrace")
|
||||
|
||||
self.runCmd("target select %d" % (base + 2))
|
||||
self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
|
||||
substrs = ['c.c:%d' % self.line_c,
|
||||
'stop reason = breakpoint'])
|
||||
|
||||
self.runCmd("target select %d" % (base + 1))
|
||||
self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
|
||||
substrs = ['b.c:%d' % self.line_b,
|
||||
'stop reason = breakpoint'])
|
||||
|
||||
self.runCmd("target list")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import atexit
|
||||
lldb.SBDebugger.Initialize()
|
||||
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
||||
unittest2.main()
|
|
@ -0,0 +1,16 @@
|
|||
//===-- main.c --------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
int *null_ptr = 0;
|
||||
printf("Hello, segfault!\n");
|
||||
printf("Now crash %d\n", *null_ptr); // Crash here.
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
//===-- main.c --------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main (int argc, char const *argv[])
|
||||
{
|
||||
return 0; // Set break point at this line.
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
//===-- main.c --------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char const *argv[])
|
||||
{
|
||||
enum days {
|
||||
Monday = 10,
|
||||
Tuesday,
|
||||
Wednesday,
|
||||
Thursday,
|
||||
Friday,
|
||||
Saturday,
|
||||
Sunday,
|
||||
kNumDays
|
||||
};
|
||||
enum days day;
|
||||
for (day = Monday - 1; day <= kNumDays + 1; day++)
|
||||
{
|
||||
printf("day as int is %i\n", (int)day);
|
||||
}
|
||||
return 0; // Set break point at this line.
|
||||
}
|
Loading…
Reference in New Issue