hotspot/test/runtime/logging/StackWalkTest.java
author rprotacio
Thu, 29 Sep 2016 13:32:17 -0400
changeset 41664 07e88a4b405f
permissions -rw-r--r--
8160064: StackWalker implementation added logging option without using UL Summary: Moved StackWalk logging to Unified Logging framework Reviewed-by: coleenp, mockner, dholmes, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     1
/*
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     4
 *
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     7
 * published by the Free Software Foundation.
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     8
 *
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    13
 * accompanied this code).
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    14
 *
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    18
 *
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    21
 * questions.
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    22
 */
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    23
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    24
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    25
/*
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    26
 * @test StackWalkTest
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    27
 * @bug 8160064
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    28
 * @summary -Xlog:stackwalk should produce logging from the source code
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    29
 * @library /test/lib
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    30
 * @run driver StackWalkTest
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    31
 */
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    32
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    33
import jdk.test.lib.process.ProcessTools;
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    34
import jdk.test.lib.process.OutputAnalyzer;
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    35
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    36
public class StackWalkTest {
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    37
    static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    38
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    39
        output.shouldContain("Start walking");
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    40
        output.shouldContain("fill_in_frames");
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    41
        output.shouldHaveExitValue(0);
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    42
    }
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    43
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    44
    static void analyzeOutputOff(ProcessBuilder pb) throws Exception {
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    45
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    46
        output.shouldNotContain("[stackwalk]");
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    47
        output.shouldHaveExitValue(0);
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    48
    }
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    49
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    50
    public static void main(String... args) throws Exception {
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    51
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:stackwalk=debug",
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    52
                                                                  InnerClass.class.getName());
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    53
        analyzeOutputOn(pb);
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    54
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    55
        pb = ProcessTools.createJavaProcessBuilder("-Xlog:stackwalk=off",
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    56
                                                   InnerClass.class.getName());
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    57
        analyzeOutputOff(pb);
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    58
    }
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    59
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    60
    public static class InnerClass {
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    61
        public static void main(String[] args) throws Exception {
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    62
            System.out.println("Testing stackwalk.");
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    63
            StackWalker sw = StackWalker.getInstance();
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    64
            sw.forEach(System.out::println);
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    65
        }
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    66
    }
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
diff changeset
    67
}