Commit 3a4a1d5f authored by Nils Kaminski's avatar Nils Kaminski
Browse files

port value tests

parent f6279b78
Pipeline #79637 failed
......@@ -45,11 +45,24 @@ public class VariablePortValueChecker extends Variable {
int id = 0;
for (VariablePortValueCheckerTestSymbol test : this.testsInitList){
String s = getNameTargetLanguageFormat()+".";
if(test.testType == VariablePortValueCheckerTestSymbolType.EqualsTest){
s += "setEqualsTest("+id+", "+test.value+");\n";
if(test.testType == VariablePortValueCheckerTestSymbolType.EqualsTest) {
s += "set_Test_Equals";
}else if(test.testType == VariablePortValueCheckerTestSymbolType.RangeTest){
s += "set_Test_Range";
}else if(test.testType == VariablePortValueCheckerTestSymbolType.GreaterTest){
s += "set_Test_Greater";
}else if(test.testType == VariablePortValueCheckerTestSymbolType.GreaterEqualsTest){
s += "set_Test_GreaterEquals";
}else if(test.testType == VariablePortValueCheckerTestSymbolType.LowerTest){
s += "set_Test_Lower";
}else if(test.testType == VariablePortValueCheckerTestSymbolType.LowerEqualsTest) {
s += "set_Test_LowerEquals";
}else if(test.testType == VariablePortValueCheckerTestSymbolType.NotEquals){
s += "set_Test_NotEquals";
}else{
continue;
}
s += "(" + id + ", " + test.value + ");\n";
init.addInstruction(new TargetCodeInstruction(s));
......@@ -71,10 +84,43 @@ public class VariablePortValueChecker extends Variable {
);
}
public void addTestSymbol_Range(String lower, String upper){
addTestSymbol(
new VariablePortValueCheckerTestSymbol(lower+", "+upper, VariablePortValueCheckerTestSymbolType.RangeTest)
);
}
public void addTestSymbol_Compare(String operator, String value){
VariablePortValueCheckerTestSymbolType t = VariablePortValueCheckerTestSymbolType.EqualsTest;
if(operator.equals(">")){
t = VariablePortValueCheckerTestSymbolType.GreaterTest;
}else if(operator.equals(">=")){
t = VariablePortValueCheckerTestSymbolType.GreaterEqualsTest;
}else if(operator.equals("<")){
t = VariablePortValueCheckerTestSymbolType.LowerTest;
}else if(operator.equals("<=")){
t = VariablePortValueCheckerTestSymbolType.LowerEqualsTest;
}else if(operator.equals("!=")){
t = VariablePortValueCheckerTestSymbolType.NotEquals;
}
addTestSymbol(
new VariablePortValueCheckerTestSymbol(value, t)
);
}
//<editor-fold desc="VariablePortValueCheckerTestSymbol">
public enum VariablePortValueCheckerTestSymbolType{
EqualsTest
EqualsTest,
RangeTest,
GreaterTest,
GreaterEqualsTest,
LowerTest,
LowerEqualsTest,
NotEquals
}
public class VariablePortValueCheckerTestSymbol{
......
......@@ -10,9 +10,7 @@ import de.monticore.lang.embeddedmontiarcdynamic.event._symboltable.expression.E
import de.monticore.lang.embeddedmontiarcdynamic.event._symboltable.expression.EventExpressionSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.event._symboltable.expression.EventLogicalOperationExpressionSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.event._symboltable.expression.EventPortExpressionValueSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.event._symboltable.expression.portvalueexpressionvalues.PortValueInputSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.event._symboltable.expression.portvalueexpressionvalues.PortValueSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.event._symboltable.expression.portvalueexpressionvalues.PortValuesArraySymbol;
import de.monticore.lang.embeddedmontiarcdynamic.event._symboltable.expression.portvalueexpressionvalues.*;
import de.monticore.lang.math._symboltable.MathStatementsSymbol;
import de.monticore.lang.monticar.generator.Instruction;
import de.monticore.lang.monticar.generator.Method;
......@@ -166,23 +164,36 @@ public class EventConverter {
public static void addTest(PortValueSymbol pvs, VariablePortValueChecker vpvc){
if(pvs instanceof PortValueInputSymbol){
addTestPortValueInputSymbol((PortValueInputSymbol) pvs, vpvc);
// addTestPortValueInputSymbol((PortValueInputSymbol) pvs, vpvc);
vpvc.addTestSymbol_Equals(((PortValueInputSymbol) pvs).getValueStringRepresentation());
}else if(pvs instanceof PortValuesArraySymbol){
PortValuesArraySymbol ar = (PortValuesArraySymbol)pvs;
for(int i = 0; i < ar.size(); ++i){
addTest(ar.getForIndex(i), vpvc);
}
}
}
}else if(pvs instanceof PortValuePrecisionSymbol){
PortValuePrecisionSymbol ps = (PortValuePrecisionSymbol)pvs;
String value = ps.getValue().getValueStringRepresentation();
String prec = ps.getPrecision().getValueStringRepresentation();
vpvc.addTestSymbol_Range("("+value+" - "+prec+")", "("+value+" + "+prec+")");
}else if(pvs instanceof PortValueRangeSymbol){
PortValueRangeSymbol ps = (PortValueRangeSymbol)pvs;
String lower = ps.getLowerBound().getValueStringRepresentation();
String upper = ps.getUpperBound().getValueStringRepresentation();
vpvc.addTestSymbol_Range(lower, upper);
}else if(pvs instanceof PortValueCompareSymbol){
PortValueCompareSymbol compare = (PortValueCompareSymbol)pvs;
vpvc.addTestSymbol_Compare(compare.getOperator(), compare.getCompareValue().getValueStringRepresentation());
public static void addTestPortValueInputSymbol(PortValueInputSymbol pvis, VariablePortValueChecker vpvc){
if(pvis.isLogic()){
vpvc.addTestSymbol_Equals(pvis.isLogicValue() ? "true" : "false");
}
}
//</editor-fold>
}
......@@ -15,73 +15,180 @@ using namespace std;
template <typename T>
class TestsInterface {
public:
virtual bool check(){
return false;
}
virtual bool check(){
return false;
}
};
template <typename T>
class EqualsTest: public TestsInterface<T>{
protected:
T value;
T* refValue;
T value;
T* refValue;
public:
EqualsTest(T val, T* rVal){
value = val;
refValue = rVal;
}
bool check(){
return value == *refValue;
}
EqualsTest(){;}
EqualsTest(T val, T* rVal){
value = val;
refValue = rVal;
}
bool check(){
return value == *refValue;
}
};
template <typename T>
class GreaterTest: public EqualsTest<T>{
public:
GreaterTest(T val, T* rVal) : EqualsTest<T>(val, rVal) {;}
bool check(){
return *(this->refValue) > this->value;
}
};
template <typename T>
class GreaterEqualsTest: public EqualsTest<T>{
public:
GreaterEqualsTest(T val, T* rVal) : EqualsTest<T>(val, rVal) {;}
bool check(){
return *(this->refValue) >= this->value;
}
};
template <typename T>
class LowerTest: public EqualsTest<T>{
public:
LowerTest(T val, T* rVal) : EqualsTest<T>(val, rVal) {;}
bool check(){
return *(this->refValue) < this->value;
}
};
template <typename T>
class LowerEqualsTest: public EqualsTest<T>{
public:
LowerEqualsTest(T val, T* rVal) : EqualsTest<T>(val, rVal) {;}
bool check(){
return *(this->refValue) <= this->value;
}
};
template <typename T>
class NotEqualsTest: public EqualsTest<T>{
public:
NotEqualsTest(T val, T* rVal) : EqualsTest<T>(val, rVal) {;}
bool check(){
return *(this->refValue) != this->value;
}
};
template <typename T>
class RangeTest: public TestsInterface<T>{
protected:
T lowerValue;
T upperValue;
T* refValue;
public:
RangeTest(T lVal, T uVal, T* rVal){
lowerValue = lVal;
upperValue = uVal;
refValue = rVal;
}
bool check(){
return (lowerValue <= *refValue) && (*refValue <= upperValue);
}
};
template < typename T, std::size_t N >
class PortValueCheck {
T* portReference;
T valueHistory[N];
TestsInterface<T>* checkers[N];
bool isChecked = false;
bool checkedValue = false;
bool isNreached = false;
int nCounter = 0;
T* portReference;
T valueHistory[N];
TestsInterface<T>* checkers[N];
bool isChecked = false;
bool checkedValue = false;
bool isNreached = false;
int nCounter = 0;
public:
void setPortReference(T* ref){
this->portReference = ref;
}
void setEqualsTest(int index, T value){
checkers[index] = new EqualsTest<T>(value, &valueHistory[index]);
}
void next(){
for(int i = 0; i < (N-1); ++i){
valueHistory[i] = valueHistory[i+1];
}
valueHistory[N-1] = *portReference;
isChecked = false;
if(isNreached){
return;
}
if(!isNreached && nCounter >= (N-1)){
isNreached = true;
}else{
++nCounter;
}
}
bool check(){
if(!isNreached){
return false;
}
if(isChecked){
return checkedValue;
}
isChecked = true;
for(int i = 0; i < N; ++i){
if(!checkers[i]->check()){
checkedValue = false;
return false;
}
}
checkedValue = true;
return true;
}
void setPortReference(T* ref){
this->portReference = ref;
}
void set_Test_Equals(int index, T value){
checkers[index] = new EqualsTest<T>(value, &valueHistory[index]);
}
void set_Test_Greater(int index, T value){
checkers[index] = new GreaterTest<T>(value, &valueHistory[index]);
}
void set_Test_GreaterEquals(int index, T value){
checkers[index] = new GreaterEqualsTest<T>(value, &valueHistory[index]);
}
void set_Test_Lower(int index, T value){
checkers[index] = new LowerTest<T>(value, &valueHistory[index]);
}
void set_Test_LowerEquals(int index, T value){
checkers[index] = new LowerEqualsTest<T>(value, &valueHistory[index]);
}
void set_Test_NotEquals(int index, T value){
checkers[index] = new NotEqualsTest<T>(value, &valueHistory[index]);
}
void set_Test_Range(int index, T lower, T upper){
checkers[index] = new RangeTest<T>(lower, upper, &valueHistory[index]);
}
void next(){
if(N == 0){
return;
}
for(int i = 0; i < (N-1); ++i){
valueHistory[i] = valueHistory[i+1];
}
valueHistory[N-1] = *portReference;
isChecked = false;
if(isNreached){
return;
}
if(!isNreached && nCounter >= (N-1)){
isNreached = true;
}else{
++nCounter;
}
}
bool check(){
if(!isNreached){
return false;
}
if(isChecked){
return checkedValue;
}
isChecked = true;
for(int i = 0; i < N; ++i){
if(!checkers[i]->check()){
checkedValue = false;
return false;
}
}
checkedValue = true;
return true;
}
};
#endif /* PortValueCheck_h */
#endif /* PortValueCheck_h */
\ No newline at end of file
......@@ -49,4 +49,18 @@ public class DynamicGenerationTest extends AbstractSymtabTest {
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
files.stream().forEach(f -> System.out.println("Generated: "+f.getName()));
}
@Test
public void Test_03_TestEventComponent1() throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/dynamics");
EMAComponentInstanceSymbol componentSymbol = symtab.<EMAComponentInstanceSymbol>resolve("testeventcomponent2.test", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/dynamics/Test_03_TestEventComponent2");
generatorCPP.setGenerateCMake(true);
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
files.stream().forEach(f -> System.out.println("Generated: "+f.getName()));
}
}
package testeventcomponent2;
component Test {
ports
in Q a,
out B b;
connect false -> b;
@ a::value(42) ||
a::value( 123.1 +/- 6 ) ||
a::value( (1234.5:5432.1) ) ||
a::value( [ >1 , >= 2, < 3, <= 4, != 5] )
{
connect true -> b;
}
}
\ No newline at end of file
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