com.oracle.java.testlibrary.Utils Java Examples

The following examples show how to use com.oracle.java.testlibrary.Utils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Platform.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * On Linux, first check the SELinux boolean "deny_ptrace" and return false
 * as we expect to be denied if that is "1".  Then expect permission to attach
 * if we are root, so return true.  Then return false for an expected denial
 * if "ptrace_scope" is 1, and true otherwise.
 */
public static boolean canPtraceAttachLinux() throws Exception {

    // SELinux deny_ptrace:
    String deny_ptrace = Utils.fileAsString("/sys/fs/selinux/booleans/deny_ptrace");
    if (deny_ptrace != null && deny_ptrace.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    if (userName.equals("root")) {
        return true;
    }

    // ptrace_scope:
    String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
    if (ptrace_scope != null && ptrace_scope.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    // Otherwise expect to be permitted:
    return true;
}
 
Example #2
Source File: DockerTestUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a docker image that contains JDK under test.
 * The jdk will be placed under the "/jdk/" folder inside the docker file system.
 *
 * @param imageName     name of the image to be created, including version tag
 * @param dockerfile    name of the dockerfile residing in the test source;
 *                      we check for a platform specific dockerfile as well
 *                      and use this one in case it exists
 * @param buildDirName  name of the docker build/staging directory, which will
 *                      be created in the jtreg's scratch folder
 * @throws Exception
 */
public static void
    buildJdkDockerImage(String imageName, String dockerfile, String buildDirName)
        throws Exception {
    Path buildDir = Paths.get(".", buildDirName);
    if (Files.exists(buildDir)) {
        throw new RuntimeException("The docker build directory already exists: " + buildDir);
    }
    // check for the existance of a platform specific docker file as well
    String platformSpecificDockerfile = dockerfile + "-" + Platform.getOsArch();
    if (Files.exists(Paths.get(Utils.TEST_SRC, platformSpecificDockerfile))) {
      dockerfile = platformSpecificDockerfile;
    }

    Path jdkSrcDir = Paths.get(Utils.TEST_JDK);
    Path jdkDstDir = buildDir.resolve("jdk");

    Files.createDirectories(jdkDstDir);

    // Copy JDK-under-test tree to the docker build directory.
    // This step is required for building a docker image.
    Files.walkFileTree(jdkSrcDir, new CopyFileVisitor(jdkSrcDir, jdkDstDir));
    buildDockerImage(imageName, Paths.get(Utils.TEST_SRC, dockerfile), buildDir);
}
 
Example #3
Source File: DockerTestUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Run Java inside the docker image with specified parameters and options.
 *
 * @param DockerRunOptions optins for running docker
 *
 * @return output of the run command
 * @throws Exception
 */
public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Exception {
    ArrayList<String> cmd = new ArrayList<>();

    cmd.add("docker");
    cmd.add("run");
    if (opts.tty)
        cmd.add("--tty=true");
    if (opts.removeContainerAfterUse)
        cmd.add("--rm");

    cmd.addAll(opts.dockerOpts);
    cmd.add(opts.imageNameAndTag);
    cmd.add(opts.command);

    cmd.addAll(opts.javaOpts);
    if (opts.appendTestJavaOptions) {
        Collections.addAll(cmd, Utils.getTestJavaOpts());
    }

    cmd.add(opts.classToRun);
    cmd.addAll(opts.classParams);
    return execute(cmd);
}
 
Example #4
Source File: Platform.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * On Linux, first check the SELinux boolean "deny_ptrace" and return false
 * as we expect to be denied if that is "1".  Then expect permission to attach
 * if we are root, so return true.  Then return false for an expected denial
 * if "ptrace_scope" is 1, and true otherwise.
 */
public static boolean canPtraceAttachLinux() throws Exception {

    // SELinux deny_ptrace:
    String deny_ptrace = Utils.fileAsString("/sys/fs/selinux/booleans/deny_ptrace");
    if (deny_ptrace != null && deny_ptrace.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    if (userName.equals("root")) {
        return true;
    }

    // ptrace_scope:
    String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
    if (ptrace_scope != null && ptrace_scope.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    // Otherwise expect to be permitted:
    return true;
}
 
Example #5
Source File: Platform.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * On Linux, first check the SELinux boolean "deny_ptrace" and return false
 * as we expect to be denied if that is "1".  Then expect permission to attach
 * if we are root, so return true.  Then return false for an expected denial
 * if "ptrace_scope" is 1, and true otherwise.
 */
public static boolean canPtraceAttachLinux() throws Exception {

    // SELinux deny_ptrace:
    String deny_ptrace = Utils.fileAsString("/sys/fs/selinux/booleans/deny_ptrace");
    if (deny_ptrace != null && deny_ptrace.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    if (userName.equals("root")) {
        return true;
    }

    // ptrace_scope:
    String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
    if (ptrace_scope != null && ptrace_scope.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    // Otherwise expect to be permitted:
    return true;
}
 
Example #6
Source File: Platform.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * On Linux, first check the SELinux boolean "deny_ptrace" and return false
 * as we expect to be denied if that is "1".  Then expect permission to attach
 * if we are root, so return true.  Then return false for an expected denial
 * if "ptrace_scope" is 1, and true otherwise.
 */
public static boolean canPtraceAttachLinux() throws Exception {

    // SELinux deny_ptrace:
    String deny_ptrace = Utils.fileAsString("/sys/fs/selinux/booleans/deny_ptrace");
    if (deny_ptrace != null && deny_ptrace.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    if (userName.equals("root")) {
        return true;
    }

    // ptrace_scope:
    String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
    if (ptrace_scope != null && ptrace_scope.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    // Otherwise expect to be permitted:
    return true;
}
 
Example #7
Source File: Platform.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * On Linux, first check the SELinux boolean "deny_ptrace" and return false
 * as we expect to be denied if that is "1".  Then expect permission to attach
 * if we are root, so return true.  Then return false for an expected denial
 * if "ptrace_scope" is 1, and true otherwise.
 */
public static boolean canPtraceAttachLinux() throws Exception {

    // SELinux deny_ptrace:
    String deny_ptrace = Utils.fileAsString("/sys/fs/selinux/booleans/deny_ptrace");
    if (deny_ptrace != null && deny_ptrace.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    if (userName.equals("root")) {
        return true;
    }

    // ptrace_scope:
    String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
    if (ptrace_scope != null && ptrace_scope.contains("1")) {
        // ptrace will be denied:
        return false;
    }

    // Otherwise expect to be permitted:
    return true;
}
 
Example #8
Source File: DockerTestUtils.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Run Java inside the docker image with specified parameters and options.
 *
 * @param DockerRunOptions optins for running docker
 *
 * @return output of the run command
 * @throws Exception
 */
public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Exception {
    ArrayList<String> cmd = new ArrayList<>();

    cmd.add("docker");
    cmd.add("run");
    if (opts.tty)
        cmd.add("--tty=true");
    if (opts.removeContainerAfterUse)
        cmd.add("--rm");

    cmd.addAll(opts.dockerOpts);
    cmd.add(opts.imageNameAndTag);
    cmd.add(opts.command);

    cmd.addAll(opts.javaOpts);
    if (opts.appendTestJavaOptions) {
        Collections.addAll(cmd, Utils.getTestJavaOpts());
    }

    cmd.add(opts.classToRun);
    cmd.addAll(opts.classParams);
    return execute(cmd);
}
 
Example #9
Source File: DockerTestUtils.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a docker image that contains JDK under test.
 * The jdk will be placed under the "/jdk/" folder inside the docker file system.
 *
 * @param imageName     name of the image to be created, including version tag
 * @param dockerfile    name of the dockerfile residing in the test source;
 *                      we check for a platform specific dockerfile as well
 *                      and use this one in case it exists
 * @param buildDirName  name of the docker build/staging directory, which will
 *                      be created in the jtreg's scratch folder
 * @throws Exception
 */
public static void
    buildJdkDockerImage(String imageName, String dockerfile, String buildDirName)
        throws Exception {
    Path buildDir = Paths.get(".", buildDirName);
    if (Files.exists(buildDir)) {
        throw new RuntimeException("The docker build directory already exists: " + buildDir);
    }
    // check for the existance of a platform specific docker file as well
    String platformSpecificDockerfile = dockerfile + "-" + Platform.getOsArch();
    if (Files.exists(Paths.get(Utils.TEST_SRC, platformSpecificDockerfile))) {
      dockerfile = platformSpecificDockerfile;
    }

    Path jdkSrcDir = Paths.get(Utils.TEST_JDK);
    Path jdkDstDir = buildDir.resolve("jdk");

    Files.createDirectories(jdkDstDir);

    // Copy JDK-under-test tree to the docker build directory.
    // This step is required for building a docker image.
    Files.walkFileTree(jdkSrcDir, new CopyFileVisitor(jdkSrcDir, jdkDstDir));
    buildDockerImage(imageName, Paths.get(Utils.TEST_SRC, dockerfile), buildDir);
}
 
Example #10
Source File: TestShrinkAuxiliaryData.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void test() throws Exception {
    ArrayList<String> vmOpts = new ArrayList();
    Collections.addAll(vmOpts, initialOpts);

    int maxCacheSize = Math.max(0, Math.min(31, getMaxCacheSize()));
    if (maxCacheSize < hotCardTableSize) {
        System.out.format("Skiping test for %d cache size due max cache size %d",
                hotCardTableSize, maxCacheSize
        );
        return;
    }

    printTestInfo(maxCacheSize);

    vmOpts.add("-XX:G1ConcRSLogCacheSize=" + hotCardTableSize);
    vmOpts.addAll(Arrays.asList(Utils.getTestJavaOpts()));

    // for 32 bits ObjectAlignmentInBytes is not a option
    if (Platform.is32bit()) {
        ArrayList<String> vmOptsWithoutAlign = new ArrayList(vmOpts);
        vmOptsWithoutAlign.add(ShrinkAuxiliaryDataTest.class.getName());
        performTest(vmOptsWithoutAlign);
        return;
    }

    for (int alignment = 3; alignment <= 8; alignment++) {
        ArrayList<String> vmOptsWithAlign = new ArrayList(vmOpts);
        vmOptsWithAlign.add("-XX:ObjectAlignmentInBytes="
                + (int) Math.pow(2, alignment));
        vmOptsWithAlign.add(ShrinkAuxiliaryDataTest.class.getName());

        performTest(vmOptsWithAlign);
    }
}
 
Example #11
Source File: BmiIntrinsicBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected void checkEmittedCode(Executable executable) {
    final byte[] nativeCode = NMethod.get(executable, false).insts;
    if (!((BmiTestCase) testCase).verifyPositive(nativeCode)) {
        throw new AssertionError(testCase.name() + "CPU instructions expected not found: " + Utils.toHexString(nativeCode));
    } else {
        System.out.println("CPU instructions found, PASSED");
    }
}
 
Example #12
Source File: RTMTestBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prepares VM options for test execution.
 * This method get test java options, filter out all RTM-related options
 * and all options that matches regexps in {@code additionalFilters},
 * adds CompileCommand=compileonly,method_name options for each method
 * from {@code methodToCompile} and finally appends all {@code vmOpts}.
 *
 * @param test test case whose methods that should be compiled.
 *             If {@code null} then no additional <i>compileonly</i>
 *             commands will be added to VM options.
 * @param additionalFilters array with regular expression that will be
 *                          used to filter out test java options.
 *                          If {@code null} then no additional filters
 *                          will be used.
 * @param vmOpts additional options to pass to VM.
 * @return array with VM options.
 */
private static String[] prepareFilteredTestOptions(CompilableTest test,
        String[] additionalFilters, String... vmOpts) {
    List<String> finalVMOpts = new LinkedList<>();
    String[] filters;

    if (additionalFilters != null) {
        filters = Arrays.copyOf(additionalFilters,
                additionalFilters.length + 1);
    } else {
        filters = new String[1];
    }

    filters[filters.length - 1] = "RTM";
    String[] filteredVMOpts = Utils.getFilteredTestJavaOpts(filters);
    Collections.addAll(finalVMOpts, filteredVMOpts);
    Collections.addAll(finalVMOpts, "-Xcomp", "-server",
            "-XX:-TieredCompilation", "-XX:+UseRTMLocking",
            CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
            CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
            "-Xbootclasspath/a:.", "-XX:+WhiteBoxAPI");

    if (test != null) {
        for (String method : test.getMethodsToCompileNames()) {
            finalVMOpts.add("-XX:CompileCommand=compileonly," + method);
        }
    }
    Collections.addAll(finalVMOpts, vmOpts);
    return finalVMOpts.toArray(new String[finalVMOpts.size()]);
}
 
Example #13
Source File: TestCPUSets.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static DockerRunOptions commonOpts() {
    DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java",
                                                 "PrintContainerInfo");
    opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
    opts.addJavaOpts("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintContainerInfo", "-cp", "/test-classes/");
    Common.addWhiteBoxOpts(opts);
    return opts;
}
 
Example #14
Source File: TestShrinkAuxiliaryData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected void test() throws Exception {
    ArrayList<String> vmOpts = new ArrayList();
    Collections.addAll(vmOpts, initialOpts);

    int maxCacheSize = Math.max(0, Math.min(31, getMaxCacheSize()));
    if (maxCacheSize < hotCardTableSize) {
        System.out.format("Skiping test for %d cache size due max cache size %d",
                hotCardTableSize, maxCacheSize
        );
        return;
    }

    printTestInfo(maxCacheSize);

    vmOpts.add("-XX:G1ConcRSLogCacheSize=" + hotCardTableSize);
    vmOpts.addAll(Arrays.asList(Utils.getTestJavaOpts()));

    // for 32 bits ObjectAlignmentInBytes is not a option
    if (Platform.is32bit()) {
        ArrayList<String> vmOptsWithoutAlign = new ArrayList(vmOpts);
        vmOptsWithoutAlign.add(ShrinkAuxiliaryDataTest.class.getName());
        performTest(vmOptsWithoutAlign);
        return;
    }

    for (int alignment = 3; alignment <= 8; alignment++) {
        ArrayList<String> vmOptsWithAlign = new ArrayList(vmOpts);
        vmOptsWithAlign.add("-XX:ObjectAlignmentInBytes="
                + (int) Math.pow(2, alignment));
        vmOptsWithAlign.add(ShrinkAuxiliaryDataTest.class.getName());

        performTest(vmOptsWithAlign);
    }
}
 
Example #15
Source File: BmiIntrinsicBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void checkEmittedCode(Executable executable) {
    final byte[] nativeCode = NMethod.get(executable, false).insts;
    if (!((BmiTestCase) testCase).verifyPositive(nativeCode)) {
        throw new AssertionError(testCase.name() + "CPU instructions expected not found: " + Utils.toHexString(nativeCode));
    } else {
        System.out.println("CPU instructions found, PASSED");
    }
}
 
Example #16
Source File: RTMTestBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prepares VM options for test execution.
 * This method get test java options, filter out all RTM-related options
 * and all options that matches regexps in {@code additionalFilters},
 * adds CompileCommand=compileonly,method_name options for each method
 * from {@code methodToCompile} and finally appends all {@code vmOpts}.
 *
 * @param test test case whose methods that should be compiled.
 *             If {@code null} then no additional <i>compileonly</i>
 *             commands will be added to VM options.
 * @param additionalFilters array with regular expression that will be
 *                          used to filter out test java options.
 *                          If {@code null} then no additional filters
 *                          will be used.
 * @param vmOpts additional options to pass to VM.
 * @return array with VM options.
 */
private static String[] prepareFilteredTestOptions(CompilableTest test,
        String[] additionalFilters, String... vmOpts) {
    List<String> finalVMOpts = new LinkedList<>();
    String[] filters;

    if (additionalFilters != null) {
        filters = Arrays.copyOf(additionalFilters,
                additionalFilters.length + 1);
    } else {
        filters = new String[1];
    }

    filters[filters.length - 1] = "RTM";
    String[] filteredVMOpts = Utils.getFilteredTestJavaOpts(filters);
    Collections.addAll(finalVMOpts, filteredVMOpts);
    Collections.addAll(finalVMOpts, "-Xcomp", "-server",
            "-XX:-TieredCompilation", "-XX:+UseRTMLocking",
            CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
            CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
            "-Xbootclasspath/a:.", "-XX:+WhiteBoxAPI");

    if (test != null) {
        for (String method : test.getMethodsToCompileNames()) {
            finalVMOpts.add("-XX:CompileCommand=compileonly," + method);
        }
    }
    Collections.addAll(finalVMOpts, vmOpts);
    return finalVMOpts.toArray(new String[finalVMOpts.size()]);
}
 
Example #17
Source File: Common.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static DockerRunOptions newOpts(String imageNameAndTag, String testClass) {
    DockerRunOptions opts =
        new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", testClass);
   opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
    opts.addJavaOpts("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintContainerInfo", "-cp", "/test-classes/");
    return opts;
}
 
Example #18
Source File: Common.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void prepareWhiteBox() throws Exception {
    Path whiteboxPath = Paths.get(Utils.TEST_CLASSES, "whitebox.jar");
    if( !Files.exists(whiteboxPath) ) {
        Files.copy(Paths.get(new File("whitebox.jar").getAbsolutePath()),
               Paths.get(Utils.TEST_CLASSES, "whitebox.jar"));
    }
}
 
Example #19
Source File: DockerTestUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute a specified command in a process, report diagnostic info.
 *
 * @param command to be executed
 * @return The output from the process
 * @throws Exception
 */
public static OutputAnalyzer execute(String... command) throws Exception {

    ProcessBuilder pb = new ProcessBuilder(command);
    System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb));

    long started = System.currentTimeMillis();
    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
    System.out.println("[STDERR]\n" + output.getStderr());
    System.out.println("[STDOUT]\n" + output.getStdout());

    return output;
}
 
Example #20
Source File: RTMTestBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prepares VM options for test execution.
 * This method get test java options, filter out all RTM-related options
 * and all options that matches regexps in {@code additionalFilters},
 * adds CompileCommand=compileonly,method_name options for each method
 * from {@code methodToCompile} and finally appends all {@code vmOpts}.
 *
 * @param test test case whose methods that should be compiled.
 *             If {@code null} then no additional <i>compileonly</i>
 *             commands will be added to VM options.
 * @param additionalFilters array with regular expression that will be
 *                          used to filter out test java options.
 *                          If {@code null} then no additional filters
 *                          will be used.
 * @param vmOpts additional options to pass to VM.
 * @return array with VM options.
 */
private static String[] prepareFilteredTestOptions(CompilableTest test,
        String[] additionalFilters, String... vmOpts) {
    List<String> finalVMOpts = new LinkedList<>();
    String[] filters;

    if (additionalFilters != null) {
        filters = Arrays.copyOf(additionalFilters,
                additionalFilters.length + 1);
    } else {
        filters = new String[1];
    }

    filters[filters.length - 1] = "RTM";
    String[] filteredVMOpts = Utils.getFilteredTestJavaOpts(filters);
    Collections.addAll(finalVMOpts, filteredVMOpts);
    Collections.addAll(finalVMOpts, "-Xcomp", "-server",
            "-XX:-TieredCompilation", "-XX:+UseRTMLocking",
            CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
            CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
            "-Xbootclasspath/a:.", "-XX:+WhiteBoxAPI");

    if (test != null) {
        for (String method : test.getMethodsToCompileNames()) {
            finalVMOpts.add("-XX:CompileCommand=compileonly," + method);
        }
    }
    Collections.addAll(finalVMOpts, vmOpts);
    return finalVMOpts.toArray(new String[finalVMOpts.size()]);
}
 
Example #21
Source File: BmiIntrinsicBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void checkEmittedCode(Executable executable) {
    final byte[] nativeCode = NMethod.get(executable, false).insts;
    if (!((BmiTestCase) testCase).verifyPositive(nativeCode)) {
        throw new AssertionError(testCase.name() + "CPU instructions expected not found: " + Utils.toHexString(nativeCode));
    } else {
        System.out.println("CPU instructions found, PASSED");
    }
}
 
Example #22
Source File: RTMTestBase.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prepares VM options for test execution.
 * This method get test java options, filter out all RTM-related options
 * and all options that matches regexps in {@code additionalFilters},
 * adds CompileCommand=compileonly,method_name options for each method
 * from {@code methodToCompile} and finally appends all {@code vmOpts}.
 *
 * @param test test case whose methods that should be compiled.
 *             If {@code null} then no additional <i>compileonly</i>
 *             commands will be added to VM options.
 * @param additionalFilters array with regular expression that will be
 *                          used to filter out test java options.
 *                          If {@code null} then no additional filters
 *                          will be used.
 * @param vmOpts additional options to pass to VM.
 * @return array with VM options.
 */
private static String[] prepareFilteredTestOptions(CompilableTest test,
        String[] additionalFilters, String... vmOpts) {
    List<String> finalVMOpts = new LinkedList<>();
    String[] filters;

    if (additionalFilters != null) {
        filters = Arrays.copyOf(additionalFilters,
                additionalFilters.length + 1);
    } else {
        filters = new String[1];
    }

    filters[filters.length - 1] = "RTM";
    String[] filteredVMOpts = Utils.getFilteredTestJavaOpts(filters);
    Collections.addAll(finalVMOpts, filteredVMOpts);
    Collections.addAll(finalVMOpts, "-Xcomp", "-server",
            "-XX:-TieredCompilation", "-XX:+UseRTMLocking",
            CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
            CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
            "-Xbootclasspath/a:.", "-XX:+WhiteBoxAPI");

    if (test != null) {
        for (String method : test.getMethodsToCompileNames()) {
            finalVMOpts.add("-XX:CompileCommand=compileonly," + method);
        }
    }
    Collections.addAll(finalVMOpts, vmOpts);
    return finalVMOpts.toArray(new String[finalVMOpts.size()]);
}
 
Example #23
Source File: DockerBasicTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testHelloDocker() throws Exception {
    DockerRunOptions opts =
        new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", "HelloDocker")
        .addJavaOpts("-cp", "/test-classes/")
        .addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");

    DockerTestUtils.dockerRunJava(opts)
        .shouldHaveExitValue(0)
        .shouldContain("Hello Docker");
}
 
Example #24
Source File: TestCPUSets.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static DockerRunOptions commonOpts() {
    DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java",
                                                 "PrintContainerInfo");
    opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
    opts.addJavaOpts("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintContainerInfo", "-cp", "/test-classes/");
    Common.addWhiteBoxOpts(opts);
    return opts;
}
 
Example #25
Source File: DockerTestUtils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute a specified command in a process, report diagnostic info.
 *
 * @param command to be executed
 * @return The output from the process
 * @throws Exception
 */
public static OutputAnalyzer execute(String... command) throws Exception {

    ProcessBuilder pb = new ProcessBuilder(command);
    System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb));

    long started = System.currentTimeMillis();
    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
    System.out.println("[STDERR]\n" + output.getStderr());
    System.out.println("[STDOUT]\n" + output.getStdout());

    return output;
}
 
Example #26
Source File: Common.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void prepareWhiteBox() throws Exception {
    Path whiteboxPath = Paths.get(Utils.TEST_CLASSES, "whitebox.jar");
    if( !Files.exists(whiteboxPath) ) {
        Files.copy(Paths.get(new File("whitebox.jar").getAbsolutePath()),
               Paths.get(Utils.TEST_CLASSES, "whitebox.jar"));
    }
}
 
Example #27
Source File: Common.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static DockerRunOptions newOpts(String imageNameAndTag, String testClass) {
    DockerRunOptions opts =
        new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", testClass);
   opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
    opts.addJavaOpts("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintContainerInfo", "-cp", "/test-classes/");
    return opts;
}
 
Example #28
Source File: TestShrinkAuxiliaryData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void test() throws Exception {
    ArrayList<String> vmOpts = new ArrayList();
    Collections.addAll(vmOpts, initialOpts);

    int maxCacheSize = Math.max(0, Math.min(31, getMaxCacheSize()));
    if (maxCacheSize < hotCardTableSize) {
        System.out.format("Skiping test for %d cache size due max cache size %d",
                hotCardTableSize, maxCacheSize
        );
        return;
    }

    printTestInfo(maxCacheSize);

    vmOpts.add("-XX:G1ConcRSLogCacheSize=" + hotCardTableSize);
    vmOpts.addAll(Arrays.asList(Utils.getTestJavaOpts()));

    // for 32 bits ObjectAlignmentInBytes is not a option
    if (Platform.is32bit()) {
        ArrayList<String> vmOptsWithoutAlign = new ArrayList(vmOpts);
        vmOptsWithoutAlign.add(ShrinkAuxiliaryDataTest.class.getName());
        performTest(vmOptsWithoutAlign);
        return;
    }

    for (int alignment = 3; alignment <= 8; alignment++) {
        ArrayList<String> vmOptsWithAlign = new ArrayList(vmOpts);
        vmOptsWithAlign.add("-XX:ObjectAlignmentInBytes="
                + (int) Math.pow(2, alignment));
        vmOptsWithAlign.add(ShrinkAuxiliaryDataTest.class.getName());

        performTest(vmOptsWithAlign);
    }
}
 
Example #29
Source File: BmiIntrinsicBase.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void checkEmittedCode(Executable executable) {
    final byte[] nativeCode = NMethod.get(executable, false).insts;
    if (!((BmiTestCase) testCase).verifyPositive(nativeCode)) {
        throw new AssertionError(testCase.name() + "CPU instructions expected not found: " + Utils.toHexString(nativeCode));
    } else {
        System.out.println("CPU instructions found, PASSED");
    }
}
 
Example #30
Source File: TestShrinkAuxiliaryData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected void test() throws Exception {
    ArrayList<String> vmOpts = new ArrayList();
    Collections.addAll(vmOpts, initialOpts);

    int maxCacheSize = Math.max(0, Math.min(31, getMaxCacheSize()));
    if (maxCacheSize < hotCardTableSize) {
        System.out.format("Skiping test for %d cache size due max cache size %d",
                hotCardTableSize, maxCacheSize
        );
        return;
    }

    printTestInfo(maxCacheSize);

    vmOpts.add("-XX:G1ConcRSLogCacheSize=" + hotCardTableSize);
    vmOpts.addAll(Arrays.asList(Utils.getTestJavaOpts()));

    // for 32 bits ObjectAlignmentInBytes is not a option
    if (Platform.is32bit()) {
        ArrayList<String> vmOptsWithoutAlign = new ArrayList(vmOpts);
        vmOptsWithoutAlign.add(ShrinkAuxiliaryDataTest.class.getName());
        performTest(vmOptsWithoutAlign);
        return;
    }

    for (int alignment = 3; alignment <= 8; alignment++) {
        ArrayList<String> vmOptsWithAlign = new ArrayList(vmOpts);
        vmOptsWithAlign.add("-XX:ObjectAlignmentInBytes="
                + (int) Math.pow(2, alignment));
        vmOptsWithAlign.add(ShrinkAuxiliaryDataTest.class.getName());

        performTest(vmOptsWithAlign);
    }
}