test/nashorn/script/nosecurity/logcoverage.js
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 39790 nashorn/test/script/nosecurity/logcoverage.js@079ffba6e096
child 55657 107ebf94ddcc
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17259
a8d0cb25d725 8013533: Increase code coverage report for types and logging
lagergren
parents:
diff changeset
     1
/*
39790
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
     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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    29
 * @fork
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    30
 * @option -Dnashorn.debug=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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    40
            Packages.jdk.nashorn.api.scripting,
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    41
            java.io, java.lang, java.util);
17259
a8d0cb25d725 8013533: Increase code coverage report for types and logging
lagergren
parents:
diff changeset
    42
39790
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    73
    'asCollector',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    74
    'asType',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    75
    'bindTo',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    76
    'dropArguments',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    77
    'explicitCastArguments',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    78
    'filterArguments',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    79
    'filterReturnValue',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    80
    'findStatic',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    81
    'findVirtual',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    82
    'foldArguments',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    83
    'getter',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    84
    'guardWithTest',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    85
    'insertArguments',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    86
    'methodType',
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    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
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    92
        if (str.indexOf(s) !== -1) {
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    93
            continue;
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    94
        }
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    95
        print(s + " not found");
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
    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
39790
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
diff changeset
   101
str = runScriptEngine(["--log=codegen,compiler=finest,methodhandles=finest,fields=finest"], __DIR__ + "../basic/NASHORN-19.js");
079ffba6e096 8142969: Nashorn logging API requires testing
mhaupt
parents: 24778
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!");