public List <VerifyResult> SyncVerify(List <ArchDesignConfig> designSet) { PATUtil util = new PATUtil(); // generate CSP Code resultSet = new List <VerifyResult>(); List <ThreadedVerificationExecuter <VerifyResult> > threadsList = new List <ThreadedVerificationExecuter <VerifyResult> >(); ThreadedVerificationExecuter <VerifyResult> thread; PAT.CSP.ModuleFacade modulebase = new PAT.CSP.ModuleFacade(); foreach (ArchDesignConfig designConfig in designSet) { VerifyAsset verifyAsset = util.GenerateAsset(designConfig.matrix); SpecificationBase specbase = modulebase.ParseSpecification(verifyAsset.CSPCode, string.Empty, string.Empty); thread = new ThreadedVerificationExecuter <VerifyResult>(collectVerifyResult, verifyAsset, specbase); threadsList.Add(thread); thread.Start(); } while (resultSet.Count < designSet.Count) { System.Diagnostics.Debug.WriteLine("Waiting for result " + resultSet.Count); } return(resultSet); }
private VerifyAsset InsertMoreLivelockCheck(VerifyAsset asset, List <ArchMatrix> matrix, string firstCallID, string lastCallID) { StringBuilder cspLivelockCheck = new StringBuilder(); List <string> livelockAssertList = new List <String>(); cspLivelockCheck.AppendLine(""); for (var i = 0; i < matrix.Count; i++) { // grad component in the middle of trace if (!matrix[i].ID.Equals(firstCallID) && !matrix[i].ID.Equals(lastCallID)) { string assert = "System() |= []<>( request." + firstCallID + "-> request." + matrix[i].ID + ")&&[]( request." + matrix[i].ID + "-> invoke." + lastCallID + ")"; cspLivelockCheck.AppendLine("#assert " + assert + ";"); livelockAssertList.Add(assert); System.Diagnostics.Debug.WriteLine("@" + assert + "@"); } } asset.CSPCode = asset.CSPCode + cspLivelockCheck.ToString(); asset.livelockCheck = livelockAssertList; return(asset); }
public VerifyResult AsyncVerify(List <ArchMatrix> matrix) { PATUtil util = new PATUtil(); // generate CSP Code VerifyAsset verifyAsset = util.GenerateAsset(matrix); int totalAsert = verifyAsset.deadloopCheck.Count + verifyAsset.livelockCheck.Count; System.Diagnostics.Debug.WriteLine("total Assertion" + totalAsert); //initialize CSP module with CSP Code PAT.CSP.ModuleFacade modulebase = new PAT.CSP.ModuleFacade(); Stopwatch sw = new Stopwatch(); sw.Start(); SpecificationBase specbase = modulebase.ParseSpecification(verifyAsset.CSPCode, string.Empty, string.Empty); // run assertions and gather results results = new ConcurrentBag <DiagnosisResult>(); foreach (String assertionName in verifyAsset.deadloopCheck) { results.Add(util.executeAssertion(specbase, assertionName)); } foreach (String assertionName in verifyAsset.livelockCheck) { results.Add(util.executeAssertion(specbase, assertionName)); } sw.Stop(); VerifyResult verResult = new VerifyResult(); verResult.elapseTime = sw.ElapsedMilliseconds; verResult.diagnosisList = results; System.Diagnostics.Debug.WriteLine("Total Result" + results.Count); return(verResult); }
private List <DiagnosisResult> executeVerification(List <ArchMatrix> matrix) { VerifyAsset verifyAsset = GenerateAsset(matrix); System.Diagnostics.Debug.WriteLine(verifyAsset.CSPCode); try { PAT.CSP.ModuleFacade modulebase = new PAT.CSP.ModuleFacade(); SpecificationBase Spec = modulebase.ParseSpecification(verifyAsset.CSPCode, string.Empty, string.Empty); System.Diagnostics.Debug.WriteLine("Specification Loaded..."); //print assertion for debugging List <KeyValuePair <string, AssertionBase> > asrtlists = Spec.AssertionDatabase.ToList(); foreach (KeyValuePair <string, AssertionBase> asrt in asrtlists) { System.Diagnostics.Debug.WriteLine("#" + asrt.Key + "#"); } List <DiagnosisResult> diagnosisList = new List <DiagnosisResult>(); // Verify deadlock loop bool deadlockFound = false; for (var i = 0; i < verifyAsset.deadloopCheck.Count; i++) { AssertionBase assertion = Spec.AssertionDatabase[verifyAsset.deadloopCheck[i]]; DiagnosisResult result = RunAssertion(assertion, 1, 0); if (!result.IsValid && result.Scenario != null && result.LoopIndex > -1) { deadlockFound = true; result.Symptom = "deadloop"; diagnosisList.Add(result); } } // Verify livelock, if deadlock is not found if (!deadlockFound) { bool livelockFound = false; string prevScenario = null; bool isAllSameScenario = true; List <DiagnosisResult> normalList = new List <DiagnosisResult>(); for (var i = 0; i < verifyAsset.livelockCheck.Count; i++) { AssertionBase assertion = Spec.AssertionDatabase[verifyAsset.livelockCheck[i]]; DiagnosisResult result = RunAssertion(assertion, 0, 0); if (!result.IsValid && result.Scenario != null && hasDuplilcateInvoke(result.Scenario)) { if (result.LoopIndex > -1) { result.Symptom = "deadloop"; } else { result.Symptom = "livelock"; } diagnosisList.Add(result); livelockFound = true; } else if (!result.IsValid && result.Scenario != null) { result.Symptom = "normal"; normalList.Add(result); if (prevScenario != null && !prevScenario.Equals(result.Scenario)) { isAllSameScenario = false; } } prevScenario = result.Scenario; System.Diagnostics.Debug.WriteLine("prevScenario : " + prevScenario); } // in case normal and all same scenario, try to generate more simulation for normal case if (!livelockFound) { diagnosisList.AddRange(normalList); if (isAllSameScenario) { diagnosisList.AddRange(normalList); string firstId = prevScenario.Substring(prevScenario.IndexOf(".") + 1, 3); string lastId = prevScenario.Substring(prevScenario.LastIndexOf(".") + 1); System.Diagnostics.Debug.WriteLine("firstId : " + firstId); System.Diagnostics.Debug.WriteLine("lastId : " + lastId); verifyAsset = InsertMoreLivelockCheck(verifyAsset, matrix, firstId, lastId); Spec = modulebase.ParseSpecification(verifyAsset.CSPCode, string.Empty, string.Empty); asrtlists = Spec.AssertionDatabase.ToList(); foreach (KeyValuePair <string, AssertionBase> asrt in asrtlists) { System.Diagnostics.Debug.WriteLine("#" + asrt.Key + "#"); } for (var i = 0; i < verifyAsset.livelockCheck.Count; i++) { AssertionBase assertion = Spec.AssertionDatabase[verifyAsset.livelockCheck[i]]; DiagnosisResult result = RunAssertion(assertion, 0, 0); if (!result.IsValid && result.Scenario != null) { result.Symptom = "normal"; diagnosisList.Add(result); } } } } } List <DiagnosisResult> rs = checkLivelockBetweenResult(diagnosisList); if (rs.Count != 0) { diagnosisList = rs; } return(diagnosisList); } catch (Exception ex) { System.Diagnostics.Trace.TraceError(ex.Message); System.Diagnostics.Trace.TraceError(ex.StackTrace); } return(null); }
private VerifyAsset GenerateAsset(List <ArchMatrix> matrix) { StringBuilder cspComponent = new StringBuilder(); StringBuilder cspMatrix = new StringBuilder(); StringBuilder cspStartSimulate = new StringBuilder(); StringBuilder cspDeadLockCheck = new StringBuilder(); StringBuilder cspLTLCheck = new StringBuilder(); List <string> livelockAssertList = new List <String>(); List <string> deadlockAssertList = new List <String>(); Dictionary <int, int> compDict = new Dictionary <int, int>(); // generate csp for component declaration for (var i = 0; i < matrix.Count; i++) { cspComponent.Append(matrix[i].ID); //cspDeadLockCheck.Append("invokecount["+i+"]"); // generate code to verify deadlock string deadlockAssert = "System() |= []<> request." + matrix[i].ID; cspDeadLockCheck.AppendLine("#assert " + deadlockAssert + ";"); deadlockAssertList.Add(deadlockAssert); compDict.Add(matrix[i].ID, i); if (i != matrix.Count - 1) { cspComponent.Append(","); } if (matrix[i].IsStartCaller) { // start simulate in concurrent if there is more than one start caller if (cspStartSimulate.Length > 0) { cspStartSimulate.Append(" ||| "); } cspStartSimulate.Append("Request(" + i + ")"); } } // generate csp for matrix for (var i = 0; i < matrix.Count; i++) { for (var j = 0; j < matrix.Count; j++) { //System.Diagnostics.Debug.WriteLine("prc mat: " + matrix[i].Calls[j]); if (matrix[i].Calls != null && j < matrix[i].Calls.Count) { cspMatrix.Append("reqmat[" + i + "][" + j + "] = " + compDict[matrix[i].Calls[j]] + ";"); } else { cspMatrix.Append("reqmat[" + i + "][" + j + "] = " + -1 + ";"); } // Generate code to verify livelock if (i != j && matrix[i].IsStartCaller && !matrix[j].IsStartCaller) { string assertionName = "System() |= []( invoke." + matrix[i].ID + "-><> request." + matrix[j].ID + ")"; cspLTLCheck.AppendLine("#assert " + assertionName + ";"); livelockAssertList.Add(assertionName); } } } string templatePath = System.Web.HttpContext.Current.Request.MapPath("~\\CSP\\com-tier-tracematrix.csp"); // read template and replace code with dynamic generated string templateTxt = File.ReadAllText(templatePath); StringBuilder cspCode = new StringBuilder(templateTxt); cspCode.Replace("/**COMPONENTNUMBER**/", matrix.Count.ToString()); cspCode.Replace("/**COMPONENTLIST**/", cspComponent.ToString()); cspCode.Replace("/**MATRIX**/", cspMatrix.ToString()); cspCode.Replace("/**START**/", cspStartSimulate.ToString()); cspCode.Replace("/**DEADLOCKCHECK**/", cspDeadLockCheck.ToString()); cspCode.Replace("/**LTLCHECK**/", cspLTLCheck.ToString()); VerifyAsset asset = new VerifyAsset(); asset.CSPCode = cspCode.ToString(); asset.deadloopCheck = deadlockAssertList; asset.livelockCheck = livelockAssertList; return(asset); }
public VerifyResult SyncVerify(List <ArchMatrix> matrix) { // change this for performance tuning int maxConcurrent = 8; PATUtil util = new PATUtil(); // generate CSP Code VerifyAsset verifyAsset = util.GenerateAsset(matrix); int totalAsert = verifyAsset.deadloopCheck.Count + verifyAsset.livelockCheck.Count; System.Diagnostics.Debug.WriteLine("total Assertion" + totalAsert); //initialize CSP module with CSP Code PAT.CSP.ModuleFacade modulebase = new PAT.CSP.ModuleFacade(); Stopwatch sw = new Stopwatch(); sw.Start(); SpecificationBase specbase = modulebase.ParseSpecification(verifyAsset.CSPCode, string.Empty, string.Empty); // run assertions and gather results results = new ConcurrentBag <DiagnosisResult>(); ThreadedAssertionExecuter <DiagnosisResult> executer; List <ThreadedAssertionExecuter <DiagnosisResult> > threadsList = new List <ThreadedAssertionExecuter <DiagnosisResult> >(); foreach (String assertionName in verifyAsset.deadloopCheck) { // System.Diagnostics.Debug.WriteLine("executing " + assertionName); executer = new ThreadedAssertionExecuter <DiagnosisResult>(callBack, specbase, assertionName); threadsList.Add(executer); } foreach (String assertionName in verifyAsset.livelockCheck) { threadsList.Add(new ThreadedAssertionExecuter <DiagnosisResult>(callBack, specbase, assertionName)); } for (int i = 0; i < totalAsert; i += maxConcurrent) { int beforeNumResult = results.Count; int num = maxConcurrent; if (i + maxConcurrent > totalAsert) { num = totalAsert % maxConcurrent; } for (int j = 0; j < num; j++) { // System.Diagnostics.Debug.WriteLine("Starting ->" + i +" "+j); threadsList[i + j].Start(); } // gather results while (results.Count < beforeNumResult + num) { // System.Diagnostics.Debug.WriteLine("Waiting to finish..." + results.Count); } } sw.Stop(); VerifyResult verResult = new VerifyResult(); verResult.elapseTime = sw.ElapsedMilliseconds; verResult.diagnosisList = results; System.Diagnostics.Debug.WriteLine("Total Results" + results.Count); return(verResult); }