OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [testsuite/] [libjava.lang/] [StackTrace2.java] - Blame information for rev 765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 765 jeremybenn
// Check that stack trace's work, and stack trace line numbers, if available,
2
// are correct.
3
 
4
public class StackTrace2
5
{
6
  public static void main(String[] args)
7
  {
8
    try
9
    {
10
      new StackTrace2().a();
11
    }
12
    catch (Exception x)
13
    {
14
      StackTraceElement[] trace = x.getStackTrace();
15
      checkTrace(trace);
16
    }
17
  }
18
 
19
  void a()
20
  {
21
    new Inner().foo();
22
  }
23
 
24
  class Inner
25
  {
26
    public void foo()
27
    {
28
      doCrash(null);
29
    }
30
 
31
    public void doCrash(Object o)
32
    {
33
      o.toString();
34
    }
35
  }
36
 
37
  static void checkTrace(StackTraceElement[] trace)
38
  {
39
    System.out.println("Trace length = " + trace.length);
40
    checkLine(trace[0], "StackTrace2$Inner", "doCrash", 33);
41
    checkLine(trace[1], "StackTrace2$Inner", "foo", 28);
42
    checkLine(trace[2], "StackTrace2", "a", 21);
43
    checkLine(trace[3], "StackTrace2", "main", 10);
44
  }
45
 
46
  static void checkLine(StackTraceElement frame, String expected_cl,
47
                        String expected_method, int expected_line)
48
  {
49
    if (frame.getClassName().equals(expected_cl))
50
      System.out.print(expected_cl);
51
    else
52
      System.out.print("FAIL - expected " + expected_cl + ", got: " +
53
                       frame.getClassName());
54
 
55
    System.out.print(".");
56
 
57
    if (frame.getMethodName().equals(expected_method))
58
      System.out.print(expected_method);
59
    else
60
      System.out.print("FAIL - expected " + expected_method + ", got: " +
61
                       frame.getMethodName());
62
 
63
    System.out.print(":");
64
 
65
    // Permit either the correct line number or no line number. This is so
66
    // we don't fail on platforms that don't yet support reading debug info 
67
    // for stack traces, or when no debug info is available.
68
    if (frame.getLineNumber() < 0
69
        || (frame.getLineNumber() == expected_line
70
            && frame.getFileName().equals("StackTrace2.java")))
71
      System.out.println("OK");
72
    else
73
      System.out.println("FAIL - expected " + expected_line + ", got: "
74
                         + frame.getLineNumber() + ", in file "
75
                         + frame.getFileName());
76
  }
77
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.