Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/currently-failing/logcoverage.js
32281 views
/*1* Copyright (c) 2010, 2013, 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* mh_coverage.js25* Screen scrape various logs to ensure that we cover enough functionality,26* e.g. method handle instrumentation27*28* @test29* @run30*/3132/*33* creates new script engine initialized with given options and34* runs given code on it. Returns standard output captured.35*/3637function runScriptEngine(opts, name) {38var imports = new JavaImporter(39Packages.jdk.nashorn.api.scripting,40java.io, java.lang, java.util);4142with(imports) {43var fac = new NashornScriptEngineFactory();44// get current System.err45var oldErr = System.err;46var oldOut = System.out;47var baosErr = new ByteArrayOutputStream();48var newErr = new PrintStream(baosErr);49var baosOut = new ByteArrayOutputStream();50var newOut = new PrintStream(baosOut);51try {52// set new standard err53System.setErr(newErr);54System.setOut(newOut);55var engine = fac.getScriptEngine(Java.to(opts, "java.lang.String[]"));56var reader = new java.io.FileReader(name);57engine.eval(reader);58newErr.flush();59newOut.flush();60return new java.lang.String(baosErr.toByteArray());61} finally {62// restore System.err to old value63System.setErr(oldErr);64System.setOut(oldOut);65}66}67}6869var str;7071var methodsCalled = [72'asCollector',73'asType',74'bindTo',75'dropArguments',76'explicitCastArguments',77'filterArguments',78'filterReturnValue',79'findStatic',80'findVirtual',81'foldArguments',82'getter',83'guardWithTest',84'insertArguments',85'methodType',86'setter'87];8889function check(str, strs) {90for each (s in strs) {91if (str.indexOf(s) !== -1) {92continue;93}94print(s + " not found");95return;96}97print("check ok!");98}99100str = runScriptEngine([ "--log=codegen,compiler=finest,methodhandles=finest,fields=finest" ], __DIR__ + "../basic/NASHORN-19.js");101str += runScriptEngine([ "--log=codegen,compiler=finest,methodhandles=finest,fields=finest" ], __DIR__ + "../basic/varargs.js");102103check(str, methodsCalled);104check(str, ['return', 'get', 'set', '[fields]']);105check(str, ['codegen']);106107print("hello, world!");108109110