diff --git a/btypes_primitives/src/main/rust_embedded/btypes/src/binteger.rs b/btypes_primitives/src/main/rust_embedded/btypes/src/binteger.rs index ee58642cf563ba8ace53ce085f2ed0d0a99ce06a..5281ec5b5d8f3673fc2928bedbf314b511f6f996 100644 --- a/btypes_primitives/src/main/rust_embedded/btypes/src/binteger.rs +++ b/btypes_primitives/src/main/rust_embedded/btypes/src/binteger.rs @@ -6,6 +6,7 @@ pub type BInteger = i128; pub trait BInt { fn equal(&self, other: &Self) -> bool; + fn unequal(&self, other: &Self) -> bool; fn greater(&self, other: &Self) -> bool; fn greaterEqual(&self, other: &Self) -> bool; @@ -26,6 +27,7 @@ pub trait BInt { impl BInt for BInteger { fn equal(&self, other: &Self) -> bool { self.eq(&other) } + fn unequal(&self, other: &Self) -> bool { !self.eq(&other) } fn greater(&self, other: &Self) -> bool { self > other } fn greaterEqual(&self, other: &Self) -> bool { self >= other } diff --git a/src/main/resources/de/hhu/stups/codegenerator/RustTemplate_e.stg b/src/main/resources/de/hhu/stups/codegenerator/RustTemplate_e.stg index e21654393bf6e6463d77779fb949d1049d50b9e2..77f849e2d6f2e515ddecfc6bb7591363b24d80ac 100644 --- a/src/main/resources/de/hhu/stups/codegenerator/RustTemplate_e.stg +++ b/src/main/resources/de/hhu/stups/codegenerator/RustTemplate_e.stg @@ -16,6 +16,7 @@ use btypes::brelation::BRelation; use btypes::brelation::RelLeftItem; use btypes::bboolean::BBoolean; use btypes::bboolean::BBool; +use btypes::bboolean::BOOL; use btypes::binteger::BInteger; use btypes::binteger::BInt; @@ -79,7 +80,7 @@ identifier(machine, identifier, isReturn, isPrivate, isLocal, isParam, isAssigne >> getter(returnType, isConstant, machine, variable) ::= << -pub fn _get_<variable>(&self) -> <returnType> { +pub fn get_<variable>(&self) -> <returnType> { return self.<variable>.clone(); } >> @@ -502,7 +503,7 @@ impl <name> { >> bool() ::= << -(*butils::BOOL) +BOOL >> include_declaration(type, identifier) ::= << diff --git a/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestArithmetic.java b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestArithmetic.java new file mode 100644 index 0000000000000000000000000000000000000000..a22ba075942ce9b12d2560c7f1c800a748f32ebf --- /dev/null +++ b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestArithmetic.java @@ -0,0 +1,42 @@ +package de.hhu.stups.codegenerator.rust_embedded; + +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; + +public class TestArithmetic extends TestRSE { + + public TestArithmetic() throws URISyntaxException, IOException {} + + @Test + public void testPlus() throws Exception { + testRSE("arithmetic/Plus", "PlusAddition.strs"); + } + + @Test + public void testMinus2() throws Exception { + testRSE("arithmetic/Minus", "MinusAddition.strs"); + } + + @Test + public void testMultiply2() throws Exception { + testRSE("arithmetic/Multiply","MultiplyAddition.strs"); + } + + @Test + public void testDivide2() throws Exception { + testRSE("arithmetic/Divide", "DivideAddition.strs"); + } + + + @Test + public void testModulo2() throws Exception { + testRSE("arithmetic/Modulo", "ModuloAddition.strs"); + } + + @Test + public void testNegative() throws Exception { + testRSE("arithmetic/Negative", "NegativeAddition.strs"); + } +} diff --git a/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestBenchmarks.java b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestBenchmarks.java new file mode 100644 index 0000000000000000000000000000000000000000..6539d70fc494ec0746cf9b1f50e7b6071851ded7 --- /dev/null +++ b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestBenchmarks.java @@ -0,0 +1,47 @@ +package de.hhu.stups.codegenerator.rust_embedded; + +import org.junit.Ignore; +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; + +public class TestBenchmarks extends TestRSE { + + public TestBenchmarks() throws URISyntaxException, IOException {} + + @Test + public void testLiftBenchmarks() throws Exception { + testRSE("liftbenchmarks/LiftExec", "LiftExecAddition.strs"); + } + + @Test + public void testTrafficLightBenchmarks() throws Exception { + testRSE("trafficlightbenchmarks/TrafficLightExec", "TrafficLightExecAddition.strs"); + } + + @Ignore + @Test //Interger-Set, so unsupported in embedded + public void testSieveBenchmarks() throws Exception { + testRSE("sievebenchmarks/Sieve", "SieveAddition.strs"); + } + + @Ignore + @Test + public void testIncreasingSet() throws Exception { + testRSE("setoperationbenchmarks/IncreasingSet", "IncreasingSetAddition.strs"); + } + + @Ignore + @Test + public void testSetOperation() throws Exception { + testRSE("setoperationbenchmarks/SetOperation", "SetOperationAddition.strs"); + } + + //TODO: CAN_BUS: either allow const-intSet or rewrite machine + + @Test + public void testCruise_finite_deterministic() throws Exception { + testRSE("Cruise_finite1_deterministic_exec", "Cruise_finite1_deterministic_execAddition.strs"); + } +} diff --git a/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestComparison.java b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestComparison.java new file mode 100644 index 0000000000000000000000000000000000000000..06cf7339f5d44bb4b171ceaf3de78ec5d1704b82 --- /dev/null +++ b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestComparison.java @@ -0,0 +1,43 @@ +package de.hhu.stups.codegenerator.rust_embedded; + +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; + +public class TestComparison extends TestRSE { + public TestComparison() throws URISyntaxException, IOException {} + + @Test + public void testLess() throws Exception { + testRSE("comparison/Less", "LessAddition.strs"); + } + + @Test + public void testLessEqual() throws Exception { + testRSE("comparison/LessEqual", "LessEqualAddition.strs"); + } + + @Test + public void testGreater() throws Exception { + testRSE("comparison/Greater", "GreaterAddition.strs"); + } + + + @Test + public void testGreaterEqual() throws Exception { + testRSE("comparison/GreaterEqual", "GreaterEqualAddition.strs"); + } + + + @Test + public void tessEqual() throws Exception { + testRSE("comparison/Equal", "EqualAddition.strs"); + } + + + @Test + public void testUnequal() throws Exception { + testRSE("comparison/Unequal", "UnequalAddition.strs"); + } +} diff --git a/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestIntegers.java b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestIntegers.java new file mode 100644 index 0000000000000000000000000000000000000000..9ca937624afe4081c204da646fc9071ccf569285 --- /dev/null +++ b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestIntegers.java @@ -0,0 +1,21 @@ +package de.hhu.stups.codegenerator.rust_embedded; + +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; + +public class TestIntegers extends TestRSE { + + public TestIntegers() throws URISyntaxException, IOException {} + + @Test + public void testSmallNumbers() throws Exception { + testRSE("integers/SmallNumbers", "SmallNumbersAddition.strs"); + } + + @Test + public void testBigNumbers() throws Exception { + testRSE("integers/BigNumbers", "BigNumbersAddition.strs"); + } +} diff --git a/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestLogical.java b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestLogical.java new file mode 100644 index 0000000000000000000000000000000000000000..4322386cc2e64512a04c8a08c0f2ec8ccd5e6913 --- /dev/null +++ b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestLogical.java @@ -0,0 +1,45 @@ +package de.hhu.stups.codegenerator.rust_embedded; + +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; + +public class TestLogical extends TestRSE { + public TestLogical() throws URISyntaxException, IOException {} + + @Test + public void testAnd2() throws Exception { + testRSE("logical/And","AndAddition.strs"); + } + + @Test + public void testOr2() throws Exception { + testRSE("logical/Or", "OrAddition.strs"); + } + + @Test + public void testImpliesPerformance() throws Exception { + testRSE("logical/Implies", "ImpliesAddition.strs"); + } + + @Test + public void testNot2() throws Exception { + testRSE("logical/Not", "NotAddition.strs"); + } + + @Test + public void testEquivalent2() throws Exception { + testRSE("logical/Equivalent", "EquivalentAddition.strs"); + } + + @Test + public void testBooleanExpression() throws Exception { + testRSE("logical/BooleanExpression", "BooleanExpressionAddition.strs"); + } + + @Test + public void testBooleanConstant() throws Exception { + testRSE("logical/BooleanConstant", "BooleanConstantAddition.strs"); + } +} diff --git a/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestRSE.java b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestRSE.java index 06ebc22df43968b9614acd33eb58e579b03512cd..cffff3fe407bd014e5d28c6748dd1992352d38a0 100644 --- a/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestRSE.java +++ b/src/test/java/de/hhu/stups/codegenerator/rust_embedded/TestRSE.java @@ -36,18 +36,19 @@ public class TestRSE { if (oldFiles != null) Arrays.stream(oldFiles).forEach(File::delete); } - public void generateTestFiles(String machineName, boolean modelChecking, String addition) throws IOException { + public void generateTestFiles(String machineRelPath, boolean modelChecking, String addition) throws IOException { if (addition == null) addition = "DefaultAddition.strs"; cleanup(); - Path machinePath = testFileBasePath.resolve(machineName + ".mch"); + Path machinePath = testFileBasePath.resolve(machineRelPath + ".mch"); List<Path> rsFilePaths = TestHelper.generateCode(machinePath, GeneratorMode.RS, modelChecking, addition, true); rsFilePaths.forEach(path -> { Path dest = rustSrcPath.resolve(Paths.get(path.toFile().getName())); path.toFile().renameTo(dest.toFile()); }); - File mainPath = rustSrcPath.resolve(machineName + ".rs").toFile(); + int i = machineRelPath.lastIndexOf('/'); + File mainPath = rustSrcPath.resolve(machineRelPath.substring(i+1) + ".rs").toFile(); File newMainFile = rustSrcPath.resolve("main.rs").toFile(); mainPath.renameTo(newMainFile); } diff --git a/src/test/resources/de/hhu/stups/codegenerator/Cruise_finite1_deterministic_exec.out b/src/test/resources/de/hhu/stups/codegenerator/Cruise_finite1_deterministic_exec.out new file mode 100644 index 0000000000000000000000000000000000000000..233d8506f5196e2aebd217a01c57bd1259b8f734 --- /dev/null +++ b/src/test/resources/de/hhu/stups/codegenerator/Cruise_finite1_deterministic_exec.out @@ -0,0 +1 @@ +false;false;RSnone;0; \ No newline at end of file diff --git a/src/test/resources/de/hhu/stups/codegenerator/Cruise_finite1_deterministic_execAddition.strs b/src/test/resources/de/hhu/stups/codegenerator/Cruise_finite1_deterministic_execAddition.strs new file mode 100644 index 0000000000000000000000000000000000000000..f774a3b52cc1d758f14cac711e90b5d52c5f7929 --- /dev/null +++ b/src/test/resources/de/hhu/stups/codegenerator/Cruise_finite1_deterministic_execAddition.strs @@ -0,0 +1,8 @@ +fn main() { + let mut cruise = Cruise_finite1_deterministic_exec::new(); + cruise.simulate(); + println!("{};", cruise._Cruise_finite1_deterministic.get_CruiseAllowed()); + println!("{};", cruise._Cruise_finite1_deterministic.get_CruiseActive()); + println!("{:?};", cruise._Cruise_finite1_deterministic.get_ObstacleRelativeSpeed()); + println!("{};", cruise._Cruise_finite1_deterministic.get_NumberOfSetCruise()); +} diff --git a/src/test/resources/de/hhu/stups/codegenerator/integers/SmallNumbersAddition.strs b/src/test/resources/de/hhu/stups/codegenerator/integers/SmallNumbersAddition.strs new file mode 100644 index 0000000000000000000000000000000000000000..02191f8fa908807bddf883f2c7317c11a971d9de --- /dev/null +++ b/src/test/resources/de/hhu/stups/codegenerator/integers/SmallNumbersAddition.strs @@ -0,0 +1,5 @@ +fn main() { + let mut numbers = SmallNumbers::new(); + numbers.simulate(); + println!("{}", numbers.getValue()); +} \ No newline at end of file diff --git a/src/test/resources/de/hhu/stups/codegenerator/logical/BooleanExpression.out b/src/test/resources/de/hhu/stups/codegenerator/logical/BooleanExpression.out index d4375a28ae7ddb7c18c90c3cd94389381c0b2ffc..f32a5804e292d30bedf68f62d32fb75d87e99fd9 100644 --- a/src/test/resources/de/hhu/stups/codegenerator/logical/BooleanExpression.out +++ b/src/test/resources/de/hhu/stups/codegenerator/logical/BooleanExpression.out @@ -1 +1 @@ -5000000 \ No newline at end of file +true \ No newline at end of file