nashorn/test/script/nosecurity/context-dependent-logging.js
author hannesw
Wed, 27 Apr 2016 15:50:33 +0200
changeset 37732 3673fec68d16
parent 34976 62f7766a44dc
permissions -rw-r--r--
8134503: support ES6 parsing in Nashorn Reviewed-by: jlaskey, sundar, mhaupt Contributed-by: andreas.woess@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34976
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     1
/*
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     4
 *
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    10
 *
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    15
 * accompanied this code).
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    16
 *
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    20
 *
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    23
 * questions.
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    24
 */
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    25
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    26
/**
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    27
 * Test that logging configuration is per engine, rather than per process.
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    28
 *
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    29
 * @test
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    30
 * @bug 8036977
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    31
 * @run/ignore-std-error
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    32
 * @fork
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    33
 * @option -scripting
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    34
 */
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    35
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    36
// To test, start another engine (testEngine) with a time logger and ensure the
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    37
// logger exists.
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    38
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    39
var NashornFactory = new (Java.type('jdk.nashorn.api.scripting.NashornScriptEngineFactory'))(),
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    40
    testEngine     = NashornFactory.getScriptEngine("-scripting", "--log=time")
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    41
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    42
if (!testEngine.eval('$OPTIONS._loggers.time')) {
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    43
    throw 'fresh testEngine does not have time logger'
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    44
}
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    45
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    46
// To test further, have the testEngine start yet another engine (e) without
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    47
// time logging, but with compiler logging. Check the logging is as configured,
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    48
// and verify the testEngine still has time logging, but no compiler logging.
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    49
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    50
var script = <<EOS
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    51
    var F = new (Java.type('jdk.nashorn.api.scripting.NashornScriptEngineFactory'))(),
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    52
        e = F.getScriptEngine('-scripting', '--log=compiler')
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    53
    if (!e.eval('$OPTIONS._loggers.compiler')) {
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    54
        throw 'e does not have compiler logger'
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    55
    }
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    56
    if (e.eval('$OPTIONS._loggers.time')) {
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    57
        throw 'e has time logger'
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    58
    }
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    59
EOS
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    60
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    61
testEngine.eval(script)
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    62
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    63
if (!testEngine.eval('$OPTIONS._loggers.time')) {
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    64
    throw 'after-test testEngine does not have time logger'
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    65
}
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    66
if (testEngine.eval('$OPTIONS._loggers.compiler')) {
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    67
    throw 'after-test testEngine has compiler logger'
62f7766a44dc 8036977: Make process singleton options to be context wide
mhaupt
parents:
diff changeset
    68
}