//Create a UPPAAL model from xml XDocument public UppaalModel(XDocument xml, string countermeasure = "") { var nta = xml.Element ("nta"); globalDeclarations = getGlobalDeclarations(nta.Element("declaration").Value); system = getSystem(nta.Element ("system").Value, countermeasure); queries.AddRange(nta.XPathSelectElements("//queries/query/formula").Select(x => x.Value)); XMLHandler xlh = new XMLHandler(xml); templates = xlh.getTemplates();//new List<Template>(); }
public void rewriteLocalFault(string path, string type = "") { string variableName = ""; // "" for locals fault, "opstack" for opstack fault if(type == "") { variableName = "locs"; }else if(type == "opstack") { variableName = "os"; } XElement localsFaultTemplateXML = XElement.Parse(XMLProvider.getFaultInjTemplate()); XMLHandler xhl = new XMLHandler(); Template localsFaultTemplate = xhl.getTemplate(localsFaultTemplateXML); templates.Add(localsFaultTemplate); foreach (var tem in templates) { if (!tem.name.Contains("Fault")) { foreach (var loc in tem.Locations) { if (loc.pc == null) { continue; } foreach (var tr in tem.Transitions) { if (tr.source.id == loc.id ) { if(tr.grds.content != "") { tr.grds.content += " && faultTime > globalClock"; } else { tr.grds.content = "faultTime > globalClock"; } } } string posString1 = string.Format( "{0}[{0}Pos] ^= 1 << {0}BitPos, faultTime = 1000", variableName); string posString2 = string.Format( "{0}Pos:int[0,{0}_size - 1], {0}BitPos:int[0,7]", variableName); Transition locFaultTrans = new Transition(loc, loc, Template.makeLabels("gus", "faultTime <= globalClock", posString1, posString2)); tem.Transitions.Add(locFaultTrans); } } } Save(path); }
public void rewriteHeapFault(string path) { XElement dataFaultTemplateXML = XElement.Parse(XMLProvider.getHeapFaultTemplate()); XMLHandler xhl = new XMLHandler(); Template dataFaultTemplate = xhl.getTemplate(dataFaultTemplateXML); dataFaultTemplate.Locations[1].Committed = true; // todo: generalize this globalDeclarations += "\nclock faultClock;\n"; globalDeclarations += "int bitPosHeap;\n"; globalDeclarations += "broadcast chan f;\n"; templates.Add(dataFaultTemplate); foreach (var te in templates) { // ignore fault template if(te.name.Contains("fault") || te.name.Contains("Fault")) { continue; } foreach (var l in te.Locations) { // if location is not a part of the original program, skip it if (l.pc == null) { continue; } var labs = Template.makeLabels("sgu", "heapIndex:int[0,heap_size - 1]", "faultClock >= faultTime", "setH(heapIndex, H(heapIndex) ^ 1 << bitPosHeap), faultTime = 1000"); Transition heapTransition = new Transition(l, l, labs); te.Transitions.Add(heapTransition); foreach (var l2 in te.Locations) { if (l.id != l2.id) { foreach (var edge in te.Transitions) { if (edge.source.id == l.id && edge.target.id == l2.id) { edge.grds.content += " && faultClock < faultTime"; } } } } } } Save(path); }
public void rewriteInstructionFault(string path) { ByteCodeInstructions insts = new ByteCodeInstructions(); foreach (var tem in templates) { foreach (var loc in tem.Locations) { if(loc.pc == null) { continue; } foreach (var l2 in tem.Locations) { if (loc.id != l2.id) { foreach (var edge in tem.Transitions) { if (edge.source.id == loc.id && edge.target.id == l2.id) { edge.grds.content += " && faultAtId != " + loc.Guid; } } } } // get instruction name and resolve to byte code instruction int index = loc.name.IndexOf("_"); string inst = loc.name.Replace("__", "_");//.Substring(loc.name.IndexOf("_") + 1); inst = Regex.Replace(inst, @"pc\d*_", ""); inst = inst.Replace("\n", ""); string instNotSpecial = Regex.Replace(inst, @"_\d*", ""); BytecodeInstruction bci = insts.instructionToBytecode(inst); BytecodeInstruction bciNotSpecial = insts.instructionToBytecode(instNotSpecial); // for handling special case in instruction, e.g. iconst_0 vs. ifeq 7 if(bciNotSpecial != null) { // special case, overwrite bci bci = bciNotSpecial; } var tempTrans = new List<Transition>(); if(bci == null || bci.relatedInstruction.mnemonic == "") // should we use "" or null for non-valid instruction? { // make transition to error state if invalid instruction var x = tem.idToLocation(Constants.errorLocId); var labs = new List<Label>() { new Label() { content = string.Format("faultAtId == {0}", loc.Guid), kind = "guard" } }; Transition errorTransition = new Transition(loc, x, labs); tempTrans.Add(errorTransition); } if (bci != null && index != -1) { foreach (var edge in tem.Transitions) { // for inst fault edges if (edge.source.id == loc.id && !edge.source.id.Contains("-") && !edge.target.id.Contains("-")) { var a = bci.relatedInstruction; var labs = a.getLabels(); // add guard to distribute probability equally among fault and valid edge Label probLbl = new Label() {content = "faultAtId == " + loc.Guid, kind = "guard", x = loc.x, y = loc.y }; labs.Add(probLbl); int lx = 50, lx2 = 90, ly = 100; Transition tt = new Transition(edge.source, edge.target, labs); List<Transition.Nail> nails = new List<Transition.Nail>(); Transition.Nail nail1 = new Transition.Nail { x = loc.x - lx, y = loc.y - ly }; Transition.Nail nail2 = new Transition.Nail { x = loc.x - lx2, y = loc.y - ly }; nails.Add(nail1); nails.Add(nail2); tt.nails = nails; tempTrans.Add(tt); } } } tem.Transitions.AddRange(tempTrans); } } // add inst fault template XElement instFaultTemplateXML = XElement.Parse(XMLProvider.getInstructionFaultTemplate()); XMLHandler xhl = new XMLHandler(); Template instFaultTemplate = xhl.getTemplate(instFaultTemplateXML); instFaultTemplate.Locations[1].Committed = true; // define number range for fault number Label selectFaultIdLabel = new Label(){content = string.Format("i:int[0,{0}]", XMLHandler.idCount), kind = "select", x = -110, y = -127}; instFaultTemplate.Transitions[0].labels.Add(selectFaultIdLabel); // todo: generalize this globalDeclarations += "\nint faultAtId;\n"; templates.Add(instFaultTemplate); Save(path); }
public void rewritePCFault(string path) { foreach (var te in templates) { te.addFaultTransitions(); } // is this still true??? this has to be first or locations from faultTemplate are not added XElement faultTemplateXML = XElement.Parse(XMLProvider.getFaultTemplate()); XMLHandler xhl = new XMLHandler(); Template faultTemplate = xhl.getTemplate(faultTemplateXML); faultTemplate.Locations[1].Committed = true; templates.Add(faultTemplate); Save(path); }