about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBrian Leibig <brian.leibig@gmail.com>2013-02-09 13:09:19 -0500
committerBrian Leibig <brian.leibig@gmail.com>2013-02-09 13:09:19 -0500
commit6bfbdadd3bdb811c16f4aecd1f123c1a1eb0ee2e (patch)
treeb856d591ec04d8983981f890664b5432ee1a0902 /src
parent0c2b4edff5009ff4d2330723d9acbc85af4b12ab (diff)
Add debug info tests
Diffstat (limited to 'src')
-rw-r--r--src/compiletest/common.rs5
-rw-r--r--src/compiletest/compiletest.rc5
-rw-r--r--src/compiletest/header.rs34
-rw-r--r--src/compiletest/runtest.rs57
-rw-r--r--src/test/debug-info/simple.rs21
-rw-r--r--src/test/debug-info/struct.rs33
6 files changed, 145 insertions, 10 deletions
diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs
index 9d4becd63d3..679f9ab93bf 100644
--- a/src/compiletest/common.rs
+++ b/src/compiletest/common.rs
@@ -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
@@ -18,6 +18,7 @@ pub enum mode {
     mode_run_fail,
     mode_run_pass,
     mode_pretty,
+    mode_debug_info,
 }
 
 pub type config = {
diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc
index b63ac5e75a2..6d3bfde0372 100644
--- a/src/compiletest/compiletest.rc
+++ b/src/compiletest/compiletest.rc
@@ -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;
 
@@ -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")
     }
 }
@@ -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",
     }
 }
 
diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs
index 0b9d67426ae..5c33c66209a 100644
--- a/src/compiletest/header.rs
+++ b/src/compiletest/header.rs
@@ -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
@@ -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
@@ -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),
@@ -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
     };
 }
 
@@ -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
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index a71b8a360a2..0f8c8761c42 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -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
@@ -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)
     }
 }
 
@@ -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) {
diff --git a/src/test/debug-info/simple.rs b/src/test/debug-info/simple.rs
new file mode 100644
index 00000000000..51bb177601a
--- /dev/null
+++ b/src/test/debug-info/simple.rs
@@ -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);
+}
diff --git a/src/test/debug-info/struct.rs b/src/test/debug-info/struct.rs
new file mode 100644
index 00000000000..b3132914477
--- /dev/null
+++ b/src/test/debug-info/struct.rs
@@ -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);
+}