< prev index next >

test/testlibrary/jdk/test/lib/Utils.java

Print this page




  25 
  26 import java.io.File;
  27 import static jdk.test.lib.Asserts.assertTrue;
  28 import java.io.IOException;
  29 import java.lang.reflect.Field;
  30 import java.net.InetAddress;
  31 import java.net.MalformedURLException;
  32 import java.net.ServerSocket;
  33 import java.net.URL;
  34 import java.net.URLClassLoader;
  35 import java.net.UnknownHostException;
  36 import java.nio.file.Files;
  37 import java.nio.file.Path;
  38 import java.nio.file.Paths;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.Collection;
  42 import java.util.Collections;
  43 import java.util.Iterator;
  44 import java.util.List;

  45 import java.util.Random;
  46 import java.util.function.BooleanSupplier;
  47 import java.util.concurrent.TimeUnit;
  48 import java.util.function.Consumer;
  49 import java.util.regex.Matcher;
  50 import java.util.regex.Pattern;
  51 import sun.misc.Unsafe;
  52 
  53 /**
  54  * Common library for various test helper functions.
  55  */
  56 public final class Utils {
  57 
  58     /**
  59      * Returns the value of 'test.class.path' system property.
  60      */
  61     public static final String TEST_CLASS_PATH = System.getProperty("test.class.path", ".");
  62 
  63     /**
  64      * Returns the sequence used by operating system to separate lines.
  65      */
  66     public static final String NEW_LINE = System.getProperty("line.separator");
  67 
  68     /**
  69      * Returns the value of 'test.vm.opts' system property.
  70      */
  71     public static final String VM_OPTIONS = System.getProperty("test.vm.opts", "").trim();
  72 
  73     /**
  74      * Returns the value of 'test.java.opts' system property.
  75      */
  76     public static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "").trim();
  77 
  78     /**
  79      * Returns the value of 'test.src' system property.
  80      */
  81     public static final String TEST_SRC = System.getProperty("test.src", ".").trim();
  82 










  83     private static Unsafe unsafe = null;
  84 
  85     /**
  86      * Defines property name for seed value.
  87      */
  88     public static final String SEED_PROPERTY_NAME = "jdk.test.lib.random.seed";
  89 
  90     /* (non-javadoc)
  91      * Random generator with (or without) predefined seed. Depends on
  92      * "jdk.test.lib.random.seed" property value.
  93      */
  94     private static volatile Random RANDOM_GENERATOR;
  95 
  96     /**
  97      * Contains the seed value used for {@link java.util.Random} creation.
  98      */
  99     public static final long SEED = Long.getLong(SEED_PROPERTY_NAME, new Random().nextLong());
 100     /**
 101     * Returns the value of 'test.timeout.factor' system property
 102     * converted to {@code double}.


 576                 return "D";
 577             } else if (type == float.class) {
 578                 return "F";
 579             } else if (type == int.class) {
 580                 return "I";
 581             } else if (type == long.class) {
 582                 return "J";
 583             } else if (type == short.class) {
 584                 return "S";
 585             } else if (type == void.class) {
 586                 return "V";
 587             } else {
 588                 throw new Error("Unsupported type: " + type);
 589             }
 590         }
 591         String result = type.getName().replaceAll("\\.", "/");
 592         if (!type.isArray()) {
 593             return "L" + result + ";";
 594         }
 595         return result;













 596     }
 597 }
 598 


  25 
  26 import java.io.File;
  27 import static jdk.test.lib.Asserts.assertTrue;
  28 import java.io.IOException;
  29 import java.lang.reflect.Field;
  30 import java.net.InetAddress;
  31 import java.net.MalformedURLException;
  32 import java.net.ServerSocket;
  33 import java.net.URL;
  34 import java.net.URLClassLoader;
  35 import java.net.UnknownHostException;
  36 import java.nio.file.Files;
  37 import java.nio.file.Path;
  38 import java.nio.file.Paths;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.Collection;
  42 import java.util.Collections;
  43 import java.util.Iterator;
  44 import java.util.List;
  45 import java.util.Objects;
  46 import java.util.Random;
  47 import java.util.function.BooleanSupplier;
  48 import java.util.concurrent.TimeUnit;
  49 import java.util.function.Consumer;
  50 import java.util.regex.Matcher;
  51 import java.util.regex.Pattern;
  52 import sun.misc.Unsafe;
  53 
  54 /**
  55  * Common library for various test helper functions.
  56  */
  57 public final class Utils {
  58 
  59     /**
  60      * Returns the value of 'test.class.path' system property.
  61      */
  62     public static final String TEST_CLASS_PATH = System.getProperty("test.class.path", ".");
  63 
  64     /**
  65      * Returns the sequence used by operating system to separate lines.
  66      */
  67     public static final String NEW_LINE = System.getProperty("line.separator");
  68 
  69     /**
  70      * Returns the value of 'test.vm.opts' system property.
  71      */
  72     public static final String VM_OPTIONS = System.getProperty("test.vm.opts", "").trim();
  73 
  74     /**
  75      * Returns the value of 'test.java.opts' system property.
  76      */
  77     public static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "").trim();
  78 
  79     /**
  80      * Returns the value of 'test.src' system property.
  81      */
  82     public static final String TEST_SRC = System.getProperty("test.src", ".").trim();
  83 
  84     /*
  85      * Returns the value of 'test.jdk' system property
  86      */
  87     public static final String TEST_JDK = System.getProperty("test.jdk");
  88 
  89     /**
  90      * Returns the value of 'test.classes' system property
  91      */
  92     public static final String TEST_CLASSES = System.getProperty("test.classes", ".");
  93 
  94     private static Unsafe unsafe = null;
  95 
  96     /**
  97      * Defines property name for seed value.
  98      */
  99     public static final String SEED_PROPERTY_NAME = "jdk.test.lib.random.seed";
 100 
 101     /* (non-javadoc)
 102      * Random generator with (or without) predefined seed. Depends on
 103      * "jdk.test.lib.random.seed" property value.
 104      */
 105     private static volatile Random RANDOM_GENERATOR;
 106 
 107     /**
 108      * Contains the seed value used for {@link java.util.Random} creation.
 109      */
 110     public static final long SEED = Long.getLong(SEED_PROPERTY_NAME, new Random().nextLong());
 111     /**
 112     * Returns the value of 'test.timeout.factor' system property
 113     * converted to {@code double}.


 587                 return "D";
 588             } else if (type == float.class) {
 589                 return "F";
 590             } else if (type == int.class) {
 591                 return "I";
 592             } else if (type == long.class) {
 593                 return "J";
 594             } else if (type == short.class) {
 595                 return "S";
 596             } else if (type == void.class) {
 597                 return "V";
 598             } else {
 599                 throw new Error("Unsupported type: " + type);
 600             }
 601         }
 602         String result = type.getName().replaceAll("\\.", "/");
 603         if (!type.isArray()) {
 604             return "L" + result + ";";
 605         }
 606         return result;
 607     }
 608 
 609     /**
 610      * Returns mandatory property value
 611      * @param propName is a name of property to request
 612      * @return a String with requested property value
 613      */
 614     public static String getMandatoryProperty(String propName) {
 615         Objects.requireNonNull(propName, "Requested null property");
 616         String prop = System.getProperty(propName);
 617         Objects.requireNonNull(prop,
 618                 String.format("A mandatory property '%s' isn't set", propName));
 619         return prop;
 620     }
 621 }
 622 
< prev index next >