LibCommon v1.4 example

LibCommon provides several modules to support the synchronization of parallel TTCN-3 test components. In addition to the library files the following sample code should help interested users to apply the features. The example is applicable to Libcommon version 1.4.


MyExample.ttcn3:

 

/***
 *
 * @desc simple sample to use LicCommon version 1.4 for synchronization of two PTCs
 *
 */
module MyExample {

import from LibCommon_Sync all;
import from LibCommon_VerdictControl all;

group sampleConfig {
    type component MyMTC extends SelfSyncComp,ServerSyncComp {};
    type component MyPTC extends SelfSyncComp {};
    type component EmptyComp {};
    
    const integer c_numSyncPTCs := 2; // number of synchronized PTCs
    const charstring c_myCheckpoint := "Checkpoint 1"; // sample checkpoint
        
    /**
     *
     * @desc shutdown of MTC before termination of testcase
     * @verdict
     */
    altstep a_MTC_shutdown()
        runs on MyMTC {
          []  syncSendPort.receive(m_syncServerStop){
              tc_sync.stop ;
              log("**** a_shutdown: Test component received STOP signal from MTC **** ");
            }              
        }  
}

group samplePTCs {
    /**
     *
     * @desc synchronized PTC1
     *
     */
    function f_ptc1() runs on MyPTC {
        activate(a_shutdown());
        f_connect4ClientSync();
        f_clientSync(c_prDone,e_success);
        f_clientSync(c_myCheckpoint,e_success);
        f_clientSync(c_tbDone,e_success);    
        }
    
    /**
     *
     * @desc synchronized PTC2
     *  
     */
    function f_ptc2(boolean p_simulateError) runs on MyPTC {
        activate(a_shutdown());
        f_connect4ClientSync();
        f_clientSync(c_prDone,e_success);
        f_clientSync(c_myCheckpoint,e_success);
        if(p_simulateError)
            {log("PTC2 local error "); setverdict(fail); f_clientSendStop();};
        f_clientSync(c_tbDone,e_success);    
        }
        
    /**
     *
     * @desc unsynchronized PTC behaviour
     * @verdict
     */
    function f_ptc_no_sync() runs on EmptyComp {
        timer t:= 100000.0;
        t.start;
        t.timeout; // "for ever"
        }    

}  

group sampleTests {
    /**
     *
     * @desc sample testcase with two synchronized PTCs
     * @verdict
     */
    testcase MyTest() runs on MyMTC system EmptyComp {    
        var MyPTC v_ptc1 := MyPTC.create("PTC1");
        var MyPTC v_ptc2 := MyPTC.create("PTC2");
        activate(a_MTC_shutdown());
        f_connect4SelfOrClientSync(); // to connect with syncSendPort (MTC only)
         v_ptc1.start(f_ptc1());
        v_ptc2.start(f_ptc2(false));
        f_serverSyncNClientsAndStop(c_numSyncPTCs,{c_prDone, c_myCheckpoint, c_tbDone});
        setverdict(pass);
        }

    /**
     *
     * @desc sample testcase with two synchronized PTCs (and PTC error)
     * @verdict
     */
    testcase MyTest_Error() runs on MyMTC system EmptyComp {    
        var MyPTC v_ptc1 := MyPTC.create("PTC1");
        var MyPTC v_ptc2 := MyPTC.create("PTC2");
        activate(a_MTC_shutdown());
        f_connect4SelfOrClientSync(); // to connect with syncSendPort (MTC only)
        v_ptc1.start(f_ptc1());
        v_ptc2.start(f_ptc2(true));
        f_serverSyncNClientsAndStop(c_numSyncPTCs,{c_prDone, c_myCheckpoint, c_tbDone});
        setverdict(pass);
        }
    
    /**
     *
     * @desc sample testcase with two synchronized PTCs and one unsynchronized PTC
     *       (please reduce PX_TSYNC_TIME_LIMIT and PX_TSHUT_DOWN_TIME_LIMIT)
     * @verdict
     */
    testcase MyTest_with_unsynchronizedPTC() runs on MyMTC system EmptyComp {    
        var MyPTC v_ptc1 := MyPTC.create("PTC1");
        var MyPTC v_ptc2 := MyPTC.create("PTC2");
        var EmptyComp v_ptc_no_sync := EmptyComp.create("PTC3 not synchronized");
        activate(a_MTC_shutdown());
        f_connect4SelfOrClientSync(); // to connect with syncSendPort (MTC only)
        v_ptc1.start(f_ptc1());
        v_ptc2.start(f_ptc2(false));
        v_ptc_no_sync.start(f_ptc_no_sync());
        f_serverSyncNClientsAndStop(c_numSyncPTCs,{c_prDone, c_myCheckpoint, c_tbDone});
        setverdict(pass);
        }
    
    /**
     *
     * @desc sample testcase with two synchronized PTCs and one unsynchronized PTC (and PTC error)
     *       (please reduce PX_TSYNC_TIME_LIMIT and PX_TSHUT_DOWN_TIME_LIMIT)
     * @verdict
     */
    testcase MyTest_with_unsynchronizedPTC_Error() runs on MyMTC system EmptyComp {    
        var MyPTC v_ptc1 := MyPTC.create("PTC1");
        var MyPTC v_ptc2 := MyPTC.create("PTC2");
        var EmptyComp v_ptc_no_sync := EmptyComp.create("PTC3 not synchronized");
        activate(a_MTC_shutdown());
        f_connect4SelfOrClientSync(); // to connect with syncSendPort (MTC only)
        v_ptc1.start(f_ptc1());
        v_ptc2.start(f_ptc2(true));
        v_ptc_no_sync.start(f_ptc_no_sync());
        f_serverSyncNClientsAndStop(c_numSyncPTCs,{c_prDone, c_myCheckpoint, c_tbDone});
        setverdict(pass);
        }
    }
    
}


FacebookTwitterGoogle BookmarksRedditNewsvineTechnoratiLinkedin