Commit 4f3eaba7 authored by Alexander David Hellwig's avatar Alexander David Hellwig

Merge branch 'StackTrace' into 'master'

Stacktrace

See merge request !32
parents 6f6fa2ba 4bea688f
Pipeline #143118 passed with stages
in 33 minutes and 11 seconds
......@@ -30,23 +30,12 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.1.9</version>
<version>0.1.10</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
<properties>
<!-- .. SE-Libraries .................................................. -->
<!--<monticore.version>5.0.0</monticore.version>-->
<!--<se-commons.version>1.7.7</se-commons.version>-->
<!--<mc.grammars.assembly.version>0.0.6-SNAPSHOT</mc.grammars.assembly.version>-->
<!--<Common-MontiCar.version>0.0.14-SNAPSHOT</Common-MontiCar.version>-->
<!--<Embedded-MontiArc.version>0.0.18-SNAPSHOT</Embedded-MontiArc.version>-->
<!--<Embedded-MontiArc-Behaviour.version>0.0.14-SNAPSHOT</Embedded-MontiArc-Behaviour.version>-->
<!--<Math.version>0.0.19-SNAPSHOT</Math.version>-->
<!--<Embedded-MontiArc-Math.version>0.0.19-SNAPSHOT</Embedded-MontiArc-Math.version>-->
<!--<tagging.version>0.0.4</tagging.version>-->
<Embedded-MontiArc-Math.version>0.1.9-SNAPSHOT</Embedded-MontiArc-Math.version>
<!-- .. Libraries .................................................. -->
......@@ -56,7 +45,6 @@
<jscience.version>4.3.1</jscience.version>
<!-- .. Plugins ....................................................... -->
<!--<monticore.plugin>4.5.3.1</monticore.plugin>-->
<assembly.plugin>2.5.4</assembly.plugin>
<compiler.plugin>3.8.0</compiler.plugin>
<source.plugin>2.4</source.plugin>
......
......@@ -35,6 +35,8 @@ import java.util.Optional;
* @author Sascha Schneiders
*/
public class Variable {
public static final String INCOMING = "Incoming";
public static final String OUTGOING = "outgoing";
public static String FORLOOPINFO = "ForLoopVariable";
public static String VARIABLE = "Variable";
public static String ORIGINPORT = "OriginPort";
......
......@@ -107,7 +107,6 @@ public final class GeneratorCppCli {
.required(false)
.build();
public static final Option OPTION_FLAG_AUTOPILOT_ADAPTER = Option.builder()
.longOpt("flag-generate-autopilot-adapter")
.desc("optional flag indicating if autopilot adapter should be generated")
......@@ -202,6 +201,7 @@ public final class GeneratorCppCli {
g.setUseAlgebraicOptimizations(cliArgs.hasOption(OPTION_FLAG_ALGEBRAIC.getLongOpt()));
g.setUseThreadingOptimization(cliArgs.hasOption(OPTION_FLAG_THREADING.getLongOpt()));
g.setExecutionLoggingActive(cliArgs.hasOption(OPTION_FLAG_EXEC_LOGGING.getLongOpt()));
g.setGenerateCMake(cliArgs.hasOption(OPTION_FLAG_CMAKE.getLongOpt()));
g.setGenerateCMake(cliArgs.hasOption(OPTION_FLAG_CMAKE.getLongOpt()));
......
......@@ -26,15 +26,14 @@ import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.cpp.instruction.ConnectInstructionCPP;
import de.monticore.lang.monticar.generator.order.ImplementExecutionOrder;
import de.monticore.lang.monticar.generator.cpp.template.AllTemplates;
import de.monticore.lang.monticar.generator.cpp.viewmodel.LoggingViewModel;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Symbol;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Sascha Schneiders
......@@ -233,9 +232,7 @@ public class LanguageUnitCPP extends LanguageUnit {
resultString += "{\n";
if (generatorCPP.isExecutionLoggingActive && method.getName().equals("execute")) {
resultString += "std::ofstream __LogExecutionFile;\n";
resultString += "__LogExecutionFile.open(\"execution\" + std::to_string(__EXECCOUNTER) + \""+bluePrint.getOriginalSymbol().getPackageName()+"."+bluePrint.getOriginalSymbol().getName() +".res\");\n";
resultString += "logStart();\n";
}
for (Instruction instruction : method.getInstructions()) {
......@@ -252,25 +249,20 @@ public class LanguageUnitCPP extends LanguageUnit {
}
if (generatorCPP.isExecutionLoggingActive && method.getName().equals("execute")) {
for (Variable v : bluePrint.getVariables()) {
if (v.hasAdditionalInformation(Variable.ORIGINPORT)) {
resultString += "__LogExecutionFile << \"" + v.getNameTargetLanguageFormat() + " : \";\n";
resultString += "toFileString(__LogExecutionFile, " + v.getNameTargetLanguageFormat() + ");\n";
resultString += "__LogExecutionFile << \"\\n\";\n";
}
}
}
if (generatorCPP.isExecutionLoggingActive && method.getName().equals("execute")) {
resultString += "__LogExecutionFile.close();\n";
resultString += "__EXECCOUNTER = __EXECCOUNTER + 1;\n";
resultString += "logEnd();\n";
}
if (generatorCPP.isExecutionLoggingActive && method.getName().equals("init")) {
resultString += "__EXECCOUNTER = 0;\n";
}
//method body end
resultString += "}\n";
if (generatorCPP.isExecutionLoggingActive && method.getName().equals("execute")) {
resultString += AllTemplates.generateLogMethods(LoggingViewModel.fromBluePrint(bluePrint));
}
return resultString;
}
}
......@@ -142,7 +142,7 @@ public final class TestsGeneratorCPP {
String executeTestTplt = "\n# execute tests\n" +
"add_custom_target(run_<name>_StreamTests ALL\n" +
" COMMAND <name>_StreamTests\n" +
" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})";
" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})";
cmake.addCMakeCommandEnd(executeTestTplt.replace("<name>",compName));
}
......
......@@ -85,6 +85,7 @@ public class PortConverter {
variable.setName(name);
variable.setVariableType(TypeConverter.getVariableTypeForMontiCarTypeName(typeNameMontiCar, variable, portSymbol).get());
variable.addAdditionalInformation(Variable.ORIGINPORT);
variable.addAdditionalInformation(portSymbol.isIncoming() ? Variable.INCOMING : Variable.OUTGOING);
bluePrint.getMathInformationRegister().addVariable(variable);
if(portSymbol instanceof EMADynamicPortInstanceSymbol){
......
......@@ -20,13 +20,7 @@
*/
package de.monticore.lang.monticar.generator.cpp.template;
import de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterDataModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ComponentStreamTestViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.EnumViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ServerWrapperViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.StructViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.TestsMainEntryViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ViewModelBase;
import de.monticore.lang.monticar.generator.cpp.viewmodel.*;
import de.se_rwth.commons.logging.Log;
import freemarker.template.Configuration;
import freemarker.template.Template;
......@@ -49,6 +43,7 @@ public final class AllTemplates {
private static final Template DYNAMICS_EVENT_PortValueCheker;
private static final Template DYNAMICS_EVENT_DynamicHelper;
private static final Template LOG_METHODS;
static {
Configuration conf = new Configuration(Configuration.VERSION_2_3_23);
......@@ -66,6 +61,7 @@ public final class AllTemplates {
SERVER_WRAPPER = conf.getTemplate("/serverwrapper/ServerWrapper.ftl");
DYNAMICS_EVENT_PortValueCheker = conf.getTemplate("/dynamics/events_port_value_check_h.ftl");
DYNAMICS_EVENT_DynamicHelper = conf.getTemplate("/dynamics/dynamic_port_request_connect_helper_h.ftl");
LOG_METHODS = conf.getTemplate("logging/Log.ftl");
} catch (IOException e) {
String msg = "could not load templates";
Log.error(msg, e);
......@@ -111,6 +107,9 @@ public final class AllTemplates {
return generateWithoutData(DYNAMICS_EVENT_DynamicHelper);
}
public static String generateLogMethods(LoggingViewModel model){
return generate(LOG_METHODS, model);
}
private static String generate(Template template, ViewModelBase viewModelBase) {
return generate(template, TemplateHelper.getDataForTemplate(viewModelBase));
......
package de.monticore.lang.monticar.generator.cpp.viewmodel;
import de.monticore.ast.ASTNode;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.BluePrint;
import de.monticore.lang.monticar.generator.Variable;
import de.se_rwth.commons.SourcePosition;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class LoggingViewModel extends ViewModelBase {
public List<Variable> variables;
public List<EMAComponentInstanceSymbol> instanceStack;
public EMAComponentInstanceSymbol originalSymbol;
public List<Variable> getVariables() {
return variables;
}
public List<EMAComponentInstanceSymbol> getInstanceStack() {
return instanceStack;
}
public EMAComponentInstanceSymbol getOriginalSymbol() {
return originalSymbol;
}
public static LoggingViewModel fromBluePrint(BluePrint bluePrint){
LoggingViewModel res = new LoggingViewModel();
res.originalSymbol = bluePrint.getOriginalSymbol();
res.variables = bluePrint.getVariables().stream()
.filter(v -> v.hasAdditionalInformation(Variable.ORIGINPORT))
.collect(Collectors.toList());
res.instanceStack = new ArrayList<>();
EMAComponentInstanceSymbol curSym = bluePrint.getOriginalSymbol();
while(curSym != null){
res.instanceStack.add(curSym);
curSym = curSym.getParent().orElse(null);
}
return res;
}
public int getLastLineOfInstance(){
return originalSymbol.getComponentType()
.getReferencedSymbol()
.getAstNode()
.map(ASTNode::get_SourcePositionEnd)
.map(SourcePosition::getLine)
.orElse(1000);
}
public String getTypeStringForVar(Variable var){
String varMontiCoreType = "var";
if(var.hasAdditionalInformation(Variable.INCOMING)){
varMontiCoreType = "in";
}else if(var.hasAdditionalInformation(Variable.OUTGOING)){
varMontiCoreType = "out";
}
return varMontiCoreType;
}
}
void logStart(){
std::ofstream __StacktraceFile;
__StacktraceFile.open("stacktrace.log", std::ios_base::out | std::ios_base::app);
__StacktraceFile << "Breakpoint reached" << std::endl;
<#list viewModel.getInstanceStack() as curSym>
__StacktraceFile << "\tat ${curSym.getFullName()}(${curSym.getComponentType().getReferencedSymbol().getFullName()?replace(".","/")}.emam:1)" << std::endl;
</#list>
__StacktraceFile << "#tick " << __EXECCOUNTER << std::endl;
addVariablesToStream(__StacktraceFile, true, true);
__StacktraceFile << "endBreakpoint" << std::endl;
__StacktraceFile.close();
}
void logEnd(){
std::ofstream __LogExecutionFile;
std::ofstream __StacktraceFile;
__LogExecutionFile.open("execution" + std::to_string(__EXECCOUNTER) + "${viewModel.getOriginalSymbol().getPackageName()}.${viewModel.getOriginalSymbol().getName()}.res");
__StacktraceFile.open("stacktrace.log", std::ios_base::out | std::ios_base::app);
__StacktraceFile << "Breakpoint reached" << std::endl;
<#list viewModel.getInstanceStack() as curSym>
<#if curSym == viewModel.getOriginalSymbol()>
<#assign line=viewModel.getLastLineOfInstance()/>
<#else>
<#assign line="1"/>
</#if>
__StacktraceFile << "\tat ${curSym.getFullName()}(${curSym.getComponentType().getReferencedSymbol().getFullName()?replace(".","/")}.emam:${line})" << std::endl;
</#list>
__StacktraceFile << "#tick " << __EXECCOUNTER << std::endl;
addVariablesToStream(__StacktraceFile, true, false);
__StacktraceFile << "endBreakpoint" << std::endl;
addVariablesToStream(__LogExecutionFile, false, false);
__StacktraceFile.close();
__LogExecutionFile.close();
__EXECCOUNTER = __EXECCOUNTER + 1;
}
void addVariablesToStream(std::ofstream& stream, bool type, bool onlyIncoming){
<#list viewModel.getVariables() as var>
<#assign type=viewModel.getTypeStringForVar(var)/>
<#if type != "in">
if(!onlyIncoming){
</#if>
stream << (type ? "${type} ${var.getVariableType().getTypeNameMontiCar()} " : "");
stream << "${var.getNameTargetLanguageFormat()} : ";
toFileString(stream, ${var.getNameTargetLanguageFormat()});
stream << std::endl;
<#if type != "in">
}
</#if>
</#list>
}
\ No newline at end of file
......@@ -131,10 +131,13 @@ void test_case_${stream.name?replace(".","_")}(){
</#list>
int runTest(){
std::ofstream __StacktraceFile;
<#list viewModel.streams as stream>
assertions = 0;
failedAssertions = 0;
__StacktraceFile.open("stacktrace.log", std::ios_base::out | std::ios_base::app);
__StacktraceFile << "~Entering ${stream.name}" << std::endl;
__StacktraceFile.close();
test_case_${stream.name?replace(".","_")}();
overallAssertions += assertions;
......
......@@ -3,6 +3,7 @@
#ifndef TESTS_MAIN
#define TESTS_MAIN
#include <iostream>
#include <stdio.h>
<#list viewModel.includes as i>
#include "${i}"
......@@ -10,6 +11,7 @@
int main(){
std::cout << "=================Start stream testing=================" << std::endl;
remove("stacktrace.log");
int errorCode = 0;
<#list viewModel.includes as i>
errorCode += ${i?replace(".hpp","")}::runTest();
......
......@@ -33,4 +33,4 @@ set_target_properties(test_basicPortsMath_StreamTests PROPERTIES LINKER_LANGUAG
# execute tests
add_custom_target(run_test_basicPortsMath_StreamTests ALL
COMMAND test_basicPortsMath_StreamTests
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
......@@ -156,9 +156,12 @@ void test_case_test_BasicPortsMath(){
}
int runTest(){
std::ofstream __StacktraceFile;
assertions = 0;
failedAssertions = 0;
__StacktraceFile.open("stacktrace.log", std::ios_base::out | std::ios_base::app);
__StacktraceFile << "~Entering test.BasicPortsMath" << std::endl;
__StacktraceFile.close();
test_case_test_BasicPortsMath();
overallAssertions += assertions;
......
......@@ -2,11 +2,13 @@
#ifndef TESTS_MAIN
#define TESTS_MAIN
#include <iostream>
#include <stdio.h>
#include "test_basicPortsMath_test.hpp"
int main(){
std::cout << "=================Start stream testing=================" << std::endl;
remove("stacktrace.log");
int errorCode = 0;
errorCode += test_basicPortsMath_test::runTest();
std::cout << "==================End stream testing==================" << std::endl;
......
......@@ -33,4 +33,4 @@ set_target_properties(test_math_floatDivisionTest_StreamTests PROPERTIES LINKER
# execute tests
add_custom_target(run_test_math_floatDivisionTest_StreamTests ALL
COMMAND test_math_floatDivisionTest_StreamTests
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
......@@ -123,9 +123,12 @@ void test_case_test_math_FloatDivisionTest(){
}
int runTest(){
std::ofstream __StacktraceFile;
assertions = 0;
failedAssertions = 0;
__StacktraceFile.open("stacktrace.log", std::ios_base::out | std::ios_base::app);
__StacktraceFile << "~Entering test.math.FloatDivisionTest" << std::endl;
__StacktraceFile.close();
test_case_test_math_FloatDivisionTest();
overallAssertions += assertions;
......
......@@ -2,11 +2,13 @@
#ifndef TESTS_MAIN
#define TESTS_MAIN
#include <iostream>
#include <stdio.h>
#include "test_math_floatDivisionTest_test.hpp"
int main(){
std::cout << "=================Start stream testing=================" << std::endl;
remove("stacktrace.log");
int errorCode = 0;
errorCode += test_math_floatDivisionTest_test::runTest();
std::cout << "==================End stream testing==================" << std::endl;
......
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