Path: blob/master/test/jdk/javax/sound/sampled/Mixers/DisabledAssertionCrash.java
41153 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.sound.sampled.AudioFormat;24import javax.sound.sampled.AudioSystem;25import javax.sound.sampled.DataLine;26import javax.sound.sampled.Line;27import javax.sound.sampled.LineUnavailableException;28import javax.sound.sampled.SourceDataLine;29import javax.sound.sampled.TargetDataLine;3031/**32* @test33* @bug 499167234* @summary disabled assertion at maximum thread priority causes audio crash35* @run main/timeout=600 DisabledAssertionCrash36*/37public class DisabledAssertionCrash {38private static final int bufferSize = 1024;3940public static void main(String[] args) {4142System.out.println("This program hangs if priority is set,");43System.out.println("and assertion is in the code.");44System.out.println("The program crashes the entire Windows system");45System.out.println("if assertions are disabled.");46try {47Thread.currentThread().setPriority(Thread.MAX_PRIORITY);48AudioFormat audioFormat = new AudioFormat(44100,16,1,true,true);49Line.Info sourceDataLineInfo = new DataLine.Info(SourceDataLine.class,audioFormat);50SourceDataLine sourceDataLine =51(SourceDataLine) AudioSystem.getLine(sourceDataLineInfo);52System.out.println("SourceDataLine: "+sourceDataLine);53sourceDataLine.open(audioFormat, bufferSize);54sourceDataLine.start();55Line.Info targetDataLineInfo =56new DataLine.Info(TargetDataLine.class,audioFormat);57TargetDataLine targetDataLine =58(TargetDataLine) AudioSystem.getLine(targetDataLineInfo);59System.out.println("TargetDataLine: "+targetDataLine);60targetDataLine.open(audioFormat, bufferSize);61targetDataLine.start();62byte[] data = new byte[bufferSize];6364// execute for 20 seconds65float bufferTime = (((float) data.length) / audioFormat.getFrameSize()) / audioFormat.getFrameRate();66int count = (int) (20.0f / bufferTime);67System.out.println("Buffer time: "+(bufferTime * 1000)+" millis. "+count+" iterations.");68for (int i = 0; i < count; i++) {69int cnt = targetDataLine.read(data,0,data.length);70sourceDataLine.write(data,0,cnt);71assert cnt == data.length;72}73System.out.println("Successfully recorded/played "+count+" buffers. Passed");74} catch(LineUnavailableException lue) {75System.out.println("Audio hardware is not available!");76lue.printStackTrace();77System.out.println("Cannot execute test. NOT failed.");78} catch(IllegalArgumentException iae) {79System.out.println("No audio hardware is installed!");80iae.printStackTrace();81System.out.println("Test system not correctly setup.");82System.out.println("Cannot execute test. NOT failed.");83} catch(Exception e) {84System.out.println("Unexpected Exception: "+e);85e.printStackTrace();86System.out.println("Cannot execute test. NOT failed.");87}88}89}909192