1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 10:15:39 +02:00

Add 6 new tests using 3.0 style build definitions

This commit is contained in:
Leo Treggiari 2005-05-12 19:17:28 +00:00
parent 297e573e08
commit 0839371d4c
21 changed files with 2046 additions and 30 deletions

View file

@ -1,24 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="tests">
<attributes>
</attributes>
</classpathentry>
<classpathentry kind="src" path="suite">
<attributes>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
</attributes>
</classpathentry>
<classpathentry excluding="tests/|suite/" kind="src" path="">
<attributes>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<attributes>
</attributes>
</classpathentry>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="src" path="suite"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,43 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
ROOT := ..
-include $(ROOT)/makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include $(SUBDIRS:%=%/subdir.mk)
-include objects.mk
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
-include $(ROOT)/makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: lib.a
# Tool invocations
lib.a: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: MBS30.archiver.gnu'
@echo ar -r lib.a $(OBJS) $(USER_OBJS) $(LIBS)
@ar -r lib.a $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(ARCHIVES)$(DEPS) lib.a
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include $(ROOT)/makefile.targets

View file

@ -0,0 +1,7 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
LIBS :=
USER_OBJS :=

View file

@ -0,0 +1,14 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
C_SRCS :=
O_SRCS :=
OBJS :=
ARCHIVES :=
DEPS :=
# Every subdirectory with source files must be described here
SUBDIRS := \
. \

View file

@ -0,0 +1,34 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
$(ROOT)/f1.c \
$(ROOT)/f2.c
OBJS += \
${addprefix ./, \
f1.o \
f2.o \
}
DEPS += \
${addprefix ./, \
f1.d \
f2.d \
}
# Each subdirectory must supply rules for building sources it contributes
%.o: $(ROOT)/%.c
@echo 'Building file: $<'
@echo 'Invoking: MBS30.compiler.gnu.c'
@echo gcc -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $<
@gcc -O0 -g3 -Wall -c -fmessage-length=0 -o$@ $< && \
echo -n $(@:%.o=%.d) $(dir $@) > $(@:%.o=%.d) && \
gcc -MM -MG -P -w -O0 -g3 -Wall -c -fmessage-length=0 $< >> $(@:%.o=%.d)
@echo 'Finished building: $<'
@echo ' '

View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include "test_ar.h"
void f1_ar()
{
printf ( "Hello from f1_ar.\n" ) ;
return ;
}

View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include "test_ar.h"
void f2_ar()
{
printf ( "Hello from f2_ar.\n" ) ;
return ;
}

View file

@ -0,0 +1,2 @@
void f1_ar() ;
void f2_ar() ;

View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include "test_ar.h"
void f1_ar()
{
printf ( "Hello from f1_ar.\n" ) ;
return ;
}

View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include "test_ar.h"
void f2_ar()
{
printf ( "Hello from f2_ar.\n" ) ;
return ;
}

View file

@ -0,0 +1,2 @@
void f1_ar() ;
void f2_ar() ;

View file

