Skip to content
Snippets Groups Projects
Commit efb727bf authored by René Schöne's avatar René Schöne
Browse files

Move tests to separate Gradle module.

parent e2b5d7e1
No related branches found
No related tags found
No related merge requests found
......@@ -157,5 +157,3 @@ jastadd {
}
generateAst.dependsOn relast
apply from: 'test.build.gradle'
......@@ -71,12 +71,17 @@ public class Compiler {
printMessage("Writing output files");
// copy MqttUpdater into outputDir
final String mqttUpdaterFileName = "MqttUpdater.jadd";
try {
Files.copy(Paths.get("src", "main", "resources", "MqttUpdater.jadd"),
Paths.get(outputDir, "MqttUpdater.jadd"),
InputStream inputStream = Compiler.class.getClassLoader().getResourceAsStream(mqttUpdaterFileName);
if (inputStream == null) {
throw new CompilerException("Could not open " + mqttUpdaterFileName);
}
Files.copy(inputStream,
Paths.get(outputDir, mqttUpdaterFileName),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new CompilerException("Could not copy MqttUpdater.java", e);
throw new CompilerException("Could not copy " + mqttUpdaterFileName, e);
}
writeToFile(outputDir + "/Grammar.relast", ros2Rag.getProgram().generateAbstractGrammar());
writeToFile(outputDir + "/ROS2RAG.jadd", ros2Rag.generateAspect(optionRootNode.getValue()));
......
02-after-ros2rag/*
03-after-relast/*
java-gen/*
aspect GrammarTypes {
public class IntPosition {
private final int x, y, z;
private IntPosition(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public static IntPosition of(int x, int y, int z) {
return new IntPosition(x, y, z);
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IntPosition that = (IntPosition) o;
return x == that.x &&
y == that.y &&
z == that.z;
}
@Override
public int hashCode() {
return java.util.Objects.hash(x, y, z);
}
@Override
public String toString() {
return "(" + x + ", " + y + ", " + z + ")";
}
}
}
Model ::= RobotArm ZoneModel ;
ZoneModel ::= <Size:IntPosition> SafetyZone:Zone* ;
Zone ::= Coordinate* ;
RobotArm ::= Joint* EndEffector <AttributeTestSource:int> /<AppropriateSpeed:double>/ ; // normally this would be: <AttributeTestSource:int> ;
Joint ::= <Name:String> <CurrentPosition:IntPosition> ; // normally this would be: <CurrentPosition:IntPosition>
EndEffector : Joint;
Coordinate ::= <Position:IntPosition> ;
/* Version 2020-04-17 */
// --- update definitions ---
read Joint.CurrentPosition using ParseLinkState, LinkStateToIntPosition ;
write RobotArm.AppropriateSpeed using CreateSpeedMessage, SerializeRobotConfig ;
// --- dependency definitions ---
RobotArm.AppropriateSpeed canDependOn Joint.CurrentPosition as dependency1 ;
RobotArm.AppropriateSpeed canDependOn RobotArm.AttributeTestSource as dependency2 ;
// --- mapping definitions ---
ParseLinkState maps byte[] bytes to panda.Linkstate.PandaLinkState {:
return panda.Linkstate.PandaLinkState.parseFrom(bytes);
:}
SerializeRobotConfig maps config.Robotconfig.RobotConfig rc to byte[] {:
return rc.toByteArray();
:}
LinkStateToIntPosition maps panda.Linkstate.PandaLinkState pls to IntPosition {:
panda.Linkstate.PandaLinkState.Position p = pls.getPos();
{ int i = 0; }
return IntPosition.of((int) p.getPositionX(), (int) p.getPositionY(), (int) p.getPositionZ());
:}
CreateSpeedMessage maps double speed to config.Robotconfig.RobotConfig {:
return config.Robotconfig.RobotConfig.newBuilder()
.setSpeed(speed)
.build();
:}
syntax = "proto3";
package panda;
message PandaLinkState {
string name = 1;
message Position {
float positionX = 1;
float positionY = 2;
float positionZ = 3;
}
message Orientation {
float orientationX = 1;
float orientationY = 2;
float orientationZ = 3;
float orientationW = 4;
}
message TwistLinear {
float twistLinearX = 1;
float twistLinearY = 2;
float twistLinearZ = 3;
}
message TwistAngular {
float twistAngularX = 1;
float twistAngularY = 2;
float twistAngularZ = 3;
}
Position pos = 2;
Orientation orient = 3;
TwistLinear tl = 4;
TwistAngular ta = 5;
}
syntax = "proto3";
package config;
message RobotConfig {
double speed = 1;
bool loopTrajectory = 2;
enum PlanningMode {
FLUID = 0;
CARTESIAN = 1;
}
PlanningMode planningMode = 3;
}
package org.jastadd.ros2rag.tests;
import example.ast.*;
import org.junit.jupiter.api.Test;
/**
* Test case "example".
*
* @author rschoene - Initial contribution
*/
public class ExampleTest {
@Test
public void buildModel() {
Model model = new Model();
model.MqttSetHost("localhost");
ZoneModel zoneModel = new ZoneModel();
zoneModel.setSize(makePosition(1, 1, 1));
IntPosition myPosition = makePosition(0, 0, 0);
Coordinate myCoordinate = new Coordinate(myPosition);
Coordinate leftPosition = new Coordinate(makePosition(-1, 0, 0));
Coordinate rightPosition = new Coordinate(makePosition(1, 0, 0));
Zone safetyZone = new Zone();
safetyZone.addCoordinate(myCoordinate);
safetyZone.addCoordinate(leftPosition);
safetyZone.addCoordinate(rightPosition);
zoneModel.addSafetyZone(safetyZone);
model.setZoneModel(zoneModel);
RobotArm robotArm = new RobotArm();
robotArm.setAttributeTestSource(1); // set initial value, no trigger
Joint joint1 = new Joint();
joint1.setName("joint1");
joint1.setCurrentPosition(myPosition);
EndEffector endEffector = new EndEffector();
endEffector.setName("gripper");
endEffector.setCurrentPosition(makePosition(2, 2, 3));
robotArm.addJoint(joint1);
robotArm.setEndEffector(endEffector);
model.setRobotArm(robotArm);
// add dependencies
robotArm.addDependency1(joint1);
robotArm.addDependency1(endEffector);
robotArm.addDependency2(robotArm);
}
private static IntPosition makePosition(int x, int y, int z) {
return IntPosition.of(x, y, z);
}
}
package org.jastadd.ros2rag.tests;
import org.jastadd.ros2rag.compiler.Compiler;
import org.jastadd.ros2rag.compiler.options.CommandLine;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.nio.file.Paths;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Disabled("migrating build logic from test to build, this test is disabled for now")
public class RosToRagTest {
void transform(String inputGrammar, String inputRos2Rag, String rootNode, String outputDir) throws CommandLine.CommandLineException, Compiler.CompilerException {
System.out.println(Paths.get(".").toAbsolutePath());
assertTrue(Paths.get(inputGrammar).toFile().exists(), "input grammar does not exist");
File outputDirFile = Paths.get(outputDir).toFile();
if (outputDirFile.exists()) {
assertTrue(outputDirFile.isDirectory());
if (Objects.requireNonNull(outputDirFile.list(), "Could not read output directory").length != 0) {
System.out.println("output directory is not empty!");
}
} else {
assertTrue(outputDirFile.mkdir());
}
String[] args = {
"--outputDir=" + outputDir,
"--inputGrammar=" + inputGrammar,
"--inputRos2Rag=" + inputRos2Rag,
"--rootNode=" + rootNode
};
new Compiler().run(args);
}
@Test
void transformMinimalExample() throws CommandLine.CommandLineException, Compiler.CompilerException {
transform("src/test/resources/Example.relast",
"src/test/resources/Example.ros2rag",
"Model",
"src/test/resources/out");
}
}
import org.jastadd.relast.plugin.RelastPlugin
import org.jastadd.relast.plugin.RelastTest
apply plugin: RelastPlugin
relastTest {
compilerLocation = '../libs/relast.jar'
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
testImplementation 'org.assertj:assertj-core:3.12.1'
testImplementation group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version: '1.15'
testImplementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
testImplementation 'com.google.protobuf:protobuf-java:3.0.0'
}
sourceSets {
test {
java.srcDir "src/test/java-gen"
}
}
task preprocessExampleTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/02-after-ros2rag/example/Grammar.relast',
'src/test/02-after-ros2rag/example/MqttUpdater.java',
'src/test/02-after-ros2rag/example/ROS2RAG.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.ros2rag.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args '--outputDir=src/test/02-after-ros2rag/example',
'--inputGrammar=src/test/01-input/example/Example.relast',
'--inputRos2Rag=src/test/01-input/example/Example.ros2rag',
'--rootNode=Model'
}
//task compileExampleTest(type: JavaExec, group: 'verification') {
//
// doFirst {
// delete 'src/test/java-gen/example'
// }
//
// classpath = sourceSets.main.runtimeClasspath
// main = 'org.jastadd.JastAdd'
// //noinspection GroovyAssignabilityCheck
// args '--o=src/test/java-gen/', '--package=example.ast',
// 'src/test/jastadd-gen/example/Grammar.relast',
// 'src/test/jastadd-gen/example/MqttUpdater.java',
// 'src/test/jastadd-gen/example/ROS2RAG.jadd',
// 'src/test/jastadd/Example.jadd'
//}
task compileExampleTest(type: RelastTest) {
verbose = true
relastFiles 'src/test/02-after-ros2rag/example/Grammar.relast'
grammarName = 'src/test/03-after-relast/example/example'
packageName = 'example.ast'
moreInputFiles 'src/test/01-input/example/Example.jadd',
'src/test/02-after-ros2rag/example/MqttUpdater.jadd',
'src/test/02-after-ros2rag/example/ROS2RAG.jadd'
}
test.dependsOn compileExampleTest
compileExampleTest.dependsOn preprocessExampleTest
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment