LibIot_Functions.ttcn 7.1 KB
Newer Older
Bostjan Pintar's avatar
Bostjan Pintar committed
/*
 *	@author 	STF 370
 *  @version    $Id: LibIot_Functions.ttcn 16 2009-06-16 15:06:42Z pintar $
 *	@desc		This module provides the functions used by the test component 
 */

module LibIot_Functions {
	import from LibCommon_VerdictControl {type FncRetCode;}

	import from LibUpperTester {
		template mw_EO_Response;
		type EquipmentOperationReq, EquipmentOperationRsp;
	}

	import from LibIot_TypesAndValues {
		type IotVerdict, IotVerdictType, Status, VerdictType;
	}

	import from LibIot_PIXITS {
		modulepar PX_EUT_TRIGGER_RESPONSE, PX_TTCN3_VERDICT;
	}

	import from LibIot_TestInterface {
		type IotEquipmentUser, OracleClient, OracleServer, TestCoordinator, EquipmentUser;
	}
	
	
	group oracleFunctions {
    
    	/**
    	 * @desc Sets the conformance verdict on the oracle client and sends it to the oracle server
    	 * @param p_verdict conformance verdict set by the monitor
    	 * @param p_reason reason why the verdict has been set
    	 */
    	function f_setConformanceVerdict(in verdicttype p_verdict,
    									 in charstring p_reason)
    	runs on OracleClient {
    		var IotVerdict v_verdict := {conformance := {p_verdict, p_reason}};
    		log("Conformance verdict set to: ", p_verdict, p_reason);
    		vPort.send(v_verdict);
    	}
    
    	/**
    	* @desc Sets the end-to-end verdict on the oracle client and sends it to the oracle server
    	* @param p_verdict e2e verdict set by the monitor
    	* @param p_reason reason why the verdict has been set
    	*/
    	function f_setE2EVerdict(in verdicttype p_verdict, in charstring p_reason)
    	runs on OracleClient {
    		var IotVerdict v_verdict := {e2e := {p_verdict, p_reason}};
    		log("E2E verdict set to: ", p_verdict, p_reason);
    		vPort.send(v_verdict);
    	}
    
    	/**
    	 * @desc Gets the conformance verdict on the oracle client
    	 * @return conformance verdict of oracle server
    	 */
    	function f_getConformanceVerdict()
    	runs on OracleServer
		return verdicttype {
    		return vc_conf_verdict.verdict;
    	}
    
    	/**
    	 * @desc Gets the end-to-end verdict on the oracle client
    	 * @return end-to-end verdict of oracle server
    	 */
    	function f_getE2EVerdict()
    	runs on OracleServer
		return verdicttype {
    		return vc_e3e_verdict.verdict;
    	}
    
    	/**
    	* @desc Computes and logs overall verdict for end-to-end and conformance separately on oracle server
    	* @param p_verdict the verdict received
    	*/
    	function f_setIotVerdict(in IotVerdict p_verdict) runs on OracleServer {
    		f_logIotVerdict(p_verdict);
    		if (ischosen(p_verdict.e2e) and PX_TTCN3_VERDICT == e_e2e) {
    			setverdict(p_verdict.e2e.verdict, p_verdict.e2e.reason);
    		} else if (ischosen(p_verdict.conformance) and PX_TTCN3_VERDICT == e_conformance) {
    			setverdict(p_verdict.conformance.verdict, p_verdict.conformance.reason);
    		}
    	}

		/**
		* @desc Set verdict PASS on main component (to be used, e.g on TestCoordinator)
		*/
		function f_setIotVerdictPASS(in charstring p_reason) runs on OracleServer {
            var IotVerdict p_verdict := {
            	conformance := {verdict := pass, reason := p_reason}
            };
            f_setIotVerdict(p_verdict);
		}
    	/**
    	* @desc Set verdict PASS on main component (to be used, e.g on TestCoordinator)
    	*/
    	function f_setIotVerdictFAIL(in charstring p_reason) runs on OracleServer {
			var IotVerdict p_verdict := {
				conformance := {verdict := fail, reason := p_reason}
			};
			f_setIotVerdict(p_verdict);
    	}

    	    	
    	/**
    	 * 
    	 * @desc logs the received IOT verdict
    	 * @param p_verdict The verdict to set
    	 */
    	function f_logIotVerdict(in IotVerdict p_verdict) runs on OracleServer {
    		if (ischosen(p_verdict.e2e)) {
    			vc_e3e_verdict := f_getWorseVerdict(vc_e3e_verdict, p_verdict.e2e);
    			log("E2E verdict set to: ", p_verdict.e2e.verdict, "Reason: " & p_verdict.e2e.reason);
    		} else  {
    			vc_conf_verdict := f_getWorseVerdict(vc_conf_verdict, p_verdict.conformance);
    			log("Conformance verdict set to: ", p_verdict.conformance.verdict, "Reason: " & p_verdict.conformance.reason);
    		}
    	}
    	
    	/**
    	 * 
    	 * @desc returns the worse verdict 
    	 * @param p_org the original verdict 
    	 * @param p_new the new verdict
    	 * @return the worse verdict
    	 */
    	function f_getWorseVerdict(in VerdictType p_org, in VerdictType p_new) return VerdictType {
    		if(p_org.verdict == pass) {
    			
    			if(p_new.verdict != pass) {
    				return p_new;
    			}
    			else {
    				return p_org;
    			}
    		}
    		else if (p_org.verdict == inconc) {
    			
    			if(p_new.verdict != pass) {
    				return p_new;
    			}
    			else {
    				return p_org;
    			}
    		}
    		else if (p_org.verdict == fail) {
    			if(p_new.verdict == pass) {
    				return p_org;
    			}
    			else if(p_new.verdict == inconc) {
    				return p_org;
    			}
    			else {
    				return p_new;
    			}
    		}
    		else if (p_org.verdict == error) {
    			return p_org;
    		}
    		
    		return p_org;
    	}
    
    	/**
    	* @desc Altstep to be used for listening continously on the verdict port of the oracle server for receiving verdicts from oracle clients
    	*/
    	altstep a_receiveIOTVerdict() runs on OracleServer {
    		var IotVerdict v_verdict;
    		[] vPort.receive(IotVerdict:?) -> value v_verdict {
    			f_setIotVerdict(v_verdict);
    			repeat;
    		}
    	}
	}
	
	group equipmentOperationFunctions { // TODO Update!
		function f_sendEquipmentCmd(in EquipmentOperationReq p_req) runs on EquipmentUser {
			var EquipmentOperationRsp v_response;
			var charstring v_reason := "";
			
			T_Equipment.start(PX_EUT_TRIGGER_RESPONSE);
			eaPort.send(p_req);
			
			alt{
				[] eaPort.receive(mw_EO_Response(e_success)) -> value v_response {
					T_Equipment.stop;
					if(ispresent(v_response.status.reason)) {
						v_reason := v_response.status.reason;
						f_setE2EVerdict(pass, "Equipment command """ & p_req.cmd & """successful: " & v_reason);
					}else {
						f_setE2EVerdict(pass, "Equipment command successful");
					}
				}
				[] eaPort.receive(mw_EO_Response(?)) -> value  v_response {
					T_Equipment.stop;
					if(ispresent(v_response.status.reason)) {
						v_reason := v_response.status.reason;
						f_setE2EVerdict(fail, "Equipment command """ & p_req.cmd & """unsuccessful: " & v_reason);
					}else {
						f_setE2EVerdict(fail, "Equipment command unsuccessful: no reason given");
					}
				}
				[] T_Equipment.timeout {
					f_setE2EVerdict(inconc, "Timer expired while waiting for reponse of Trigger command """ & p_req.cmd & """");
				}
			}
		}
	}
	
	group miscFunctions {
    	/**
    	* @desc 	searches the array for a given name and returns 
    	* 			the corresponding index
    	* @param 	p_idx index of the port
    	* @return 	the index
    	*/
    	function f_getMonitorIdx(in charstring p_name)
    	runs on TestCoordinator return integer {
    		var integer v_size := lengthof(vc_compIds);
    		for (var integer i := 0; i < v_size; i := i + 1) {
    			if (vc_compIds[i].name == p_name) {
    				return vc_compIds[i].index;
    			}
    		}
    		return - 1;
    	}
	}
}