@ -32,7 +32,6 @@ import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
@ -244,10 +243,7 @@ public class ManagedBuildTestHelper {
static public StringBuffer readContentsStripLineEnds(IProject project, IPath path) {
StringBuffer buff = new StringBuffer();
IFile file = project.getFile(path);
IWorkspaceRoot root = project.getWorkspace().getRoot();
IPath fullPath = root.getLocation();
fullPath = fullPath.append(file.getFullPath());
IPath fullPath = project.getLocation().append(path);
try {
FileReader input = null;
try {
@ -255,7 +251,7 @@ public class ManagedBuildTestHelper {
} catch (Exception e) {
Assert.fail("File " + fullPath.toString() + " could not be read.");
}
//InputStream input = file.getContents(true);
//InputStream input = file.getContents(true); // A different way to read the file...
int c;
do {
c = input.read();
@ -266,7 +262,7 @@ public class ManagedBuildTestHelper {
} while (c != -1);
input.close();
} catch (Exception e) {
Assert.fail("File " + file.toString() + " could not be read.");
Assert.fail("File " + fullPath.toString() + " could not be read.");
}
return buff;
}
@ -362,13 +358,15 @@ public class ManagedBuildTestHelper {
}
static private void deleteDirectory(File dir) {
boolean b;
File[] toDelete = dir.listFiles();
for (int i=0; i<toDelete.length; i++) {
File fileToDelete = toDelete[i];
if (fileToDelete.isDirectory()) {
deleteDirectory(fileToDelete);
}
fileToDelete.delete();
}
b = fileToDelete.delete();
}
b = dir.delete();
}
}

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.managedbuild.core.tests.ManagedCommandLineGeneratorTest;
import org.eclipse.cdt.managedbuild.core.tests.ManagedProjectUpdateTests;
import org.eclipse.cdt.managedbuild.core.tests.ResourceBuildCoreTests;
import org.eclipse.cdt.managedbuild.core.tests.ManagedProject21MakefileTests;
import org.eclipse.cdt.managedbuild.core.tests.ManagedProject30MakefileTests;
import junit.framework.Test;
import junit.framework.TestSuite;
@ -40,6 +41,7 @@ public class AllManagedBuildTests {
suite.addTest(ManagedCommandLineGeneratorTest.suite());
suite.addTest(ResourceBuildCoreTests.suite());
suite.addTest(ManagedProject21MakefileTests.suite());
suite.addTest(ManagedProject30MakefileTests.suite());
//$JUnit-END$
return suite;
}

View file

@ -52,7 +52,10 @@ public class ManagedProject21MakefileTests extends TestCase {
suite.addTest(new ManagedProject21MakefileTests("testSingleFileExe"));
suite.addTest(new ManagedProject21MakefileTests("testTwoFileSO"));
suite.addTest(new ManagedProject21MakefileTests("testMultiResConfig"));
//suite.addTest(new ManagedProject21MakefileTests("testLinkedLib"));
suite.addTest(new ManagedProject21MakefileTests("testLinkedLib"));
// TODO: testLinkedFolder fails intermittently saying that it cannot find
// the makefiles to compare. This appears to be a test set issue,
// rather than an MBS functionality issue
//suite.addTest(new ManagedProject21MakefileTests("testLinkedFolder"));
return suite;
@ -175,6 +178,7 @@ public class ManagedProject21MakefileTests extends TestCase {
try {
if (pathMan.validateName(name).isOK() && pathMan.validateValue(tmpDir).isOK()) {
pathMan.setValue(name, tmpDir);
assertTrue(pathMan.isDefined(name));
} else {
fail("could not create the path variable " + name);
}

View file

@ -0,0 +1,324 @@
/**********************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
**********************************************************************/
/**********************************************************************
* These tests are for a 3.0 style tool integration.
**********************************************************************/
package org.eclipse.cdt.managedbuild.core.tests;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.dialogs.IOverwriteQuery;
public class ManagedProject30MakefileTests extends TestCase {
public static final String MBS_TEMP_DIR = "MBSTemp";
static boolean pathVariableCreated = false;
public ManagedProject30MakefileTests(String name) {
super(name);
}
public static Test suite() {
TestSuite suite = new TestSuite(ManagedProject30MakefileTests.class.getName());
suite.addTest(new ManagedProject30MakefileTests("test30SingleFileExe"));
suite.addTest(new ManagedProject30MakefileTests("test30TwoFileSO"));
suite.addTest(new ManagedProject30MakefileTests("test30MultiResConfig"));
suite.addTest(new ManagedProject30MakefileTests("test30LinkedLib"));
// TODO: testLinkedFolder fails intermittently saying that it cannot find
// the makefiles to compare. This appears to be a test set issue,
// rather than an MBS functionality issue
//suite.addTest(new ManagedProject30MakefileTests("test30LinkedFolder"));
suite.addTest(new ManagedProject30MakefileTests("test30CopyandDeploy"));
return suite;
}
private IProject[] createProject(String projName, IPath location, String projectTypeId, boolean containsZip){
File testDir = CTestPlugin.getFileInPlugin(new Path("resources/test30Projects/" + projName));
if(testDir == null) {
fail("Test project directory " + testDir.getName() + " is missing.");
return null;
}
ArrayList projectList = null;
if (containsZip) {
File projectZips[] = testDir.listFiles(new FileFilter(){
public boolean accept(File pathname){
if(pathname.isDirectory())
return false;
return true;
}
});
projectList = new ArrayList(projectZips.length);
for(int i = 0; i < projectZips.length; i++){
try{
String projectName = projectZips[i].getName();
if(!projectName.endsWith(".zip"))
continue;
projectName = projectName.substring(0,projectName.length()-".zip".length());
if(projectName.length() == 0)
continue;
IProject project = ManagedBuildTestHelper.createProject(projectName, projectZips[i], location, projectTypeId);
if(project != null)
projectList.add(project);
}
catch(Exception e){
}
}
if(projectList.size() == 0) {
fail("No projects found in test project directory " + testDir.getName() + ". The .zip file may be missing or corrupt.");
return null;
}
} else {
try{
IProject project = ManagedBuildTestHelper.createProject(projName, null, location, projectTypeId);
if(project != null)
projectList = new ArrayList(1);
projectList.add(project);
} catch(Exception e){}
}
return (IProject[])projectList.toArray(new IProject[projectList.size()]);
}
private IProject[] createProjects(String projName, IPath location, String projectTypeId, boolean containsZip) {
// In case the projects need to be updated...
IOverwriteQuery queryALL = new IOverwriteQuery(){
public String queryOverwrite(String file) {
return ALL;
}};
IOverwriteQuery queryNOALL = new IOverwriteQuery(){
public String queryOverwrite(String file) {
return NO_ALL;
}};
UpdateManagedProjectManager.setBackupFileOverwriteQuery(queryALL);
UpdateManagedProjectManager.setUpdateProjectQuery(queryALL);
IProject projects[] = createProject(projName, location, projectTypeId, containsZip);
return projects;
}
private void buildProjects(IProject projects[], IPath[] files) {
if(projects == null || projects.length == 0)
return;
for(int i = 0; i < projects.length; i++){
IProject curProject = projects[i];
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(curProject);
//check whether the managed build info is converted
boolean isCompatible = UpdateManagedProjectManager.isCompatibleProject(info);
assertTrue(isCompatible);
if(isCompatible){
// Build the project in order to generate the maekfiles
try{
curProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD,null);
}
catch(CoreException e){
fail(e.getStatus().getMessage());
}
catch(OperationCanceledException e){
fail("the project \"" + curProject.getName() + "\" build was cancelled, exception message: " + e.getMessage());
}
//compare the generated makefiles to their benchmarks
if (files != null && files.length > 0) {
if (i == 0) {
String configName = info.getDefaultConfiguration().getName();
IPath buildDir = Path.fromOSString(configName);
ManagedBuildTestHelper.compareBenchmarks(curProject, buildDir, files);
}
}
}
}
for(int i = 0; i < projects.length; i++)
ManagedBuildTestHelper.removeProject(projects[i].getName());
}
private void createPathVariable(IPath tmpDir) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace = ResourcesPlugin.getWorkspace();
IPathVariableManager pathMan = workspace.getPathVariableManager();
String name = MBS_TEMP_DIR;
try {
if (pathMan.validateName(name).isOK() && pathMan.validateValue(tmpDir).isOK()) {
pathMan.setValue(name, tmpDir);
assertTrue(pathMan.isDefined(name));
} else {
fail("could not create the path variable " + name);
}
} catch (Exception e) {fail("could not create the path variable " + name);}
}
private void createFileLink(IProject project, IPath tmpDir, String linkName, String fileName) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
String name = MBS_TEMP_DIR;
if (!pathVariableCreated) {
createPathVariable(tmpDir);
pathVariableCreated = true;
}
try {
// Now we can create a linked resource relative to the defined path variable:
IFile linkF1 = project.getFile(linkName);
IPath location = new Path("MBSTemp/" + fileName);
if (workspace.validateLinkLocation(linkF1, location).isOK()) {
linkF1.createLink(location, IResource.NONE, null);
} else {
fail("could not create the link to " + name);
}
} catch (Exception e) {fail("could not create the link to " + name);}
}
/* (non-Javadoc)
* tests 3.0 style tool integration for a single file executable
*/
public void test30SingleFileExe(){
IPath[] makefiles = {
Path.fromOSString("makefile"),
Path.fromOSString("objects.mk"),
Path.fromOSString("sources.mk"),
Path.fromOSString("subdir.mk")};
IProject[] projects = createProjects("singleFileExe", null, null, true);
buildProjects(projects, makefiles);
}
/* (non-Javadoc)
* tests 3.0 style tool integration for a two file SO
*/
public void test30TwoFileSO(){
IPath[] makefiles = {
Path.fromOSString("makefile"),
Path.fromOSString("objects.mk"),
Path.fromOSString("sources.mk"),
Path.fromOSString("subdir.mk")};
IProject[] projects = createProjects("twoFileSO", null, null, true);
buildProjects(projects, makefiles);
}
/* (non-Javadoc)
* tests 3.0 style tool integration for multiple source files & a resource configuration
*/
public void test30MultiResConfig(){
IPath[] makefiles = {
Path.fromOSString("makefile"),
Path.fromOSString("objects.mk"),
Path.fromOSString("sources.mk"),
Path.fromOSString("subdir.mk"),
Path.fromOSString("source1/subdir.mk"),
Path.fromOSString("source2/subdir.mk"),
Path.fromOSString("source2/source21/subdir.mk")};
IProject[] projects = createProjects("multiResConfig", null, null, true);
buildProjects(projects, makefiles);
}
/* (non-Javadoc)
* tests 3.0 style tool integration for linked files
*/
public void test30LinkedLib(){
IPath[] makefiles = {
Path.fromOSString("makefile"),
Path.fromOSString("objects.mk"),
//Path.fromOSString("subdir.mk") // Can't compare this yet since it contains absolute paths!
Path.fromOSString("sources.mk")};
IPath[] linkedFiles = {
Path.fromOSString("f1.c"),
Path.fromOSString("f2.c"),
Path.fromOSString("test_ar.h")};
File srcDirFile = CTestPlugin.getFileInPlugin(new Path("resources/test30Projects/linkedLib/"));
IPath srcDir = Path.fromOSString(srcDirFile.toString());
IPath tmpSubDir = Path.fromOSString("CDTMBSTest");
IPath tmpDir = ManagedBuildTestHelper.copyFilesToTempDir(srcDir, tmpSubDir, linkedFiles);
try {
IProject[] projects = createProjects("linkedLib", null, "cdt.managedbuild.target.gnu30.lib", true);
// There should be only one project. Add our linked files to it.
IProject project = projects[0];
createFileLink(project, tmpDir, "f1.c", "f1.c");
createFileLink(project, tmpDir, "f2link.c", "f2.c");
createFileLink(project, tmpDir, "test_ar.h", "test_ar.h");
// Build the project
buildProjects(projects, makefiles);
} finally {ManagedBuildTestHelper.deleteTempDir(tmpSubDir, linkedFiles);}
}
/* (non-Javadoc)
* tests 3.0 style tool integration for a linked folder
*/
public void test30LinkedFolder(){
IPath[] makefiles = {
Path.fromOSString("makefile"),
Path.fromOSString("objects.mk"),
Path.fromOSString("subdir.mk"),
Path.fromOSString("sources.mk")};
IPath[] linkedFiles = {
Path.fromOSString("f1.c"),
Path.fromOSString("f2.c"),
Path.fromOSString("test_ar.h"),
Path.fromOSString("Benchmarks/makefile"),
Path.fromOSString("Benchmarks/objects.mk"),
Path.fromOSString("Benchmarks/subdir.mk"),
Path.fromOSString("Benchmarks/sources.mk")};
File srcDirFile = CTestPlugin.getFileInPlugin(new Path("resources/test30Projects/linkedFolder/"));
IPath srcDir = Path.fromOSString(srcDirFile.toString());
IPath tmpSubDir = Path.fromOSString("CDTMBSTest");
IPath tmpDir = ManagedBuildTestHelper.copyFilesToTempDir(srcDir, tmpSubDir, linkedFiles);
if (!pathVariableCreated) {
createPathVariable(tmpDir);
pathVariableCreated = true;
}
try {
IPath location = Path.fromOSString(MBS_TEMP_DIR);
IProject[] projects = createProjects("linkedFolder", location, "cdt.managedbuild.target.gnu30.lib", false);
// Build the project
buildProjects(projects, makefiles);
} finally {ManagedBuildTestHelper.deleteTempDir(tmpSubDir, linkedFiles);}
}
/* (non-Javadoc)
* tests 3.0 style tool integration with pre and post process steps added to typical compile & link
*/
public void test30CopyandDeploy(){
IPath[] makefiles = {
Path.fromOSString("makefile"),
Path.fromOSString("objects.mk"),
Path.fromOSString("sources.mk"),
Path.fromOSString("subdir.mk"),
Path.fromOSString("Functions/subdir.mk")};
IProject[] projects = createProjects("copyandDeploy", null, null, true);
buildProjects(projects, makefiles);
}
}