changeset 335:8f0aa19766e6

Sample @GMB parameter tests.
author shade
date Sat, 11 Jan 2014 00:15:04 +0400
parents 3b689c865a9f
children 3b50d1b2260b
files jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/Parameters.java jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/fork/BenchForkTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/fork/BenchMethodForkTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/fork/MethodForkTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/threads/BenchmarkGroupThreadsTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/threads/BenchmarkMethodThreadsTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/threads/BenchmarkThreadsTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/threads/MethodThreadsTest.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/Option.java
diffstat 9 files changed, 386 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/Parameters.java	Sat Jan 11 00:15:04 2014 +0400
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.it.parameters;
+
+import org.junit.Assert;
+import org.openjdk.jmh.output.format.OutputFormatFactory;
+import org.openjdk.jmh.runner.BenchmarkRecord;
+import org.openjdk.jmh.runner.MicroBenchmarkList;
+import org.openjdk.jmh.runner.options.VerboseMode;
+
+import java.util.Collections;
+import java.util.Set;
+
+public class Parameters {
+
+    public static BenchmarkRecord get(Class<?> klass) {
+        MicroBenchmarkList list = MicroBenchmarkList.fromFile("target/test-classes/META-INF/MicroBenchmarks");
+        Set<BenchmarkRecord> set = list.find(OutputFormatFactory.createFormatInstance(System.out, VerboseMode.Silent), ".*" + klass.getName() + ".*", Collections.<String>emptyList());
+        Assert.assertEquals(1, set.size());
+        return set.iterator().next();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/fork/BenchForkTest.java	Sat Jan 11 00:15:04 2014 +0400
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.it.parameters.fork;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.it.parameters.Parameters;
+import org.openjdk.jmh.it.parameters.threads.BenchmarkThreadsTest;
+
+@Fork(10)
+public class BenchForkTest {
+
+    @GenerateMicroBenchmark
+    public void bench() {
+        // do nothing
+    }
+
+    @Test
+    public void test() {
+        Assert.assertEquals(Integer.valueOf(10), Parameters.get(BenchmarkThreadsTest.class).getForks().get());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/fork/BenchMethodForkTest.java	Sat Jan 11 00:15:04 2014 +0400
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.it.parameters.fork;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.it.parameters.Parameters;
+import org.openjdk.jmh.it.parameters.threads.BenchmarkThreadsTest;
+
+@Fork(20)
+public class BenchMethodForkTest {
+
+    @Fork(10)
+    @GenerateMicroBenchmark
+    public void bench() {
+        // do nothing
+    }
+
+    @Test
+    public void test() {
+        Assert.assertEquals(Integer.valueOf(10), Parameters.get(BenchmarkThreadsTest.class).getForks().get());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/fork/MethodForkTest.java	Sat Jan 11 00:15:04 2014 +0400
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.it.parameters.fork;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.it.parameters.Parameters;
+import org.openjdk.jmh.it.parameters.threads.BenchmarkThreadsTest;
+
+public class MethodForkTest {
+
+    @Fork(10)
+    @GenerateMicroBenchmark
+    public void bench() {
+        // do nothing
+    }
+
+    @Test
+    public void test() {
+        Assert.assertEquals(Integer.valueOf(10), Parameters.get(BenchmarkThreadsTest.class).getForks().get());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/threads/BenchmarkGroupThreadsTest.java	Sat Jan 11 00:15:04 2014 +0400
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.it.parameters.threads;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.annotations.Group;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.it.parameters.Parameters;
+
+@Threads(10)
+public class BenchmarkGroupThreadsTest {
+
+    @Group("a")
+    @GenerateMicroBenchmark
+    public void bench1() {
+        // do nothing
+    }
+
+    @Group("a")
+    @GenerateMicroBenchmark
+    public void bench2() {
+        // do nothing
+    }
+
+    @Test
+    public void test() {
+        Assert.assertEquals(Integer.valueOf(10), Parameters.get(BenchmarkThreadsTest.class).getThreads().get());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/threads/BenchmarkMethodThreadsTest.java	Sat Jan 11 00:15:04 2014 +0400
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.it.parameters.threads;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.it.parameters.Parameters;
+
+@Threads(20)
+public class BenchmarkMethodThreadsTest {
+
+    @Threads(10)
+    @GenerateMicroBenchmark
+    public void bench() {
+        // do nothing
+    }
+
+    @Test
+    public void test() {
+        Assert.assertEquals(Integer.valueOf(10), Parameters.get(BenchmarkThreadsTest.class).getThreads().get());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/threads/BenchmarkThreadsTest.java	Sat Jan 11 00:15:04 2014 +0400
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.it.parameters.threads;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.it.parameters.Parameters;
+
+@Threads(10)
+public class BenchmarkThreadsTest {
+
+    @GenerateMicroBenchmark
+    public void bench() {
+        // do nothing
+    }
+
+    @Test
+    public void test() {
+        Assert.assertEquals(Integer.valueOf(10), Parameters.get(BenchmarkThreadsTest.class).getThreads().get());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/parameters/threads/MethodThreadsTest.java	Sat Jan 11 00:15:04 2014 +0400
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.it.parameters.threads;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.it.parameters.Parameters;
+
+public class MethodThreadsTest {
+
+    @Threads(10)
+    @GenerateMicroBenchmark
+    public void bench() {
+        // do nothing
+    }
+
+    @Test
+    public void test() {
+        Assert.assertEquals(Integer.valueOf(10), Parameters.get(BenchmarkThreadsTest.class).getThreads().get());
+    }
+
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/Option.java	Fri Jan 10 23:42:49 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/Option.java	Sat Jan 11 00:15:04 2014 +0400
@@ -93,6 +93,13 @@
         }
     }
 
+    public T get() {
+        if (val == null) {
+            throw new IllegalStateException("Option is null");
+        }
+        return val;
+    }
+
     public interface Extractor<T> {
         T valueOf(String s);
     }