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 import java.util.NoSuchElementException; 29 30 /** 31 * Regression for 6426129 abort() after close() throws 32 * NoSuchElementException. 33 */ 34 public class TestAbort { 35 static boolean aborted = false; 36 37 public static void 38 main(String[] args) 39 { 40 Consumer consumer = new LocalConsumer(); 41 42 // Test for deadlock (bug 6419880) 43 try { 44 consumer.open(); 45 consumer.compile("syscall:::entry { @[execname] = count(); } " + 46 "tick-101ms { printa(@); }"); 47 consumer.enable(); 48 consumer.go(); 49 try { 50 Thread.sleep(1000); 51 } catch (InterruptedException e) { 52 e.printStackTrace(); 53 System.exit(1); 54 } 55 consumer.close(); 56 } catch (DTraceException e) { 57 e.printStackTrace(); 58 System.exit(1); 59 } 60 61 consumer = new LocalConsumer(); 62 63 // Should be able to abort an unopened consumer 64 try { 65 aborted = false; 66 consumer.addConsumerListener(new ConsumerAdapter() { 67 public void consumerStopped(ConsumerEvent e) { 68 aborted = true; 69 } 70 }); 71 consumer.abort(); 72 consumer.open(); 73 consumer.compile("syscall:::entry { @[execname] = count(); } " + 74 "tick-101ms { printa(@); }"); 75 consumer.enable(); 76 consumer.go(); 77 try { 78 Thread.sleep(1000); 79 } catch (InterruptedException e) { 80 e.printStackTrace(); 81 System.exit(1); 82 } 83 if (!aborted) { 84 throw new IllegalStateException("consumer not aborted"); 85 } 86 consumer.close(); 87 } catch (Exception e) { 88 e.printStackTrace(); 89 System.exit(1); 90 } 91 92 consumer = new LocalConsumer(); 93 94 // Should be safe to call abort() in any state 95 try { 96 consumer.abort(); 97 consumer.open(); 98 consumer.abort(); 99 consumer.compile("syscall:::entry { @[execname] = count(); } " + 100 "tick-101ms { printa(@); }"); 101 consumer.abort(); 102 consumer.enable(); 103 consumer.abort(); 104 consumer.go(); 105 consumer.abort(); 106 consumer.close(); 107 // Should be safe to call after close() 108 try { 109 consumer.abort(); 110 } catch (NoSuchElementException e) { 111 e.printStackTrace(); 112 System.exit(1); 113 } 114 } catch (Exception e) { 115 e.printStackTrace(); 116 System.exit(1); 117 } 118 119 consumer = new LocalConsumer(); 120 121 // Tests that close() throws expected exception when called on 122 // synchronized consumer. 123 try { 124 consumer.open(); 125 consumer.compile("syscall:::entry { @[execname] = count(); } " + 126 "tick-101ms { printa(@); }"); 127 consumer.enable(); 128 consumer.go(); 129 try { 130 Thread.sleep(1000); 131 } catch (InterruptedException e) { 132 e.printStackTrace(); 133 System.exit(1); 134 } 135 try { 136 synchronized (consumer) { 137 consumer.close(); 138 } 139 } catch (IllegalThreadStateException e) { 140 try { 141 consumer.close(); 142 System.out.println("Successful"); 143 System.exit(0); 144 } catch (NoSuchElementException x) { 145 x.printStackTrace(); 146 System.exit(1); 147 } 148 } 149 } catch (DTraceException e) { 150 e.printStackTrace(); 151 System.exit(1); 152 } 153 System.err.println("Failed"); 154 System.exit(1); 155 } 156 } 157