changeset 93:d8ec3efea915

Two regression tests for sync iterations.
author shade
date Tue, 11 Jun 2013 18:37:40 +0400
parents 12b90923045c
children a481d1e64cda
files jmh-core-it/src/test/java/org/openjdk/jmh/it/synciter/SyncIterMeasurementOnlyTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/synciter/SyncIterNotOnlyMeasurementTest.java jmh-core/src/main/java/org/openjdk/jmh/logic/Global.java
diffstat 3 files changed, 140 insertions(+), 7 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/synciter/SyncIterMeasurementOnlyTest.java	Tue Jun 11 18:37:40 2013 +0400
@@ -0,0 +1,62 @@
+/**
+ * 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.synciter;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.Main;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.it.Fixtures;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Aleksey Shipilev (aleksey.shipilev@oracle.com)
+ */
+@State(Scope.Benchmark)
+public class SyncIterMeasurementOnlyTest {
+
+    @GenerateMicroBenchmark
+    @Warmup(iterations = 0)
+    @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS)
+    @Threads(2)
+    public void test() {
+        Assert.assertTrue(isInMeasurementLoop());
+    }
+
+    private boolean isInMeasurementLoop() {
+        boolean inMeasurementLoop = false;
+        for (StackTraceElement element : new Exception().getStackTrace()) {
+            inMeasurementLoop |= element.getMethodName().contains("measurementLoop");
+        }
+        return inMeasurementLoop;
+    }
+
+    @Test
+    public void invoke() {
+        Main.testMain(Fixtures.getTestMask(this.getClass()) + " -foe -si false");
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/synciter/SyncIterNotOnlyMeasurementTest.java	Tue Jun 11 18:37:40 2013 +0400
@@ -0,0 +1,76 @@
+/**
+ * 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.synciter;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.Main;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.it.Fixtures;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Aleksey Shipilev (aleksey.shipilev@oracle.com)
+ */
+@State(Scope.Benchmark)
+public class SyncIterNotOnlyMeasurementTest {
+
+    private boolean inMeasurementLoopOnly = true;
+
+    @TearDown(Level.Trial)
+    public void check() {
+        Assert.assertFalse(inMeasurementLoopOnly);
+    }
+
+    @GenerateMicroBenchmark
+    @Warmup(iterations = 0)
+    @Measurement(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS)
+    @Threads(2)
+    public void test() {
+        inMeasurementLoopOnly &= isInMeasurementLoop();
+    }
+
+    private boolean isInMeasurementLoop() {
+        boolean inMeasurementLoop = false;
+        for (StackTraceElement element : new Exception().getStackTrace()) {
+            inMeasurementLoop |= element.getMethodName().contains("measurementLoop");
+        }
+        return inMeasurementLoop;
+    }
+
+    @Test
+    public void invoke() {
+        Main.testMain(Fixtures.getTestMask(this.getClass()) + " -foe -si true");
+    }
+
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/logic/Global.java	Tue Jun 11 18:13:46 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/logic/Global.java	Tue Jun 11 18:37:40 2013 +0400
@@ -57,13 +57,8 @@
         this.warmupVisited = new AtomicInteger();
         this.warmdownVisited = new AtomicInteger();
 
-        if (!syncIterations) {
-            warmupShouldWait = false;
-            warmdownShouldWait = false;
-        } else {
-            warmupShouldWait = true;
-            warmdownShouldWait = true;
-        }
+        warmupShouldWait = syncIterations;
+        warmdownShouldWait = syncIterations;
     }
 
     public void announceWarmupReady() {