Commit 62135c87 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

moved gcc test

refs 822
parent a12c4847
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test-src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
......
......@@ -7,7 +7,8 @@ Bundle-Activator: org.fortiss.af3.testing.ui.Af3TestingUIActivator
Bundle-Vendor: fortiss GmbH
Require-Bundle: org.fortiss.af3.testing;bundle-version="2.1.0";visibility:=reexport,
org.fortiss.af3.operatorpanel.ui;bundle-version="2.1.0";visibility:=reexport,
org.fortiss.af3.mode.ui;bundle-version="2.1.0";visibility:=reexport
org.fortiss.af3.mode.ui;bundle-version="2.1.0";visibility:=reexport,
org.fortiss.af3.deployment.ui;bundle-version="2.1.0";visibility:=reexport
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.fortiss.af3.testing.ui,
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package test.org.fortiss.af3.testing.ui.gcctest;
import static org.eclipse.emf.common.util.URI.createPlatformPluginURI;
import static org.fortiss.af3.project.utils.FileUtils.loadTextFileFromPlugin;
import static org.fortiss.af3.project.utils.ProjectUtils.loadProjectFromPlugin;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickFirstInstanceOf;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;
import org.fortiss.af3.deployment.generator.DeploymentExecutable;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.deployment.ui.generator.DeploymentGeneratorExecutionTarget;
import org.fortiss.af3.project.extension.IExecutionTarget;
import org.fortiss.af3.project.extension.data.Executable;
import org.fortiss.af3.project.extension.exception.ExecutablePreparationFailedException;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.project.services.IExecutionService;
import org.fortiss.af3.testing.Af3TestingActivator;
import org.fortiss.af3.tools.gcc.BuiltProgramRunner;
import org.fortiss.af3.tools.gcc.ConfigureRunner;
import org.fortiss.af3.tools.gcc.MakeRunner;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for the C code equivalence. These tests are based on the data from
* "test-data/gcctest/*.*"
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: CF9F0DDCB5AB5326BC54C727AF4996E7
*/
public class CCodeEquivalenceTest {
/** The timeout for executing NuSMV once during tests. */
private final static int TIMEOUT_IN_MILLISECONDS = 50000;
/** The test-data area. */
private static final String TEST_DATA_AREA = "test-data/gcctest/";
/** The executable of the deployment generator. */
private DeploymentExecutable executable;
/** The location where the source code is placed. */
private File targetLocation;
/** set-up */
@Before
public void setup() {
targetLocation = new File(System.getProperty("java.io.tmpdir")
+ getClass().getName());
if (targetLocation.exists()) {
targetLocation.delete();
}
FileProject project = loadProjectFromPlugin(
Af3TestingActivator.PLUGIN_ID, TEST_DATA_AREA
+ "ACCRefinementWithLocalMachineDeployment.af3_20",
true);
Deployment deployment = pickFirstInstanceOf(Deployment.class,
project.getRootElementsList());
IExecutionTarget target = IExecutionService.INSTANCE
.getSpecificExecutionTarget(DeploymentGeneratorExecutionTarget.class);
try {
Executable wrapped = IExecutionService.INSTANCE.prepareExecutable(
deployment, target);
executable = (DeploymentExecutable) wrapped.getExecutableObject();
executable.getSourcePackage().writeToLocation(
targetLocation.getAbsolutePath());
copyCodeToTargetLocation();
} catch (ExecutablePreparationFailedException prepex) {
fail(prepex.getMessage());
} catch (IOException ioex) {
fail(ioex.getMessage());
}
}
/** Simple test if code generation succeeded. */
@Test
public void codeGenerationTest() {
assertTrue(targetLocation.isDirectory());
File localMachine = new File(targetLocation, "LocalMachine");
assertTrue(localMachine.isDirectory());
String[] folders = new String[] { "inc-gen", "inc", "src-gen", "src" };
for (String folder : folders) {
assertTrue(new File(localMachine, folder).isDirectory());
}
assertTrue(new File(localMachine, "Makedefs").isFile());
assertTrue(new File(localMachine, "configure").isFile());
System.out.println(targetLocation.getAbsolutePath());
}
/** Configure, make, run test. */
@Test
public void configureMakeRunTest() throws TimeoutException {
ConfigureRunner confRunner = new ConfigureRunner(targetLocation);
List<String> result = confRunner.runTool().get(TIMEOUT_IN_MILLISECONDS);
assertNotNull(result);
assertRunSuccess(result, "Success.");
MakeRunner makeRunner = new MakeRunner(new File(targetLocation,
"Makefile"));
result = makeRunner.runTool().get(TIMEOUT_IN_MILLISECONDS);
assertNotNull(result);
assertFalse(result.contains("Error"));
assertRunSuccess(result, "linking application");
File buildDir = new File(targetLocation, "LocalMachine/build");
assertTrue(buildDir.isDirectory());
assertTrue(new File(buildDir, "LocalMachine.run").exists());
BuiltProgramRunner localRunner = new BuiltProgramRunner(
"LocalMachine.run", buildDir);
result = localRunner.runTool().get(TIMEOUT_IN_MILLISECONDS);
assertNotNull(result);
assertRunSuccess(result, "Hello world");
}
/** Copies the test data files to the target location. */
private void copyCodeToTargetLocation() throws IOException {
File headerLocation = new File(targetLocation, "LocalMachine/inc");
String[] headers = new String[] { "InputOutput.h" };
copyFiles(headers, headerLocation);
File sourceLocation = new File(targetLocation, "LocalMachine/src");
String[] sources = new String[] { "InputOutput.c", "main.c" };
copyFiles(sources, sourceLocation);
}
/** Copy the given files from the plugin to the given target location. */
private void copyFiles(String[] headers, File targetLocation)
throws IOException {
for (String h : headers) {
String src = Af3TestingActivator.PLUGIN_ID + File.separator
+ TEST_DATA_AREA + h;
String srcContent = loadTextFileFromPlugin(createPlatformPluginURI(
src, true));
File target = new File(targetLocation, h);
BufferedWriter targetWriter = new BufferedWriter(new FileWriter(
target));
targetWriter.write(srcContent);
targetWriter.close();
}
}
/** Asserts that configure or make ran successfully. */
private void assertRunSuccess(List<String> output, String successTrigger) {
boolean found = false;
for (String l : output) {
found = found || l.contains(successTrigger);
}
assertTrue(found);
}
}
/* written by hoelzl for AutoFOCUS 3 GCC test. */
#include "inc/InputOutput.h"
void init_InputOutput(void) {
}
void term_InputOutput(void) {
}
void prepare_input_InputOutput(void) {
}
void finish_input_InputOutput(void) {
}
void prepare_output_InputOutput(void) {
}
void finish_output_InputOutput(void) {
}
TYPE_boolean is_noval_InputOutput_SensedSpeedSys(void) {
return false;
}
TYPE_int read_InputOutput_SensedSpeedSys(void) {
return 0;
}
TYPE_boolean is_noval_InputOutput_SensedDistSys(void) {
return false;
}
TYPE_int read_InputOutput_SensedDistSys(void) {
return 0;
}
TYPE_boolean is_noval_InputOutput_SetSpeedSys(void) {
return false;
}
TYPE_SpeedCommand read_InputOutput_SetSpeedSys(void) {
return Hold();
}
TYPE_boolean is_noval_InputOutput_SetDistSys(void) {
return false;
}
TYPE_DistanceMode read_InputOutput_SetDistSys(void) {
return Off();
}
TYPE_boolean is_noval_InputOutput_BreakCmdSys(void) {
return false;
}
TYPE_int read_InputOutput_BreakCmdSys(void) {
return 0;
}
TYPE_boolean is_noval_InputOutput_AccCmdSys(void) {
return false;
}
TYPE_int read_InputOutput_AccCmdSys(void) {
return 0;
}
void set_noval_InputOutput_CmdAccSys(void) {
}
void write_InputOutput_CmdAccSys(TYPE_int value) {
}
/* written by hoelzl for AutoFOCUS 3 GCC test.*/
#ifndef __HEADER_InputOutput_h
#define __HEADER_InputOutput_h
#include "inc-gen/data_dictionary.h"
extern void init_InputOutput(void);
extern void term_InputOutput(void);
extern void prepare_input_InputOutput(void);
extern void finish_input_InputOutput(void);
extern void prepare_output_InputOutput(void);
extern void finish_output_InputOutput(void);
extern TYPE_boolean is_noval_InputOutput_SensedSpeedSys(void);
extern TYPE_int read_InputOutput_SensedSpeedSys(void);
extern TYPE_boolean is_noval_InputOutput_SensedDistSys(void);
extern TYPE_int read_InputOutput_SensedDistSys(void);
extern TYPE_boolean is_noval_InputOutput_SetSpeedSys(void);
extern TYPE_SpeedCommand read_InputOutput_SetSpeedSys(void);
extern TYPE_boolean is_noval_InputOutput_SetDistSys(void);
extern TYPE_DistanceMode read_InputOutput_SetDistSys(void);
extern TYPE_boolean is_noval_InputOutput_BreakCmdSys(void);
extern TYPE_int read_InputOutput_BreakCmdSys(void);
extern TYPE_boolean is_noval_InputOutput_AccCmdSys(void);
extern TYPE_int read_InputOutput_AccCmdSys(void);
extern void set_noval_InputOutput_CmdAccSys(void);
extern void write_InputOutput_CmdAccSys(TYPE_int);
#endif // __HEADER_InputOutput_h
/* written by hoelzl for AutoFOCUS 3 GCC test. */
#include "inc-gen/system.h"
#include <stdio.h>
int main(int argc, char **argv) {
printf("Hello world %f!\n", 2.0);
}
......@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.base;
import static java.lang.System.arraycopy;
import static org.eclipse.core.runtime.Assert.isNotNull;
import static org.eclipse.core.runtime.Assert.isTrue;
......@@ -73,7 +74,7 @@ public abstract class SimpleToolRunnerBase extends ToolRunnerBase<INamedElement,
/** Constructor. */
SimpleToolRunningTask() {
super(SimpleToolRunnerBase.this.physicalFile, new SimpleResultBuilder(),
getCommandList());
computeCmdArray());
}
/** {@inheritDoc} */
......@@ -94,5 +95,14 @@ public abstract class SimpleToolRunnerBase extends ToolRunnerBase<INamedElement,
}
/** The command list for this tool runner. */
public abstract String[] getCommandList();
public abstract String[] getArgumentsList();
/** Creates the command array from tool command and arguments. */
public String[] computeCmdArray() {
String[] args = getArgumentsList();
String[] result = new String[args.length + 1];
arraycopy(args, 0, result, 1, args.length);
result[0] = getToolCommand();
return result;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.tools.gcc;
import static org.conqat.lib.commons.filesystem.FileSystemUtils.readFile;
import static org.eclipse.core.runtime.Assert.isNotNull;
import static org.eclipse.core.runtime.Assert.isTrue;
import java.io.File;
import java.io.IOException;
import org.fortiss.af3.tools.base.SimpleToolRunnerBase;
/**
* Tool runner class for running GCC-built programs.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class BuiltProgramRunner extends SimpleToolRunnerBase {
/** The program to be run. */
private final String program;
/** The arguments for the configure script. */
private final String[] arguments;
/** Constructor. */
public BuiltProgramRunner(String program, File targetDirectory, String[] arguments) {
super(new File(targetDirectory, program));
isTrue(targetDirectory.isDirectory());
isNotNull(arguments);
this.arguments = arguments;
isNotNull(program);
this.program = program;
}
/** Constructor. */
public BuiltProgramRunner(String program, File sourceDirectory) {
this(program, sourceDirectory, new String[0]);
}
/** {@inheritDoc} */
@Override
protected String getToolCommand() {
return program;
}
/** {@inheritDoc} */
@Override
public String[] getArgumentsList() {
return arguments;
}
/**
* {@inheritDoc} Returns the content of the configure script if it exists and can be read.
*/
@Override
public String testToolAvailability() {
try {
return readFile(physicalFile);
} catch(IOException e) {
e.printStackTrace();
}
return null;
}
}
......@@ -55,12 +55,12 @@ public class ConfigureRunner extends SimpleToolRunnerBase {
/** {@inheritDoc} */
@Override
protected String getToolCommand() {
return "configure";
return "./configure";
}
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
public String[] getArgumentsList() {
return arguments;
}
......
......@@ -47,7 +47,7 @@ public class GCCRunner extends GCCToolChainRunnerBase {
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
public String[] getArgumentsList() {
return new String[] {physicalFile.getAbsolutePath()};
}
......
......@@ -49,7 +49,7 @@ public class MakeRunner extends GCCToolChainRunnerBase {
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
public String[] getArgumentsList() {
return new String[0];
}
......
......@@ -48,7 +48,7 @@ public class ShellRunner extends GCCToolChainRunnerBase {
/** {@inheritDoc} */
@Override
public String[] getCommandList() {
public String[] getArgumentsList() {
return new String[] {physicalFile.getAbsolutePath()};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment