< prev index next >

test/jtreg-ext/requires/VMProps.java

Print this page
rev 49499 : Exclude NativeLibraryTest.java on musl.


   5  * This code is free software; you can redistribute it and/or modify it
   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 package requires;
  24 


  25 import java.io.IOException;
  26 import java.nio.file.Files;
  27 import java.nio.file.Path;
  28 import java.nio.file.Paths;
  29 import java.nio.file.StandardOpenOption;
  30 import java.util.ArrayList;
  31 import java.util.HashMap;
  32 import java.util.List;
  33 import java.util.Map;
  34 import java.util.concurrent.Callable;
  35 import java.util.concurrent.TimeUnit;
  36 import java.util.regex.Matcher;
  37 import java.util.regex.Pattern;
  38 
  39 import sun.hotspot.cpuinfo.CPUInfo;
  40 import sun.hotspot.gc.GC;
  41 import sun.hotspot.WhiteBox;
  42 import jdk.test.lib.Platform;
  43 
  44 /**


  62         Map<String, String> map = new HashMap<>();
  63         map.put("vm.flavor", vmFlavor());
  64         map.put("vm.compMode", vmCompMode());
  65         map.put("vm.bits", vmBits());
  66         map.put("vm.flightRecorder", vmFlightRecorder());
  67         map.put("vm.simpleArch", vmArch());
  68         map.put("vm.debug", vmDebug());
  69         map.put("vm.jvmci", vmJvmci());
  70         map.put("vm.emulatedClient", vmEmulatedClient());
  71         map.put("vm.cpu.features", cpuFeatures());
  72         map.put("vm.rtm.cpu", vmRTMCPU());
  73         map.put("vm.rtm.os", vmRTMOS());
  74         map.put("vm.aot", vmAOT());
  75         // vm.cds is true if the VM is compiled with cds support.
  76         map.put("vm.cds", vmCDS());
  77         map.put("vm.cds.custom.loaders", vmCDSForCustomLoaders());
  78         map.put("vm.cds.archived.java.heap", vmCDSForArchivedJavaHeap());
  79         // vm.graal.enabled is true if Graal is used as JIT
  80         map.put("vm.graal.enabled", isGraalEnabled());
  81         map.put("docker.support", dockerSupport());

  82         vmGC(map); // vm.gc.X = true/false
  83 
  84         VMProps.dump(map);
  85         return map;
  86     }
  87 
  88     /**
  89      * Prints a stack trace before returning null.
  90      * Used by the various helper functions which parse information from
  91      * VM properties in the case where they don't find an expected property
  92      * or a propoerty doesn't conform to an expected format.
  93      *
  94      * @return null
  95      */
  96     private String nullWithException(String message) {
  97         new Exception(message).printStackTrace();
  98         return null;
  99     }
 100 
 101     /**


 389 
 390         if (isSupported) {
 391            try {
 392               isSupported = checkDockerSupport();
 393            } catch (Exception e) {
 394               isSupported = false;
 395            }
 396          }
 397 
 398         return (isSupported) ? "true" : "false";
 399     }
 400 
 401     private boolean checkDockerSupport() throws IOException, InterruptedException {
 402         ProcessBuilder pb = new ProcessBuilder("docker", "ps");
 403         Process p = pb.start();
 404         p.waitFor(10, TimeUnit.SECONDS);
 405 
 406         return (p.exitValue() == 0);
 407     }
 408 
 409 


















 410 
 411     /**
 412      * Dumps the map to the file if the file name is given as the property.
 413      * This functionality could be helpful to know context in the real
 414      * execution.
 415      *
 416      * @param map
 417      */
 418     protected static void dump(Map<String, String> map) {
 419         String dumpFileName = System.getProperty("vmprops.dump");
 420         if (dumpFileName == null) {
 421             return;
 422         }
 423         List<String> lines = new ArrayList<>();
 424         map.forEach((k, v) -> lines.add(k + ":" + v));
 425         try {
 426             Files.write(Paths.get(dumpFileName), lines, StandardOpenOption.APPEND);
 427         } catch (IOException e) {
 428             throw new RuntimeException("Failed to dump properties into '"
 429                     + dumpFileName + "'", e);


   5  * This code is free software; you can redistribute it and/or modify it
   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 package requires;
  24 
  25 import java.io.BufferedReader;
  26 import java.io.InputStreamReader;
  27 import java.io.IOException;
  28 import java.nio.file.Files;
  29 import java.nio.file.Path;
  30 import java.nio.file.Paths;
  31 import java.nio.file.StandardOpenOption;
  32 import java.util.ArrayList;
  33 import java.util.HashMap;
  34 import java.util.List;
  35 import java.util.Map;
  36 import java.util.concurrent.Callable;
  37 import java.util.concurrent.TimeUnit;
  38 import java.util.regex.Matcher;
  39 import java.util.regex.Pattern;
  40 
  41 import sun.hotspot.cpuinfo.CPUInfo;
  42 import sun.hotspot.gc.GC;
  43 import sun.hotspot.WhiteBox;
  44 import jdk.test.lib.Platform;
  45 
  46 /**


  64         Map<String, String> map = new HashMap<>();
  65         map.put("vm.flavor", vmFlavor());
  66         map.put("vm.compMode", vmCompMode());
  67         map.put("vm.bits", vmBits());
  68         map.put("vm.flightRecorder", vmFlightRecorder());
  69         map.put("vm.simpleArch", vmArch());
  70         map.put("vm.debug", vmDebug());
  71         map.put("vm.jvmci", vmJvmci());
  72         map.put("vm.emulatedClient", vmEmulatedClient());
  73         map.put("vm.cpu.features", cpuFeatures());
  74         map.put("vm.rtm.cpu", vmRTMCPU());
  75         map.put("vm.rtm.os", vmRTMOS());
  76         map.put("vm.aot", vmAOT());
  77         // vm.cds is true if the VM is compiled with cds support.
  78         map.put("vm.cds", vmCDS());
  79         map.put("vm.cds.custom.loaders", vmCDSForCustomLoaders());
  80         map.put("vm.cds.archived.java.heap", vmCDSForArchivedJavaHeap());
  81         // vm.graal.enabled is true if Graal is used as JIT
  82         map.put("vm.graal.enabled", isGraalEnabled());
  83         map.put("docker.support", dockerSupport());
  84         map.put("vm.musl", isMusl());
  85         vmGC(map); // vm.gc.X = true/false
  86 
  87         VMProps.dump(map);
  88         return map;
  89     }
  90 
  91     /**
  92      * Prints a stack trace before returning null.
  93      * Used by the various helper functions which parse information from
  94      * VM properties in the case where they don't find an expected property
  95      * or a propoerty doesn't conform to an expected format.
  96      *
  97      * @return null
  98      */
  99     private String nullWithException(String message) {
 100         new Exception(message).printStackTrace();
 101         return null;
 102     }
 103 
 104     /**


 392 
 393         if (isSupported) {
 394            try {
 395               isSupported = checkDockerSupport();
 396            } catch (Exception e) {
 397               isSupported = false;
 398            }
 399          }
 400 
 401         return (isSupported) ? "true" : "false";
 402     }
 403 
 404     private boolean checkDockerSupport() throws IOException, InterruptedException {
 405         ProcessBuilder pb = new ProcessBuilder("docker", "ps");
 406         Process p = pb.start();
 407         p.waitFor(10, TimeUnit.SECONDS);
 408 
 409         return (p.exitValue() == 0);
 410     }
 411 
 412     /**
 413      * Check if we run with musl libc.
 414      *
 415      * @return true if we run with musl libc.
 416      */
 417     protected String isMusl() {
 418         try {
 419             ProcessBuilder pb = new ProcessBuilder("ldd", "--version");
 420             pb.redirectErrorStream(true);
 421             final Process p = pb.start();
 422             BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
 423             String line = br.readLine();
 424             if (line != null && line.contains("musl")) {
 425                 return "true";
 426             }
 427         } catch (Exception e) {
 428         }
 429         return "false";
 430     }
 431 
 432     /**
 433      * Dumps the map to the file if the file name is given as the property.
 434      * This functionality could be helpful to know context in the real
 435      * execution.
 436      *
 437      * @param map
 438      */
 439     protected static void dump(Map<String, String> map) {
 440         String dumpFileName = System.getProperty("vmprops.dump");
 441         if (dumpFileName == null) {
 442             return;
 443         }
 444         List<String> lines = new ArrayList<>();
 445         map.forEach((k, v) -> lines.add(k + ":" + v));
 446         try {
 447             Files.write(Paths.get(dumpFileName), lines, StandardOpenOption.APPEND);
 448         } catch (IOException e) {
 449             throw new RuntimeException("Failed to dump properties into '"
 450                     + dumpFileName + "'", e);
< prev index next >