Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: df4dd89f48043a18c48f61029b6e51e5431bf001 (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
/*******************************************************************************
 * Copyright (c) 2012 Wind River Systems, Inc. and others. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tests.utils;

import java.io.IOException;

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

import org.eclipse.cdt.utils.elf.Elf;
import org.eclipse.cdt.utils.elf.Elf.ELFhdr;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.tcf.te.core.cdt.elf.ElfUtils;
import org.eclipse.tcf.te.runtime.utils.Host;
import org.eclipse.tcf.te.tests.CoreTestCase;

/**
 * Utility test cases
 */
@SuppressWarnings("restriction")
public class UtilityTestCase extends CoreTestCase {

	/**
	 * Provides a test suite to the caller which combines all single
	 * test bundled within this category.
	 *
	 * @return Test suite containing all test for this test category.
	 */
	public static Test getTestSuite() {
		TestSuite testSuite = new TestSuite("Test utility classes"); //$NON-NLS-1$

			// add ourself to the test suite
			testSuite.addTestSuite(UtilityTestCase.class);

		return testSuite;
	}

	//***** BEGIN SECTION: Single test methods *****
	//NOTE: All method which represents a single test case must
	//      start with 'test'!

    public void testElfUtils() {
		// Test case works on Linux only
		if (!Host.isLinuxHost()) return;

		// Use the Linux agent to test the ELF utilities
		IPath path =  getDataLocation("agent", true, true); //$NON-NLS-1$
		assertNotNull("Unexpected null value from getDataLocation()", path); //$NON-NLS-1$
		path = path.append("agent"); //$NON-NLS-1$
		assertTrue("Test ELF file does not exist or is not readable", path.toFile().canRead()); //$NON-NLS-1$

		Exception error = null;
		String message = null;

		// Get the ELF type and class;
		int type = -1;
		try {
			type = ElfUtils.getELFType(path.toFile());
		} catch (IOException e) {
			error = e;
			message = e.getLocalizedMessage();
		}
		assertNull("Filed to get ELF type. Possible cause: " + message, error); //$NON-NLS-1$
		assertEquals("Unexpected ELF type", Elf.Attribute.ELF_TYPE_EXE, type); //$NON-NLS-1$

		int elfClass = ELFhdr.ELFCLASSNONE;
		try {
			elfClass = ElfUtils.getELFClass(path.toFile());
		} catch (IOException e) {
			error = e;
			message = e.getLocalizedMessage();
		}
		assertNull("Filed to get ELF class. Possible cause: " + message, error); //$NON-NLS-1$
		assertEquals("Unexpected ELF class", "x86_64".equals(Platform.getOSArch()) ? ELFhdr.ELFCLASS64 : ELFhdr.ELFCLASS32, elfClass); //$NON-NLS-1$ //$NON-NLS-2$

		org.eclipse.tcf.te.core.cdt.activator.CoreBundleActivator.getContext();
		org.eclipse.tcf.te.core.cdt.activator.CoreBundleActivator.getUniqueIdentifier();
		org.eclipse.tcf.te.core.cdt.activator.CoreBundleActivator.getTraceHandler();
	}

	//***** END SECTION: Single test methods *****

}

Back to the top