Skip to main content
summaryrefslogtreecommitdiffstats
blob: a56c563e6c8d1fb2739accc0607895400622e3b2 (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
/*******************************************************************************
 * Copyright (c) 2009 STMicroelectronics.
 * 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:
 *   Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.gprof.test;



import java.io.File;
import java.io.IOException;

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

import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.linuxtools.binutils.utils.STSymbolManager;
import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTTreeViewer;
import org.eclipse.linuxtools.gprof.action.SwitchContentProviderAction;
import org.eclipse.linuxtools.gprof.action.SwitchSampleTimeAction;
import org.eclipse.linuxtools.gprof.parser.GmonDecoder;
import org.eclipse.linuxtools.gprof.view.CallGraphContentProvider;
import org.eclipse.linuxtools.gprof.view.FileHistogramContentProvider;
import org.eclipse.linuxtools.gprof.view.FlatHistogramContentProvider;
import org.eclipse.linuxtools.gprof.view.FunctionHistogramContentProvider;
import org.eclipse.linuxtools.gprof.view.GmonView;
import org.eclipse.linuxtools.gprof.view.fields.SampleProfField;
import org.eclipse.swt.widgets.TreeColumn;


/**
 * @author Xavier Raynaud <xavier.raynaud@st.com>
 */
public class GprofTest extends TestCase {
	private static final String GMON_BINARY_FILE = "a.out"; 
	private static final String GMON_OUTPUT_FILE = "gmon.out"; 
	private static final String GMON_DIRECTORY_SUFFIX = "_gprof_input"; 

	public GprofTest() {
	}

	public static Test suite() {
		TestSuite ats = new TestSuite("GProf:View CSV Export");

		File[] testDirs = STJunitUtils.getTestDirs("org.eclipse.linuxtools.gprof.test", ".*" + GMON_DIRECTORY_SUFFIX);
		for (File testDir : testDirs) {
			final File gmonFile = new File(testDir, GMON_OUTPUT_FILE);
			final File binaryFile = new File(testDir, GMON_BINARY_FILE);
			final File view_cg_RefFile = new File(testDir, "testCallgraphView.ref");
			final File view_cg_DumpFile = new File(testDir, "testCallgraphView.dump");
			final File view_cg2_RefFile = new File(testDir, "testCallgraphTimeView.ref");
			final File view_cg2_DumpFile = new File(testDir, "testCallgraphTimeView.dump");

			final File view_samplesFile_RefFile = new File(testDir, "testSampleView.ref");
			final File view_samplesFile_DumpFile = new File(testDir, "testSampleView.dump");
			final File view_samplesFileT_RefFile = new File(testDir, "testTimeView.ref");
			final File view_samplesFileT_DumpFile = new File(testDir, "testTimeView.dump");

			final File view_samplesFunction_RefFile = new File(testDir, "testFunctionSampleView.ref");
			final File view_samplesFunction_DumpFile = new File(testDir, "testFunctionSampleView.dump");
			final File view_samplesFunctionT_RefFile = new File(testDir, "testFunctionTimeView.ref");
			final File view_samplesFunctionT_DumpFile = new File(testDir, "testFunctionTimeView.dump");
			final File view_samplesFlat_RefFile = new File(testDir, "testFlatSampleView.ref");
			final File view_samplesFlat_DumpFile = new File(testDir, "testFlatSampleView.dump");
			final File view_samplesFlatT_RefFile = new File(testDir, "testFlatTimeView.ref");
			final File view_samplesFlatT_DumpFile = new File(testDir, "testFlatTimeView.dump");

			IBinaryObject binary = STSymbolManager.sharedInstance.getBinaryObject(new Path(binaryFile.getAbsolutePath()));
			final GmonDecoder gd = new GmonDecoder(binary);
			try {
				gd.read(gmonFile.getAbsolutePath());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			ats.addTest(
					new TestCase(testDir.getName() + ":CSV-CALLGRAPH") {
						public void runTest() throws Throwable {
							testView(gmonFile, gd, view_cg_RefFile, view_cg_DumpFile, CallGraphContentProvider.sharedInstance, false);
						}
					}
			);
			ats.addTest(
					new TestCase(testDir.getName() + ":CSV-CALLGRAPH-TIMED") {
						public void runTest() throws Throwable {
							testView(gmonFile, gd, view_cg2_RefFile, view_cg2_DumpFile, CallGraphContentProvider.sharedInstance, true);
						}
					}
			);
			ats.addTest(
					new TestCase(testDir.getName() + ":CSV-FILE") {
						public void runTest() throws Throwable {
							testView(gmonFile, gd, view_samplesFile_RefFile, view_samplesFile_DumpFile, FileHistogramContentProvider.sharedInstance, false);
						}
					}
			);
			ats.addTest(
					new TestCase(testDir.getName() + ":CSV-FILE-TIMED") {
						public void runTest() throws Throwable {
							testView(gmonFile, gd, view_samplesFileT_RefFile, view_samplesFileT_DumpFile, FileHistogramContentProvider.sharedInstance, true);
						}
					}
			);
			ats.addTest(
					new TestCase(testDir.getName() + ":CSV-FUNCTION") {
						public void runTest() throws Throwable {
							testView(gmonFile, gd, view_samplesFunction_RefFile, view_samplesFunction_DumpFile, FunctionHistogramContentProvider.sharedInstance, false);
						}
					}
			);
			ats.addTest(
					new TestCase(testDir.getName() + ":CSV-FUNCTION-TIMED") {
						public void runTest() throws Throwable {
							testView(gmonFile, gd, view_samplesFunctionT_RefFile, view_samplesFunctionT_DumpFile, FunctionHistogramContentProvider.sharedInstance, true);
						}
					}
			);
			ats.addTest(
					new TestCase(testDir.getName() + ":CSV-FLAT") {
						public void runTest() throws Throwable {
							testView(gmonFile, gd, view_samplesFlat_RefFile, view_samplesFlat_DumpFile, FlatHistogramContentProvider.sharedInstance, false);
						}
					}
			);
			ats.addTest(
					new TestCase(testDir.getName() + ":CSV-FLAT-TIMED") {
						public void runTest() throws Throwable {
							testView(gmonFile, gd, view_samplesFlatT_RefFile, view_samplesFlatT_DumpFile, FlatHistogramContentProvider.sharedInstance, true);
						}
					}
			);
		}	
		return ats;
	}


	public static void changeMode(GmonView view, boolean timeModeRequested) {
		AbstractSTTreeViewer gmonViewer = (AbstractSTTreeViewer)view.getSTViewer();
		GmonDecoder decoder = (GmonDecoder) gmonViewer.getInput();
		int prof_rate = decoder.getHistogramDecoder().getProf_rate();
		if (prof_rate == 0) {
			return;
		}

		TreeColumn tc = gmonViewer.getViewer().getTree().getColumn(1);
		SampleProfField spf = (SampleProfField) tc.getData();

		if (spf.getColumnHeaderText().endsWith("Samples") ^ !timeModeRequested) {
			new SwitchSampleTimeAction(view).run();
		}
	}

	public static void testView(File gmonFile, GmonDecoder gd,
			File refFile, File dumpFile,
			ITreeContentProvider contentProvider, boolean timeMode) throws Exception {
		GmonView view = GmonView.displayGprofView(gd, gmonFile.getAbsolutePath(), null);
		SwitchContentProviderAction action = new SwitchContentProviderAction("testAction", "icons/ch_callees.png" /*to avoid error*/, view.getSTViewer().getViewer(), contentProvider);
		action.run();
		changeMode(view, timeMode);
		STJunitUtils.testCSVExport(view, dumpFile.getAbsolutePath(), refFile.getAbsolutePath());
	}
}

Back to the top