hotspot/test/runtime/ThreadSignalMask/ThreadSignalMask.java
author stsmirno
Fri, 20 Nov 2015 09:44:16 -0500
changeset 34247 f91af85bcb5f
child 38152 80e5da81fb2c
permissions -rw-r--r--
8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java Summary: rewrote test in Java with a number of improvements and conditional exclusion using make file Reviewed-by: dholmes, ctornqvi, ddmitriev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34247
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     1
/*
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     4
 *
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     8
 *
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    13
 * accompanied this code).
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    14
 *
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    18
 *
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    21
 * questions.
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    22
 */
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    23
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    24
import java.lang.ProcessBuilder.Redirect;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    25
import java.nio.file.Files;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    26
import java.nio.file.Path;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    27
import java.nio.file.Paths;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    28
import java.nio.file.StandardCopyOption;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    29
import java.util.Arrays;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    30
import java.util.List;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    31
import jdk.test.lib.Asserts;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    32
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    33
/*
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    34
 * @test
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    35
 * @key cte_test
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    36
 * @bug 4345157
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    37
 * @summary JDK 1.3.0 alters thread signal mask
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    38
 * @requires (os.simpleArch == "sparcv9")
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    39
 * @library /testlibrary
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    40
 * @compile Prog.java
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    41
 * @run main/native ThreadSignalMask
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    42
 */
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    43
public class ThreadSignalMask {
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    44
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    45
    public static void main(String args[]) throws Exception {
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    46
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    47
        String testClasses = getSystemProperty("test.classes");
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    48
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    49
        String testNativePath = getSystemProperty("test.nativepath");
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    50
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    51
        String testJdk = getSystemProperty("test.jdk");
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    52
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    53
        Path currentDirPath = Paths.get(".");
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    54
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    55
        Path classFilePath = Paths.get(testClasses,
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    56
                Prog.class.getSimpleName() + ".class");
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    57
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    58
        // copy Prog.class file to be invoked from native
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    59
        Files.copy(classFilePath,
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    60
                currentDirPath.resolve(Prog.class.getSimpleName() + ".class"),
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    61
                StandardCopyOption.REPLACE_EXISTING);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    62
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    63
        Path executableFilePath = Paths.get(testNativePath,
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    64
                ThreadSignalMask.class.getSimpleName());
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    65
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    66
        Path executableFileLocalPath = currentDirPath.resolve(
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    67
                ThreadSignalMask.class.getSimpleName());
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    68
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    69
        // copy compiled native executable ThreadSignalMask
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    70
        Files.copy(executableFilePath,
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    71
                executableFileLocalPath,
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    72
                StandardCopyOption.REPLACE_EXISTING);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    73
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    74
        executableFileLocalPath.toFile().setExecutable(true);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    75
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    76
        long[] intervalsArray = {2000, 5000, 10000, 20000};
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    77
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    78
        List<String> processArgs = Arrays.asList(
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    79
                executableFileLocalPath.toString(),
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    80
                testJdk);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    81
        ProcessBuilder pb = new ProcessBuilder(processArgs);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    82
        pb.redirectOutput(Redirect.INHERIT);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    83
        pb.redirectError(Redirect.INHERIT);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    84
        int result = 0;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    85
        for (long interval : intervalsArray) {
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    86
            Process p = pb.start();
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    87
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    88
            // sleep for a specified period of time to let native run
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    89
            sleep(interval);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    90
            p.destroy();
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    91
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    92
            // wait for process to finish, get exit value and validate it
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    93
            result = p.waitFor();
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    94
            System.out.println("Result = " + result);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    95
            if (result == 0) {
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    96
                break;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    97
            }
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    98
        }
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
    99
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   100
        Asserts.assertEquals(result, 0);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   101
    }
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   102
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   103
    // Utility method to handle Thread.sleep
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   104
    private static void sleep(long millis) throws InterruptedException {
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   105
        System.out.println("Sleep for " + millis);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   106
        Thread.sleep(millis);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   107
    }
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   108
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   109
    // Utility method to retrieve and validate system properties
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   110
    private static String getSystemProperty(String propertyName) throws Error {
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   111
        String systemProperty = System.getProperty(propertyName, "").trim();
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   112
        System.out.println(propertyName + " = " + systemProperty);
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   113
        if (systemProperty.isEmpty()) {
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   114
            throw new Error("TESTBUG: property " + propertyName + " is empty");
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   115
        }
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   116
        return systemProperty;
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   117
    }
f91af85bcb5f 8133416: [TESTBUG] Remove @ignore for closed/runtime/4345157/Prog.java
stsmirno
parents:
diff changeset
   118
}