test/hotspot/jtreg/runtime/containers/docker/TestCPUAwareness.java
author bobv
Tue, 12 Jun 2018 18:51:45 -0400
changeset 50545 292a4a87c321
parent 49058 15765495db12
child 53640 0bde5d88aafe
permissions -rw-r--r--
8203357: Container Metrics Reviewed-by: mchung, dholmes, mseledtsov, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
     1
/*
49058
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
     4
 *
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
     8
 *
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    13
 * accompanied this code).
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    14
 *
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    18
 *
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    21
 * questions.
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    22
 */
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    23
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    24
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    25
/*
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    26
 * @test
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    27
 * @summary Test JVM's CPU resource awareness when running inside docker container
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    28
 * @requires docker.support
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    29
 * @library /test/lib
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    31
 *          java.management
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    32
 *          jdk.jartool/sun.tools.jar
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    33
 * @run driver TestCPUAwareness
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    34
 */
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    35
import java.util.List;
50545
292a4a87c321 8203357: Container Metrics
bobv
parents: 49058
diff changeset
    36
import jdk.test.lib.containers.docker.Common;
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    37
import jdk.test.lib.containers.docker.DockerRunOptions;
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    38
import jdk.test.lib.containers.docker.DockerTestUtils;
50545
292a4a87c321 8203357: Container Metrics
bobv
parents: 49058
diff changeset
    39
