< prev index next >

test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java

Print this page
@  rev 58200 : 8240189: [TESTBUG] Some cgroup tests are failing after JDK-8231111
|  Reviewed-by: mbaesken
~


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.util.Arrays;
  25 
  26 import jdk.internal.platform.Metrics;
  27 import jdk.internal.platform.CgroupV1Metrics;

  28 
  29 public class MetricsMemoryTester {



  30     public static void main(String[] args) {
  31         System.out.println(Arrays.toString(args));
  32         switch (args[0]) {
  33             case "memory":
  34                 testMemoryLimit(args[1]);
  35                 break;
  36             case "memoryswap":
  37                 testMemoryAndSwapLimit(args[1], args[2]);
  38                 break;
  39             case "kernelmem":
  40                 testKernelMemoryLimit(args[1]);
  41                 break;
  42             case "oomkill":
  43                 testOomKillFlag(Boolean.parseBoolean(args[2]));
  44                 break;
  45             case "failcount":
  46                 testMemoryFailCount();
  47                 break;
  48             case "softlimit":
  49                 testMemorySoftLimit(args[1]);


  98     private static void testMemorySoftLimit(String softLimit) {
  99 
 100         long memorySoftLimit = Metrics.systemMetrics().getMemorySoftLimit();
 101         long newmemorySoftLimit = getMemoryValue(softLimit);
 102 
 103         if (newmemorySoftLimit != memorySoftLimit) {
 104             throw new RuntimeException("Memory softlimit not equal, Actual : ["
 105                     + newmemorySoftLimit + "]" + ", Expected : ["
 106                     + memorySoftLimit + "]");
 107         }
 108         System.out.println("TEST PASSED!!!");
 109     }
 110 
 111     private static void testKernelMemoryLimit(String value) {
 112         Metrics m = Metrics.systemMetrics();
 113         if (m instanceof CgroupV1Metrics) {
 114             CgroupV1Metrics mCgroupV1 = (CgroupV1Metrics)m;
 115             System.out.println("TEST PASSED!!!");
 116             long limit = getMemoryValue(value);
 117             long kmemlimit = mCgroupV1.getKernelMemoryLimit();
 118             if (kmemlimit != 0 && limit != kmemlimit) {
 119                 throw new RuntimeException("Kernel Memory limit not equal, expected : ["
 120                         + limit + "]" + ", got : ["
 121                         + kmemlimit + "]");
 122             }
 123         } else {
 124             throw new RuntimeException("oomKillFlag test not supported for cgroups v2");
 125         }
 126     }
 127 
 128     private static void testMemoryAndSwapLimit(String memory, String memAndSwap) {
 129         long expectedMem = getMemoryValue(memory);
 130         long expectedMemAndSwap = getMemoryValue(memAndSwap);
 131 
 132         if (expectedMem != Metrics.systemMetrics().getMemoryLimit()
 133                 || expectedMemAndSwap != Metrics.systemMetrics().getMemoryAndSwapLimit()) {
 134             System.err.println("Memory and swap limit not equal, expected : ["
 135                     + expectedMem + ", " + expectedMemAndSwap + "]"
 136                     + ", got : [" + Metrics.systemMetrics().getMemoryLimit()
 137                     + ", " + Metrics.systemMetrics().getMemoryAndSwapLimit() + "]");
 138         }
 139         System.out.println("TEST PASSED!!!");
 140     }
 141 
 142     private static long getMemoryValue(String value) {
 143         long result;
 144         if (value.endsWith("m")) {




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.util.Arrays;
  25 

  26 import jdk.internal.platform.CgroupV1Metrics;
  27 import jdk.internal.platform.Metrics;
  28 
  29 public class MetricsMemoryTester {
  30 
  31     public static final long UNLIMITED = -1;
  32 
  33     public static void main(String[] args) {
  34         System.out.println(Arrays.toString(args));
  35         switch (args[0]) {
  36             case "memory":
  37                 testMemoryLimit(args[1]);
  38                 break;
  39             case "memoryswap":
  40                 testMemoryAndSwapLimit(args[1], args[2]);
  41                 break;
  42             case "kernelmem":
  43                 testKernelMemoryLimit(args[1]);
  44                 break;
  45             case "oomkill":
  46                 testOomKillFlag(Boolean.parseBoolean(args[2]));
  47                 break;
  48             case "failcount":
  49                 testMemoryFailCount();
  50                 break;
  51             case "softlimit":
  52                 testMemorySoftLimit(args[1]);


 101     private static void testMemorySoftLimit(String softLimit) {
 102 
 103         long memorySoftLimit = Metrics.systemMetrics().getMemorySoftLimit();
 104         long newmemorySoftLimit = getMemoryValue(softLimit);
 105 
 106         if (newmemorySoftLimit != memorySoftLimit) {
 107             throw new RuntimeException("Memory softlimit not equal, Actual : ["
 108                     + newmemorySoftLimit + "]" + ", Expected : ["
 109                     + memorySoftLimit + "]");
 110         }
 111         System.out.println("TEST PASSED!!!");
 112     }
 113 
 114     private static void testKernelMemoryLimit(String value) {
 115         Metrics m = Metrics.systemMetrics();
 116         if (m instanceof CgroupV1Metrics) {
 117             CgroupV1Metrics mCgroupV1 = (CgroupV1Metrics)m;
 118             System.out.println("TEST PASSED!!!");
 119             long limit = getMemoryValue(value);
 120             long kmemlimit = mCgroupV1.getKernelMemoryLimit();
 121             if (kmemlimit != UNLIMITED && limit != kmemlimit) {
 122                 throw new RuntimeException("Kernel Memory limit not equal, expected : ["
 123                         + limit + "]" + ", got : ["
 124                         + kmemlimit + "]");
 125             }
 126         } else {
 127             throw new RuntimeException("kernel memory limit test not supported for cgroups v2");
 128         }
 129     }
 130 
 131     private static void testMemoryAndSwapLimit(String memory, String memAndSwap) {
 132         long expectedMem = getMemoryValue(memory);
 133         long expectedMemAndSwap = getMemoryValue(memAndSwap);
 134 
 135         if (expectedMem != Metrics.systemMetrics().getMemoryLimit()
 136                 || expectedMemAndSwap != Metrics.systemMetrics().getMemoryAndSwapLimit()) {
 137             System.err.println("Memory and swap limit not equal, expected : ["
 138                     + expectedMem + ", " + expectedMemAndSwap + "]"
 139                     + ", got : [" + Metrics.systemMetrics().getMemoryLimit()
 140                     + ", " + Metrics.systemMetrics().getMemoryAndSwapLimit() + "]");
 141         }
 142         System.out.println("TEST PASSED!!!");
 143     }
 144 
 145     private static long getMemoryValue(String value) {
 146         long result;
 147         if (value.endsWith("m")) {


< prev index next >