lagergren@237: /* lagergren@237: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. lagergren@237: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@962: * lagergren@237: * This code is free software; you can redistribute it and/or modify it lagergren@237: * under the terms of the GNU General Public License version 2 only, as lagergren@237: * published by the Free Software Foundation. attila@962: * lagergren@237: * This code is distributed in the hope that it will be useful, but WITHOUT lagergren@237: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or lagergren@237: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License lagergren@237: * version 2 for more details (a copy is included in the LICENSE file that lagergren@237: * accompanied this code). attila@962: * lagergren@237: * You should have received a copy of the GNU General Public License version lagergren@237: * 2 along with this work; if not, write to the Free Software Foundation, lagergren@237: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@962: * lagergren@237: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA lagergren@237: * or visit www.oracle.com if you need additional information or have any lagergren@237: * questions. lagergren@237: */ lagergren@237: lagergren@237: /** lagergren@237: * mh_coverage.js attila@962: * Screen scrape various logs to ensure that we cover enough functionality, lagergren@237: * e.g. method handle instrumentation lagergren@237: * lagergren@237: * @test lagergren@237: * @run lagergren@237: */ lagergren@237: lagergren@237: /* lagergren@237: * creates new script engine initialized with given options and lagergren@237: * runs given code on it. Returns standard output captured. lagergren@237: */ lagergren@237: lagergren@237: function runScriptEngine(opts, name) { lagergren@237: var imports = new JavaImporter( lagergren@237: Packages.jdk.nashorn.api.scripting, lagergren@237: java.io, java.lang, java.util); lagergren@237: lagergren@237: with(imports) { lagergren@237: var fac = new NashornScriptEngineFactory(); lagergren@237: // get current System.err lagergren@237: var oldErr = System.err; attila@962: var oldOut = System.out; lagergren@237: var baosErr = new ByteArrayOutputStream(); lagergren@237: var newErr = new PrintStream(baosErr); lagergren@237: var baosOut = new ByteArrayOutputStream(); attila@962: var newOut = new PrintStream(baosOut); lagergren@237: try { lagergren@237: // set new standard err lagergren@237: System.setErr(newErr); lagergren@237: System.setOut(newOut); attila@279: var engine = fac.getScriptEngine(Java.to(opts, "java.lang.String[]")); attila@962: var reader = new java.io.FileReader(name); lagergren@237: engine.eval(reader); lagergren@237: newErr.flush(); attila@962: newOut.flush(); lagergren@237: return new java.lang.String(baosErr.toByteArray()); lagergren@237: } finally { lagergren@237: // restore System.err to old value lagergren@237: System.setErr(oldErr); attila@962: System.setOut(oldOut); lagergren@237: } lagergren@237: } lagergren@237: } lagergren@237: lagergren@237: var str; lagergren@237: lagergren@237: var methodsCalled = [ attila@962: 'asCollector', attila@962: 'asType', attila@962: 'bindTo', attila@962: 'dropArguments', attila@962: 'explicitCastArguments', attila@962: 'filterArguments', attila@962: 'filterReturnValue', attila@962: 'findStatic', attila@962: 'findVirtual', attila@962: 'foldArguments', attila@962: 'getter', attila@962: 'guardWithTest', attila@962: 'insertArguments', attila@962: 'methodType', lagergren@237: 'setter' lagergren@237: ]; lagergren@237: lagergren@237: function check(str, strs) { lagergren@237: for each (s in strs) { lagergren@247: if (str.indexOf(s) !== -1) { attila@962: continue; lagergren@237: } lagergren@247: print(s + " not found"); lagergren@237: return; lagergren@237: } lagergren@237: print("check ok!"); lagergren@237: } lagergren@237: lagergren@237: str = runScriptEngine([ "--log=codegen,compiler=finest,methodhandles=finest,fields=finest" ], __DIR__ + "../basic/NASHORN-19.js"); lagergren@247: str += runScriptEngine([ "--log=codegen,compiler=finest,methodhandles=finest,fields=finest" ], __DIR__ + "../basic/varargs.js"); lagergren@237: lagergren@237: check(str, methodsCalled); lagergren@237: check(str, ['return', 'get', 'set', '[fields]']); lagergren@237: check(str, ['codegen']); lagergren@237: lagergren@237: print("hello, world!");