Thu, 12 Oct 2017 19:52:15 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
attila@962 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
attila@962 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
attila@962 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
attila@962 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /** |
aoqi@0 | 25 | * mh_coverage.js |
attila@962 | 26 | * Screen scrape various logs to ensure that we cover enough functionality, |
aoqi@0 | 27 | * e.g. method handle instrumentation |
aoqi@0 | 28 | * |
aoqi@0 | 29 | * @test |
aoqi@0 | 30 | * @run |
aoqi@0 | 31 | */ |
aoqi@0 | 32 | |
aoqi@0 | 33 | /* |
aoqi@0 | 34 | * creates new script engine initialized with given options and |
aoqi@0 | 35 | * runs given code on it. Returns standard output captured. |
aoqi@0 | 36 | */ |
aoqi@0 | 37 | |
aoqi@0 | 38 | function runScriptEngine(opts, name) { |
aoqi@0 | 39 | var imports = new JavaImporter( |
aoqi@0 | 40 | Packages.jdk.nashorn.api.scripting, |
aoqi@0 | 41 | java.io, java.lang, java.util); |
aoqi@0 | 42 | |
aoqi@0 | 43 | with(imports) { |
aoqi@0 | 44 | var fac = new NashornScriptEngineFactory(); |
aoqi@0 | 45 | // get current System.err |
aoqi@0 | 46 | var oldErr = System.err; |
attila@962 | 47 | var oldOut = System.out; |
aoqi@0 | 48 | var baosErr = new ByteArrayOutputStream(); |
aoqi@0 | 49 | var newErr = new PrintStream(baosErr); |
aoqi@0 | 50 | var baosOut = new ByteArrayOutputStream(); |
attila@962 | 51 | var newOut = new PrintStream(baosOut); |
aoqi@0 | 52 | try { |
aoqi@0 | 53 | // set new standard err |
aoqi@0 | 54 | System.setErr(newErr); |
aoqi@0 | 55 | System.setOut(newOut); |
aoqi@0 | 56 | var engine = fac.getScriptEngine(Java.to(opts, "java.lang.String[]")); |
attila@962 | 57 | var reader = new java.io.FileReader(name); |
aoqi@0 | 58 | engine.eval(reader); |
aoqi@0 | 59 | newErr.flush(); |
attila@962 | 60 | newOut.flush(); |
aoqi@0 | 61 | return new java.lang.String(baosErr.toByteArray()); |
aoqi@0 | 62 | } finally { |
aoqi@0 | 63 | // restore System.err to old value |
aoqi@0 | 64 | System.setErr(oldErr); |
attila@962 | 65 | System.setOut(oldOut); |
aoqi@0 | 66 | } |
aoqi@0 | 67 | } |
aoqi@0 | 68 | } |
aoqi@0 | 69 | |
aoqi@0 | 70 | var str; |
aoqi@0 | 71 | |
aoqi@0 | 72 | var methodsCalled = [ |
attila@962 | 73 | 'asCollector', |
attila@962 | 74 | 'asType', |
attila@962 | 75 | 'bindTo', |
attila@962 | 76 | 'dropArguments', |
attila@962 | 77 | 'explicitCastArguments', |
attila@962 | 78 | 'filterArguments', |
attila@962 | 79 | 'filterReturnValue', |
attila@962 | 80 | 'findStatic', |
attila@962 | 81 | 'findVirtual', |
attila@962 | 82 | 'foldArguments', |
attila@962 | 83 | 'getter', |
attila@962 | 84 | 'guardWithTest', |
attila@962 | 85 | 'insertArguments', |
attila@962 | 86 | 'methodType', |
aoqi@0 | 87 | 'setter' |
aoqi@0 | 88 | ]; |
aoqi@0 | 89 | |
aoqi@0 | 90 | function check(str, strs) { |
aoqi@0 | 91 | for each (s in strs) { |
aoqi@0 | 92 | if (str.indexOf(s) !== -1) { |
attila@962 | 93 | continue; |
aoqi@0 | 94 | } |
aoqi@0 | 95 | print(s + " not found"); |
aoqi@0 | 96 | return; |
aoqi@0 | 97 | } |
aoqi@0 | 98 | print("check ok!"); |
aoqi@0 | 99 | } |
aoqi@0 | 100 | |
aoqi@0 | 101 | str = runScriptEngine([ "--log=codegen,compiler=finest,methodhandles=finest,fields=finest" ], __DIR__ + "../basic/NASHORN-19.js"); |
aoqi@0 | 102 | str += runScriptEngine([ "--log=codegen,compiler=finest,methodhandles=finest,fields=finest" ], __DIR__ + "../basic/varargs.js"); |
aoqi@0 | 103 | |
aoqi@0 | 104 | check(str, methodsCalled); |
aoqi@0 | 105 | check(str, ['return', 'get', 'set', '[fields]']); |
aoqi@0 | 106 | check(str, ['codegen']); |
aoqi@0 | 107 | |
aoqi@0 | 108 | print("hello, world!"); |