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