1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 import org.opensolaris.os.dtrace.*;
28 
29 /**
30  * Regression for bug 6419880 close() hangs running consumer.
31  */
32 public class TestClose {
33     public static void
main(String[] args)34     main(String[] args)
35     {
36 	Consumer consumer = new LocalConsumer();
37 
38 	try {
39 	    consumer.open();
40 	    consumer.compile("syscall:::entry { @[execname] = count(); } " +
41 		    "tick-101ms { printa(@); }");
42 	    consumer.enable();
43 	    consumer.go();
44 	    try {
45 		Thread.sleep(1000);
46 	    } catch (InterruptedException e) {
47 		e.printStackTrace();
48 		System.exit(1);
49 	    }
50 	    consumer.close();
51 	} catch (DTraceException e) {
52 	    e.printStackTrace();
53 	    System.exit(1);
54 	}
55 
56 	consumer = new LocalConsumer();
57 
58 	try {
59 	    consumer.open();
60 	    consumer.compile("syscall:::entry { @[execname] = count(); } " +
61 		    "tick-101ms { printa(@); }");
62 	    consumer.enable();
63 	    consumer.go();
64 	    try {
65 		Thread.sleep(1000);
66 	    } catch (InterruptedException e) {
67 		e.printStackTrace();
68 		System.exit(1);
69 	    }
70 	    try {
71 		// Test new rule that close() is illegal while holding
72 		// lock on consumer.
73 		synchronized (consumer) {
74 		    consumer.close();
75 		}
76 	    } catch (IllegalThreadStateException e) {
77 		consumer.close();
78 		System.out.println("Successful");
79 		System.exit(0);
80 	    }
81 	} catch (DTraceException e) {
82 	    e.printStackTrace();
83 	    System.exit(1);
84 	}
85 	System.err.println("Failed");
86 	System.exit(1);
87     }
88 }
89