1178476Sjb/* 2178476Sjb * CDDL HEADER START 3178476Sjb * 4178476Sjb * The contents of this file are subject to the terms of the 5178476Sjb * Common Development and Distribution License (the "License"). 6178476Sjb * You may not use this file except in compliance with the License. 7178476Sjb * 8178476Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9178476Sjb * or http://www.opensolaris.org/os/licensing. 10178476Sjb * See the License for the specific language governing permissions 11178476Sjb * and limitations under the License. 12178476Sjb * 13178476Sjb * When distributing Covered Code, include this CDDL HEADER in each 14178476Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15178476Sjb * If applicable, add the following below this CDDL HEADER, with the 16178476Sjb * fields enclosed by brackets "[]" replaced with your own identifying 17178476Sjb * information: Portions Copyright [yyyy] [name of copyright owner] 18178476Sjb * 19178476Sjb * CDDL HEADER END 20178476Sjb */ 21178476Sjb 22178476Sjb/* 23178476Sjb * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24178476Sjb * Use is subject to license terms. 25178476Sjb * 26178476Sjb * ident "%Z%%M% %I% %E% SMI" 27178476Sjb */ 28178476Sjb 29178476Sjbimport java.util.*; 30178476Sjbimport org.opensolaris.os.dtrace.*; 31178476Sjb 32178476Sjb/** 33178476Sjb * Regression test verifies that ProbeData instances sort as expected 34178476Sjb * with multiple enabled probe IDs and multiple records including byte 35178476Sjb * array (sorted as unsigned bytes), stand-alone ufunc() action, and 36178476Sjb * signed integer. 37178476Sjb */ 38178476Sjbpublic class TestProbeData { 39178476Sjb public static final String PROGRAM = 40178476Sjb "pid$target::fN:entry\n" + 41178476Sjb "{\n" + 42178476Sjb " tracemem(copyin(arg1, 6), 6);\n" + 43178476Sjb " ufunc(arg0);\n" + 44178476Sjb " trace((int)arg2);\n" + 45178476Sjb "}" + 46178476Sjb "" + 47178476Sjb "pid$target::fN2:entry\n" + 48178476Sjb "{\n" + 49178476Sjb " tracemem(copyin(arg1, 6), 6);\n" + 50178476Sjb " ufunc(arg0);\n" + 51178476Sjb " trace((int)arg2);\n" + 52178476Sjb "}"; 53178476Sjb 54178476Sjb static String 55178476Sjb getString(ProbeData p) 56178476Sjb { 57178476Sjb StringBuilder buf = new StringBuilder(); 58178476Sjb buf.append("[probe "); 59178476Sjb buf.append(p.getEnabledProbeID()); 60178476Sjb buf.append(' '); 61178476Sjb ProbeDescription d = p.getEnabledProbeDescription(); 62178476Sjb buf.append("pid$target"); 63178476Sjb buf.append(':'); 64178476Sjb buf.append(d.getModule()); 65178476Sjb buf.append(':'); 66178476Sjb buf.append(d.getFunction()); 67178476Sjb buf.append(':'); 68178476Sjb buf.append(d.getName()); 69178476Sjb buf.append(' '); 70178476Sjb buf.append(p.getRecords()); 71178476Sjb buf.append("]"); 72178476Sjb return buf.toString(); 73178476Sjb } 74178476Sjb 75178476Sjb public static void 76178476Sjb main(String[] args) 77178476Sjb { 78178476Sjb if (args.length != 1) { 79178476Sjb System.err.println("usage: java TestProbedata <command>"); 80178476Sjb System.exit(2); 81178476Sjb } 82178476Sjb 83178476Sjb String command = args[0]; 84178476Sjb final Consumer consumer = new LocalConsumer(); 85178476Sjb final List <ProbeData> list = new ArrayList <ProbeData> (); 86178476Sjb consumer.addConsumerListener(new ConsumerAdapter() { 87178476Sjb public void dataReceived(DataEvent e) { 88178476Sjb list.add(e.getProbeData()); 89178476Sjb } 90178476Sjb public void consumerStopped(ConsumerEvent e) { 91178476Sjb Collections.sort(list); 92178476Sjb for (ProbeData p : list) { 93178476Sjb System.out.println(getString(p)); 94178476Sjb System.out.println(); 95178476Sjb } 96178476Sjb consumer.close(); 97178476Sjb } 98178476Sjb }); 99178476Sjb 100178476Sjb try { 101178476Sjb consumer.open(); 102178476Sjb consumer.createProcess(command); 103178476Sjb consumer.compile(PROGRAM); 104178476Sjb consumer.enable(); 105178476Sjb consumer.go(); 106178476Sjb } catch (DTraceException e) { 107178476Sjb e.printStackTrace(); 108178476Sjb } 109178476Sjb } 110178476Sjb} 111