Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/parser/DirectiveParserTest.java
41154 views
/*1* Copyright (c) 2015, 2016, 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*/2223/*24* @test25* @bug 813716726* @summary Tests directive json parser27* @modules java.base/jdk.internal.misc28* @library /test/lib /29*30* @run driver compiler.compilercontrol.parser.DirectiveParserTest31*/3233package compiler.compilercontrol.parser;3435import compiler.compilercontrol.share.JSONFile;36import jdk.test.lib.Asserts;37import jdk.test.lib.process.OutputAnalyzer;38import jdk.test.lib.Utils;3940public class DirectiveParserTest {41private static final String ERROR_MSG = "VM should exit with error "42+ "on incorrect JSON file: ";43private static final String EXPECTED_ERROR_STRING = "Parsing of compiler"44+ " directives failed";4546public static void main(String[] args) {47simpleTest();48nonMatchingBrackets();49arrayTest();50emptyObjectTest();51emptyFile();52noFile();53directory();54}5556private static void simpleTest() {57String fileName = "simple.json";58try (JSONFile file = new JSONFile(fileName)) {59file.write(JSONFile.Element.ARRAY)60.write(JSONFile.Element.OBJECT)61.write(JSONFile.Element.PAIR, "match")62.write(JSONFile.Element.VALUE, "\"java/lang/String.*\"")63.write(JSONFile.Element.PAIR, "c2")64.write(JSONFile.Element.OBJECT)65.write(JSONFile.Element.PAIR, "inline")66.write(JSONFile.Element.ARRAY)67.write(JSONFile.Element.VALUE, "\"+*.indexOf\"")68.write(JSONFile.Element.VALUE, "\"-a.b\"")69.end()70.end()71.end() // end object72.write(JSONFile.Element.OBJECT)73.write(JSONFile.Element.PAIR, "match")74.write(JSONFile.Element.VALUE, "\"*.indexOf\"")75.write(JSONFile.Element.PAIR, "c1")76.write(JSONFile.Element.OBJECT)77.write(JSONFile.Element.PAIR, "enable")78.write(JSONFile.Element.VALUE, "false")79.end()80.end(); // end object81file.end();82}83OutputAnalyzer output = HugeDirectiveUtil.execute(fileName);84output.shouldHaveExitValue(0);85output.shouldNotContain(EXPECTED_ERROR_STRING);86}8788private static void nonMatchingBrackets() {89String fileName = "non-matching.json";90try (JSONFile file = new JSONFile(fileName)) {91file.write(JSONFile.Element.ARRAY)92.write(JSONFile.Element.OBJECT)93.write(JSONFile.Element.PAIR, "match")94.write(JSONFile.Element.VALUE, "\"java/lang/String.*\"")95.end();96// don't write matching }97}98OutputAnalyzer output = HugeDirectiveUtil.execute(fileName);99Asserts.assertNE(output.getExitValue(), 0, ERROR_MSG + "non matching "100+ "brackets");101output.shouldContain(EXPECTED_ERROR_STRING);102}103104private static void arrayTest() {105String fileName = "array.json";106try (JSONFile file = new JSONFile(fileName)) {107file.write(JSONFile.Element.ARRAY);108file.end();109}110OutputAnalyzer output = HugeDirectiveUtil.execute(fileName);111Asserts.assertNE(output.getExitValue(), 0, ERROR_MSG + "empty array");112}113114private static void emptyObjectTest() {115String fileName = "emptyObject.json";116try (JSONFile file = new JSONFile(fileName)) {117file.write(JSONFile.Element.OBJECT);118file.end();119}120OutputAnalyzer output = HugeDirectiveUtil.execute(fileName);121Asserts.assertNE(output.getExitValue(), 0, ERROR_MSG + "empty object "122+ "without any match");123output.shouldContain(EXPECTED_ERROR_STRING);124}125126private static void emptyFile() {127String fileName = "empty.json";128try (JSONFile file = new JSONFile(fileName)) {129// empty130}131OutputAnalyzer output = HugeDirectiveUtil.execute(fileName);132Asserts.assertNE(output.getExitValue(), 0, ERROR_MSG + "empty file");133output.shouldContain(EXPECTED_ERROR_STRING);134}135136private static void noFile() {137OutputAnalyzer output = HugeDirectiveUtil.execute("nonexistent.json");138Asserts.assertNE(output.getExitValue(), 0, ERROR_MSG + "non existing "139+ "file");140}141142private static void directory() {143OutputAnalyzer output = HugeDirectiveUtil.execute(Utils.TEST_SRC);144Asserts.assertNE(output.getExitValue(), 0, ERROR_MSG + "directory as "145+ "a name");146}147}148149150