All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.plugins.PerfPublisher.MatrixTestReportAction Maven / Gradle / Ivy

Go to download

The PerfPublisher plug-in scans for xml tests reports defined in the administration panel and generates trend graphs, computes stats and underline regressions and modifications. The xml files must be generated by your own testing tool.

There is a newer version: 7.97
Show newest version
package hudson.plugins.PerfPublisher;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;

import org.apache.commons.lang.text.StrBuilder;

import hudson.matrix.AxisList;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.plugins.PerfPublisher.Report.ReportContainer;
import hudson.plugins.PerfPublisher.Report.Test;
import hudson.plugins.PerfPublisher.matrixBuild.PerfPublisherMatrixBuild;
import hudson.plugins.PerfPublisher.matrixBuild.PerfPublisherMatrixSubBuild;

public class MatrixTestReportAction extends AbstractPerfPublisherAction
		implements Action {

	PerfPublisherMatrixBuild matrixbuild;
	private int numberOfExecutedTest;
	private int numberOfTest;
	private int numberOfPassedTest;
	private int numberOfNotExecutedTest;
	private int numberOfTrueFalseTest;
	private int numberOfFailedTest;
	private MatrixBuild build;
	private MatrixProject project;

	public MatrixTestReportAction(MatrixBuild build) {
		this.matrixbuild = new PerfPublisherMatrixBuild(build.getNumber());
		this.build = build;
		this.project = build.getProject();
	}

	public MatrixBuild getBuild() {
		return build;
	}

	public MatrixProject getProject() {
		return project;
	}

	public String getDisplayName() {
		return PerfPublisherPlugin.MATRIX_BUILD_DISPLAY_NAME;
	}

	public String getSearchUrl() {
		return PerfPublisherPlugin.URL;
	}

	public String getIconFileName() {
		return PerfPublisherPlugin.ICON_FILE_NAME;
	}

	public String getUrlName() {
		return PerfPublisherPlugin.URL;
	}

	/**
	 * Add a subBuild result
	 * @param report
	 * @param buildVariables
	 */
	public void addSubBuildResult(ReportContainer report,
			Map buildVariables) {
		Map buildVars = new TreeMap();
		buildVars.putAll(buildVariables);
		this.matrixbuild.addSubBuild(new PerfPublisherMatrixSubBuild(buildVars, report));
		computeStats();
	}
	public PerfPublisherMatrixBuild getMatrixBuild() {
		return this.matrixbuild;
	}

	public void computeStats() {
		numberOfExecutedTest = 0;
		numberOfFailedTest = 0;
		numberOfTest = 0;
		numberOfPassedTest = 0;
		numberOfTrueFalseTest = 0;
		
		List subBuilds = this.matrixbuild.getSubBuilds();
		for (int i=0; i");
		int tmp1 = this.getNumberOfFailedTest();
		int tmp2 = this.getNumberOfPassedTest();
		double tmp3 = this.getPercentOfFailedTest();
		double tmp4 = this.getPercentOfPassedTest();
		
		if (tmp3<15) {
			strbuilder.append("
"+tmp1+"
"); strbuilder.append("
"+tmp2+"
"); } else { strbuilder.append("
"+tmp3+"% ("+tmp1+")
"); strbuilder.append("
"+tmp4+"% ("+tmp2+")
"); } strbuilder.append("
"); return strbuilder.toString(); } private int getNumberOfFailedTest() { return this.numberOfFailedTest; } private int getNumberOfPassedTest() { return this.numberOfPassedTest; } private int getNumberOfTrueFalseTest() { return this.numberOfTrueFalseTest; } private double getPercentOfFailedTest() { double resultat = 0; resultat = ((double) getNumberOfFailedTest() / getNumberOfTrueFalseTest()) * 100; return floor(resultat, 2); } private double getPercentOfPassedTest() { double resultat = 0; resultat = ((double) getNumberOfPassedTest() / getNumberOfTrueFalseTest()) * 100; return floor(resultat, 2); } /** * Round a double with n decimals * * @param a * value to convert * @param n * Number of decimals * @return the rounded number */ public static double floor(double a, int n) { double p = Math.pow(10.0, n); return Math.floor((a * p) + 0.5) / p; } public String getDetailSummary() { StringBuilder strbuilder = new StringBuilder(); strbuilder.append("Number of executed tests : "+this.getNumberOfExecutedTest()+"."); strbuilder.append("
"); return strbuilder.toString(); } // public String getRegression() { // // StringBuilder strb = new StringBuilder(); // List regressions = new ArrayList(); // if (this.getTrendReport()!=null) { // List tmpTests = this.getTrendReport().getSuccessStatusChangedTests(); // for (int i=0; i"); // strb.append("This build has discovered "+regressions.size()+" regression(s)."); // strb.append(""); // } // } // // return strb.toString(); // } public String getHtmlArrayDisplay() { StringBuilder strb = new StringBuilder(); /** * Generate HTML Header Table */ strb.append("\n"); strb.append(generateHtmlArrayHeader()); /** * Generate HTML Table Content */ strb.append(generateHtmlArrayContent()); strb.append("
"); return strb.toString(); } private String generateHtmlArrayContent() { StringBuilder strb = new StringBuilder(); List subBuilds = this.matrixbuild.getSubBuilds(); Collections.sort(subBuilds); Map> values = new HashMap>(); for (int i=0; i nbs = values.get("Nb tests"); nbs.add(subBuilds.get(i).getReport().getNumberOfTest()); } else { List nbs = new ArrayList(); nbs.add(subBuilds.get(i).getReport().getNumberOfTest()); values.put("Nb tests", nbs); } if (values.containsKey("Nb Executed tests")) { List nbs = values.get("Nb Executed tests"); nbs.add(subBuilds.get(i).getReport().getNumberOfExecutedTest()); } else { List nbs = new ArrayList(); nbs.add(subBuilds.get(i).getReport().getNumberOfExecutedTest()); values.put("Nb Executed tests", nbs); } if (values.containsKey("Nb not executed tests")) { List nbs = values.get("Nb not executed tests"); nbs.add(subBuilds.get(i).getReport().getNumberOfNotExecutedTest()); } else { List nbs = new ArrayList(); nbs.add(subBuilds.get(i).getReport().getNumberOfNotExecutedTest()); values.put("Nb not executed tests", nbs); } if (values.containsKey("Succeeded tests")) { List nbs = values.get("Succeeded tests"); nbs.add(subBuilds.get(i).getReport().getNumberOfPassedTest()); } else { List nbs = new ArrayList(); nbs.add(subBuilds.get(i).getReport().getNumberOfPassedTest()); values.put("Succeeded tests", nbs); } if (values.containsKey("Failed tests")) { List nbs = values.get("Failed tests"); nbs.add(subBuilds.get(i).getReport().getNumberOfFailedTest()); } else { List nbs = new ArrayList(); nbs.add(subBuilds.get(i).getReport().getNumberOfFailedTest()); values.put("Failed tests", nbs); } if (values.containsKey("Avg Compile time")) { List nbs = values.get("Avg Compile time"); nbs.add((int)subBuilds.get(i).getReport().getAverageOfCompileTime()); } else { List nbs = new ArrayList(); nbs.add((int)subBuilds.get(i).getReport().getAverageOfCompileTime()); values.put("Avg Compile time", nbs); } if (values.containsKey("Avg Execution time")) { List nbs = values.get("Avg Execution time"); nbs.add((int)subBuilds.get(i).getReport().getAverageOfExecutionTime()); } else { List nbs = new ArrayList(); nbs.add((int)subBuilds.get(i).getReport().getAverageOfExecutionTime()); values.put("Avg Execution time", nbs); } if (values.containsKey("Avg Performance")) { List nbs = values.get("Avg Performance"); nbs.add((int)subBuilds.get(i).getReport().getAverageOfPerformance()); } else { List nbs = new ArrayList(); nbs.add((int)subBuilds.get(i).getReport().getAverageOfPerformance()); values.put("Avg Performance", nbs); } } strb.append(generateHtmlContentRow(values)); return strb.toString(); } private String generateHtmlContentRow(Map> values) { StringBuilder strb = new StringBuilder(); Set>> entry = values.entrySet(); Iterator>> iterator = entry.iterator(); int zebra = 2; while (iterator.hasNext()) { Entry> axe = iterator.next(); strb.append("\n"); strb.append(""+axe.getKey()+"\n"); List i_min = new ArrayList(); int tmp_min = 0; List i_max = new ArrayList(); int tmp_max = 0; for (int i=0; iaxe.getValue().get(j)) { tmp_min = axe.getValue().get(j); i_min = new ArrayList(); i_min.add(j); } if (tmp_max(); i_max.add(j); } if (tmp_min == axe.getValue().get(j)) { i_min.add(j); } if (tmp_max == axe.getValue().get(j)) { i_max.add(j); } } } if (i_min.contains(i)) { strb.append(""+axe.getValue().get(i)+""); } else if (i_max.contains(i)) { strb.append(""+axe.getValue().get(i)+""); } else { strb.append(""+axe.getValue().get(i)+""); } } strb.append("\n"); if (zebra==1) { zebra = 2; } else { zebra = 1; } } return strb.toString(); } private String generateHtmlArrayHeader() { StringBuilder strb = new StringBuilder(); // /** // * First a row which contains as cols as combinations // */ // strb.append("\n"); // strb.append("\n"); // // strb.append("Sub-Builds\n"); // for (int i=0; i"+i+"\n"); // } // strb.append("\n"); // strb.append("\n"); /** * Rows for each axis */ int factor = 1; int colspan = this.matrixbuild.getNbCombinations(); for (int i_row=0; i_row"); String axis = this.matrixbuild.getAxis().get(i_row); /** * Add the row description */ strb.append(""+axis+"\n"); /** * Separate the current row with axis values cols */ List values = matrixbuild.getAxisValues(axis); Collections.sort(values); colspan = colspan/values.size(); /** * repeat axis cols on the same row */ for (int i_factor=0; i_factor 1) { strb.append(""+values.get(i_value)+""); } else { strb.append(""+values.get(i_value)+"\n"); } } } factor *= values.size(); strb.append("\n"); } return strb.toString(); } public int getNumberOfExecutedTest() { return numberOfExecutedTest; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy