Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9af967b3b00265b241e92fdd19f72d564ed4cd47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
 * Created on May 16, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.eclipse.cdt.core.suite;

import java.text.DecimalFormat;
import java.util.ArrayList;

import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestListener;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import org.eclipse.cdt.core.build.managed.tests.ManagedBuildTests;
import org.eclipse.cdt.core.build.managed.tests.StandardBuildTests;
import org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest;
import org.eclipse.cdt.core.indexer.tests.IndexManagerTests;
import org.eclipse.cdt.core.model.failedTests.CModelElementsFailedTests;
import org.eclipse.cdt.core.model.tests.AllCoreTests;
import org.eclipse.cdt.core.model.tests.BinaryTests;
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests;
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
import org.eclipse.cdt.core.search.tests.SearchTestSuite;
import org.eclipse.core.boot.IPlatformRunnable;

/**
 * @author vhirsl
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class AutomatedIntegrationSuite extends TestSuite 
									   implements TestListener, IPlatformRunnable {

	private TestResult testResult = null;
	private String currentTestName;
	// success tests
	private int numberOfSuccessTests = 0;
	private int numberOfFailedSuccessTests = 0;
	// failed tests for open bug reports
	private int numberOfFailedTests = 0;
	private int numberOfFailedFailedTests = 0;
	// switching to failed tests
	protected boolean failedTests = false;
	protected boolean skipTest = false;
	

	public AutomatedIntegrationSuite() {}
	
	public AutomatedIntegrationSuite(Class theClass, String name) {
		super(theClass, name);
	}
	
	public AutomatedIntegrationSuite(Class theClass) {
		super(theClass);
	}
	
	public AutomatedIntegrationSuite(String name) {
		super(name);
	}
	
	public static Test suite() {
		final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
		
		// First test to trigger report generation
		suite.addTest(suite.new GenerateReport("startSuccessTests"));

		// Add all success tests
		suite.addTest(ManagedBuildTests.suite());
		suite.addTest(StandardBuildTests.suite());
		suite.addTest(ParserTestSuite.suite());
		suite.addTest(AllCoreTests.suite());
		suite.addTest(BinaryTests.suite());
		suite.addTest(ElementDeltaTests.suite());
		suite.addTest(WorkingCopyTests.suite());
		suite.addTest(SearchTestSuite.suite());
		suite.addTestSuite( CompletionProposalsTest.class);
		//Indexer Tests need to be run after any indexer client tests
		//as the last test shuts down the indexing thread
		suite.addTest(IndexManagerTests.suite());
		// Last test to trigger report generation
		suite.addTest(suite.new GenerateReport("startFailedTests"));
		
		// Add all failed tests
		suite.addTestSuite(ASTFailedTests.class);
		suite.addTestSuite(STLFailedTests.class);
		suite.addTestSuite(CModelElementsFailedTests.class);
//		suite.addTestSuite(FailedCompleteParseASTExpressionTest.class);

		// Last test to trigger report generation
		suite.addTest(suite.new GenerateReport("generateReport"));

		return suite;
	}
	
	/**
	 * Runs the tests and collects their result in a TestResult.
	 * Overloaded method
	 */
	public void run(TestResult result) {
		// To get counts from the result
		testResult = result;
		// Add oneself as a listener
		result.addListener(this);
		// Call a base class method
		super.run(result);
		// Remove a listener
		result.removeListener(this);
	}

	 
	/**
	 * An error occurred.
	 */
	public void addError(Test test, Throwable t) {
//		System.out.println("Error : " + test);
//		System.out.println("\tReason : " + t);
//		System.out.println("\tStack trace : ");
//		t.printStackTrace(System.out);
	}
	/**
	 * A failure occurred.
	 */
	public void addFailure(Test test, AssertionFailedError t) {
		if (failedTests) {
			++numberOfFailedFailedTests;  
		}
		else {
			++numberOfFailedSuccessTests;
		}
//		System.out.println("Failure : " + test);
//		System.out.println("\tReason : " + t);
//		System.out.println("\tStackTrace : ");
//		t.printStackTrace(System.out);
	}
	/**
	 * A test ended.
	 */
	public void endTest(Test test) {
		if (currentTestName == null) {
			System.out.println("Internal error - endTest: currentTestName == null");
		}
		else {
			if (skipTest) {
				skipTest = false;
			}
			else {
				if (failedTests) {
					++numberOfFailedTests;
					// System.out.println(test);
				}
				else {
					++numberOfSuccessTests;
				}
				System.out.println(test);
			}
			currentTestName = null;
		}
	}
	/**
	 * A test started.
	 */
	public void startTest(Test test) {
		if (currentTestName != null) {
			System.out.println("Internal error - startTest: currentTestName != null");
		}
		else {
			currentTestName = test.toString();
		}
	}
	
	/*
	 * generateReport
	 * 
	 * @author vhirsl
	 *
	 * To change the template for this generated type comment go to
	 * Window>Preferences>Java>Code Generation>Code and Comments
	 */
	protected void generateReport() {
		int numberOfRuns = testResult.runCount();
		int numberOfFailures = testResult.failureCount();
		int numberOfErrors = testResult.errorCount();

		System.out.println();
	 	System.out.println("*** Generating report: ***");
		System.out.println();
	 	System.out.println("\tNumber of runs: " + numberOfRuns);
		System.out.println("\tNumber of failures: " + numberOfFailures);
		System.out.println("\tNumber of errors: " + numberOfErrors);
		float successRate = (numberOfRuns-numberOfFailures-numberOfErrors)/(float)numberOfRuns;
		DecimalFormat df = new DecimalFormat("##.##%");
		System.out.println("Sanity success rate : " + df.format(successRate));
		System.out.println("\tNumber of success tests: " + numberOfSuccessTests);
		System.out.println("\tNumber of failed tests: " + numberOfFailedTests);
		successRate = numberOfSuccessTests/(float)(numberOfSuccessTests+numberOfFailedTests);
		System.out.println("Expected success test rate : " + df.format(successRate));
		successRate = (numberOfSuccessTests-numberOfFailedSuccessTests)/
					  (float)(numberOfSuccessTests+numberOfFailedTests-numberOfFailedFailedTests);
		System.out.print("Observed success test rate : " + df.format(successRate)); 
		System.out.println(" (failed success tests = " + numberOfFailedSuccessTests + ", failed failed tests = " + numberOfFailedFailedTests + ")");
		System.out.println();
	}
	
		protected void startSuccessTests() {
			failedTests = false;
			System.out.println();
			System.out.println("*** Starting success tests ***");
			System.out.println();
		}
	
		protected void startFailedTests() {
			failedTests = true;
			System.out.println();
			System.out.println("*** Starting failed tests ***");
			System.out.println();
		}
		
	/*
	 * Public inner class to invoke generateReport
	 * 
	 * @author vhirsl
	 *
	 * To change the template for this generated type comment go to
	 * Window>Preferences>Java>Code Generation>Code and Comments
	 */
	public class GenerateReport extends TestCase {
		public GenerateReport(String name) {
			super(name);
		}
		public GenerateReport(){}
		
		public void generateReport() {
			// skip this one
			AutomatedIntegrationSuite.this.skipTest = true;

			// Calls a method of the outer class
			AutomatedIntegrationSuite.this.generateReport();
		}
		
		public void startSuccessTests() {
			// skip this one
			AutomatedIntegrationSuite.this.skipTest = true;
			
			// Calls a method of the outer class
			AutomatedIntegrationSuite.this.startSuccessTests();
		}

		public void startFailedTests() {
			// skip this one
			AutomatedIntegrationSuite.this.skipTest = true;
			
			// Calls a method of the outer class
			AutomatedIntegrationSuite.this.startFailedTests();
		}

		/* (non-Javadoc)
		 * @see junit.framework.Test#countTestCases()
		 * We don't want these test cases to be counted
		 */
		public int countTestCases() {
			return 0;
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.core.boot.IPlatformRunnable#run(java.lang.Object)
	 */
	public Object run(Object args) throws Exception {
		// Used when started from as a regression test suite after the build
		TestRunner testRunner = new TestRunner(new AISResultPrinter(System.out));
		TestResult testResult = testRunner.doRun(suite());
		
		return prepareReport(testResult);
	}

	protected ArrayList prepareReport(TestResult testResult) {	
		// TestRunner.run(suite());
		ArrayList efMessages = new ArrayList();
		int errorCount = testResult.errorCount();
		int failureCount = testResult.failureCount();
		if (errorCount > 0) {
			String em = new String("There ");
			em += (errorCount == 1)?"is ":"are ";
			em += Integer.toString(errorCount);
			em += " error";
			em += (errorCount == 1)?"!":"s!";
			efMessages.add(em);
		}
		if (failureCount > 0) {
			String fm = new String("There ");
			fm += (failureCount == 1)?"is ":"are ";
			fm += Integer.toString(failureCount);
			fm += " failure";
			fm += (failureCount == 1)?"!":"s!";
			efMessages.add(fm);
		}
		if (efMessages.isEmpty()) {
			efMessages.add(new String("Regression test run SUCCESSFUL!"));
		}
		else {
			efMessages.add(new String("Please see raw test suite output for details."));
		}
		return efMessages;
	}
}

Back to the top