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.
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.
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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * ident "%Z%%M% %I% %E% SMI"
30 import java.io.IOException;
31 import java.util.List;
32 import org.opensolaris.os.dtrace.*;
35 * Regression for multi-aggregation printa() corner cases.
37 public class TestMultiAggPrinta {
38 static int exitStatus;
40 // Gets a string representation of the given PrintaRecord minus the
41 // timestamp of the aggregate snapshot, so that the output is
42 // comparable across multiple test runs.
44 printaRecordString(PrintaRecord rec)
46 StringBuffer buf = new StringBuffer();
47 buf.append(PrintaRecord.class.getName());
48 buf.append("[aggregations = ");
49 buf.append(rec.getAggregations());
50 buf.append(", formattedStrings = ");
51 buf.append(rec.getFormattedStrings());
52 buf.append(", tuples = ");
53 buf.append(rec.getTuples());
54 buf.append(", output = ");
55 buf.append(rec.getOutput());
57 return buf.toString();
61 probeDataString(ProbeData data)
63 StringBuffer buf = new StringBuffer();
64 buf.append(ProbeData.class.getName());
65 buf.append("[epid = ");
66 buf.append(data.getEnabledProbeID());
67 // Do not include cpu, since it can change across test runs
68 buf.append(", enabledProbeDescription = ");
69 buf.append(data.getEnabledProbeDescription());
70 buf.append(", flow = ");
71 buf.append(data.getFlow());
72 buf.append(", records = ");
74 List <Record> records = data.getRecords();
78 for (int i = 0; i < records.size(); ++i) {
82 record = records.get(i);
83 if (record instanceof ValueRecord) {
84 value = ((ValueRecord)record).getValue();
85 if (value instanceof String) {
87 buf.append((String)value);
92 } else if (record instanceof PrintaRecord) {
93 PrintaRecord printa = (PrintaRecord)record;
94 buf.append(printaRecordString(printa));
100 return buf.toString();
106 if (args.length != 1) {
107 System.err.println("usage: java TestMultiAggPrinta <script>");
111 final Consumer consumer = new LocalConsumer();
112 consumer.addConsumerListener(new ConsumerAdapter() {
113 public void dataReceived(DataEvent e) {
114 ProbeData data = e.getProbeData();
115 List <Record> records = data.getRecords();
116 for (Record r : records) {
117 if (r instanceof ExitRecord) {
118 ExitRecord exitRecord = (ExitRecord)r;
119 exitStatus = exitRecord.getStatus();
122 System.out.println(probeDataString(e.getProbeData()));
124 public void consumerStopped(ConsumerEvent e) {
126 System.exit(exitStatus);
130 File file = new File(args[0]);
133 consumer.compile(file);
136 } catch (DTraceException e) {
139 } catch (IOException e) {