< prev index next >

test/javax/sound/sampled/DirectAudio/bug6400879.java

Print this page
rev 14569 : 8148915: Intermittent failures of bug6400879.java
Reviewed-by: amenkov


   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 /*
  25  * @test
  26  * @bug 6400879 7100140
  27  * @summary Tests that Start/Stop sequence doesn't hang
  28  * @author Alexey Menkov
  29  * @run main bug6400879
  30  * @key intermittent
  31  */
  32 


  33 import javax.sound.sampled.*;
  34 
  35 public class bug6400879 extends Thread {
  36 
  37     public static void main(String args[]) throws Exception {
  38         bug6400879 pThis = new bug6400879();
  39         //pThis.init();
  40         pThis.setDaemon(true);
  41         pThis.start();
  42         monitor(pThis);
  43     }
  44 
  45     static final long BLOCK_TIMEOUT = 5000;    // 5 sec
  46 
  47     // monitors that pThis doesn't hang
  48     public static void monitor(bug6400879 pThis) throws Exception {
  49         long prevLoop = -1;
  50         long prevTime = currentTimeMillis();
  51         while (pThis.isAlive()) {
  52             if (pThis.loopCounter == prevLoop) {
  53                 if (currentTimeMillis() - prevTime > BLOCK_TIMEOUT) {
  54                     // block!
  55                     log("Test FAILED.");
  56                     throw new RuntimeException("Test FAILED: thread has been blocked!");
  57                 }
  58             } else {
  59                 prevLoop = pThis.loopCounter;
  60                 prevTime = currentTimeMillis();
  61             }
  62             delay(500);    // sleep for 0.5 sec
  63         }
  64         log("Test sucessfully passed.");
  65     }
  66 
  67     volatile long loopCounter = 0;
  68     final long LOOPS_PER_LINE = 100;
  69 
  70     public void run() {
  71         SourceDataLine line = null;
  72 
  73         DataLine.Info line_info = new DataLine.Info(SourceDataLine.class, null);
  74         Line.Info infos[] = AudioSystem.getSourceLineInfo(line_info);
  75 
  76         log("total " + infos.length + " lines");
  77 
  78         for (int lineNum = 0; lineNum < infos.length; lineNum++) {
  79             try {
  80                 line = (SourceDataLine)AudioSystem.getLine(infos[lineNum]);
  81                 log("testing line: " + line);
  82                 line.open(line.getFormat());


  94                 log(e1.getMessage());
  95             } catch (SecurityException e2) {
  96                 log("SecurityException caught, test okay.");
  97                 log(e2.getMessage());
  98             } catch (IllegalArgumentException e3) {
  99                 log("IllegalArgumentException caught, test okay.");
 100                 log(e3.getMessage());
 101             }
 102             if (line != null) {
 103                 line.close();
 104                 line = null;
 105             }
 106         }
 107 
 108     }
 109 
 110 
 111     // helper routines
 112     static long startTime = currentTimeMillis();
 113     static long currentTimeMillis() {
 114         //return System.nanoTime() / 1000000L;
 115         return System.currentTimeMillis();
 116     }
 117     static void log(String s) {
 118         long time = currentTimeMillis() - startTime;
 119         long ms = time % 1000;
 120         time /= 1000;
 121         long sec = time % 60;
 122         time /= 60;
 123         long min = time % 60;
 124         time /= 60;
 125         System.out.println(""
 126                 + (time < 10 ? "0" : "") + time
 127                 + ":" + (min < 10 ? "0" : "") + min
 128                 + ":" + (sec < 10 ? "0" : "") + sec
 129                 + "." + (ms < 10 ? "00" : (ms < 100 ? "0" : "")) + ms
 130                 + " (" + Thread.currentThread().getName() + ") " + s);
 131     }
 132     static void delay(int millis) {
 133         try {
 134             Thread.sleep(millis);
 135         } catch (InterruptedException e) {}


   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 /*
  25  * @test
  26  * @bug 6400879 7100140
  27  * @summary Tests that Start/Stop sequence doesn't hang
  28  * @author Alexey Menkov
  29  * @run main/othervm bug6400879

  30  */
  31 
  32 import java.util.concurrent.TimeUnit;
  33 
  34 import javax.sound.sampled.*;
  35 
  36 public class bug6400879 extends Thread {
  37 
  38     public static void main(String args[]) throws Exception {
  39         bug6400879 pThis = new bug6400879();
  40         //pThis.init();
  41         pThis.setDaemon(true);
  42         pThis.start();
  43         monitor(pThis);
  44     }
  45 
  46     static final long BLOCK_TIMEOUT = 5000;    // 5 sec
  47 
  48     // monitors that pThis doesn't hang
  49     public static void monitor(bug6400879 pThis) throws Exception {
  50         long prevLoop = -1;
  51         long prevTime = currentTimeMillis();
  52         while (pThis.isAlive()) {
  53             if (pThis.loopCounter == prevLoop) {
  54                 long delay = currentTimeMillis() - prevTime;
  55                 if (delay > BLOCK_TIMEOUT) {
  56                     // blocked?
  57                     log("The test is slow, delay = " + delay);
  58                 }
  59             } else {
  60                 prevLoop = pThis.loopCounter;
  61                 prevTime = currentTimeMillis();
  62             }
  63             delay(1000);    // sleep for 1 sec
  64         }
  65         log("Test sucessfully passed.");
  66     }
  67 
  68     volatile long loopCounter = 0;
  69     final long LOOPS_PER_LINE = 100;
  70 
  71     public void run() {
  72         SourceDataLine line = null;
  73 
  74         DataLine.Info line_info = new DataLine.Info(SourceDataLine.class, null);
  75         Line.Info infos[] = AudioSystem.getSourceLineInfo(line_info);
  76 
  77         log("total " + infos.length + " lines");
  78 
  79         for (int lineNum = 0; lineNum < infos.length; lineNum++) {
  80             try {
  81                 line = (SourceDataLine)AudioSystem.getLine(infos[lineNum]);
  82                 log("testing line: " + line);
  83                 line.open(line.getFormat());


  95                 log(e1.getMessage());
  96             } catch (SecurityException e2) {
  97                 log("SecurityException caught, test okay.");
  98                 log(e2.getMessage());
  99             } catch (IllegalArgumentException e3) {
 100                 log("IllegalArgumentException caught, test okay.");
 101                 log(e3.getMessage());
 102             }
 103             if (line != null) {
 104                 line.close();
 105                 line = null;
 106             }
 107         }
 108 
 109     }
 110 
 111 
 112     // helper routines
 113     static long startTime = currentTimeMillis();
 114     static long currentTimeMillis() {
 115         return TimeUnit.NANOSECONDS.toMillis(System.nanoTime());

 116     }
 117     static void log(String s) {
 118         long time = currentTimeMillis() - startTime;
 119         long ms = time % 1000;
 120         time /= 1000;
 121         long sec = time % 60;
 122         time /= 60;
 123         long min = time % 60;
 124         time /= 60;
 125         System.out.println(""
 126                 + (time < 10 ? "0" : "") + time
 127                 + ":" + (min < 10 ? "0" : "") + min
 128                 + ":" + (sec < 10 ? "0" : "") + sec
 129                 + "." + (ms < 10 ? "00" : (ms < 100 ? "0" : "")) + ms
 130                 + " (" + Thread.currentThread().getName() + ") " + s);
 131     }
 132     static void delay(int millis) {
 133         try {
 134             Thread.sleep(millis);
 135         } catch (InterruptedException e) {}
< prev index next >