import jdk.test.lib.containers.cgroup.CPUSetsReader;
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    40
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    41
public class TestCPUAwareness {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    42
    private static final String imageName = Common.imageName("cpu");
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    43
    private static final int availableCPUs = Runtime.getRuntime().availableProcessors();
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    44
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    46
        if (!DockerTestUtils.canTestDocker()) {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    47
            return;
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    48
        }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    49
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    50
        System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    51
        DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    52
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    53
        try {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    54
            // cpuset, period, shares, expected Active Processor Count
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    55
            testComboWithCpuSets();
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    56
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    57
            // cpu shares - it should be safe to use CPU shares exceeding available CPUs
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    58
            testCpuShares(256, 1);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    59
            testCpuShares(2048, 2);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    60
            testCpuShares(4096, 4);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    61
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    62
            // leave one CPU for system and tools, otherwise this test may be unstable
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    63
            int maxNrOfAvailableCpus =  availableCPUs - 1;
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    64
            for (int i=1; i < maxNrOfAvailableCpus; i = i * 2) {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    65
                testCpus(i, i);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    66
            }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    67
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    68
            // If ActiveProcessorCount is set, the VM should use it, regardless of other
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    69
            // container settings, host settings or available CPUs on the host.
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    70
            testActiveProcessorCount(1, 1);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    71
            testActiveProcessorCount(2, 2);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    72
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    73
            // cpu quota and period
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    74
            testCpuQuotaAndPeriod(50*1000, 100*1000);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    75
            testCpuQuotaAndPeriod(100*1000, 100*1000);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    76
            testCpuQuotaAndPeriod(150*1000, 100*1000);
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    77
            testCpuQuotaAndPeriod(400*1000, 100*1000);
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    78
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    79
        } finally {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    80
            DockerTestUtils.removeDockerImage(imageName);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    81
        }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    82
    }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    83
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
    84
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    85
    private static void testComboWithCpuSets() throws Exception {
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    86
        String cpuSetStr = CPUSetsReader.readFromProcStatus("Cpus_allowed_list");
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    87
        System.out.println("cpuSetStr = " + cpuSetStr);
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    88
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    89
        if (cpuSetStr == null) {
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    90
            System.out.printf("The cpuset test cases are skipped");
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    91
        } else {
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    92
            List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    93
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    94
            // Test subset of cpuset with one element
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    95
            if (cpuSet.size() >= 1) {
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    96
                String testCpuSet = CPUSetsReader.listToString(cpuSet, 1);
49058
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
    97
                testAPCCombo(testCpuSet, 200*1000, 100*1000,   4*1024, true, 1);
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    98
            }
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
    99
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   100
            // Test subset of cpuset with two elements
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   101
            if (cpuSet.size() >= 2) {
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   102
                String testCpuSet = CPUSetsReader.listToString(cpuSet, 2);
49058
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   103
                testAPCCombo(testCpuSet, 200*1000, 100*1000, 4*1024, true, 2);
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   104
                testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023,   true, 2);
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   105
                testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023,   false,  1);
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   106
            }
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   107
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   108
            // Test subset of cpuset with three elements
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   109
            if (cpuSet.size() >= 3) {
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   110
                String testCpuSet = CPUSetsReader.listToString(cpuSet, 3);
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   111
                testAPCCombo(testCpuSet, 100*1000, 100*1000, 2*1024, true, 1);
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   112
                testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023,   true, 2);
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   113
                testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023,   false,  1);
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   114
            }
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   115
        }
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   116
    }
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   117
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   118
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   119
    private static void testActiveProcessorCount(int valueToSet, int expectedValue) throws Exception {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   120
        Common.logNewTestCase("Test ActiveProcessorCount: valueToSet = " + valueToSet);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   121
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   122
        DockerRunOptions opts = Common.newOpts(imageName)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   123
            .addJavaOpts("-XX:ActiveProcessorCount=" + valueToSet, "-Xlog:os=trace");
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   124
        Common.run(opts)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   125
            .shouldMatch("active processor count set by user.*" + expectedValue);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   126
    }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   127
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   128
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   129
    private static void testCpus(int valueToSet, int expectedTraceValue) throws Exception {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   130
        Common.logNewTestCase("test cpus: " + valueToSet);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   131
        DockerRunOptions opts = Common.newOpts(imageName)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   132
            .addDockerOpts("--cpus", "" + valueToSet);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   133
        Common.run(opts)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   134
            .shouldMatch("active_processor_count.*" + expectedTraceValue);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   135
    }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   136
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   137
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   138
    // Expected active processor count can not exceed available CPU count
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   139
    private static int adjustExpectedAPCForAvailableCPUs(int expectedAPC) {
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   140
        if (expectedAPC > availableCPUs) {
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   141
            expectedAPC = availableCPUs;
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   142
            System.out.println("Adjusted expectedAPC = " + expectedAPC);
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   143
        }
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   144
        return expectedAPC;
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   145
    }
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   146
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   147
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   148
    private static void testCpuQuotaAndPeriod(int quota, int period)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   149
        throws Exception {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   150
        Common.logNewTestCase("test cpu quota and period: ");
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   151
        System.out.println("quota = " + quota);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   152
        System.out.println("period = " + period);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   153
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   154
        int expectedAPC = (int) Math.ceil((float) quota / (float) period);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   155
        System.out.println("expectedAPC = " + expectedAPC);
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   156
        expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   157
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   158
        DockerRunOptions opts = Common.newOpts(imageName)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   159
            .addDockerOpts("--cpu-period=" + period)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   160
            .addDockerOpts("--cpu-quota=" + quota);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   161
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   162
        Common.run(opts)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   163
            .shouldMatch("CPU Period is.*" + period)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   164
            .shouldMatch("CPU Quota is.*" + quota)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   165
            .shouldMatch("active_processor_count.*" + expectedAPC);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   166
    }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   167
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   168
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   169
    // Test correctess of automatically selected active processor cound
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   170
    private static void testAPCCombo(String cpuset, int quota, int period, int shares,
49058
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   171
                                     boolean usePreferContainerQuotaForCPUCount,
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   172
                                     int expectedAPC) throws Exception {
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   173
        Common.logNewTestCase("test APC Combo");
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   174
        System.out.println("cpuset = " + cpuset);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   175
        System.out.println("quota = " + quota);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   176
        System.out.println("period = " + period);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   177
        System.out.println("shares = " + period);
49058
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   178
        System.out.println("usePreferContainerQuotaForCPUCount = " + usePreferContainerQuotaForCPUCount);
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   179
        System.out.println("expectedAPC = " + expectedAPC);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   180
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   181
        expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   182
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   183
        DockerRunOptions opts = Common.newOpts(imageName)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   184
            .addDockerOpts("--cpuset-cpus", "" + cpuset)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   185
            .addDockerOpts("--cpu-period=" + period)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   186
            .addDockerOpts("--cpu-quota=" + quota)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   187
            .addDockerOpts("--cpu-shares=" + shares);
49058
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   188
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   189
        if (!usePreferContainerQuotaForCPUCount) opts.addJavaOpts("-XX:-PreferContainerQuotaForCPUCount");
15765495db12 8197589: Update CPU count algorithm when both cpu shares and quotas are used
bobv
parents: 48176
diff changeset
   190
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   191
        Common.run(opts)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   192
            .shouldMatch("active_processor_count.*" + expectedAPC);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   193
    }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   194
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   195
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   196
    private static void testCpuShares(int shares, int expectedAPC) throws Exception {
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   197
        Common.logNewTestCase("test cpu shares, shares = " + shares);
48176
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   198
        System.out.println("expectedAPC = " + expectedAPC);
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   199
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   200
        expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
59ebea050a0d 8191943: [TESTBUG] docker/TestCPUAwareness fails on machine with 2 CPUs
mseledtsov
parents: 47908
diff changeset
   201
47908
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   202
        DockerRunOptions opts = Common.newOpts(imageName)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   203
            .addDockerOpts("--cpu-shares=" + shares);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   204
        Common.run(opts)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   205
            .shouldMatch("CPU Shares is.*" + shares)
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   206
            .shouldMatch("active_processor_count.*" + expectedAPC);
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   207
    }
d6d00f785f39 8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff changeset
   208
}