Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbHistory.java
41152 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.HashMap;24import java.util.List;25import java.util.Map;2627import jdk.test.lib.apps.LingeredApp;28import jdk.test.lib.Utils;29import jtreg.SkippedException;3031/**32* @test33* @bug 819019834* @bug 821761235* @bug 821784536* @summary Test clhsdb command line history support37* @requires vm.hasSA38* @library /test/lib39* @run main/othervm ClhsdbHistory40*/4142public class ClhsdbHistory {4344public static void testHistory() throws Exception {45System.out.println("Starting ClhsdbHistory basic test");4647LingeredApp theApp = null;48try {49ClhsdbLauncher test = new ClhsdbLauncher();50theApp = LingeredApp.startApp();51System.out.println("Started LingeredApp with pid " + theApp.getPid());5253List<String> cmds = List.of(54"echo true",55"assert false",56"!!", // !! repeats previous command57"versioncheck !$", // !$ is last argument from previous command58"assert foo bar baz",59"versioncheck !*", // !* is all arguments from previous command60"versioncheck !$ !$", // !$ !$ should result in "baz baz"61"assert maybe never",62"!!- !*", // !!- is the previous command, minus the last arg63"!echo", // match previous echo command, with args64"assert \\!foo", // quote the ! so it is not used for command history expansion65"!10", // match the 10th command in the history, with args66"history");6768// Unfortunately we can't create a map table that maps the clhsdb commands above69// to the expected output because the commands as you see them above won't be in70// the output. Instead their expanded forms will. So instead we just rely on71// the history output looking as expected.72Map<String, List<String>> expStrMap = new HashMap<>();73expStrMap.put("history", List.of(74"0 echo true", // issued by ClhsdbLauncher75"1 verbose true", // issued by ClhsdbLauncher76"2 echo true",77"3 assert false",78"4 assert false",79"5 versioncheck false",80"6 assert foo bar baz",81"7 versioncheck foo bar baz",82"8 versioncheck baz baz",83"9 assert maybe never",84"10 assert maybe maybe never",85"11 echo true",86"12 assert !foo",87"13 assert maybe maybe never",88"14 history"));8990test.run(theApp.getPid(), cmds, expStrMap, null);91} catch (SkippedException se) {92throw se;93} catch (Exception ex) {94throw new RuntimeException("Test ERROR " + ex, ex);95} finally {96LingeredApp.stopApp(theApp);97}98System.out.println("Test PASSED");99}100101public static void main(String[] args) throws Exception {102testHistory();103}104}105106107