public TestOracle(TaskNode goalTaskNode, MessageUnitList messages) { // define task operator only one time if (mapOperator == null) { MapTaskOperators(); } // Must be a goal node & has child nodes if (goalTaskNode.Type == NODE_TYPE.GOAL && goalTaskNode.HasChildNodes) { // initialize _goalTaskNode = goalTaskNode; //_taskNodeList = goalTaskNode.ChildNodes; _messages = messages; // Add all task nodes this.Clear(); foreach (TaskNode tNode in goalTaskNode.ChildNodes) { this.Add(tNode); } } else { throw new ApplicationException("Test oracle must take a goal type task node which contains child nodes."); } }
public bool CompareOutput(string goalName, MessageUnitList actualOutput) { COMPARISON_INFO comparisonInfo; comparisonInfo = new COMPARISON_INFO(); comparisonInfo.GoalName = goalName; comparisonInfo.Result = true; comparisonInfo.CurrentIndex = 0; comparisonInfo = CompareOutputInternal(goalName, actualOutput, comparisonInfo); return comparisonInfo.Result; }
public bool CompareOutput(string goalName, MessageUnitList actualOutput) { COMPARISON_INFO comparisonInfo; comparisonInfo = new COMPARISON_INFO(); comparisonInfo.GoalName = goalName; comparisonInfo.Result = true; comparisonInfo.CurrentIndex = 0; comparisonInfo = CompareOutputInternal(goalName, actualOutput, comparisonInfo); return(comparisonInfo.Result); }
private TestOracle GenerateTestOracleByGoal(TaskNode goalNode) { TaskNodeTraversalCallback nodeAction; TaskNode goalTaskNode; MessageUnitList messagesList; goalTaskNode = null; messagesList = new MessageUnitList(); // Define lambda callback nodeAction = new TaskNodeTraversalCallback((taskNode) => { // Found the target goal if (taskNode.IsSameContent(goalNode)) { if (taskNode.HasChildNodes) { goalTaskNode = taskNode; foreach (TaskNode node in taskNode.ChildNodes) { messagesList.Add(_tAgentMapper.GetMessageUnitFromTask(node)); } } // Terminate node traversing return(false); } // Continue traversing return(true); }); _tModel.TraverseTaskNodes(ref nodeAction); // if error if (goalTaskNode == null) { throw new ApplicationException("Task node list cannot be null."); } return(new TestOracle(goalTaskNode, messagesList)); }
private COMPARISON_INFO CompareOutputInternal(string goalName, MessageUnitList actualOutput, COMPARISON_INFO comparisonInfo) { TaskNodeTraversalCallback nodeAction; bool bFoundGoal; nodeAction = null; bFoundGoal = false; comparisonInfo.Result = true; // Define lambda callback nodeAction = new TaskNodeTraversalCallback((taskNode) => { // Found the target goal if (taskNode.Name == goalName) { bFoundGoal = true; comparisonInfo = recCompareOutputInternal(actualOutput, taskNode.ChildNodes, comparisonInfo); // Terminate node traversing return false; } // Continue traversing return true; }); _tModel.TraverseTaskNodes(ref nodeAction); // if goal is not found, throw exception if (!bFoundGoal) { throw new ApplicationException(String.Format("Goal ({0}) is not found.", goalName)); } return comparisonInfo; }
private COMPARISON_INFO CompareOutputInternal(string goalName, MessageUnitList actualOutput, COMPARISON_INFO comparisonInfo) { TaskNodeTraversalCallback nodeAction; bool bFoundGoal; nodeAction = null; bFoundGoal = false; comparisonInfo.Result = true; // Define lambda callback nodeAction = new TaskNodeTraversalCallback((taskNode) => { // Found the target goal if (taskNode.Name == goalName) { bFoundGoal = true; comparisonInfo = recCompareOutputInternal(actualOutput, taskNode.ChildNodes, comparisonInfo); // Terminate node traversing return(false); } // Continue traversing return(true); }); _tModel.TraverseTaskNodes(ref nodeAction); // if goal is not found, throw exception if (!bFoundGoal) { throw new ApplicationException(String.Format("Goal ({0}) is not found.", goalName)); } return(comparisonInfo); }
/// <summary> /// Create an instance of MonitorAgent /// </summary> /// <param name="simulator">A simulator related to the MonitorAgent.</param> public MonitorAgent(Simulator simulator) : base(simulator) { _simLog = new MessageUnitList(); }
// Analyze single-level tasks in a specific goal (after found goal) private COMPARISON_INFO recCompareOutputInternal(MessageUnitList actualOutput, TaskNodeList taskOracleNodes, COMPARISON_INFO comparisonInfo) { bool bSubResult; int iSubResultCount; bool bBreakLoop; //bool bCompareResult; MessageUnit msgOracle; COMPARISON_INFO tempInfo; //int currentIndex; bSubResult = false; bBreakLoop = false; tempInfo = new COMPARISON_INFO(); //currentIndex = 0; // Traverse child nodes foreach (TaskNode node in taskOracleNodes) { // Convert task to message msgOracle = _tAgentMapper.GetMessageUnitFromTask(node); iSubResultCount = 0; // if there is a nested goal in the sequence //bFoundEntry = CompareOutputFromMessage(actualOutput, msgOracle, iPointer); // Compare output with oracle for (int i = comparisonInfo.CurrentIndex; i < actualOutput.Count; i++) { bSubResult = false; // Undefined node type exception if (node.Type == NODE_TYPE.NONE) { throw new ApplicationException("Undefined node type detected."); } // If oracle matches with a task name if (actualOutput[i] == msgOracle) { switch (ComparisonLevel) { case COMPARISON_LEVEL.LEVEL1: bSubResult = true; break; case COMPARISON_LEVEL.LEVEL2: if (node.RecursionCount != -1) { iSubResultCount++; } else { bSubResult = true; } break; case COMPARISON_LEVEL.LEVEL3: if (node.RecursionCount != -1) { iSubResultCount = actualOutput.OccurrenceOf(msgOracle); } else { bSubResult = true; } break; default: break; } if (!bSubResult && iSubResultCount == node.RecursionCount) { bSubResult = true; } } else if (node.Type == NODE_TYPE.GOAL) // abstract task { tempInfo = CompareOutputInternal(node.Name, actualOutput, comparisonInfo); bSubResult = tempInfo.Result; // comparisonInfo.Result &= tempInfo.Result; // comparisonInfo.CurrentIndex = tempInfo.CurrentIndex; } // Setup next task if (bSubResult) { // Define next index by checking the operator switch (node.Operator) { case TASK_OPERATOR.INTERLEAVING: // ORDER INDEPENDENT + CHOICE + CONCURRENCY comparisonInfo.CurrentIndex = 0; comparisonInfo.CurrentIndex = actualOutput.Count; // Exit for if (comparisonInfo.Result) { return comparisonInfo; } else { // reset for the next optional comparison comparisonInfo.Result = true; } break; case TASK_OPERATOR.CHOICE: comparisonInfo.CurrentIndex = actualOutput.Count; // Exit for if (comparisonInfo.Result) { return comparisonInfo; } else { // reset for the next optional comparison comparisonInfo.Result = true; } break; case TASK_OPERATOR.SYNCHRONIZATION: // CONCURRENCY with Information Passing if (actualOutput[i].Parameter.Length > 0 && actualOutput[i].Cycle == actualOutput[i + 1].Cycle) { bSubResult = true; } break; case TASK_OPERATOR.CONCURRENCY: // CONCURRENCY if (actualOutput[i].Cycle == actualOutput[i + 1].Cycle) { bSubResult = true; } break; case TASK_OPERATOR.ENABLE: comparisonInfo.CurrentIndex = i; break; case TASK_OPERATOR.ENABLEINFO: if (actualOutput[i].Parameter.Length > 0) { comparisonInfo.CurrentIndex = i; } break; case TASK_OPERATOR.ORDER_INDEPENDENT: comparisonInfo.CurrentIndex = 0; break; case TASK_OPERATOR.NONE: bBreakLoop = true; break; default: throw new ApplicationException("Undefined operator detected."); } // exit for-loop break; } } comparisonInfo.Result &= bSubResult; if (bBreakLoop) { break; } } comparisonInfo.Result &= bSubResult; return comparisonInfo; }
// Analyze single-level tasks in a specific goal (after found goal) private COMPARISON_INFO recCompareOutputInternal(MessageUnitList actualOutput, TaskNodeList taskOracleNodes, COMPARISON_INFO comparisonInfo) { bool bSubResult; int iSubResultCount; bool bBreakLoop; //bool bCompareResult; MessageUnit msgOracle; COMPARISON_INFO tempInfo; //int currentIndex; bSubResult = false; bBreakLoop = false; tempInfo = new COMPARISON_INFO(); //currentIndex = 0; // Traverse child nodes foreach (TaskNode node in taskOracleNodes) { // Convert task to message msgOracle = _tAgentMapper.GetMessageUnitFromTask(node); iSubResultCount = 0; // if there is a nested goal in the sequence //bFoundEntry = CompareOutputFromMessage(actualOutput, msgOracle, iPointer); // Compare output with oracle for (int i = comparisonInfo.CurrentIndex; i < actualOutput.Count; i++) { bSubResult = false; // Undefined node type exception if (node.Type == NODE_TYPE.NONE) { throw new ApplicationException("Undefined node type detected."); } // If oracle matches with a task name if (actualOutput[i] == msgOracle) { switch (ComparisonLevel) { case COMPARISON_LEVEL.LEVEL1: bSubResult = true; break; case COMPARISON_LEVEL.LEVEL2: if (node.RecursionCount != -1) { iSubResultCount++; } else { bSubResult = true; } break; case COMPARISON_LEVEL.LEVEL3: if (node.RecursionCount != -1) { iSubResultCount = actualOutput.OccurrenceOf(msgOracle); } else { bSubResult = true; } break; default: break; } if (!bSubResult && iSubResultCount == node.RecursionCount) { bSubResult = true; } } else if (node.Type == NODE_TYPE.GOAL) // abstract task { tempInfo = CompareOutputInternal(node.Name, actualOutput, comparisonInfo); bSubResult = tempInfo.Result; // comparisonInfo.Result &= tempInfo.Result; // comparisonInfo.CurrentIndex = tempInfo.CurrentIndex; } // Setup next task if (bSubResult) { // Define next index by checking the operator switch (node.Operator) { case TASK_OPERATOR.INTERLEAVING: // ORDER INDEPENDENT + CHOICE + CONCURRENCY comparisonInfo.CurrentIndex = 0; comparisonInfo.CurrentIndex = actualOutput.Count; // Exit for if (comparisonInfo.Result) { return(comparisonInfo); } else { // reset for the next optional comparison comparisonInfo.Result = true; } break; case TASK_OPERATOR.CHOICE: comparisonInfo.CurrentIndex = actualOutput.Count; // Exit for if (comparisonInfo.Result) { return(comparisonInfo); } else { // reset for the next optional comparison comparisonInfo.Result = true; } break; case TASK_OPERATOR.SYNCHRONIZATION: // CONCURRENCY with Information Passing if (actualOutput[i].Parameter.Length > 0 && actualOutput[i].Cycle == actualOutput[i + 1].Cycle) { bSubResult = true; } break; case TASK_OPERATOR.CONCURRENCY: // CONCURRENCY if (actualOutput[i].Cycle == actualOutput[i + 1].Cycle) { bSubResult = true; } break; case TASK_OPERATOR.ENABLE: comparisonInfo.CurrentIndex = i; break; case TASK_OPERATOR.ENABLEINFO: if (actualOutput[i].Parameter.Length > 0) { comparisonInfo.CurrentIndex = i; } break; case TASK_OPERATOR.ORDER_INDEPENDENT: comparisonInfo.CurrentIndex = 0; break; case TASK_OPERATOR.NONE: bBreakLoop = true; break; default: throw new ApplicationException("Undefined operator detected."); } // exit for-loop break; } } comparisonInfo.Result &= bSubResult; if (bBreakLoop) { break; } } comparisonInfo.Result &= bSubResult; return(comparisonInfo); }
private TestOracle GenerateTestOracleByGoal(TaskNode goalNode) { TaskNodeTraversalCallback nodeAction; TaskNode goalTaskNode; MessageUnitList messagesList; goalTaskNode = null; messagesList = new MessageUnitList(); // Define lambda callback nodeAction = new TaskNodeTraversalCallback((taskNode) => { // Found the target goal if (taskNode.IsSameContent(goalNode)) { if (taskNode.HasChildNodes) { goalTaskNode = taskNode; foreach (TaskNode node in taskNode.ChildNodes) { messagesList.Add(_tAgentMapper.GetMessageUnitFromTask(node)); } } // Terminate node traversing return false; } // Continue traversing return true; }); _tModel.TraverseTaskNodes(ref nodeAction); // if error if (goalTaskNode == null) { throw new ApplicationException("Task node list cannot be null."); } return new TestOracle(goalTaskNode, messagesList); }