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 import java.util.NoSuchElementException; 2923b5c241Stomee 3023b5c241Stomee /** 3123b5c241Stomee * Regression for 6426129 abort() after close() throws 3223b5c241Stomee * NoSuchElementException. 3323b5c241Stomee */ 3423b5c241Stomee public class TestAbort { 3523b5c241Stomee static boolean aborted = false; 3623b5c241Stomee 3723b5c241Stomee public static void main(String[] args)3823b5c241Stomee main(String[] args) 3923b5c241Stomee { 4023b5c241Stomee Consumer consumer = new LocalConsumer(); 4123b5c241Stomee 4223b5c241Stomee // Test for deadlock (bug 6419880) 4323b5c241Stomee try { 4423b5c241Stomee consumer.open(); 4523b5c241Stomee consumer.compile("syscall:::entry { @[execname] = count(); } " + 4623b5c241Stomee "tick-101ms { printa(@); }"); 4723b5c241Stomee consumer.enable(); 4823b5c241Stomee consumer.go(); 4923b5c241Stomee try { 50*4d0eb50eSRichard PALO Thread.sleep(1000); 5123b5c241Stomee } catch (InterruptedException e) { 5223b5c241Stomee e.printStackTrace(); 5323b5c241Stomee System.exit(1); 5423b5c241Stomee } 5523b5c241Stomee consumer.close(); 5623b5c241Stomee } catch (DTraceException e) { 5723b5c241Stomee e.printStackTrace(); 5823b5c241Stomee System.exit(1); 5923b5c241Stomee } 6023b5c241Stomee 6123b5c241Stomee consumer = new LocalConsumer(); 6223b5c241Stomee 6323b5c241Stomee // Should be able to abort an unopened consumer 6423b5c241Stomee try { 6523b5c241Stomee aborted = false; 6623b5c241Stomee consumer.addConsumerListener(new ConsumerAdapter() { 6723b5c241Stomee public void consumerStopped(ConsumerEvent e) { 6823b5c241Stomee aborted = true; 6923b5c241Stomee } 7023b5c241Stomee }); 7123b5c241Stomee consumer.abort(); 7223b5c241Stomee consumer.open(); 7323b5c241Stomee consumer.compile("syscall:::entry { @[execname] = count(); } " + 7423b5c241Stomee "tick-101ms { printa(@); }"); 7523b5c241Stomee consumer.enable(); 7623b5c241Stomee consumer.go(); 7723b5c241Stomee try { 78*4d0eb50eSRichard PALO Thread.sleep(1000); 7923b5c241Stomee } catch (InterruptedException e) { 8023b5c241Stomee e.printStackTrace(); 8123b5c241Stomee System.exit(1); 8223b5c241Stomee } 8323b5c241Stomee if (!aborted) { 8423b5c241Stomee throw new IllegalStateException("consumer not aborted"); 8523b5c241Stomee } 8623b5c241Stomee consumer.close(); 8723b5c241Stomee } catch (Exception e) { 8823b5c241Stomee e.printStackTrace(); 8923b5c241Stomee System.exit(1); 9023b5c241Stomee } 9123b5c241Stomee 9223b5c241Stomee consumer = new LocalConsumer(); 9323b5c241Stomee 9423b5c241Stomee // Should be safe to call abort() in any state 9523b5c241Stomee try { 9623b5c241Stomee consumer.abort(); 9723b5c241Stomee consumer.open(); 9823b5c241Stomee consumer.abort(); 9923b5c241Stomee consumer.compile("syscall:::entry { @[execname] = count(); } " + 10023b5c241Stomee "tick-101ms { printa(@); }"); 10123b5c241Stomee consumer.abort(); 10223b5c241Stomee consumer.enable(); 10323b5c241Stomee consumer.abort(); 10423b5c241Stomee consumer.go(); 10523b5c241Stomee consumer.abort(); 10623b5c241Stomee consumer.close(); 10723b5c241Stomee // Should be safe to call after close() 10823b5c241Stomee try { 10923b5c241Stomee consumer.abort(); 11023b5c241Stomee } catch (NoSuchElementException e) { 11123b5c241Stomee e.printStackTrace(); 11223b5c241Stomee System.exit(1); 11323b5c241Stomee } 11423b5c241Stomee } catch (Exception e) { 11523b5c241Stomee e.printStackTrace(); 11623b5c241Stomee System.exit(1); 11723b5c241Stomee } 11823b5c241Stomee 11923b5c241Stomee consumer = new LocalConsumer(); 12023b5c241Stomee 12123b5c241Stomee // Tests that close() throws expected exception when called on 12223b5c241Stomee // synchronized consumer. 12323b5c241Stomee try { 12423b5c241Stomee consumer.open(); 12523b5c241Stomee consumer.compile("syscall:::entry { @[execname] = count(); } " + 12623b5c241Stomee "tick-101ms { printa(@); }"); 12723b5c241Stomee consumer.enable(); 12823b5c241Stomee consumer.go(); 12923b5c241Stomee try { 130*4d0eb50eSRichard PALO Thread.sleep(1000); 13123b5c241Stomee } catch (InterruptedException e) { 13223b5c241Stomee e.printStackTrace(); 13323b5c241Stomee System.exit(1); 13423b5c241Stomee } 13523b5c241Stomee try { 13623b5c241Stomee synchronized (consumer) { 13723b5c241Stomee consumer.close(); 13823b5c241Stomee } 13923b5c241Stomee } catch (IllegalThreadStateException e) { 14023b5c241Stomee try { 14123b5c241Stomee consumer.close(); 14223b5c241Stomee System.out.println("Successful"); 14323b5c241Stomee System.exit(0); 14423b5c241Stomee } catch (NoSuchElementException x) { 14523b5c241Stomee x.printStackTrace(); 14623b5c241Stomee System.exit(1); 14723b5c241Stomee } 14823b5c241Stomee } 14923b5c241Stomee } catch (DTraceException e) { 15023b5c241Stomee e.printStackTrace(); 15123b5c241Stomee System.exit(1); 15223b5c241Stomee } 15323b5c241Stomee System.err.println("Failed"); 15423b5c241Stomee System.exit(1); 15523b5c241Stomee } 15623b5c241Stomee } 157