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

STL example runs as GCC equivalence test

refs 727
parent 6f648dd8
......@@ -18,6 +18,10 @@ $Id$
package test.org.fortiss.af3.testing.ui.gcctest;
import static org.eclipse.emf.common.util.URI.createPlatformPluginURI;
import static org.fortiss.af3.expression.language.evaluation.NoVal.isNoValConst;
import static org.fortiss.af3.expression.model.terms.impl.BoolConstStaticImpl.FALSE;
import static org.fortiss.af3.expression.model.terms.impl.BoolConstStaticImpl.TRUE;
import static org.fortiss.af3.generator.common.utils.CSourcePackageUtils.findSubPackageByName;
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;
......@@ -30,18 +34,30 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeoutException;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.InputPort;
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.expression.model.types.impl.TBoolStaticImpl;
import org.fortiss.af3.generator.common.model.c.HeaderFile;
import org.fortiss.af3.generator.common.model.c.StaticArray;
import org.fortiss.af3.generator.common.model.source.SourcePackage;
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.model.typesystem.ITerm;
import org.fortiss.af3.project.services.IExecutionService;
import org.fortiss.af3.testing.Af3TestingActivator;
import org.fortiss.af3.testing.model.TestCase;
import org.fortiss.af3.testing.model.TestStep;
import org.fortiss.af3.testing.model.TestSuite;
import org.fortiss.af3.tools.gcc.BuiltProgramRunner;
import org.fortiss.af3.tools.gcc.ConfigureRunner;
import org.fortiss.af3.tools.gcc.MakeRunner;
......@@ -92,8 +108,11 @@ public class CCodeEquivalenceTest {
Executable wrapped = IExecutionService.INSTANCE.prepareExecutable(
deployment, target);
executable = (DeploymentExecutable) wrapped.getExecutableObject();
executable.getSourcePackage().writeToLocation(
targetLocation.getAbsolutePath());
SourcePackage sourcePackage = executable.getSourcePackage();
// addTestcaseCode(deployment, sourcePackage);
sourcePackage.writeToLocation(targetLocation.getAbsolutePath());
copyCodeToTargetLocation();
} catch (ExecutablePreparationFailedException prepex) {
......@@ -103,6 +122,53 @@ public class CCodeEquivalenceTest {
}
}
/** Create the code for the test case specification. */
private void addTestcaseCode(Deployment deployment,
SourcePackage sourcePackage) {
HeaderFile testCaseH = new HeaderFile("TestCase");
findSubPackageByName("inc",
findSubPackageByName("LocalMachine", sourcePackage))
.addSourceUnit(testCaseH);
Component testee = deployment.getComponentAllocations(0).getComponent();
TestSuite tSuite = pickFirstInstanceOf(TestSuite.class,
testee.getSpecificationsList());
// FIXME: generalize
TestCase tc = tSuite.getTestCases(0);
// buffer to create static arrays
HashMap<InputPort, List<ITerm>> buffer = new HashMap<InputPort, List<ITerm>>();
for (InputPort inport : testee.getInputPorts()) {
buffer.put(inport, new ArrayList<ITerm>());
}
// get test inputs
for (int i = 0; i < tc.getTestStepsLength(); i++) {
TestStep curStep = tc.getTestSteps(i);
for (int j = 0; j < curStep.getInputsLength(); j++) {
InputPort inport = tSuite.getInputPorts(j);
ITerm value = curStep.getInputs(j).getValue();
buffer.get(inport).add(value);
}
}
// create arrays
for (InputPort inport : testee.getInputPorts()) {
List<ITerm> novalBuffer = new ArrayList<ITerm>();
List<ITerm> tcValues = buffer.get(inport);
for (ITerm tcVal : tcValues) {
if (isNoValConst(tcVal)) {
novalBuffer.add(TRUE);
} else {
novalBuffer.add(FALSE);
}
}
StaticArray valArray = new StaticArray(inport
.getPortSpecification().getType(), "VALUE_"
+ inport.getName(), tcValues);
testCaseH.addDeclaration(valArray.getDeclaration());
StaticArray novalArray = new StaticArray(TBoolStaticImpl.INSTANCE,
"NOVAL_" + inport.getName(), novalBuffer);
testCaseH.addDeclaration(novalArray.getDeclaration());
}
}
/** Simple test if code generation succeeded. */
@Test
public void codeGenerationTest() {
......@@ -142,13 +208,13 @@ public class CCodeEquivalenceTest {
"./LocalMachine.run", buildDir);
result = localRunner.runTool().get(TIMEOUT_IN_MILLISECONDS);
assertNotNull(result);
assertRunSuccess(result, "Hello world");
// 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" };
String[] headers = new String[] { "InputOutput.h", "TestCase.h" };
copyFiles(headers, headerLocation);
File sourceLocation = new File(targetLocation, "LocalMachine/src");
......
......@@ -2,8 +2,11 @@
#include "inc/InputOutput.h"
void init_InputOutput(void) {
#include "inc/TestCase.h"
#include <stdio.h>
void init_InputOutput(void) {
init_ctrlInRequest();
}
void term_InputOutput(void) {
......@@ -23,43 +26,83 @@ void finish_output_InputOutput(void) {
}
void printTrafficColor(TYPE_TrafficColor value) {
if (value == Green_ID6) {
printf("Green");
}
else if (value == Red_ID7) {
printf("Red");
}
else if (value == RedYellow_ID8) {
printf("RedYellow");
}
else if (value == Yellow_ID9) {
printf("Yellow");
}
}
void printPedestrianColor(TYPE_PedestrianColor value) {
if (value == Stop_ID14) {
printf("Stop");
}
else if (value == Walk_ID15) {
printf("Walk");
}
}
void printSignal(TYPE_Signal value) {
if (value == Present_ID17) {
printf("Present");
}
}
TYPE_boolean is_noval_InputOutput_ctrlInRequest(void) {
return false;
return NOVAL_ctrlInRequest[STEP_COUNTER];
}
TYPE_Signal read_InputOutput_ctrlInRequest(void) {
return Present();
return VALUE_ctrlInRequest[STEP_COUNTER];
}
void set_noval_InputOutput_ctrlOutTrafficSignal(void) {
void set_noval_InputOutput_ctrlOutTrafficSignal(void) {
printf("ctrlOutTrafficSignal=NoVal,");
}
void write_InputOutput_ctrlOutTrafficSignal(TYPE_TrafficColor value) {
printf("ctrlOutTrafficSignal=");
printTrafficColor(value);
printf(",");
}
void set_noval_InputOutput_ctrlOutPedestrianSignal(void) {
printf("ctrlOutPedestrianSignal=NoVal,");
}
void write_InputOutput_ctrlOutPedestrianSignal(TYPE_PedestrianColor value) {
printf("ctrlOutPedestrianSignal=");
printPedestrianColor(value);
printf(",");
}
void set_noval_InputOutput_ctrlOutIndicatorSignalA(void) {
printf("ctrlOutIndicatorSignalA=NoVal,");
}
void write_InputOutput_ctrlOutIndicatorSignalA(TYPE_IndicatorSignal value) {
printf("ctrlOutIndicatorSignalA=");
printSignal(value);
printf(",");
}
void set_noval_InputOutput_ctrlOutIndicatorSignalB(void) {
printf("ctrlOutIndicatorSignalB=NoVal,");
}
void write_InputOutput_ctrlOutIndicatorSignalB(TYPE_IndicatorSignal value) {
printf("ctrlOutIndicatorSignalB=");
printSignal(value);
printf(",");
}
......@@ -28,4 +28,8 @@ extern void write_InputOutput_ctrlOutIndicatorSignalA(TYPE_IndicatorSignal);
extern void set_noval_InputOutput_ctrlOutIndicatorSignalB(void);
extern void write_InputOutput_ctrlOutIndicatorSignalB(TYPE_IndicatorSignal);
extern int STEP_COUNTER;
extern void printTrafficColor(TYPE_TrafficColor);
#endif // __HEADER_InputOutput_h
/* generated by AutoFOCUS 3 (Mon May 21 15:28:28 CEST 2012) */
#ifndef __HEADER_TestCase_h
#define __HEADER_TestCase_h
TYPE_Signal VALUE_ctrlInRequest[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
TYPE_boolean NOVAL_ctrlInRequest[9] = { false, false, false, false, false, false, false, false, false };
void init_ctrlInRequest() {
}
#endif // __HEADER_TestCase_h
......@@ -3,6 +3,13 @@
#include "inc-gen/system.h"
#include <stdio.h>
int STEP_COUNTER = 0;
int MAX_STEP = 9;
int main(int argc, char **argv) {
printf("Hello world %f!\n", 2.0);
initialize_system();
for (STEP_COUNTER = 0; STEP_COUNTER < MAX_STEP; STEP_COUNTER++) {
run_system();
printf("\n");
}
}
Supports Markdown
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