Skip to content

Add debug info tests #4862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ do
make_dir $h/test/bench
make_dir $h/test/perf
make_dir $h/test/pretty
make_dir $h/test/debug-info
make_dir $h/test/doc-tutorial
make_dir $h/test/doc-tutorial-ffi
make_dir $h/test/doc-tutorial-macros
Expand Down
14 changes: 12 additions & 2 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ cleantestlibs:
-name '*.dSYM' -o \
-name '*.libaux' -o \
-name '*.out' -o \
-name '*.err' \
-name '*.err' -o \
-name '*.debugger.script' \
| xargs rm -rf


Expand Down Expand Up @@ -284,6 +285,7 @@ CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
DEBUGINFO_RS := $(wildcard $(S)src/test/pretty/*.rs)

# perf tests are the same as bench tests only they run under
# a performance monitor.
Expand All @@ -296,6 +298,7 @@ CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
BENCH_TESTS := $(BENCH_RS)
PERF_TESTS := $(PERF_RS)
PRETTY_TESTS := $(PRETTY_RS)
DEBUGINFO_TESTS := $(DEBUGINFO_RS)

CTEST_SRC_BASE_rpass = run-pass
CTEST_BUILD_BASE_rpass = run-pass
Expand Down Expand Up @@ -327,6 +330,11 @@ CTEST_BUILD_BASE_perf = perf
CTEST_MODE_perf = run-pass
CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)

CTEST_SRC_BASE_debuginfo = debug-info
CTEST_BUILD_BASE_debuginfo = debug-info
CTEST_MODE_debuginfo = debug-info
CTEST_RUNTOOL_debuginfo = $(CTEST_RUNTOOL)

define DEF_CTEST_VARS

# All the per-stage build rules you might want to call from the
Expand Down Expand Up @@ -358,6 +366,7 @@ CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
CTEST_DEPS_debuginfo_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_TESTS)

endef

Expand Down Expand Up @@ -388,7 +397,7 @@ $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \

endef

CTEST_NAMES = rpass rpass-full rfail cfail bench perf
CTEST_NAMES = rpass rpass-full rfail cfail bench perf debuginfo

$(foreach host,$(CFG_TARGET_TRIPLES), \
$(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
Expand Down Expand Up @@ -496,6 +505,7 @@ TEST_GROUPS = \
cfail \
bench \
perf \
debuginfo \
doc \
$(foreach docname,$(DOC_TEST_NAMES),$(docname)) \
pretty \
Expand Down
5 changes: 3 additions & 2 deletions src/compiletest/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// Copyright 2012-2013 The Rust Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
Expand All @@ -18,6 +18,7 @@ pub enum mode {
mode_run_fail,
mode_run_pass,
mode_pretty,
mode_debug_info,
}

pub type config = {
Expand Down
5 changes: 4 additions & 1 deletion src/compiletest/compiletest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use common::mode_run_pass;
use common::mode_run_fail;
use common::mode_compile_fail;
use common::mode_pretty;
use common::mode_debug_info;
use common::mode;
use util::logv;

Expand Down Expand Up @@ -131,6 +132,7 @@ pub fn str_mode(s: ~str) -> mode {
~"run-fail" => mode_run_fail,
~"run-pass" => mode_run_pass,
~"pretty" => mode_pretty,
~"debug-info" => mode_debug_info,
_ => die!(~"invalid mode")
}
}
Expand All @@ -140,7 +142,8 @@ pub fn mode_str(mode: mode) -> ~str {
mode_compile_fail => ~"compile-fail",
mode_run_fail => ~"run-fail",
mode_run_pass => ~"run-pass",
mode_pretty => ~"pretty"
mode_pretty => ~"pretty",
mode_debug_info => ~"debug-info",
}
}

Expand Down
34 changes: 30 additions & 4 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// Copyright 2012-2013 The Rust Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
Expand Down Expand Up @@ -28,7 +28,11 @@ pub struct TestProps {
// Modules from aux directory that should be compiled
aux_builds: ~[~str],
// Environment settings to use during execution
exec_env: ~[(~str,~str)]
exec_env: ~[(~str,~str)],
// Commands to be given to the debugger, when testing debug info
debugger_cmds: ~[~str],
// Lines to check if they appear in the expected debugger output
check_lines: ~[~str],
}

// Load any test directives embedded in the file
Expand All @@ -38,6 +42,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut exec_env = ~[];
let mut compile_flags = None;
let mut pp_exact = None;
let mut debugger_cmds = ~[];
let mut check_lines = ~[];
for iter_header(testfile) |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns.push(ep),
Expand All @@ -59,13 +65,25 @@ pub fn load_props(testfile: &Path) -> TestProps {
do parse_exec_env(ln).iter |ee| {
exec_env.push(*ee);
}

match parse_debugger_cmd(ln) {
Some(dc) => debugger_cmds.push(dc),
None => ()
};

match parse_check_line(ln) {
Some(cl) => check_lines.push(cl),
None => ()
};
};
return TestProps {
error_patterns: error_patterns,
compile_flags: compile_flags,
pp_exact: pp_exact,
aux_builds: aux_builds,
exec_env: exec_env
exec_env: exec_env,
debugger_cmds: debugger_cmds,
check_lines: check_lines
};
}

Expand Down Expand Up @@ -112,6 +130,14 @@ fn parse_compile_flags(line: ~str) -> Option<~str> {
parse_name_value_directive(line, ~"compile-flags")
}

fn parse_debugger_cmd(line: ~str) -> Option<~str> {
parse_name_value_directive(line, ~"debugger")
}

fn parse_check_line(line: ~str) -> Option<~str> {
parse_name_value_directive(line, ~"check")
}

fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
do parse_name_value_directive(line, ~"exec-env").map |nv| {
// nv is either FOO or FOO=BAR
Expand Down
57 changes: 54 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// Copyright 2012-2013 The Rust Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
Expand Down Expand Up @@ -39,11 +39,13 @@ pub fn run(config: config, testfile: ~str) {
let testfile = Path(testfile);
debug!("running %s", testfile.to_str());
let props = load_props(&testfile);
debug!("loaded props");
match config.mode {
mode_compile_fail => run_cfail_test(config, props, &testfile),
mode_run_fail => run_rfail_test(config, props, &testfile),
mode_run_pass => run_rpass_test(config, props, &testfile),
mode_pretty => run_pretty_test(config, props, &testfile)
mode_pretty => run_pretty_test(config, props, &testfile),
mode_debug_info => run_debuginfo_test(config, props, &testfile)
}
}

Expand Down Expand Up @@ -224,6 +226,55 @@ actual:\n\
}
}

fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
// compile test file (it shoud have 'compile-flags:-g' in the header)
let mut ProcRes = compile_test(config, props, testfile);
if ProcRes.status != 0 {
fatal_ProcRes(~"compilation failed!", ProcRes);
}

// write debugger script
let script_str = str::append(str::connect(props.debugger_cmds, "\n"),
~"\nquit\n");
debug!("script_str = %s", script_str);
dump_output_file(config, testfile, script_str, ~"debugger.script");

// run debugger script with gdb
#[cfg(windows)]
fn debugger() -> ~str { ~"gdb.exe" }
#[cfg(unix)]
fn debugger() -> ~str { ~"gdb" }
let debugger_script = make_out_name(config, testfile, ~"debugger.script");
let debugger_opts = ~[~"-quiet", ~"-batch", ~"-nx",
~"-command=" + debugger_script.to_str(),
make_exe_name(config, testfile).to_str()];
let ProcArgs = ProcArgs {prog: debugger(), args: debugger_opts};
ProcRes = compose_and_run(config, testfile, ProcArgs, ~[], ~"", None);
if ProcRes.status != 0 {
fatal(~"gdb failed to execute");
}

let num_check_lines = vec::len(props.check_lines);
if num_check_lines > 0 {
// check if each line in props.check_lines appears in the
// output (in order)
let mut i = 0u;
for str::lines(ProcRes.stdout).each |line| {
if props.check_lines[i].trim() == line.trim() {
i += 1u;
}
if i == num_check_lines {
// all lines checked
break;
}
}
if i != num_check_lines {
fatal(fmt!("line not found in debugger output: %s",
props.check_lines[i]));
}
}
}

fn check_error_patterns(props: TestProps,
testfile: &Path,
ProcRes: ProcRes) {
Expand Down
21 changes: 21 additions & 0 deletions src/test/debug-info/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-test
// compile-flags:-g
// debugger:break 20
// debugger:run
// debugger:print x
// check:$1 = 42

fn main() {
let x = 42;
debug!("The answer is %d", x);
}
33 changes: 33 additions & 0 deletions src/test/debug-info/struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-test
// compile-flags:-g
// debugger:break 32
// debugger:run
// debugger:print pair
// check:$1 = {
// check:x = 1,
// check:y = 2,
// check:}
// debugger:print pair.x
// check:$2 = 1
// debugger:print pair.y
// check:$3 = 2

struct Pair {
x: int,
y: int
}

fn main() {
let pair = Pair { x: 1, y: 2 };
debug!("x = %d, y = %d", pair.x, pair.y);
}