Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/tracing/BasicFunctionality.java
38839 views
/*1* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 653750626* @ignore 696253527* @summary Basic unit test for tracing framework28*/2930import com.sun.tracing.*;31import java.lang.reflect.Method;3233@ProviderName("NamedProvider")34interface BasicProvider extends Provider {35void plainProbe();36void probeWithArgs(int a, float f, String s, Long l);37@ProbeName("namedProbe") void probeWithName();38void overloadedProbe();39void overloadedProbe(int i);40}4142interface InvalidProvider extends Provider {43int nonVoidProbe();44}4546public class BasicFunctionality {4748public static ProviderFactory factory;49public static BasicProvider bp;5051public static void main(String[] args) throws Exception {5253factory = ProviderFactory.getDefaultFactory();54if (factory != null) {55bp = factory.createProvider(BasicProvider.class);56}5758testProviderFactory();59testProbe();60testProvider();61}6263static void fail(String s) throws Exception {64throw new Exception(s);65}6667static void testProviderFactory() throws Exception {68if (factory == null) {69fail("ProviderFactory.getDefaultFactory: Did not create factory");70}71if (bp == null) {72fail("ProviderFactory.createProvider: Did not create provider");73}74try {75factory.createProvider(null);76fail("ProviderFactory.createProvider: Did not throw NPE for null");77} catch (NullPointerException e) {}7879try {80factory.createProvider(InvalidProvider.class);81fail("Factory.createProvider: Should error with non-void probes");82} catch (IllegalArgumentException e) {}83}8485public static void testProvider() throws Exception {8687// These just shouldn't throw any exeptions:88bp.plainProbe();89bp.probeWithArgs(42, (float)3.14, "spam", new Long(2L));90bp.probeWithArgs(42, (float)3.14, null, null);91bp.probeWithName();92bp.overloadedProbe();93bp.overloadedProbe(42);9495Method m = BasicProvider.class.getMethod("plainProbe");96Probe p = bp.getProbe(m);97if (p == null) {98fail("Provider.getProbe: Did not return probe");99}100101Method m2 = BasicFunctionality.class.getMethod("testProvider");102p = bp.getProbe(m2);103if (p != null) {104fail("Provider.getProbe: Got probe with invalid spec");105}106107bp.dispose();108// These just shouldn't throw any exeptions:109bp.plainProbe();110bp.probeWithArgs(42, (float)3.14, "spam", new Long(2L));111bp.probeWithArgs(42, (float)3.14, null, null);112bp.probeWithName();113bp.overloadedProbe();114bp.overloadedProbe(42);115116if (bp.getProbe(m) != null) {117fail("Provider.getProbe: Should return null after dispose()");118}119120bp.dispose(); // just to make sure nothing bad happens121}122123static void testProbe() throws Exception {124Method m = BasicProvider.class.getMethod("plainProbe");125Probe p = bp.getProbe(m);126p.isEnabled(); // just make sure it doesn't do anything bad127p.trigger();128129try {130p.trigger(0);131fail("Probe.trigger: too many arguments not caught");132} catch (IllegalArgumentException e) {}133134p = bp.getProbe(BasicProvider.class.getMethod(135"probeWithArgs", int.class, float.class, String.class, Long.class));136try {137p.trigger();138fail("Probe.trigger: too few arguments not caught");139} catch (IllegalArgumentException e) {}140141try {142p.trigger((float)3.14, (float)3.14, "", new Long(0L));143fail("Probe.trigger: wrong type primitive arguments not caught");144} catch (IllegalArgumentException e) {}145}146}147148149