1 18 package org.apache.batik.test; 19 20 import java.awt.AlphaComposite ; 21 import java.awt.Color ; 22 import java.awt.Graphics2D ; 23 import java.awt.geom.AffineTransform ; 24 import java.awt.image.BufferedImage ; 25 26 32 public class PerformanceTestValidator extends AbstractTest { 33 public TestReport runImpl() throws Exception { 34 SimplePerformanceTest p = new SimplePerformanceTest(); 38 TestReport r = p.run(); 39 assertTrue(!r.hasPassed()); 40 assertTrue(r.getErrorCode().equals("no.reference.score.set")); 41 p.setReferenceScore(p.getLastScore()); 42 p.run(); 43 p.setReferenceScore(p.getLastScore()); 44 p.run(); 45 46 double score = p.getLastScore(); 47 p.setReferenceScore(score); 48 r = p.run(); 49 50 if (!r.hasPassed()) { 51 TestReport result = reportError("unexpected.performance.test.failure"); 52 result.addDescriptionEntry("error.code", r.getErrorCode()); 53 result.addDescriptionEntry("expected.score", "" + score); 54 result.addDescriptionEntry("actual.score", "" + p.getLastScore()); 55 result.addDescriptionEntry("regression.percentage", "" + 100*(score - p.getLastScore())/p.getLastScore()); 56 return result; 57 } 58 59 p.setReferenceScore(score*0.5); 62 r = p.run(); 63 assertTrue(!r.hasPassed()); 64 if (!r.getErrorCode().equals("performance.regression")) { 65 TestReport result = reportError("unexpected.performance.test.error.code"); 66 result.addDescriptionEntry("expected.code", "performance.regression"); 67 result.addDescriptionEntry("actual.code", r.getErrorCode()); 68 result.addDescriptionEntry("expected.score", "" + score); 69 result.addDescriptionEntry("actual.score", "" + p.getLastScore()); 70 result.addDescriptionEntry("regression.percentage", "" + 100*(score - p.getLastScore())/p.getLastScore()); 71 return result; 72 } 73 74 p.setReferenceScore(score*2); 75 r = p.run(); 76 assertTrue(!r.hasPassed()); 77 if (!r.getErrorCode().equals("unexpected.performance.improvement")) { 78 TestReport result = reportError("unexpected.performance.test.error.code"); 79 result.addDescriptionEntry("expected.code", "unexpected.performance.improvement"); 80 result.addDescriptionEntry("actual.code", r.getErrorCode()); 81 result.addDescriptionEntry("expected.score", "" + score); 82 result.addDescriptionEntry("actual.score", "" + p.getLastScore()); 83 result.addDescriptionEntry("regression.percentage", "" + 100*(score - p.getLastScore())/p.getLastScore()); 84 return result; 85 } 86 87 return reportSuccess(); 88 } 89 90 static class SimplePerformanceTest extends PerformanceTest { 91 public void runOp() { 92 BufferedImage buf = new BufferedImage (200, 200, BufferedImage.TYPE_INT_ARGB); 94 Graphics2D g = buf.createGraphics(); 95 AffineTransform txf = new AffineTransform (); 96 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); 97 g.setPaint(new Color (30, 100, 200)); 98 99 for (int j=0; j<20; j++) { 100 txf.setToIdentity(); 101 txf.translate(-100, -100); 102 txf.rotate(j*Math.PI/100); 103 txf.translate(100, 100); 104 g.setTransform(txf); 105 g.drawRect(30, 30, 140, 140); 106 } 107 118 } 119 } 120 } 121 | Popular Tags |