author | lagergren |
Fri, 23 Aug 2013 15:46:09 +0200 | |
changeset 19632 | c9d704ad422e |
parent 17758 | 2b056941e4dd |
child 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
17259
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
1 |
/* |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
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. |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
4 |
* |
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. |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
8 |
* |
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). |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
14 |
* |
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. |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
18 |
* |
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 |
/** |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
25 |
* mh_coverage.js |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
26 |
* Screen scrape various logs to ensure that we cover enough functionality, |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
27 |
* e.g. method handle instrumentation |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
28 |
* |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
29 |
* @test |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
30 |
* @run |
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( |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
40 |
Packages.jdk.nashorn.api.scripting, |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
41 |
java.io, java.lang, java.util); |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
42 |
|
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
43 |
with(imports) { |
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; |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
47 |
var oldOut = System.out; |
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(); |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
51 |
var newOut = new PrintStream(baosOut); |
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[]")); |
17259
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
57 |
var reader = new java.io.FileReader(name); |
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(); |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
60 |
newOut.flush(); |
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); |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
65 |
System.setOut(oldOut); |
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 = [ |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
73 |
'asCollector', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
74 |
'asType', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
75 |
'bindTo', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
76 |
'dropArguments', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
77 |
'explicitCastArguments', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
78 |
'filterArguments', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
79 |
'filterReturnValue', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
80 |
'findStatic', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
81 |
'findVirtual', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
82 |
'foldArguments', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
83 |
'getter', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
84 |
'guardWithTest', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
85 |
'insertArguments', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
86 |
'methodType', |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
87 |
'setter' |
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) { |
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17259
diff
changeset
|
92 |
if (str.indexOf(s) !== -1) { |
17259
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
93 |
continue; |
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
94 |
} |
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17259
diff
changeset
|
95 |
print(s + " not found"); |
17259
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
96 |
return; |
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 |
|
a8d0cb25d725
8013533: Increase code coverage report for types and logging
lagergren
parents:
diff
changeset
|
101 |
str = runScriptEngine([ "--log=codegen,compiler=finest,methodhandles=finest,fields=finest" ], __DIR__ + "../basic/NASHORN-19.js"); |
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17259
diff
changeset
|
102 |
str += runScriptEngine([ "--log=codegen,compiler=finest,methodhandles=finest,fields=finest" ], __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!"); |