Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b61f8ad94aac3767a1b1c8e4e35d58915ba6939e (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
/*******************************************************************************
 * Copyright (c) 2005, 2011 BEA Systems, Inc. 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    mkaufman@bea.com - initial API and implementation
 *    
 *******************************************************************************/

package org.eclipse.jdt.apt.tests;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.zip.ZipInputStream;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.apt.core.util.AptConfig;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.tests.builder.Problem;
import org.eclipse.jdt.core.tests.builder.BuilderTests;

public class PerfTests extends BuilderTests
{
	
	private IPath projectPath;

	public PerfTests(String name)
	{
		super( name );
	}

	public static Test suite()
	{
		return new TestSuite( PerfTests.class );
	}

	public void setUp() throws Exception
	{
		super.setUp();
		
		IWorkspace ws = env.getWorkspace();
		IWorkspaceRoot root = ws.getRoot();
		IPath path = root.getLocation();
		File destRoot = path.toFile();
		
		URL platformURL = Platform.getBundle("org.eclipse.jdt.core.tests.binaries").getEntry("/");  //$NON-NLS-1$//$NON-NLS-2$
		File f = new File(FileLocator.toFileURL(platformURL).getFile());
		f = new File(f, "perf-test-project.zip"); //$NON-NLS-1$

		InputStream in = new FileInputStream(f);
		ZipInputStream zipIn = new ZipInputStream(in);
		try {
			TestUtil.unzip(zipIn, destRoot);
		}
		finally {
			zipIn.close();
		}
		
		// project will be deleted by super-class's tearDown() method
		projectPath = env.addProject( "org.eclipse.jdt.core", "1.4" ); //$NON-NLS-1$ //$NON-NLS-2$
		
		System.out.println("Performing full build..."); //$NON-NLS-1$
		fullBuild( projectPath );
		System.out.println("Completed build."); //$NON-NLS-1$
		
		assertNoUnexpectedProblems();
		
	}
	
	/**
	 * JDT Core has one warning on the use of IWorkingCopy, and a number
	 * of TODOs, XXXs and FIXMEs.
	 */
	private void assertNoUnexpectedProblems() {
		Problem[] problems = env.getProblems();
		for (Problem problem : problems) {
			if (problem.getMessage().startsWith("TODO") || 
				problem.getMessage().startsWith("XXX") ||
				problem.getMessage().startsWith("FIXME")) {
				continue;
			}
			else {
				if (problem.getMessage().equals("The type IWorkingCopy is deprecated"))
					continue;
			}
			fail("Found unexpected problem: " + problem);
		}
	}
	
	public static String getProjectName()
	{
		return PerfTests.class.getName() + "Project"; //$NON-NLS-1$
	}

	public IPath getSourcePath()
	{
		IProject project = env.getProject( getProjectName() );
		IFolder srcFolder = project.getFolder( "src" ); //$NON-NLS-1$
		IPath srcRoot = srcFolder.getFullPath();
		return srcRoot;
	}
	
	public void testBuilding() throws Throwable {
		IProject proj = env.getProject(projectPath);
		IJavaProject jproj = JavaCore.create(proj); // doesn't actually create anything
		
		assertNoUnexpectedProblems();
		
		// Start with APT turned off
		AptConfig.setEnabled(jproj, false);
		proj.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
		
		assertNoUnexpectedProblems();
		
		System.out.println("Performing full build without apt...");
		long start = System.currentTimeMillis();
		proj.build(IncrementalProjectBuilder.FULL_BUILD, null);
		long totalWithoutAPT = System.currentTimeMillis() - start;
		System.out.println("Completed full build without APT in " + totalWithoutAPT + "ms.");
		
		assertNoUnexpectedProblems();
		
		// Now turn on APT
		AptConfig.setEnabled(jproj, true);
		proj.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
		
		assertNoUnexpectedProblems();
		
		System.out.println("Performing full build with apt...");
		start = System.currentTimeMillis();
		proj.build(IncrementalProjectBuilder.FULL_BUILD, null);
		long totalWithAPT = System.currentTimeMillis() - start;
		System.out.println("Completed full build with APT in " + totalWithAPT + "ms.");
		
		assertNoUnexpectedProblems();
		
		if (totalWithAPT > totalWithoutAPT * 1.15) {
			fail("APT performance degradation greater than 15%");
		}
	}
	
}

Back to the top