123b5c241Stomee /*
223b5c241Stomee  * CDDL HEADER START
323b5c241Stomee  *
423b5c241Stomee  * The contents of this file are subject to the terms of the
523b5c241Stomee  * Common Development and Distribution License (the "License").
623b5c241Stomee  * You may not use this file except in compliance with the License.
723b5c241Stomee  *
823b5c241Stomee  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
923b5c241Stomee  * or http://www.opensolaris.org/os/licensing.
1023b5c241Stomee  * See the License for the specific language governing permissions
1123b5c241Stomee  * and limitations under the License.
1223b5c241Stomee  *
1323b5c241Stomee  * When distributing Covered Code, include this CDDL HEADER in each
1423b5c241Stomee  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1523b5c241Stomee  * If applicable, add the following below this CDDL HEADER, with the
1623b5c241Stomee  * fields enclosed by brackets "[]" replaced with your own identifying
1723b5c241Stomee  * information: Portions Copyright [yyyy] [name of copyright owner]
1823b5c241Stomee  *
1923b5c241Stomee  * CDDL HEADER END
2023b5c241Stomee  */
2123b5c241Stomee 
2223b5c241Stomee /*
2323b5c241Stomee  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
2423b5c241Stomee  * Use is subject to license terms.
2523b5c241Stomee  */
2623b5c241Stomee 
2723b5c241Stomee import org.opensolaris.os.dtrace.*;
2823b5c241Stomee 
2923b5c241Stomee /**
3023b5c241Stomee  * Regression for bug 6419880 close() hangs running consumer.
3123b5c241Stomee  */
3223b5c241Stomee public class TestClose {
3323b5c241Stomee     public static void
main(String[] args)3423b5c241Stomee     main(String[] args)
3523b5c241Stomee     {
3623b5c241Stomee 	Consumer consumer = new LocalConsumer();
3723b5c241Stomee 
3823b5c241Stomee 	try {
3923b5c241Stomee 	    consumer.open();
4023b5c241Stomee 	    consumer.compile("syscall:::entry { @[execname] = count(); } " +
4123b5c241Stomee 		    "tick-101ms { printa(@); }");
4223b5c241Stomee 	    consumer.enable();
4323b5c241Stomee 	    consumer.go();
4423b5c241Stomee 	    try {
45*4d0eb50eSRichard PALO 		Thread.sleep(1000);
4623b5c241Stomee 	    } catch (InterruptedException e) {
4723b5c241Stomee 		e.printStackTrace();
4823b5c241Stomee 		System.exit(1);
4923b5c241Stomee 	    }
5023b5c241Stomee 	    consumer.close();
5123b5c241Stomee 	} catch (DTraceException e) {
5223b5c241Stomee 	    e.printStackTrace();
5323b5c241Stomee 	    System.exit(1);
5423b5c241Stomee 	}
5523b5c241Stomee 
5623b5c241Stomee 	consumer = new LocalConsumer();
5723b5c241Stomee 
5823b5c241Stomee 	try {
5923b5c241Stomee 	    consumer.open();
6023b5c241Stomee 	    consumer.compile("syscall:::entry { @[execname] = count(); } " +
6123b5c241Stomee 		    "tick-101ms { printa(@); }");
6223b5c241Stomee 	    consumer.enable();
6323b5c241Stomee 	    consumer.go();
6423b5c241Stomee 	    try {
65*4d0eb50eSRichard PALO 		Thread.sleep(1000);
6623b5c241Stomee 	    } catch (InterruptedException e) {
6723b5c241Stomee 		e.printStackTrace();
6823b5c241Stomee 		System.exit(1);
6923b5c241Stomee 	    }
7023b5c241Stomee 	    try {
7123b5c241Stomee 		// Test new rule that close() is illegal while holding
7223b5c241Stomee 		// lock on consumer.
7323b5c241Stomee 		synchronized (consumer) {
7423b5c241Stomee 		    consumer.close();
7523b5c241Stomee 		}
7623b5c241Stomee 	    } catch (IllegalThreadStateException e) {
7723b5c241Stomee 		consumer.close();
7823b5c241Stomee 		System.out.println("Successful");
7923b5c241Stomee 		System.exit(0);
8023b5c241Stomee 	    }
8123b5c241Stomee 	} catch (DTraceException e) {
8223b5c241Stomee 	    e.printStackTrace();
8323b5c241Stomee 	    System.exit(1);
8423b5c241Stomee 	}
8523b5c241Stomee 	System.err.println("Failed");
8623b5c241Stomee 	System.exit(1);
8723b5c241Stomee     }
8823b5c241Stomee }
89