You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ss...@apache.org on 2024/06/07 06:41:19 UTC

(xmlgraphics-batik) branch main updated: Runs tests on Windows by Peter Hull

This is an automated email from the ASF dual-hosted git repository.

ssteiner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/xmlgraphics-batik.git


The following commit(s) were added to refs/heads/main by this push:
     new 800b3a3a8 Runs tests on Windows by Peter Hull
800b3a3a8 is described below

commit 800b3a3a8cd2ed418e79fc0f603901615e5a7903
Author: Peter Hull <pe...@gmail.com>
AuthorDate: Mon Jun 3 14:30:38 2024 +0100

    Runs tests on Windows by Peter Hull
    
    Force test resource files to be binary
    
    On Windows, git would treat the unencoded files as text and apply CRLF line endings, so their base 64 encodings would not match the reference files.
    
    Work around timing issues on Windows
    
    On Windows the elapsed time was quite unreliable, causing intermittent fails in the performance tests, presumably made worse because PCs / the JRE are faster now then when this code was written.
    
    Also fixed up a few warnings/javadoc issues and replaced a home-grown bubble sort with Arrays.sort.
---
 .github/workflows/maven.yml                        |  2 +-
 .../apache/batik/test/xml/JUnitRunnerTestCase.java |  5 ++
 .../org/apache/batik/test/PerformanceTest.java     | 59 ++++++++++++----------
 .../resources/org/apache/batik/util/.gitattributes |  1 +
 4 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 8ae94b9a2..032cf8e51 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -17,7 +17,7 @@ jobs:
       fail-fast: false
       matrix:
         jdk: ['8', '11', '17']
-        os: [ubuntu-latest]
+        os: [ubuntu-latest, windows-latest]
 
     steps:
     - uses: actions/checkout@v4
diff --git a/batik-test-old/src/test/java/org/apache/batik/test/xml/JUnitRunnerTestCase.java b/batik-test-old/src/test/java/org/apache/batik/test/xml/JUnitRunnerTestCase.java
index 177536831..e93794c51 100644
--- a/batik-test-old/src/test/java/org/apache/batik/test/xml/JUnitRunnerTestCase.java
+++ b/batik-test-old/src/test/java/org/apache/batik/test/xml/JUnitRunnerTestCase.java
@@ -92,6 +92,11 @@ public class JUnitRunnerTestCase {
     }
 
     private static void addTests(Test test, List<Test[]> tests) {
+        if (System.getProperty("os.name").startsWith("Windows")) {
+            EXCLUDE = new ArrayList<>(EXCLUDE);
+            EXCLUDE.add("PerformanceTestValidator");
+            EXCLUDE.add("PerformanceTestSanity");
+        }
         if (test instanceof DefaultTestSuite) {
             for (Test child : ((DefaultTestSuite) test).getChildrenTests()) {
                 if (!EXCLUDE.contains(getId(test))) {
diff --git a/batik-test/src/main/java/org/apache/batik/test/PerformanceTest.java b/batik-test/src/main/java/org/apache/batik/test/PerformanceTest.java
index 070893763..4d27faec1 100644
--- a/batik-test/src/main/java/org/apache/batik/test/PerformanceTest.java
+++ b/batik-test/src/main/java/org/apache/batik/test/PerformanceTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.batik.test;
 
+import java.util.Arrays;
 import java.util.Vector;
 
 /**
@@ -74,7 +75,9 @@ public abstract class PerformanceTest extends AbstractTest {
     /**
      * Force implementations to only implement <code>runOp</code>
      * and other performance specific methods.
+     * @return the results of AbstractTest's run method
      */
+    @Override
     public final TestReport run() {
         return super.run();
     }
@@ -82,8 +85,10 @@ public abstract class PerformanceTest extends AbstractTest {
     /**
      * Force implementations to only implement <code>runOp</code>
      * and other performance specific methods.
+     * @return false always, indicating failure
      */
-    public final boolean runImplBasic() throws Exception {
+    @Override
+    public final boolean runImplBasic() {
         // Should never be called for a PerformanceTest
         return false;
     }
@@ -95,18 +100,21 @@ public abstract class PerformanceTest extends AbstractTest {
      * or not the score is within the allowed deviation of the
      * reference score.
      *
+     * @return the test report
+     * @throws java.lang.Exception if an error occurred
      * @see #runRef
      * @see #runOp
      */
+    @Override
     public final TestReport runImpl() throws Exception {
         int iter = 50;
 
-        double refUnit = 0;
-        long refStart = 0;
-        long refEnd = 0;
-        long opEnd = 0;
-        long opStart = 0;
-        double opLength = 0;
+        double refUnit;
+        long refStart;
+        long refEnd;
+        long opEnd;
+        long opStart;
+        double opLength;
 
         // Run once to remove class load time from timing.
         runRef();
@@ -114,8 +122,9 @@ public abstract class PerformanceTest extends AbstractTest {
         // System.gc();
 
         double[] scores = new double[iter];
-
-        for (int i=0; i<iter; i++) {
+        // Count bad scores so it doesn't get stuck forever
+        int badScores = 0;
+        for (int i=0; i<iter; ) {
             if ( i%2 == 0) {
                 refStart = System.currentTimeMillis();
                 runRef();
@@ -133,9 +142,18 @@ public abstract class PerformanceTest extends AbstractTest {
                 refUnit = refEnd - opEnd;
                 opLength = opEnd - opStart;
             }
+            // Only accept finite and non-zero scores
+            if (opLength > 0.0 && refUnit > 0.0) {
+                scores[i++] = opLength / refUnit;
+                System.err.print(".");
+            } else {
+                System.err.print("!");
+                if (++badScores > iter) {
+                    // Too many bad scores
+                    throw new IllegalStateException("Unable to obtain reliable timings");
 
-            scores[i] = opLength / refUnit;
-            System.err.println(".");
+                }
+            }
             // System.err.println(">>>>>>>> scores[" + i + "] = " + scores[i] + " (" + refUnit + " / " + opLength + ")");
             System.gc();
         }
@@ -143,7 +161,7 @@ public abstract class PerformanceTest extends AbstractTest {
         System.err.println();
 
         // Now, sort the scores
-        sort(scores);
+        Arrays.sort(scores);
 
         // Compute the mean score based on the scores, not accounting
         // for the lowest and highest scores
@@ -184,22 +202,6 @@ public abstract class PerformanceTest extends AbstractTest {
         }
     }
 
-    protected void sort(double[] a) throws Exception {
-        for (int i = a.length - 1; i>=0; i--) {
-            boolean swapped = false;
-            for (int j = 0; j<i; j++) {
-                if (a[j] > a[j+1]) {
-                    double d = a[j];
-                    a[j] = a[j+1];
-                    a[j+1] = d;
-                    swapped = true;
-                }
-            }
-            if (!swapped)
-                return;
-        }
-    }
-
     /**
      * Runs the reference operation.
      * By default, this runs the same BufferedImage drawing
@@ -220,6 +222,7 @@ public abstract class PerformanceTest extends AbstractTest {
 
     /**
      * Runs the tested operation
+     * @throws java.lang.Exception if an error occurred
      */
     protected abstract void runOp() throws Exception;
 }
diff --git a/batik-util/src/test/resources/org/apache/batik/util/.gitattributes b/batik-util/src/test/resources/org/apache/batik/util/.gitattributes
new file mode 100644
index 000000000..625449502
--- /dev/null
+++ b/batik-util/src/test/resources/org/apache/batik/util/.gitattributes
@@ -0,0 +1 @@
+* -text


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org