void GenerateTestRteHFile(ComponentDefenition compDef, String outputDir) { String FileName = outputDir + "\\" + Properties.Resources.TEST_RTE_H_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, Properties.Resources.TEST_RTE_H_FILENAME, "This file contains structure for provide test environment."); String guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer); /* Add includes */ RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, "Rte_" + compDef.Name + ".h"); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.TEST_FRAMEWORK_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, "<string.h>"); /* Create structure */ CreateTestArtefactStructure(writer, compDef); writer.WriteLine("/* All periodical runnables */"); foreach (PeriodicRunnableDefenition runnable in compDef.Runnables) { writer.WriteLine(RteFunctionsGenerator.Generate_RunnableFunction(compDef, runnable) + ";"); } writer.WriteLine(); writer.WriteLine("/* All server calls */"); CreateRteCallFunctionDeclarations(writer, compDef); writer.WriteLine(); RteFunctionsGenerator.CloseGuardDefine(writer); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void GenerateTestRteCFile(ComponentDefenition compDef, String outputDir) { String FileName = outputDir + "\\" + Properties.Resources.TEST_RTE_C_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, Properties.Resources.TEST_RTE_C_FILENAME, "This file contains function for test environment."); String guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer); /* Add includes */ RteFunctionsGenerator.AddInclude(writer, Properties.Resources.TEST_RTE_H_FILENAME); writer.WriteLine(); /* Declare test structure */ writer.WriteLine(TestArtefactsStructureDataType + " " + TestArtefactsVariable + ";"); writer.WriteLine(); /* Create functions */ CreateRteWriteFunctions(writer, compDef); CreateRteReadFunctions(writer, compDef); CreateRteCDataFunctions(writer, compDef); CreateRtePimFunctions(writer, compDef); CreateRteCallFunctions(writer, compDef); RteFunctionsGenerator.CloseGuardDefine(writer); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void GenerateTestInitializationFile(ComponentDefenition compDef, String outputDir) { String FileName = outputDir + "\\" + Properties.Resources.TEST_INITIALIZATION_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, Properties.Resources.TEST_RTE_C_FILENAME, "This file contains functions for component initialization before each test"); String guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer); /* Add includes */ RteFunctionsGenerator.AddInclude(writer, Properties.Resources.TEST_RTE_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME); writer.WriteLine(); /* Write parameters count as equal value to component instances */ ComponentInstancesList componentInstances = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef); writer.WriteLine("const int " + ParametersCount + " = " + componentInstances.Count.ToString() + ";"); writer.WriteLine(); /* Add function for component variable initialization */ writer.WriteLine("/* User function for variable initialization */"); writer.WriteLine("extern void VariableInitialization();"); writer.WriteLine(); /* Declare test initialization function */ writer.WriteLine("void " + TestInitializationFunctionName + "(int paramIndex)"); writer.WriteLine("{"); /* Clear test structure */ writer.WriteLine(" memset(&" + TestArtefactsVariable + ", 0, sizeof(" + TestArtefactsStructureDataType + " ));"); if (componentInstances.Count > 0) { /* Fill CData constants */ writer.WriteLine(" switch(paramIndex)"); writer.WriteLine(" {"); for (int i = 0; i < componentInstances.Count; i++) { writer.WriteLine(" case " + i.ToString() + ":"); writer.WriteLine(" {"); /* CDATA */ for (int j = 0; j < compDef.CDataDefenitions.Count; j++) { CDataDefenition cdataDef = compDef.CDataDefenitions[j]; CDataInstance cdataInstance = componentInstances[i].CDataInstances.GetCData(cdataDef.GUID); writer.Write(" " + TestArtefactsVariable + "." + RteFunctionsGenerator.GenerateShortCDataFunctionName(cdataDef) + ".Value = "); IGUID datatype = cdataDef.DataType; if ((datatype is BaseDataType) || (datatype is SimpleDataType) || (datatype is EnumDataType)) { RteFunctionsGenerator.WriteDefaultValueForCDataDefenition(writer, componentInstances[i], cdataInstance); } writer.WriteLine(";"); } for (int j = 0; j < compDef.PerInstanceMemoryList.Count; j++) { PimDefenition pimDef = compDef.PerInstanceMemoryList[j]; PimInstance pimInstance = componentInstances[i].PerInstanceMemories.GetPim(pimDef.GUID); WritePIMDefaultValues(writer, pimInstance); } writer.WriteLine(" break;"); writer.WriteLine(" }"); } writer.WriteLine(" }"); } /* Write RTE_OK to all return functions */ foreach (PortDefenition portDef in compDef.Ports) { if (portDef.InterfaceDatatype is SenderReceiverInterface) { SenderReceiverInterface srInterface = (SenderReceiverInterface)portDef.InterfaceDatatype; foreach (SenderReceiverInterfaceField srField in srInterface.Fields) { String fieldName = RteFunctionsGenerator.GenerateReadWriteFunctionName(portDef, srField); writer.WriteLine(" " + TestArtefactsVariable + "." + fieldName + ".ReturnValue = RTE_E_OK;"); } } } writer.WriteLine(); /* Initialize component variables */ writer.WriteLine(" VariableInitialization();"); writer.WriteLine("}"); RteFunctionsGenerator.CloseGuardDefine(writer); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }