LibItsDcc_Functions.ttcn3 27.4 KB
Newer Older
schmitting's avatar
schmitting committed
module LibItsDcc_Functions {
schmitting's avatar
schmitting committed
    
    // Libcommon
    import from LibCommon_Sync all;
    import from LibCommon_VerdictControl all;
    
    // LibIts
    import from LibItsDcc_TypesAndValues all;
schmitting's avatar
schmitting committed
    import from LibItsDcc_Templates all;
    import from LibItsDcc_Pixits all;
    import from LibItsDcc_Pics all;
    import from LibItsDcc_TestSystem all; 

    group dccConfigurationFunctions {
        
        /**
         * @desc    Setups default configuration   
         */
schmitting's avatar
schmitting committed
        function f_cfUp(out UtComp p_utComp,
                        out ItsDcc p_itsDcc) runs on ServerSyncComp {
schmitting's avatar
schmitting committed
            
schmitting's avatar
schmitting committed
            // Create
            p_utComp := UtComp.create;
            p_itsDcc := ItsDcc.create;
            
            // Connect
            connect(p_utComp:syncPort, self:syncPort);
            connect(p_itsDcc:syncPort, self:syncPort);
            
            //Map
            map(p_utComp:utPort, system:utPort);
            map(p_itsDcc:inPort, system:inPort);
schmitting's avatar
schmitting committed
            
        } // end f_cfUp
        
        /**
         * @desc    Deletes default configuration 
         */
schmitting's avatar
schmitting committed
        function f_cfDown(in UtComp p_utComp,
                          in ItsDcc p_itsDcc) runs on ServerSyncComp {
            
            f_serverWaitForAllClientsToStop();
            // Disconnect
            disconnect(p_utComp:syncPort, self:syncPort);
            disconnect(p_itsDcc:syncPort, self:syncPort);
            
            // Unmap
            unmap(p_utComp:utPort, system:utPort);
            unmap(p_itsDcc:inPort, system:inPort);
schmitting's avatar
schmitting committed
            
            
        } // end f_cfDown
        
    } // end of dccConfigurationFunctions
    
schmitting's avatar
schmitting committed
      /* @desc    Implements synchronization of 2 clients from server side
      *           on one or more synchronization points.
      *           If problem occurs, then server sends STOP to all clients.
      *           Waits for PX_TSYNC_TIME_LIMIT to let clients
      *           finish executing their behavior until this
      *           synchronization point.
      * @remark  The use of this function requires prior connection of
      *          the server sync ports!
      * @param   p_syncPointIds list of synchronization point name/ids
      * @return  execution status
      */
      function f_serverSync2Clients( in SyncPointList p_syncPointIds )
      runs on ServerSyncComp {
            var integer i, v_noOfSyncIds := sizeof(p_syncPointIds);
            for ( i := 0; i < v_noOfSyncIds; i := i+1 ) {
                  f_serverSyncClientsTimed(2,p_syncPointIds[i], PX_TSYNC_TIME_LIMIT);
            }
      }

schmitting's avatar
schmitting committed
    /**
     * @desc Upper tester functions
     */
    group utFuntions { 
        
        /**
         * @desc    Requests to bring the IUT in an initial state
         * @param   p_init The initialisation to trigger.
         */
schmitting's avatar
schmitting committed
        function f_utInitializeIut(template (value) UtInitialize p_init) runs on UtComp {
schmitting's avatar
schmitting committed
        
            utPort.send(p_init);
            tc_wait.start;
            alt {
                [] utPort.receive(UtResult:true) {
                    tc_wait.stop;
                    log("*** f_utInitializeIut: INFO: IUT initialized ***");
                }
                [] utPort.receive {
                    tc_wait.stop;
                    log("*** f_utInitializeIut: INFO: IUT could not be initialized ***");
                    f_selfOrClientSyncAndVerdict("error", e_error);
                }
                [] tc_wait.timeout {
                    log("*** f_utInitializeIut: INFO: IUT could not be initialized in time ***");
                    f_selfOrClientSyncAndVerdict("error", e_timeout);
                }
                [else] { // Shortcut defaults
                    repeat; 
                }
            }
        }
        
        /**
         * @desc    Triggers event on the radio interface
         * @param   p_trigger The event to trigger.
         */
schmitting's avatar
schmitting committed
        function f_utTriggerEvent(template (value) UtTrigger p_trigger) runs on UtComp {
schmitting's avatar
schmitting committed
            
            utPort.send(p_trigger);
            alt {
                [] utPort.receive(UtResult:true) {
                    tc_wait.stop;
                    log("*** f_utTriggerEvent: INFO: Event sccessfully triggered ***");
                }
                [] utPort.receive {
                    tc_wait.stop;
                    log("*** f_utTriggerEvent: INFO: Event could not be triggered ***");
                    f_selfOrClientSyncAndVerdict("error", e_error);
                }
                [] tc_wait.timeout {
                    log("*** f_utTriggerEvent: INFO: Event could not be triggered in time ***");
                    f_selfOrClientSyncAndVerdict("error", e_timeout);
                }
                [else] { // Shortcut defaults
                    repeat; 
                }
            }
        
        }
        
        /**
         * @desc Capture the next event sent to the Upper Tester
         * @param   p_event     Receive template of the expected event
         * @param   p_result    Return the value of the received event if template matchs
         */
        function f_utCommandIndication( 
            in template UtCommandIndication p_event,
            out UtCommandIndication p_result
schmitting's avatar
schmitting committed
        ) runs on UtComp {
schmitting's avatar
schmitting committed
            
            tc_wait.start;
            alt {
                [] utPort.receive(p_event) -> value p_result {
                    tc_wait.stop;
                }
schmitting's avatar
schmitting committed
                [] utPort.receive {
                    tc_wait.stop;
                    log("*** f_utCommandIndication: INFO: Another event indicated at application layer, repeating check ***");
                }
                [] tc_wait.timeout {
                    log("*** f_utCommandIndication: ERROR: Timeout while waiting for event check result ***");
                }
            } // end of 'alt' statement
        
        } // End of function f_utCommandIndication
    
schmitting's avatar
schmitting committed
        /**
         * @desc Receive frames via the radio link and check that all frames are sent with
         *       the requested Tx power and inter-packet spacing on the chosen channel 
         * @param   p_testDuration         Overall test duration
         * @param   p_tOff                 Requested Toff value
         * @param   p_requestedTxPower     Requested Tx send power value
         * @param   p_dCCProfileIdentifier Requested DCC profile
         * @param   p_channel              Channel on which the frame has been sent
         */
        function f_ut_AllRequestedFramesSent(float   p_testDuration,
                                             float   p_tOff,
                                             ChannelState p_cch,
                                             ChannelState p_sch1,
                                             ChannelState p_sch2,
                                             ChannelState p_sch3, 
                                             ChannelState p_sch4,
                                             integer p_requestedTxPower,
                                             Channel p_channel) runs on UtComp {
            
            var integer v_frameReceivedCount := 0;
            
            timer tc_testDuration := p_testDuration;
            timer tc_tOff := p_tOff;
            
            // Initialize radio equipment
            f_utInitializeIut(m_utInitialize(m_utRadioInitialize));
            // Put channel(s) into defined state
            f_utTriggerEvent(m_utRadioEvent(p_cch, p_sch1, p_sch2, p_sch3, p_sch4));

            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
        } // End of function f_ut_AllRequestedFramesSent
schmitting's avatar
schmitting committed
    } // End of group utFunctions

schmitting's avatar
schmitting committed
    /**
     * @desc IN SAP functions
     */
    group inFuntions { 
schmitting's avatar
schmitting committed

        /**
         * @desc Request sending of frames via the IN_SAP and check that all frames are 
         *       reported as sent with the requested Tx power
         * @param   p_testDuration         Overall test duration
         * @param   p_tOff                 Requested Toff value
         * @param   p_requestedTxPower     Requested Tx send power value
         * @param   p_dCCProfileIdentifier Requested DCC profile
         * @param   p_channel              Channel on which the frame has been sent
         */
        function f_iN_AllRequestedFramesSent(float   p_testDuration,
                                             float   p_tOff,
                                             integer p_requestedTxPower,
                                             integer p_dCCProfileIdentifier,
                                             Channel p_channel) runs on ItsDcc {
            
            var integer v_commandReference := float2int(int2float(c_maxCommandReference)*rnd());
            var InSta v_inSta;
schmitting's avatar
schmitting committed
            var integer v_frameRequestedCount := 1;
            var integer v_frameAcknowledgedCount := 0;
            
            timer tc_testDuration := p_testDuration;
            timer tc_tOff := p_tOff;
            
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
            
            inPort.send(m_In_Request(v_commandReference,
                                     PIXIT_REFERENCE_BURST,
                                     p_requestedTxPower,
                                     p_dCCProfileIdentifier));
            tc_testDuration.start;
            
            alt {
                [] inPort.receive(mw_In_Status(v_commandReference,
                                               p_channel,
                                               true)) -> value v_inSta {
                    v_commandReference := (v_commandReference + 1) mod c_maxCommandReference;
schmitting's avatar
schmitting committed
                    v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                    if(v_inSta.achievedSendPower != p_requestedTxPower)
                       {setverdict(fail)}
                    tc_tOff.start;
                    repeat;
                }
                
                [] tc_tOff.timeout {
                    inPort.send(m_In_Request(v_commandReference,
                                PIXIT_REFERENCE_BURST,
                                p_requestedTxPower,
                                p_dCCProfileIdentifier));
schmitting's avatar
schmitting committed
                    v_frameRequestedCount := v_frameRequestedCount + 1;
                    repeat;
                }
                                               
                [] tc_testDuration.timeout {
schmitting's avatar
schmitting committed
                    if(v_frameAcknowledgedCount == v_frameRequestedCount)
                       {setverdict(pass)}
                    else
                      {tc_tOff.start;
                      alt {
                          [] inPort.receive(mw_In_Status(v_commandReference,
                                                         p_channel,
                                                         true)) -> value v_inSta {
                              tc_tOff.stop;
schmitting's avatar
schmitting committed
                              v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                              if((v_inSta.achievedSendPower != p_requestedTxPower)
schmitting's avatar
schmitting committed
                                or (v_frameAcknowledgedCount != v_frameRequestedCount))
                                 {setverdict(fail)}
schmitting's avatar
schmitting committed
                              else
                                 {setverdict(pass)}
                          }
                          
                          [] tc_tOff.timeout {
                             setverdict(fail)}
                         }
                      }     
                }
             }
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
        } // End of function f_iN_AllRequestedFramesSent

        /**
         * @desc Request sending of frames via the IN_SAP and check that all frames are 
         *       reported as sent with reduced Tx power being lower than the maximum allowed Tx power
         * @param   p_testDuration         Overall test duration
         * @param   p_tOff                 Requested Toff value
         * @param   p_requestedTxPower     Requested Tx send power value
         * @param   p_dCCProfileIdentifier Requested DCC profile
         * @param   p_channel              Channel on which the frame has been sent
         * @param   p_maxTxPower           Maximum allowed Tx power value
         */
        function f_iN_FramesSentTxPowerReduction(float   p_testDuration,
                                                 float   p_tOff,
                                                 integer p_requestedTxPower,
                                                 integer p_dCCProfileIdentifier,
                                                 Channel p_channel,
                                                 integer p_maxTxPower) runs on ItsDcc {
            
            var integer v_commandReference := float2int(int2float(c_maxCommandReference)*rnd());
            var InSta v_inSta;
schmitting's avatar
schmitting committed
            var integer v_frameRequestedCount := 1;
            var integer v_frameAcknowledgedCount := 0;
            
            timer tc_testDuration := p_testDuration;
            timer tc_tOff := p_tOff;
            
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
            
            inPort.send(m_In_Request(v_commandReference,
                                     PIXIT_REFERENCE_BURST,
                                     p_requestedTxPower,
                                     p_dCCProfileIdentifier));
            tc_testDuration.start;
            
            alt {
                [] inPort.receive(mw_In_Status(v_commandReference,
                                               p_channel,
                                               true)) -> value v_inSta {
                    v_commandReference := (v_commandReference + 1) mod c_maxCommandReference;
schmitting's avatar
schmitting committed
                    v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                    if(v_inSta.achievedSendPower >= p_maxTxPower)
                       {setverdict(fail)}
                    tc_tOff.start;
                    repeat;
                }
                
                [] tc_tOff.timeout {
                    inPort.send(m_In_Request(v_commandReference,
                                PIXIT_REFERENCE_BURST,
                                p_requestedTxPower,
                                p_dCCProfileIdentifier));
schmitting's avatar
schmitting committed
                    v_frameRequestedCount := v_frameRequestedCount + 1;
                    repeat;
                }
                                               
                [] tc_testDuration.timeout {
schmitting's avatar
schmitting committed
                    if(v_frameAcknowledgedCount == v_frameRequestedCount)
                       {setverdict(pass)}
                    else
                      {tc_tOff.start;
                      alt {
                          [] inPort.receive(mw_In_Status(v_commandReference,
                                                         p_channel,
                                                         true)) -> value v_inSta {
                              tc_tOff.stop;
schmitting's avatar
schmitting committed
                              v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                              if((v_inSta.achievedSendPower >= p_maxTxPower)
schmitting's avatar
schmitting committed
                                 or (v_frameAcknowledgedCount != v_frameRequestedCount))
                                 {setverdict(fail)}
schmitting's avatar
schmitting committed
                              else
                                 {setverdict(pass)}
                          }
                          
                          [] tc_tOff.timeout {
                             setverdict(fail)}
                         }
                      }     
                }
             }
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
        } // End of function f_iN_FramesSentTxPowerReduction

        /**
         * @desc Request sending of frames via the IN_SAP and check that all frames are dropped
         * @param   p_testDuration         Overall test duration
         * @param   p_tOff                 Requested Toff value
         * @param   p_requestedTxPower     Requested Tx send power value
         * @param   p_dCCProfileIdentifier Requested DCC profile
         */
        function f_iN_AllRequestedFramesDropped(float   p_testDuration,
                                                float   p_tOff,
                                                integer p_requestedTxPower,
                                                integer p_dCCProfileIdentifier) runs on ItsDcc {
            
            var integer v_commandReference := float2int(int2float(c_maxCommandReference)*rnd());
            var InSta v_inSta;
            
            timer tc_testDuration := p_testDuration;
            timer tc_tOff := p_tOff;
            
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
            
            inPort.send(m_In_Request(v_commandReference,
                                     PIXIT_REFERENCE_BURST,
                                     p_requestedTxPower,
                                     p_dCCProfileIdentifier));
            tc_testDuration.start;
            
            alt {
                [] inPort.receive(mw_In_Status(v_commandReference,
                                               ?,
                                               ?)) -> value v_inSta {
                    v_commandReference := (v_commandReference + 1) mod c_maxCommandReference;
                    if(v_inSta.transmissionSuccessStatus)
                      {setverdict(fail)}
                    tc_tOff.start;
                    repeat;
                }
                
                [] tc_tOff.timeout {
                    inPort.send(m_In_Request(v_commandReference,
                                PIXIT_REFERENCE_BURST,
                                p_requestedTxPower,
                                p_dCCProfileIdentifier));
                    repeat;
                }
                                               
                [] tc_testDuration.timeout {
                    setverdict(pass)
                }
             }
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
        } // End of function f_iN_AllRequestedFramesDropped

        /**
         * @desc Request sending of frames via the IN_SAP and check that some frames are 
         *       reported as sent and some reported as dropped
         * @param   p_testDuration         Overall test duration
         * @param   p_tOff                 Requested Toff value
         * @param   p_requestedTxPower     Requested Tx send power value
         * @param   p_dCCProfileIdentifier Requested DCC profile
         * @param   p_channel              Channel on which the frame has been sent
         */
        function f_iN_SomeRequestedFramesSent(float   p_testDuration,
                                              float   p_tOff,
                                              integer p_requestedTxPower,
                                              integer p_dCCProfileIdentifier,
                                              Channel p_channel) runs on ItsDcc {
            
            var integer v_commandReference := float2int(int2float(c_maxCommandReference)*rnd());
            var InSta v_inSta;
schmitting's avatar
schmitting committed
            var integer v_frameRequestedCount := 1;
            var integer v_frameAcknowledgedCount := 0;
            var boolean v_frameSent, v_frameDropped := false;
            
            timer tc_testDuration := p_testDuration;
            timer tc_tOff := p_tOff;
            
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
            
            inPort.send(m_In_Request(v_commandReference,
                                     PIXIT_REFERENCE_BURST,
                                     p_requestedTxPower,
                                     p_dCCProfileIdentifier));
            tc_testDuration.start;
            
            alt {
                [] inPort.receive(mw_In_Status(v_commandReference,
                                               p_channel,
                                               true)) -> value v_inSta {
                    v_commandReference := (v_commandReference + 1) mod c_maxCommandReference;
schmitting's avatar
schmitting committed
                    v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                    v_frameSent := true;
                    tc_tOff.start;
                    repeat;
                }
                
                [] inPort.receive(mw_In_Status(v_commandReference,
                                               p_channel,
                                               false)) -> value v_inSta {
                    v_commandReference := (v_commandReference + 1) mod c_maxCommandReference;
schmitting's avatar
schmitting committed
                    v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                    v_frameDropped := true;
                    tc_tOff.start;
                    repeat;
                }
                
                [] tc_tOff.timeout {
                    inPort.send(m_In_Request(v_commandReference,
                                PIXIT_REFERENCE_BURST,
                                p_requestedTxPower,
                                p_dCCProfileIdentifier));
schmitting's avatar
schmitting committed
                    v_frameRequestedCount := v_frameRequestedCount + 1;
                    repeat;
                }
                                               
                [] tc_testDuration.timeout {
                    if(not v_frameSent and v_frameDropped)
                       {setverdict(fail)}
schmitting's avatar
schmitting committed
                    if(v_frameAcknowledgedCount == v_frameRequestedCount)
                       {setverdict(pass)}
                    else
                      {tc_tOff.start;
                      alt {
                          [] inPort.receive(mw_In_Status(v_commandReference,
                                                         p_channel,
                                                         ?)) -> value v_inSta {
                              tc_tOff.stop;
schmitting's avatar
schmitting committed
                              v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                              if(v_frameAcknowledgedCount != v_frameRequestedCount)
                                 {setverdict(fail)}
schmitting's avatar
schmitting committed
                              else
                                 {setverdict(pass)}
                          }
                          
                          [] tc_tOff.timeout {
                             setverdict(fail)}
                         }
                      }     
                }
             }
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
        } // End of function f_iN_SomeRequestedFramesSent
schmitting's avatar
schmitting committed

        /**
         * @desc Request sending of frames via the IN_SAP and check that all frames are 
         *       reported as sent via two different channels
         * @param   p_testDuration         Overall test duration
         * @param   p_tOff                 Requested Toff value
         * @param   p_requestedTxPower     Requested Tx send power value
         * @param   p_dCCProfileIdentifier Requested DCC profile
         * @param   p_channel_1            First channel on which the frame has been sent
         * @param   p_channel_2            Second channel on which the frame has been sent
         */
        function f_iN_AllRequestedFramesSentOn2Channels(float   p_testDuration,
                                                        float   p_tOff,
                                                        integer p_requestedTxPower,
                                                        integer p_dCCProfileIdentifier,
                                                        Channel p_channel_1,
                                                        Channel p_channel_2) runs on ItsDcc {
            
            var integer v_commandReference := float2int(int2float(c_maxCommandReference)*rnd());
            var InSta v_inSta;
schmitting's avatar
schmitting committed
            var integer v_frameRequestedCount := 1;
            var integer v_frameAcknowledgedCount := 0;
            var boolean v_channel_1, v_channel_2 := false;
            
            timer tc_testDuration := p_testDuration;
            timer tc_tOff := p_tOff;
            
            f_selfOrClientSyncAndVerdict(c_prDone, e_success);
            
            inPort.send(m_In_Request(v_commandReference,
                                     PIXIT_REFERENCE_BURST,
                                     p_requestedTxPower,
                                     p_dCCProfileIdentifier));
            tc_testDuration.start;
            
            alt {
                [] inPort.receive(mw_In_Status(v_commandReference,
                                               p_channel_1,
                                               true)) -> value v_inSta {
                    v_commandReference := (v_commandReference + 1) mod c_maxCommandReference;
schmitting's avatar
schmitting committed
                    v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                    v_channel_1 := true;
                    tc_tOff.start;
                    repeat;
                }
                
                [] inPort.receive(mw_In_Status(v_commandReference,
                                               p_channel_2,
                                               true)) -> value v_inSta {
                    v_commandReference := (v_commandReference + 1) mod c_maxCommandReference;
schmitting's avatar
schmitting committed
                    v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                    v_channel_2 := true;
                    tc_tOff.start;
                    repeat;
                }
                
                [] tc_tOff.timeout {
                    inPort.send(m_In_Request(v_commandReference,
                                PIXIT_REFERENCE_BURST,
                                p_requestedTxPower,
                                p_dCCProfileIdentifier));
schmitting's avatar
schmitting committed
                    v_frameRequestedCount := v_frameRequestedCount + 1;
                    repeat;
                }
                                               
                [] tc_testDuration.timeout {
                    if(not v_channel_1 and v_channel_2)
                       {setverdict(fail)}
schmitting's avatar
schmitting committed
                    if(v_frameAcknowledgedCount == v_frameRequestedCount)
                       {setverdict(pass)}
                    else
                      {tc_tOff.start;
                      alt {
                          [] inPort.receive(mw_In_Status(v_commandReference,
                                                         ?,
                                                         true)) -> value v_inSta {
                              tc_tOff.stop;
schmitting's avatar
schmitting committed
                              v_frameAcknowledgedCount := v_frameAcknowledgedCount + 1;
                              if(v_frameAcknowledgedCount != v_frameRequestedCount)
                                 {setverdict(fail)}
schmitting's avatar
schmitting committed
                              else
                                 {setverdict(pass)}
                          }
                          
                          [] tc_tOff.timeout {
                             setverdict(fail)}
                         }
                      }     
                }
             }
schmitting's avatar
schmitting committed
            f_selfOrClientSyncAndVerdict(c_tbDone, e_success);
            
        } // End of function f_iN_AllRequestedFramesSentOn2Channels
schmitting's avatar
schmitting committed
    } // End of group inFunctions
schmitting's avatar
schmitting committed
} // End of module LibItsDcc_Functions