From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- .../cmd/dtrace/test/tst/common/java_api/Makefile | 79 +++ .../dtrace/test/tst/common/java_api/Makefile.kup | 0 .../test/tst/common/java_api/manifest/Makefile.kup | 0 .../tst/common/java_api/manifest/test.jar-manifest | 2 + .../test/tst/common/java_api/src/Makefile.kup | 0 .../test/tst/common/java_api/src/TestAbort.java | 158 +++++ .../test/tst/common/java_api/src/TestBean.java | 706 ++++++++++++++++++++ .../test/tst/common/java_api/src/TestClose.java | 90 +++ .../test/tst/common/java_api/src/TestDrop.java | 169 +++++ .../test/tst/common/java_api/src/TestEnable.java | 151 +++++ .../common/java_api/src/TestFunctionLookup.java | 114 ++++ .../tst/common/java_api/src/TestGetAggregate.java | 252 +++++++ .../tst/common/java_api/src/TestMaxConsumers.java | 97 +++ .../common/java_api/src/TestMultiAggPrinta.java | 144 ++++ .../tst/common/java_api/src/TestProbeData.java | 110 ++++ .../common/java_api/src/TestProbeDescription.java | 55 ++ .../tst/common/java_api/src/TestStateMachine.java | 627 ++++++++++++++++++ .../test/tst/common/java_api/src/TestStopLock.java | 67 ++ .../dtrace/test/tst/common/java_api/tst.Abort.ksh | 39 ++ .../test/tst/common/java_api/tst.Abort.ksh.out | 1 + .../dtrace/test/tst/common/java_api/tst.Bean.ksh | 41 ++ .../test/tst/common/java_api/tst.Bean.ksh.out | 722 +++++++++++++++++++++ .../dtrace/test/tst/common/java_api/tst.Close.ksh | 38 ++ .../test/tst/common/java_api/tst.Close.ksh.out | 1 + .../dtrace/test/tst/common/java_api/tst.Drop.ksh | 38 ++ .../test/tst/common/java_api/tst.Drop.ksh.out | 1 + .../dtrace/test/tst/common/java_api/tst.Enable.ksh | 40 ++ .../test/tst/common/java_api/tst.Enable.ksh.out | 6 + .../test/tst/common/java_api/tst.FunctionLookup.c | 51 ++ .../tst/common/java_api/tst.FunctionLookup.ksh | 39 ++ .../tst/common/java_api/tst.FunctionLookup.ksh.out | 3 + .../test/tst/common/java_api/tst.GetAggregate.ksh | 36 + .../test/tst/common/java_api/tst.MaxConsumers.ksh | 47 ++ .../tst/common/java_api/tst.MaxConsumers.ksh.out | 17 + .../tst/common/java_api/tst.MultiAggPrinta.ksh | 38 ++ .../tst/common/java_api/tst.MultiAggPrinta.ksh.out | 78 +++ .../test/tst/common/java_api/tst.ProbeData.c | 93 +++ .../test/tst/common/java_api/tst.ProbeData.ksh | 38 ++ .../test/tst/common/java_api/tst.ProbeData.ksh.out | 50 ++ .../tst/common/java_api/tst.ProbeDescription.ksh | 45 ++ .../common/java_api/tst.ProbeDescription.ksh.out | 8 + .../test/tst/common/java_api/tst.StateMachine.ksh | 40 ++ .../tst/common/java_api/tst.StateMachine.ksh.out | 70 ++ .../test/tst/common/java_api/tst.StopLock.ksh | 39 ++ .../test/tst/common/java_api/tst.StopLock.ksh.out | 1 + .../dtrace/test/tst/common/java_api/tst.printa.d | 78 +++ .../test/tst/common/java_api/tst.printa.d.out | 47 ++ 47 files changed, 4566 insertions(+) create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/Makefile create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/Makefile.kup create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/manifest/Makefile.kup create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/manifest/test.jar-manifest create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/Makefile.kup create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestAbort.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestBean.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestClose.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestDrop.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestEnable.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestFunctionLookup.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestGetAggregate.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestMaxConsumers.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestMultiAggPrinta.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestProbeData.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestProbeDescription.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestStateMachine.java create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestStopLock.java create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Abort.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Abort.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Bean.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Bean.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Close.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Close.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Drop.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Drop.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Enable.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.Enable.ksh.out create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.FunctionLookup.c create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.FunctionLookup.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.FunctionLookup.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.GetAggregate.ksh create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.MaxConsumers.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.MaxConsumers.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.MultiAggPrinta.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.MultiAggPrinta.ksh.out create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.ProbeData.c create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.ProbeData.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.ProbeData.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.ProbeDescription.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.ProbeDescription.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.StateMachine.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.StateMachine.ksh.out create mode 100755 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.StopLock.ksh create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.StopLock.ksh.out create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.printa.d create mode 100644 src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/tst.printa.d.out (limited to 'src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api') diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/Makefile b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/Makefile new file mode 100644 index 00000000..fe213dd2 --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/Makefile @@ -0,0 +1,79 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "%Z%%M% %I% %E% SMI" + +include $(SRC)/Makefile.master + +ROOTOPTPKG = $(ROOT)/opt/SUNWdtrt +JAR_DSTDIR = $(ROOTOPTPKG)/tst/common/java_api +JAR_SRCDIR = $(SRC)/cmd/dtrace/test/tst/common/java_api + +# Use the proto dtrace.jar if it exists, otherwise use whatever is +# installed on the system. It should be possible to build +# usr/src/cmd/dtrace/test independently, even if only on systems that +# have a compatible dtrace.jar installed. +DTRACE_JAR=usr/share/lib/java/dtrace.jar +PROTO_DTRACE_JAR=$(ROOT)/$(DTRACE_JAR) +INSTALLED_DTRACE_JAR=/$(DTRACE_JAR) +CLASSPATH=$(PROTO_DTRACE_JAR):$(INSTALLED_DTRACE_JAR) +SRCDIR=src +CLASSDIR=classes +MANIFESTDIR=manifest +MANIFEST=$(MANIFESTDIR)/test.jar-manifest +TEST_JAR=$(JAR_SRCDIR)/test.jar +PROTO_TEST_JAR=$(JAR_DSTDIR)/test.jar + +default: $(TEST_JAR) + +clean: + $(RM) $(CLASSDIR)/*.class + +clobber: clean + $(RM) $(TEST_JAR) + +all: default + +lint: + +install: all $(PROTO_TEST_JAR) + +JFLAGS= -g -cp $(CLASSPATH) -d $(CLASSDIR) -deprecation +JFLAGS += -target 1.5 +JFLAGS += -Xlint +COMPILE.java=$(JAVAC) $(JFLAGS) + +$(TEST_JAR): $(SRCDIR)/*.java + @mkdir -p $(CLASSDIR) + $(COMPILE.java) $(SRCDIR)/*.java + $(JAR) -cmf $(MANIFEST) $(TEST_JAR) -C $(CLASSDIR) . + +$(PROTO_TEST_JAR): $(JAR_DSTDIR) + +$(JAR_DSTDIR): + $(INS.dir) + +$(JAR_DSTDIR)/%: $(JAR_SRCDIR)/% + $(INS.file) diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/Makefile.kup b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/Makefile.kup new file mode 100644 index 00000000..e69de29b diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/manifest/Makefile.kup b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/manifest/Makefile.kup new file mode 100644 index 00000000..e69de29b diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/manifest/test.jar-manifest b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/manifest/test.jar-manifest new file mode 100644 index 00000000..7e454ad8 --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/manifest/test.jar-manifest @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Class-Path: /usr/share/lib/java/dtrace.jar diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/Makefile.kup b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/Makefile.kup new file mode 100644 index 00000000..e69de29b diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestAbort.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestAbort.java new file mode 100644 index 00000000..310dd184 --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestAbort.java @@ -0,0 +1,158 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * ident "%Z%%M% %I% %E% SMI" + */ + +import org.opensolaris.os.dtrace.*; +import java.util.NoSuchElementException; + +/** + * Regression for 6426129 abort() after close() throws + * NoSuchElementException. + */ +public class TestAbort { + static boolean aborted = false; + + public static void + main(String[] args) + { + Consumer consumer = new LocalConsumer(); + + // Test for deadlock (bug 6419880) + try { + consumer.open(); + consumer.compile("syscall:::entry { @[execname] = count(); } " + + "tick-101ms { printa(@); }"); + consumer.enable(); + consumer.go(); + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + consumer.close(); + } catch (DTraceException e) { + e.printStackTrace(); + System.exit(1); + } + + consumer = new LocalConsumer(); + + // Should be able to abort an unopened consumer + try { + aborted = false; + consumer.addConsumerListener(new ConsumerAdapter() { + public void consumerStopped(ConsumerEvent e) { + aborted = true; + } + }); + consumer.abort(); + consumer.open(); + consumer.compile("syscall:::entry { @[execname] = count(); } " + + "tick-101ms { printa(@); }"); + consumer.enable(); + consumer.go(); + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + if (!aborted) { + throw new IllegalStateException("consumer not aborted"); + } + consumer.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + + consumer = new LocalConsumer(); + + // Should be safe to call abort() in any state + try { + consumer.abort(); + consumer.open(); + consumer.abort(); + consumer.compile("syscall:::entry { @[execname] = count(); } " + + "tick-101ms { printa(@); }"); + consumer.abort(); + consumer.enable(); + consumer.abort(); + consumer.go(); + consumer.abort(); + consumer.close(); + // Should be safe to call after close() + try { + consumer.abort(); + } catch (NoSuchElementException e) { + e.printStackTrace(); + System.exit(1); + } + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + + consumer = new LocalConsumer(); + + // Tests that close() throws expected exception when called on + // synchronized consumer. + try { + consumer.open(); + consumer.compile("syscall:::entry { @[execname] = count(); } " + + "tick-101ms { printa(@); }"); + consumer.enable(); + consumer.go(); + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + try { + synchronized (consumer) { + consumer.close(); + } + } catch (IllegalThreadStateException e) { + try { + consumer.close(); + System.out.println("Successful"); + System.exit(0); + } catch (NoSuchElementException x) { + x.printStackTrace(); + System.exit(1); + } + } + } catch (DTraceException e) { + e.printStackTrace(); + System.exit(1); + } + System.err.println("Failed"); + System.exit(1); + } +} diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestBean.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestBean.java new file mode 100644 index 00000000..dd4a969d --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestBean.java @@ -0,0 +1,706 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * ident "%Z%%M% %I% %E% SMI" + */ + +import org.opensolaris.os.dtrace.*; +import java.util.*; +import java.io.*; +import java.beans.*; +import java.lang.reflect.*; + +/** + * Regression test for serialization and XML encoding/decoding. Tests + * every Serializable class in the Java DTrace API by creating a dummy + * instance, writing it to a file, then reading it back in and comparing + * the string values of the object before and after, as well as + * verifying object equality before and after if the class overrides the + * equals() method. + */ +public class TestBean { + public static final String[] TESTS = new String[] { + "ExitRecord", + "AggregationRecord", + "Aggregation", + "Tuple", + "ScalarRecord", + "KernelStackRecord", + "LogDistribution", + "LinearDistribution", + "Option", + "ProcessState", + "ProbeDescription", + "PrintaRecord", + "PrintfRecord", + "ProbeData", + "Aggregate", + "UserStackRecord", + "AvgValue", + "CountValue", + "SumValue", + "MinValue", + "MaxValue", + "Error", + "Drop", + "InterfaceAttributes", + "ProgramInfo", + "ProbeInfo", + "Probe", + "Flow", + "KernelSymbolRecord", + "UserSymbolRecord", + "UserSymbolRecord$Value", + "Program", + "Program$File", + "StddevValue" + }; + + static File file; + + static void + exit(int status) + { + System.out.flush(); + System.err.flush(); + System.exit(status); + } + + public static XMLEncoder + getXMLEncoder(File file) + { + XMLEncoder encoder = null; + try { + OutputStream out = new BufferedOutputStream + (new FileOutputStream(file)); + encoder = new XMLEncoder(out); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + return encoder; + } + + public static XMLDecoder + getXMLDecoder(File file) + { + return getXMLDecoder(file, null); + } + + public static XMLDecoder + getXMLDecoder(File file, ExceptionListener exceptionListener) + { + XMLDecoder decoder = null; + try { + InputStream in = new BufferedInputStream + (new FileInputStream(file)); + decoder = new XMLDecoder(in, null, exceptionListener); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + return decoder; + } + + public static ExitRecord + getExitRecord() + { + ExitRecord r = new ExitRecord(1); + return r; + } + + public static AggregationRecord + getAggregationRecord() + { + Tuple tuple = getTuple(); + AggregationValue value = new CountValue(7); + AggregationRecord r = new AggregationRecord(tuple, value); + return r; + } + + public static Aggregation + getAggregation() + { + List < AggregationRecord > list = + new ArrayList < AggregationRecord > (); + AggregationRecord r; + r = getAggregationRecord(); + list.add(r); + + ValueRecord v1 = new ScalarRecord(new byte[] {(byte)1, (byte)2, + (byte)3}, 3); + ValueRecord v2 = new ScalarRecord("shebang!", 256); + Tuple tuple = new Tuple(v1, v2); + AggregationValue value = getLinearDistribution(); + r = new AggregationRecord(tuple, value); + list.add(r); + + Aggregation a = new Aggregation("counts", 2, list); + return a; + } + + public static Tuple + getTuple() + { + ValueRecord r1 = new ScalarRecord("cat", 256); + ValueRecord r2 = new ScalarRecord(new Integer(9), 2); + ValueRecord r3 = new KernelStackRecord( + new StackFrame[] { + new StackFrame("has"), + new StackFrame("nine"), + new StackFrame("lives")}, + new byte[] { (byte)0, (byte)1, (byte)2 }); + ValueRecord r4 = new ScalarRecord(new byte[] {(byte)1, (byte)2, + (byte)3}, 3); + + Tuple tuple = new Tuple(r1, r2, r3, r4); + return tuple; + } + + public static ScalarRecord + getScalarRecord() + { + Object v = new byte[] {(byte)1, (byte)2, (byte)3}; + ScalarRecord r = new ScalarRecord(v, 3); + return r; + } + + public static KernelStackRecord + getKernelStackRecord() + { + StackFrame[] stackFrames = new StackFrame[] { + new StackFrame("Frame 1"), + new StackFrame("Frame 2"), + new StackFrame("Frame 3") + }; + KernelStackRecord r = new KernelStackRecord(stackFrames, + new byte[] { (byte)0, (byte)1, (byte)2 }); + return r; + } + + public static LogDistribution + getLogDistribution() + { + List < Distribution.Bucket > buckets = + new ArrayList < Distribution.Bucket > (); + Distribution.Bucket bucket; + int n = 0; + long base = 0; + long i; + long sign; + long nextSign; + long power; + long nextPower; + long lowerBound; + long upperBound; + for (i = -62; i <= 62; ++i) { + if (i == 0) { + bucket = new Distribution.Bucket(-1, -1, n++); + buckets.add(bucket); + bucket = new Distribution.Bucket(0, 0, n++); + buckets.add(bucket); + bucket = new Distribution.Bucket(1, 1, n++); + buckets.add(bucket); + continue; + } + sign = ((i < 0) ? -1L : 1L); + power = (sign * i); + nextSign = (((i + 1) < 0) ? -1L : 1L); + nextPower = (nextSign * (i + 1)); + lowerBound = sign * ((long) Math.pow(2L, power)); + upperBound = (nextPower == 0 ? -2L : + (nextSign * ((long) Math.pow(2L, nextPower))) - 1); + if ((upperBound > 0) && ((upperBound * 2L) < 0)) { + upperBound = Long.MAX_VALUE; + } + bucket = new Distribution.Bucket(lowerBound, upperBound, n++); + buckets.add(bucket); + } + LogDistribution d = new LogDistribution(buckets); + return d; + } + + public static LinearDistribution + getLinearDistribution() + { + List < Distribution.Bucket > buckets = + new ArrayList < Distribution.Bucket > (); + Distribution.Bucket bucket; + int n = 10; // number of buckets + int base = 1; + int step = 10; + bucket = new Distribution.Bucket(Long.MIN_VALUE, (base - 1), 0); + buckets.add(bucket); + for (int i = base; i < (n * step); i += step) { + bucket = new Distribution.Bucket(i, (i + (step - 1)), + ((i - 1) / step)); + buckets.add(bucket); + } + bucket = new Distribution.Bucket((n * step) + 1, Long.MAX_VALUE, 0); + buckets.add(bucket); + LinearDistribution d = new LinearDistribution(base, step, buckets); + return d; + } + + public static Option + getOption() + { + Option option = new Option("aggrate", "1s"); + return option; + } + + public static ProcessState + getProcessState() + { + ProcessState p = new ProcessState(123456, "UNDEAD", + 3, "SIGSTOP", + -2, "Process stopped on dime"); + return p; + } + + public static ProbeDescription + getProbeDescription() + { + ProbeDescription d = new ProbeDescription(256, "syscall", null, + "malloc", "entry"); + return d; + } + + public static PrintaRecord + getPrintaRecord() + { + List < Aggregation > aggregations = new ArrayList < Aggregation > (); + Aggregation a = getAggregation(); + aggregations.add(a); + aggregations.add(a); + Map < Tuple, String > formattedOutput = + new HashMap < Tuple, String > (); + for (Tuple t : a.asMap().keySet()) { + formattedOutput.put(t, "cat"); + } + List < Tuple > tuples = new ArrayList < Tuple > (); + for (Tuple t : a.asMap().keySet()) { + tuples.add(t); + } + Collections.sort(tuples); + PrintaRecord r = new PrintaRecord(1234567890L, + aggregations, formattedOutput, tuples, + "Yes, this is the formatted printa() output"); + return r; + } + + public static PrintfRecord + getPrintfRecord() + { + List < ValueRecord > list = new ArrayList < ValueRecord > (); + ValueRecord v1 = getScalarRecord(); + ValueRecord v2 = new ScalarRecord(new Integer(7), 4); + list.add(v1); + list.add(v2); + PrintfRecord r = new PrintfRecord(list, + "long formatted string"); + return r; + } + + public static ProbeData + getProbeData() + { + List < Record > list = new ArrayList < Record > (); + list.add(getPrintaRecord()); + list.add(getPrintfRecord()); + list.add(getScalarRecord()); + list.add(getUserSymbolRecord()); + list.add(getUserStackRecord()); + list.add(getExitRecord()); + ProbeData d = new ProbeData(7, 1, getProbeDescription(), + getFlow(), list); + return d; + } + + public static Aggregate + getAggregate() + { + List < Aggregation > list = new ArrayList < Aggregation > (); + list.add(getAggregation()); + + List < AggregationRecord > reclist = + new ArrayList < AggregationRecord > (); + AggregationRecord r; + ValueRecord v1 = new ScalarRecord("cat", 256); + ValueRecord v2 = new ScalarRecord("dog", 256); + ValueRecord v3 = new ScalarRecord("mouse", 256); + ValueRecord v4 = new ScalarRecord("mouse", 256); + ValueRecord v5 = new ScalarRecord(new Byte((byte) 'C'), 1); + ValueRecord v6 = new ScalarRecord(new Short((short) 7), 2); + Tuple tuple = new Tuple(v1, v2, v3, v4, v5, v6); + AggregationValue value = getCountValue(); + r = new AggregationRecord(tuple, value); + reclist.add(r); + list.add(new Aggregation("times", 1, reclist)); + + Aggregate a = new Aggregate(1234567890L, list); + return a; + } + + public static UserStackRecord + getUserStackRecord() + { + StackFrame[] frames = new StackFrame[] { + new StackFrame("User Stack Frame 1"), + new StackFrame("User Stack Frame 2"), + new StackFrame("User Stack Frame 3") + }; + UserStackRecord r = new UserStackRecord(123456, frames, + new byte[] { (byte)0, (byte)1, (byte)2 }); + return r; + } + + public static AvgValue + getAvgValue() + { + AvgValue v = new AvgValue(5, 20, 4); + return v; + } + + public static CountValue + getCountValue() + { + CountValue v = new CountValue(9); + return v; + } + + public static MinValue + getMinValue() + { + MinValue v = new MinValue(101); + return v; + } + + public static MaxValue + getMaxValue() + { + MaxValue v = new MaxValue(101); + return v; + } + + public static SumValue + getSumValue() + { + SumValue v = new SumValue(25); + return v; + } + + public static org.opensolaris.os.dtrace.Error + getError() + { + ProbeDescription probe = getProbeDescription(); + org.opensolaris.os.dtrace.Error e = + new org.opensolaris.os.dtrace.Error(probe, 8, 3, + 1, 20, "DTRACEFLT_BADALIGN", -1, "error on enabled probe ID 8 " + + "(ID " + probe.getID() + ": " + probe + "): Bad alignment " + + "(0x33ef) in action #1 at DIF offset 20"); + return e; + } + + public static Drop + getDrop() + { + Drop drop = new Drop(2, "SPECBUSY", 72, 1041, + "Guess we dropped stuff all over the place."); + return drop; + } + + public static InterfaceAttributes + getInterfaceAttributes() + { + InterfaceAttributes a = new InterfaceAttributes( + InterfaceAttributes.Stability.UNSTABLE, + InterfaceAttributes.Stability.EVOLVING, + InterfaceAttributes.DependencyClass.ISA); + return a; + } + + public static ProgramInfo + getProgramInfo() + { + ProgramInfo info = new ProgramInfo(getInterfaceAttributes(), + getInterfaceAttributes(), 256); + return info; + } + + public static ProbeInfo + getProbeInfo() + { + ProbeInfo info = new ProbeInfo(getInterfaceAttributes(), + getInterfaceAttributes()); + return info; + } + + public static Probe + getProbe() + { + Probe p = new Probe(getProbeDescription(), getProbeInfo()); + return p; + } + + public static Flow + getFlow() + { + Flow f = new Flow(Flow.Kind.RETURN.name(), 3); + return f; + } + + public static KernelSymbolRecord + getKernelSymbolRecord() + { + KernelSymbolRecord r = new KernelSymbolRecord("mod`func+0x4", -1L); + return r; + } + + public static UserSymbolRecord + getUserSymbolRecord() + { + UserSymbolRecord r = new UserSymbolRecord(7, "mod`func+0x4", -1L); + return r; + } + + public static UserSymbolRecord.Value + getUserSymbolRecord$Value() + { + UserSymbolRecord.Value v = new UserSymbolRecord.Value(7, -1L); + return v; + } + + public static Program + getProgram() + { + final String PROGRAM = "syscall:::entry { @[execname] = count(); }"; + Consumer consumer = new LocalConsumer(); + Program p; + try { + consumer.open(); + p = consumer.compile(PROGRAM); + consumer.close(); + } catch (DTraceException e) { + e.printStackTrace(); + p = null; + } + return p; + } + + public static Program.File + getProgram$File() + { + final String PROGRAM = "syscall:::entry { @[execname] = count(); }"; + Consumer consumer = new LocalConsumer(); + Program p; + try { + OutputStream out = new FileOutputStream(file); + out.write(PROGRAM.getBytes(), 0, PROGRAM.length()); + out.flush(); + out.close(); + consumer.open(); + p = consumer.compile(file); + consumer.close(); + } catch (Exception e) { + e.printStackTrace(); + p = null; + } + return Program.File.class.cast(p); + } + + public static StddevValue + getStddevValue() + { + StddevValue v = new StddevValue(37, 114, 5, Integer.toString(9544)); + return v; + } + + @SuppressWarnings("unchecked") + static String + getString(Object o) + { + String s; + if (o instanceof ScalarRecord) { + o = ((ScalarRecord)o).getValue(); + } + + if (o instanceof byte[]) { + s = Arrays.toString((byte[])o); + } else if (o instanceof Object[]) { + s = Arrays.toString((Object[])o); + } else { + Class c = o.getClass(); + try { + Method m = c.getDeclaredMethod("toLogString"); + s = (String)m.invoke(o); + } catch (Exception e) { + s = o.toString(); + } + } + return s; + } + + static void + checkEquality(Object obj, Object newobj) + { + // If the class overrides equals(), make sure the re-created + // object still equals the original object + try { + Method eq = obj.getClass().getDeclaredMethod("equals", + Object.class); + Boolean ret = (Boolean) eq.invoke(obj, newobj); + if (ret != true) { + System.err.println("serialization failed: " + + obj.getClass().getName()); + exit(1); + } + } catch (Exception e) { + // Does not override equals(), although a super-class might. + // A better test would check for any superclass other than + // Object.class. + } + } + + static void + performSerializationTest(File file, String classname) + throws IOException, ClassNotFoundException + { + String methodName = "get" + classname; + Object obj = null; + Object newobj = null; + try { + Method method = TestBean.class.getDeclaredMethod(methodName); + obj = method.invoke(null); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + + System.out.println(classname + ":"); + String serialized = getString(obj); + System.out.println(" serialized: " + serialized); + FileOutputStream fos = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(fos); + out.writeObject(obj); + out.close(); + FileInputStream fis = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(fis); + newobj = in.readObject(); + in.close(); + String deserialized = getString(newobj); + System.out.println(" deserialized: " + deserialized); + + if (!serialized.equals(deserialized)) { + System.err.println("serialization failed: " + classname); + exit(1); + } + checkEquality(obj, newobj); + } + + static void + performBeanTest(File file, String classname) + { + String methodName = "get" + classname; + Object obj = null; + Object newobj = null; + try { + Method method = TestBean.class.getDeclaredMethod(methodName); + obj = method.invoke(null); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + + Class c = obj.getClass(); + if (c.getConstructors().length == 0) { + return; + } + + System.out.println(classname + ":"); + XMLEncoder encoder = getXMLEncoder(file); + String encoded = getString(obj); + System.out.println(" encoded: " + encoded); + encoder.writeObject(obj); + encoder.close(); + XMLDecoder decoder = getXMLDecoder(file); + newobj = decoder.readObject(); + String decoded = getString(newobj); + System.out.println(" decoded: " + decoded); + decoder.close(); + + if (!encoded.equals(decoded)) { + System.err.println("bean persistence failed: " + classname); + exit(1); + } + checkEquality(obj, newobj); + } + + public static void + main(String[] args) + { + if ((args.length != 1) && (args.length != 2)) { + System.err.println("usage: java TestBean < filename > " + + "[ < classname > ]"); + exit(1); + } + + String filename = args[0]; + String classname = null; + if (args.length >= 2) { + classname = args[1]; + } + + file = new File(filename); + try { + if (!file.canRead()) { + try { + file.createNewFile(); + } catch (Exception e) { + System.err.println("failed to create " + filename); + exit(1); + } + } + } catch (SecurityException e) { + System.err.println("failed to open " + filename); + exit(1); + } + + String[] tests = (classname == null ? TESTS: + new String[] { classname }); + try { + for (int i = 0; i < tests.length; ++i) { + performSerializationTest(file, tests[i]); + performBeanTest(file, tests[i]); + } + } catch (IOException e) { + e.printStackTrace(); + exit(1); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + exit(1); + } + } +} diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestClose.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestClose.java new file mode 100644 index 00000000..c7a9e89d --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestClose.java @@ -0,0 +1,90 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * ident "%Z%%M% %I% %E% SMI" + */ + +import org.opensolaris.os.dtrace.*; + +/** + * Regression for bug 6419880 close() hangs running consumer. + */ +public class TestClose { + public static void + main(String[] args) + { + Consumer consumer = new LocalConsumer(); + + try { + consumer.open(); + consumer.compile("syscall:::entry { @[execname] = count(); } " + + "tick-101ms { printa(@); }"); + consumer.enable(); + consumer.go(); + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + consumer.close(); + } catch (DTraceException e) { + e.printStackTrace(); + System.exit(1); + } + + consumer = new LocalConsumer(); + + try { + consumer.open(); + consumer.compile("syscall:::entry { @[execname] = count(); } " + + "tick-101ms { printa(@); }"); + consumer.enable(); + consumer.go(); + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + try { + // Test new rule that close() is illegal while holding + // lock on consumer. + synchronized (consumer) { + consumer.close(); + } + } catch (IllegalThreadStateException e) { + consumer.close(); + System.out.println("Successful"); + System.exit(0); + } + } catch (DTraceException e) { + e.printStackTrace(); + System.exit(1); + } + System.err.println("Failed"); + System.exit(1); + } +} diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestDrop.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestDrop.java new file mode 100644 index 00000000..b5ace25b --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestDrop.java @@ -0,0 +1,169 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * ident "%Z%%M% %I% %E% SMI" + */ +import java.util.*; +import java.util.concurrent.atomic.*; +import org.opensolaris.os.dtrace.*; + +/** + * Regression test for 6521523 aggregation drops can hang the Java + * DTrace API. + */ +public class TestDrop { + static final String PROGRAM = + "fbt:genunix::entry { @[execname, pid] = count(); }"; + + static AtomicLong consumerThreadID = new AtomicLong(); + static AtomicLong getAggregateThreadID = new AtomicLong(); + static AtomicBoolean done = new AtomicBoolean(); + static int seconds; + + private static void + startTimer() + { + if (seconds <= 0) { + return; + } + + final Timer timer = new Timer(); + timer.schedule(new TimerTask() { + public void run() { + done.set(true); + timer.cancel(); + } + }, seconds * 1000L); + } + + private static void + sampleAggregate(Consumer consumer) throws DTraceException + { + while (consumer.isRunning() && !done.get()) { + try { + Thread.currentThread().sleep(50); + } catch (InterruptedException e) { + } + + consumer.getAggregate(Collections. emptySet()); + } + } + + private static void + startAggregateThread(final Consumer consumer) + { + Runnable aggregateSampler = new Runnable() { + public void run() { + Thread t = Thread.currentThread(); + getAggregateThreadID.set(t.getId()); + Throwable x = null; + try { + sampleAggregate(consumer); + } catch (Throwable e) { + x = e; + } + + if (Thread.holdsLock(LocalConsumer.class)) { + if (x != null) { + x.printStackTrace(); + } + System.out.println("Lock held"); + System.exit(1); + } else { + System.out.println("Lock released"); + consumer.close(); // blocks if lock held + } + } + }; + + Thread t = new Thread(aggregateSampler, "Aggregate Sampler"); + t.start(); + } + + static void + usage() + { + System.err.println("usage: java TestDrop [ seconds ]"); + System.exit(2); + } + + public static void + main(String[] args) + { + if (args.length == 1) { + try { + seconds = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + usage(); + } + } else if (args.length > 1) { + usage(); + } + + final Consumer consumer = new LocalConsumer() { + protected Thread createThread() { + Runnable worker = new Runnable() { + public void run() { + Thread t = Thread.currentThread(); + consumerThreadID.set(t.getId()); + work(); + } + }; + Thread t = new Thread(worker); + return t; + } + }; + + consumer.addConsumerListener(new ConsumerAdapter() { + public void consumerStarted(ConsumerEvent e) { + startAggregateThread(consumer); + startTimer(); + } + public void dataDropped(DropEvent e) throws ConsumerException { + Thread t = Thread.currentThread(); + if (t.getId() == getAggregateThreadID.get()) { + Drop drop = e.getDrop(); + throw new ConsumerException(drop.getDefaultMessage(), + drop); + } + } + }); + + try { + consumer.open(); + consumer.setOption(Option.aggsize, Option.kb(1)); + consumer.setOption(Option.aggrate, Option.millis(101)); + consumer.compile(PROGRAM); + consumer.enable(); + consumer.go(new ExceptionHandler() { + public void handleException(Throwable e) { + e.printStackTrace(); + } + }); + } catch (DTraceException e) { + e.printStackTrace(); + } + } +} diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestEnable.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestEnable.java new file mode 100644 index 00000000..0e5a6086 --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestEnable.java @@ -0,0 +1,151 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * ident "%Z%%M% %I% %E% SMI" + */ + +import org.opensolaris.os.dtrace.*; + +/** + * Prove that enable() handles multiple programs, recognizing programs + * that are already enabled and programs that were compiled by another + * consumer. + */ +public class TestEnable { + static void + exit(int status) + { + System.out.flush(); + System.err.flush(); + System.exit(status); + } + + public static void + main(String[] args) + { + Consumer consumer = new LocalConsumer(); + + try { + consumer.open(); + Program p0 = consumer.compile("dtrace:::BEGIN"); + Program p1 = consumer.compile("syscall:::entry"); + Program p2 = consumer.compile("dtrace:::END"); + consumer.enable(p0); + consumer.enable(p1); + try { + consumer.go(); + System.err.println("go() illegal, not all programs " + + "enabled (p0, p1)"); + exit(1); + } catch (IllegalStateException e) { + System.out.println(e); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + try { + consumer.enable(); + System.err.println("enable() illegal, some programs " + + "already enabled (p0, p1)"); + exit(1); + } catch (IllegalStateException e) { + System.out.println(e); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + try { + consumer.enable(p0); + System.err.println("cannot enable a program that " + + "has already been enabled (p0)"); + exit(1); + } catch (IllegalStateException e) { + System.out.println(e); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + consumer.enable(p2); + Program p3 = consumer.compile("syscall:::return"); + try { + consumer.go(); + System.err.println("go() illegal, not all programs " + + "enabled (p0, p1, p2)"); + exit(1); + } catch (IllegalStateException e) { + System.out.println(e); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + try { + consumer.enable(); + System.err.println("enable() illegal, some programs " + + "already enabled (p0, p1, p2)"); + exit(1); + } catch (IllegalStateException e) { + System.out.println(e); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } + // Try to fool the consumer with a program compiled by + // another consumer + Consumer consumer2 = new LocalConsumer(); + consumer2.open(); + Program p3x = consumer2.compile("syscall:::return"); + try { + consumer.enable(p3x); + System.err.println("cannot enable program compiled " + + "by another consumer"); + exit(1); + } catch (IllegalArgumentException e) { + System.out.println(e); + } catch (Exception e) { + e.printStackTrace(); + exit(1); + } finally { + consumer2.close(); + } + consumer.enable(p3); + consumer.go(); + consumer.close(); + + // Enable all compiled programs at once + consumer = new LocalConsumer(); + consumer.open(); + consumer.compile("dtrace:::BEGIN"); + consumer.compile("syscall:::entry"); + consumer.compile("dtrace:::END"); + consumer.enable(); + consumer.go(); + consumer.close(); + exit(0); + } catch (DTraceException e) { + e.printStackTrace(); + exit(1); + } + } +} diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestFunctionLookup.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestFunctionLookup.java new file mode 100644 index 00000000..2bc43ea6 --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestFunctionLookup.java @@ -0,0 +1,114 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +import org.opensolaris.os.dtrace.*; + +/** + * Regression for bug 6413280 lookupKernelFunction() and + * lookupUserFunction() truncate last character. + */ +public class TestFunctionLookup { + static final String kernelLookupProgram = "sdt:::callout-start { " + + "@[((callout_t *)arg0)->c_func] = count(); }"; + static final String userLookupProgram = "pid$target::f2:entry { " + + "@[arg0] = count(); }"; + + public static void + main(String[] args) + { + if (args.length != 1) { + System.err.println("usage: java TestFunctionLookup "); + System.exit(1); + } + String cmd = args[0]; + + Consumer consumer = new LocalConsumer(); + try { + consumer.open(); + consumer.compile(kernelLookupProgram); + consumer.enable(); + consumer.go(); + Aggregate a; + Number address; + String f; + boolean done = false; + for (int i = 0; (i < 20) && !done; ++i) { + Thread.currentThread().sleep(100); + a = consumer.getAggregate(); + for (Aggregation agg : a.getAggregations()) { + for (Tuple tuple : agg.asMap().keySet()) { + address = (Number)tuple.get(0).getValue(); + if (address instanceof Integer) { + int addr = (Integer)address; + f = consumer.lookupKernelFunction(addr); + } else { + long addr = (Long)address; + f = consumer.lookupKernelFunction(addr); + } + if (f.equals("genunix`cv_wakeup")) { + System.out.println(f); + done = true; + } + } + } + } + consumer.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + + consumer = new LocalConsumer(); + try { + consumer.open(); + int pid = consumer.createProcess(cmd); + consumer.compile(userLookupProgram); + consumer.enable(); + consumer.go(); + Thread.currentThread().sleep(500); + Aggregate a = consumer.getAggregate(); + Number address; + String f; + for (Aggregation agg : a.getAggregations()) { + for (Tuple tuple : agg.asMap().keySet()) { + address = (Number)tuple.get(0).getValue(); + if (address instanceof Integer) { + int addr = (Integer)address; + f = consumer.lookupUserFunction(pid, addr); + } else { + long addr = (Long)address; + f = consumer.lookupUserFunction(pid, addr); + } + System.out.println(f); + } + } + consumer.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestGetAggregate.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestGetAggregate.java new file mode 100644 index 00000000..e02df858 --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestGetAggregate.java @@ -0,0 +1,252 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +import org.opensolaris.os.dtrace.*; +import java.util.*; + +/** + * Assert getAggregate() can explicitly specify the anonymous aggregation. + */ +public class TestGetAggregate { + static final String programString = + "profile:::tick-50ms" + + "{" + + " @ = count();" + + " @a = count();" + + "}"; + + static final String ANONYMOUS_AGGREGATION = ""; + static final int TICK = 50; + static final int EXPECTED_TICKS = 3; + static final int INTERVALS = 4; + + static void + testIncluded(Consumer consumer, String ... aggregationNames) + throws DTraceException, InterruptedException + { + Aggregate aggregate; + Set included = new HashSet (); + int n = 1; + + for (String name : aggregationNames) { + included.add(name); + } + + // Wait up to a full second to obtain aggregate data. Without a + // time limit, we'll loop forever if no aggregation was + // successfully included. + do { + Thread.sleep(TICK); + aggregate = consumer.getAggregate(included, null); + } while (aggregate.asMap().isEmpty() && n++ < (1000 / TICK)); + + for (String name : included) { + if (aggregate.getAggregation(name) == null) { + throw new IllegalStateException("@" + name + + " was explicitly included but did not appear " + + "in the aggregate"); + } + } + for (Aggregation a : aggregate.getAggregations()) { + if (!included.contains(a.getName())) { + throw new IllegalStateException("@" + a.getName() + + " was not explicitly included but appeared " + + "in the aggregate anyway"); + } + } + + if (!consumer.isRunning()) { + throw new IllegalStateException("consumer exited"); + } + } + + static void + testCleared(Consumer consumer, String ... aggregationNames) + throws DTraceException, InterruptedException + { + Aggregate aggregate; + AggregationRecord rec; + long value; + Long firstValue; + int n = 1; + Map firstValues = new HashMap (); + Set cleared = new HashSet (); + + for (String name : aggregationNames) { + cleared.add(name); + } + + do { + Thread.sleep(TICK); + aggregate = consumer.getAggregate(null, cleared); + } while (aggregate.asMap().isEmpty() && n++ < (1000 / TICK)); + n = 1; + + do { + Thread.sleep(TICK * EXPECTED_TICKS); + aggregate = consumer.getAggregate(null, cleared); + + for (Aggregation a : aggregate.getAggregations()) { + if (!firstValues.containsKey(a.getName())) { + rec = a.getRecord(Tuple.EMPTY); + value = rec.getValue().getValue().longValue(); + firstValues.put(a.getName(), value); + } + } + } while (consumer.isRunning() && n++ < INTERVALS); + + for (Aggregation a : aggregate.getAggregations()) { + rec = a.getRecord(Tuple.EMPTY); + value = rec.getValue().getValue().longValue(); + firstValue = firstValues.get(a.getName()); + + if (cleared.contains(a.getName())) { + // last value should be about the same as first value + if (value > (firstValue * 2)) { + throw new IllegalStateException( + "@" + a.getName() + " should have " + + "been cleared but instead grew from " + + firstValue + " to " + value); + } + } else { + // last value should be about (INTERVALS * firstValue) + if (value < (firstValue * 2)) { + throw new IllegalStateException( + "@" + a.getName() + " should have " + + "accumulated a running total but " + + "instead went from " + + firstValue + " to " + value); + } + } + } + + if (!consumer.isRunning()) { + throw new IllegalStateException("consumer exited"); + } + } + + static Integer includedStatus; + static Integer clearedStatus; + + static void + startIncludedTest() + { + final Consumer consumer = new LocalConsumer(); + consumer.addConsumerListener(new ConsumerAdapter() { + public void consumerStarted(ConsumerEvent e) { + new Thread(new Runnable() { + public void run() { + try { + testIncluded(consumer, ANONYMOUS_AGGREGATION); + includedStatus = 0; + } catch (Exception e) { + includedStatus = 1; + e.printStackTrace(); + } finally { + consumer.abort(); + } + } + }).start(); + } + }); + + try { + consumer.open(); + consumer.setOption(Option.aggrate, Option.millis(TICK)); + consumer.compile(programString); + consumer.enable(); + consumer.go(); + } catch (Exception e) { + includedStatus = 1; + e.printStackTrace(); + } + } + + static void + startClearedTest() + { + final Consumer consumer = new LocalConsumer(); + consumer.addConsumerListener(new ConsumerAdapter() { + public void consumerStarted(ConsumerEvent e) { + new Thread(new Runnable() { + public void run() { + try { + testCleared(consumer, ANONYMOUS_AGGREGATION); + clearedStatus = 0; + } catch (Exception e) { + clearedStatus = 1; + e.printStackTrace(); + } finally { + consumer.abort(); + } + } + }).start(); + } + }); + + try { + consumer.open(); + consumer.setOption(Option.aggrate, Option.millis(TICK)); + consumer.compile(programString); + consumer.enable(); + consumer.go(); + } catch (Exception e) { + clearedStatus = 1; + e.printStackTrace(); + } + } + + public static void + main(String[] args) + { + startIncludedTest(); + + do { + try { + Thread.sleep(TICK); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } while (includedStatus == null); + + startClearedTest(); + + do { + try { + Thread.sleep(TICK); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } while (clearedStatus == null); + + if (includedStatus != 0 || clearedStatus != 0) { + System.out.println("Failure"); + System.exit(1); + } + + System.out.println("Success"); + } +} diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestMaxConsumers.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestMaxConsumers.java new file mode 100644 index 00000000..50eeac23 --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestMaxConsumers.java @@ -0,0 +1,97 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * ident "%Z%%M% %I% %E% SMI" + */ + +import org.opensolaris.os.dtrace.*; + +/** + * Regression for 6506495 -DJAVA_DTRACE_MAX_CONSUMERS=N for any N < 8 + * is treated as if it were 8. + */ +public class TestMaxConsumers { + static final String MAX_CONSUMERS_PROPERTY_NAME = + "JAVA_DTRACE_MAX_CONSUMERS"; + + static Integer + getIntegerProperty(String name) + { + Integer value = null; + String property = System.getProperty(name); + if (property != null && property.length() != 0) { + try { + value = Integer.parseInt(property); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + return value; + } + + public static void + main(String[] args) + { + Integer property = getIntegerProperty(MAX_CONSUMERS_PROPERTY_NAME); + int max = (property == null ? 0 : property); + int n = (property == null ? 11 : (max < 1 ? 1 : max)); + + Consumer[] consumers = new Consumer[n]; + try { + for (int i = 0; i < n; ++i) { + consumers[i] = new LocalConsumer(); + consumers[i].open(); + } + for (int i = 0; i < n; ++i) { + consumers[i].close(); + } + for (int i = 0; i < n; ++i) { + consumers[i] = new LocalConsumer(); + consumers[i].open(); + } + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + + try { + Consumer consumer = new LocalConsumer(); + consumer.open(); + if (max > 0) { + System.out.println("Error: " + (max + 1) + " > " + + MAX_CONSUMERS_PROPERTY_NAME); + } else { + System.out.println("Success"); + } + consumer.close(); + } catch (Exception e) { + System.out.println("Success"); + } finally { + for (int i = 0; i < n; ++i) { + consumers[i].close(); + } + } + } +} diff --git a/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestMultiAggPrinta.java b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestMultiAggPrinta.java new file mode 100644 index 00000000..facdf7fa --- /dev/null +++ b/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/test/tst/common/java_api/src/TestMultiAggPrinta.java @@ -0,0 +1,144 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * ident "%Z%%M% %I% %E% SMI" + */ + +import java.io.File; +import java.io.IOException; +import java.util.List; +import org.opensolaris.os.dtrace.*; + +/** + * Regression for multi-aggregation printa() corner cases. + */ +public class TestMultiAggPrinta { + static int exitStatus; + + // Gets a string representation of the given PrintaRecord minus the + // timestamp of the aggregate snapshot, so that the output is + // comparable across multiple test runs. + static String + printaRecordString(PrintaRecord rec) + { + StringBuffer buf = new StringBuffer(); + buf.append(PrintaRecord.class.getName()); + buf.append("[aggregations = "); + buf.append(rec.getAggregations()); + buf.append(", formattedStrings = "); + buf.append(rec.getFormattedStrings()); + buf.append(", tuples = "); + buf.append(rec.getTuples()); + buf.append(", output = "); + buf.append(rec.getOutput()); + buf.append(']'); + return buf.toString(); + } + + static String + probeDataString(ProbeData data) + { + StringBuffer buf = new StringBuffer(); + buf.append(ProbeData.class.getName()); + buf.append("[epid = "); + buf.append(data.getEnabledProbeID()); + // Do not include cpu, since it can change across test runs + buf.append(", enabledProbeDescription = "); + buf.append(data.getEnabledProbeDescription()); + buf.append(", flow = "); + buf.append(data.getFlow()); + buf.append(", records = "); + + List records = data.getRecords(); + Record record; + Object value; + buf.append('['); + for (int i = 0; i < records.size(); ++i) { + if (i > 0) { + buf.append(", "); + } + record = records.get(i); + if (record instanceof ValueRecord) { + value = ((ValueRecord)record).getValue(); + if (value instanceof String) { + buf.append("\""); + buf.append((String)value); + buf.append("\""); + } else { + buf.append(record); + } + } else if (record instanceof PrintaRecord) { + PrintaRecord printa = (PrintaRecord)record; + buf.append(printaRecordString(printa)); + } else { + buf.append(record); + } + } + buf.append(']'); + return buf.toString(); + } + + public static void + main(String[] args) + { + if (args.length != 1) { + System.err.println("usage: java TestMultiAggPrinta