|  | /////////////////////////////////////////////////////////////////////////////// | 
|  | //                                                                           // | 
|  | // Copyright (c) 2000-2018 Ericsson Telecom AB                               // | 
|  | //                                                                           // | 
|  | // All rights reserved. This program and the accompanying materials          // | 
|  | // are made available under the terms of the Eclipse Public License v2.0     // | 
|  | // which accompanies this distribution, and is available at                  // | 
|  | // https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html                                 // | 
|  | /////////////////////////////////////////////////////////////////////////////// | 
|  |  | 
|  | /////////////////////////////////////////////////////////// | 
|  | // Module: EPTF_Base_Test_Functions | 
|  | // | 
|  | // Purpose: | 
|  | //   This module contains functions for testing EPTF Base. | 
|  | // | 
|  | // Module Parameters: | 
|  | //    - | 
|  | //  Module depends on: | 
|  | //    <EPTF_Base_Test_Definitions> | 
|  | //    <EPTF_CLL_Base_Functions> | 
|  | // | 
|  | // Current Owner: | 
|  | //    Balazs Barcsik (ebalbar) | 
|  | // | 
|  | // Last Review Date: | 
|  | //    - | 
|  | // | 
|  | //  Detailed Comments: | 
|  | //    - | 
|  | /////////////////////////////////////////////////////////// | 
|  | module EPTF_Base_Test_Functions { | 
|  |  | 
|  | //========================================================================= | 
|  | // Import Part | 
|  | //========================================================================= | 
|  | import from EPTF_CLL_Base_Definitions all; | 
|  | import from EPTF_Base_Test_Definitions all; | 
|  | import from EPTF_CLL_Base_Functions all; | 
|  |  | 
|  | //========================================================================= | 
|  | // Functions | 
|  | //========================================================================= | 
|  | // mandatory functions for A_CT: | 
|  |  | 
|  | function f_A_init_CT(in charstring pl_selfName /* your additional input parameters */) runs on A_CT { | 
|  | if (v_A_initialized) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // call all the init functions of the components that your component extends _explicitly_: | 
|  | f_EPTF_Base_init_CT(pl_selfName /*additional parameters*/); | 
|  |  | 
|  | // initialize your component variables here... | 
|  | v_A_Var := 0; | 
|  |  | 
|  | v_A_initialized := true; | 
|  |  | 
|  | // register your cleanup function: | 
|  | f_EPTF_Base_registerCleanup(refers(f_A_cleanup_CT)); | 
|  |  | 
|  | log("----A INIT DONE----"); | 
|  | } | 
|  |  | 
|  |  | 
|  | function f_A_cleanup_CT() runs on A_CT { | 
|  | if (v_A_initialized == false) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // reset your variables here if needed... | 
|  |  | 
|  | log("A: v_A_Var: ", v_A_Var); | 
|  | v_A_initialized := false; | 
|  | log("----A CLEANUP DONE----"); | 
|  | // additional cleanup functions can be called here, but better if you do not call them. Register them instead. | 
|  | } | 
|  |  | 
|  | function f_A_Behaviour(in charstring pl_selfName) runs on A_CT { | 
|  | f_A_init_CT(pl_selfName); | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | // mandatory functions for B_CT: | 
|  |  | 
|  | function f_B_init_CT(in charstring pl_selfName /* your additional input parameters */) runs on B_CT { | 
|  | if (v_B_initialized) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // call all the init functions of the components that your component extends _explicitly_: | 
|  | f_EPTF_Base_init_CT(pl_selfName /*additional parameters*/); | 
|  |  | 
|  | // initialize your component variables here... | 
|  | v_B_Var := 0; | 
|  |  | 
|  | v_B_initialized := true; | 
|  |  | 
|  | // register your cleanup function: | 
|  | f_EPTF_Base_registerCleanup(refers(f_B_cleanup_CT)); | 
|  |  | 
|  | log("----B INIT DONE----"); | 
|  | } | 
|  |  | 
|  |  | 
|  | function f_B_cleanup_CT() runs on B_CT { | 
|  | if (v_B_initialized == false) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // reset your variables here if needed... | 
|  |  | 
|  | log("B: v_B_Var: ", v_B_Var); | 
|  | v_B_initialized := false; | 
|  | log("----B CLEANUP DONE----"); | 
|  | // additional cleanup functions can be called here, but better if you do not call them. Register them instead. | 
|  | } | 
|  |  | 
|  | function f_B_Behaviour(in charstring pl_selfName) runs on B_CT { | 
|  | f_B_init_CT(pl_selfName); | 
|  | timer t_wait := 1.0; | 
|  | t_wait.start; t_wait.timeout; | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | // mandatory functions for C_CT: | 
|  |  | 
|  | function f_C_init_CT(in charstring pl_selfName /* your additional input parameters */) runs on C_CT { | 
|  | if (v_C_initialized) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // call all the init functions of the components that your component extends _explicitly_: | 
|  | f_A_init_CT(pl_selfName /*additional parameters*/); | 
|  | f_B_init_CT(pl_selfName /*additional parameters*/); | 
|  |  | 
|  | // initialize your component variables here... | 
|  | v_A_Var := v_A_Var + 1; | 
|  | v_B_Var := v_B_Var + 1; | 
|  | v_C_Var := 0; | 
|  |  | 
|  | v_C_initialized := true; | 
|  |  | 
|  | // register your cleanup function: | 
|  | f_EPTF_Base_registerCleanup(refers(f_C_cleanup_CT)); | 
|  |  | 
|  | log("----C INIT DONE----"); | 
|  | } | 
|  |  | 
|  |  | 
|  | function f_C_cleanup_CT() runs on C_CT { | 
|  | if (v_C_initialized == false) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // reset your variables here if needed... | 
|  |  | 
|  | log("A: v_A_Var: ", v_A_Var); | 
|  | log("B: v_B_Var: ", v_B_Var); | 
|  | log("C: v_C_Var: ", v_C_Var); | 
|  | v_C_initialized := false; | 
|  | log("----C CLEANUP DONE----"); | 
|  | // additional cleanup functions can be called here, but better if you do not call them. Register them instead. | 
|  | } | 
|  |  | 
|  | function f_C_Behaviour(in charstring pl_selfName) runs on C_CT { | 
|  | f_C_init_CT(pl_selfName); | 
|  | timer t_wait := 100.0; | 
|  | t_wait.start; t_wait.timeout; | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | // mandatory functions for D_CT: | 
|  |  | 
|  | function f_D_init_CT(in charstring pl_selfName /* your additional input parameters */) runs on D_CT { | 
|  | if (v_D_initialized) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // call all the init functions of the components that your component extends _explicitly_: | 
|  | f_C_init_CT(pl_selfName /*additional parameters*/); | 
|  | f_B_init_CT(pl_selfName /*additional parameters*/); | 
|  | f_A_init_CT(pl_selfName /*additional parameters*/); | 
|  | f_EPTF_Base_init_CT(pl_selfName); | 
|  |  | 
|  | // initialize your component variables here... | 
|  | v_A_Var := v_A_Var + 1; | 
|  | v_B_Var := v_B_Var + 1; | 
|  | v_C_Var := v_C_Var + 1; | 
|  | v_D_Var := 0; | 
|  |  | 
|  | v_D_initialized := true; | 
|  |  | 
|  | // register your cleanup function: | 
|  | f_EPTF_Base_registerCleanup(refers(f_D_cleanup_CT)); | 
|  |  | 
|  | log("----D INIT DONE----"); | 
|  | } | 
|  |  | 
|  |  | 
|  | function f_D_cleanup_CT() runs on D_CT { | 
|  | if (v_D_initialized == false) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // reset your variables here if needed... | 
|  |  | 
|  | log("A: v_A_Var: ", v_A_Var); | 
|  | log("B: v_B_Var: ", v_B_Var); | 
|  | log("C: v_C_Var: ", v_C_Var); | 
|  | log("D: v_D_Var: ", v_D_Var); | 
|  | v_D_initialized := false; | 
|  | log("----D CLEANUP DONE----"); | 
|  | // additional cleanup functions can be called here, but better if you do not call them. Register them instead. | 
|  | } | 
|  |  | 
|  | function f_D_Behaviour(in charstring pl_selfName) runs on D_CT { | 
|  | f_D_init_CT(pl_selfName); | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  | ///////////////////////////////////////////// | 
|  | // stop remote test | 
|  | ///////////////////////////////////////////// | 
|  |  | 
|  | // creates two comp-s and exits | 
|  | function f_Comp_A_Behaviour(in charstring pl_selfName) runs on A_CT { | 
|  | f_A_init_CT(pl_selfName); | 
|  | var B_CT v_B_CT := B_CT.create; | 
|  | var C_CT v_C_CT := C_CT.create; | 
|  | v_B_CT.start(f_Comp_B_Behaviour("B",v_C_CT)); | 
|  | v_C_CT.start(f_Comp_C_Behaviour("C")); | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | // Kills the C comp and exits | 
|  | function f_Comp_B_Behaviour(in charstring pl_selfName, in C_CT pl_C_CT) runs on B_CT { | 
|  | f_B_init_CT(pl_selfName); | 
|  | // wait a bit before killing C | 
|  | timer t_wait := 1.0; | 
|  | t_wait.start; t_wait.timeout; | 
|  |  | 
|  | // stop C | 
|  | f_EPTF_Base_stopRemote(pl_C_CT); | 
|  |  | 
|  | // wait a bit before stopping mtc | 
|  | t_wait.start; t_wait.timeout; | 
|  |  | 
|  | // stop mtc | 
|  | f_EPTF_Base_stopRemote(mtc); | 
|  |  | 
|  | // wait a bit before exiting | 
|  | t_wait.start; t_wait.timeout; | 
|  |  | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | // waits for a long time and exits | 
|  | function f_Comp_C_Behaviour(in charstring pl_selfName) runs on C_CT { | 
|  | f_C_init_CT(pl_selfName); | 
|  | // wait a lot before exiting | 
|  | timer t_wait := 10.0; | 
|  | t_wait.start; t_wait.timeout; | 
|  |  | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | // exits | 
|  | function f_Comp_D_Behaviour(in charstring pl_selfName) runs on D_CT { | 
|  | f_D_init_CT(pl_selfName); | 
|  | timer t_wait := 5.0; | 
|  | // wait a little before exiting | 
|  | t_wait.start; t_wait.timeout; | 
|  |  | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  | ///////////////////////////////////////////// | 
|  | // stop all test | 
|  | ///////////////////////////////////////////// | 
|  |  | 
|  | // creates two comp-s and exits | 
|  | function f_Comp_A2_Behaviour(in charstring pl_selfName) runs on A_CT { | 
|  | f_A_init_CT(pl_selfName); | 
|  | var B_CT v_B_CT := B_CT.create; | 
|  | var C_CT v_C_CT := C_CT.create; | 
|  | v_B_CT.start(f_Comp_B2_Behaviour("B",v_C_CT)); | 
|  | v_C_CT.start(f_Comp_C2_Behaviour("C")); | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | // Kills the C comp and exits | 
|  | function f_Comp_B2_Behaviour(in charstring pl_selfName, in C_CT pl_C_CT) runs on B_CT { | 
|  | f_B_init_CT(pl_selfName); | 
|  | timer t_wait := 1.0; | 
|  | // wait a bit before stopping mtc | 
|  | t_wait.start; t_wait.timeout; | 
|  |  | 
|  | // stop all components including the current one | 
|  | f_EPTF_Base_stopAll(pass); | 
|  | } | 
|  |  | 
|  | // waits for a long time and exits | 
|  | function f_Comp_C2_Behaviour(in charstring pl_selfName) runs on C_CT { | 
|  | f_C_init_CT(pl_selfName); | 
|  | // wait a lot before exiting | 
|  | timer t_wait := 10.0; | 
|  | t_wait.start; t_wait.timeout; | 
|  |  | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | // exits | 
|  | function f_Comp_D2_Behaviour(in charstring pl_selfName) runs on D_CT { | 
|  | f_D_init_CT(pl_selfName); | 
|  | timer t_wait := 10.0; | 
|  | // wait for kill | 
|  | t_wait.start; t_wait.timeout; | 
|  |  | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | ///////////////////////////////////////////// | 
|  | // assert test | 
|  | ///////////////////////////////////////////// | 
|  |  | 
|  | // calls assert | 
|  | function f_Comp_A3_Behaviour(in charstring pl_selfName) runs on A_CT { | 
|  | f_A_init_CT(pl_selfName); | 
|  | f_EPTF_Base_setNegativeTestMode(); | 
|  | f_EPTF_Base_setExpectedAssertMsg("msg2"); // this message is expected as the first assert | 
|  | f_EPTF_Base_assert("",true); | 
|  | f_EPTF_Base_assert("msg1",true); | 
|  | action("NEGATIVE TEST!!! THE VERDICT OF THIS TESTCASE SHOULD BE PASS!"); | 
|  | f_EPTF_Base_assert("msg2",false); | 
|  | log("This will not be printed"); | 
|  | f_EPTF_Base_assert("msg3",false); | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  | ///////////////////////////////////////////// | 
|  | // DeadLock | 
|  | ///////////////////////////////////////////// | 
|  | function f_A_deadlock_init_CT(in charstring pl_selfName /* your additional input parameters */) runs on A_DeadLock_CT { | 
|  | if (v_A_initialized) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // call all the init functions of the components that your component extends _explicitly_: | 
|  | f_EPTF_Base_init_CT(pl_selfName /*additional parameters*/); | 
|  |  | 
|  | // initialize your component variables here... | 
|  | v_A_Var := 0; | 
|  |  | 
|  | v_A_initialized := true; | 
|  |  | 
|  | // register your cleanup function: | 
|  | f_EPTF_Base_registerCleanup(refers(f_A_deadlock_cleanup_CT)); | 
|  |  | 
|  | log("----A INIT DONE----"); | 
|  | } | 
|  |  | 
|  | function f_A_deadlock_cleanup_CT() runs on A_DeadLock_CT { | 
|  | if (v_A_initialized == false) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | v_A_initialized := false; | 
|  | hello_PCO.send(1); // this is only sent if this component is stopped | 
|  | log("----A CLEANUP DONE----"); | 
|  | // additional cleanup functions can be called here, but better if you do not call them. Register them instead. | 
|  | } | 
|  |  | 
|  | function f_A_deadlock_Behaviour(in charstring pl_selfName) runs on A_DeadLock_CT { | 
|  | f_A_deadlock_init_CT(pl_selfName); | 
|  | timer t_wait := 100.0; | 
|  | t_wait.start; t_wait.timeout; // 'infinite while' | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  |  | 
|  | function f_C_deadlock_init_CT(in charstring pl_selfName /* your additional input parameters */) runs on C_DeadLock_CT { | 
|  | if (v_C_initialized) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // call all the init functions of the components that your component extends _explicitly_: | 
|  | f_EPTF_Base_init_CT(pl_selfName /*additional parameters*/); | 
|  |  | 
|  | // initialize your component variables here... | 
|  | v_A_Var := 0; | 
|  |  | 
|  | v_C_initialized := true; | 
|  |  | 
|  | // register your cleanup function: | 
|  | f_EPTF_Base_registerCleanup(refers(f_C_deadlock_cleanup_CT)); | 
|  |  | 
|  | log("----C INIT DONE----"); | 
|  | } | 
|  |  | 
|  |  | 
|  | function f_C_deadlock_cleanup_CT() runs on C_DeadLock_CT { | 
|  | if (v_C_initialized == false) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | v_C_initialized := false; | 
|  | hello_PCO.receive; // this will wait forever if someone does not kill the A component | 
|  | log("----C CLEANUP DONE----"); | 
|  | // additional cleanup functions can be called here, but better if you do not call them. Register them instead. | 
|  | } | 
|  |  | 
|  | ///////////////////////////////////////////// | 
|  | // stopRemote from MTC test | 
|  | ///////////////////////////////////////////// | 
|  |  | 
|  | function f_A_StopRemoteFromMTC_init_CT(in charstring pl_selfName /* your additional input parameters */) runs on A_CT { | 
|  | if (v_A_initialized) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | // call all the init functions of the components that your component extends _explicitly_: | 
|  | f_EPTF_Base_init_CT(pl_selfName /*additional parameters*/); | 
|  |  | 
|  | // initialize your component variables here... | 
|  | v_A_Var := 0; | 
|  |  | 
|  | v_A_initialized := true; | 
|  |  | 
|  | // register your cleanup function: | 
|  | f_EPTF_Base_registerCleanup(refers(f_A_StopRemoteFromMTC_cleanup_CT)); | 
|  |  | 
|  | log("----A INIT DONE----"); | 
|  | } | 
|  |  | 
|  | function f_A_StopRemoteFromMTC_cleanup_CT() runs on A_CT { | 
|  | if (v_A_initialized == false) { | 
|  | return; | 
|  | } | 
|  |  | 
|  | v_A_initialized := false; | 
|  | log("----A CLEANUP DONE----"); | 
|  | // additional cleanup functions can be called here, but better if you do not call them. Register them instead. | 
|  | } | 
|  |  | 
|  | function f_A_StopRemoteFromMTC_Behaviour(in charstring pl_selfName) runs on A_CT { | 
|  | f_A_StopRemoteFromMTC_init_CT(pl_selfName); | 
|  | timer t_wait := 10.0; | 
|  | t_wait.start; t_wait.timeout; // wait for a long time | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  | ///////////////////////////////////////////// | 
|  | // Regression | 
|  | ///////////////////////////////////////////// | 
|  | function f_Acomp_cleanup_CT() runs on Test_CT { | 
|  | if(v_initialized) { | 
|  | v_initialized := false; | 
|  | setverdict(pass); | 
|  |  | 
|  | } else { | 
|  | log("Error: component not initialized"); | 
|  | setverdict(fail); | 
|  | } | 
|  |  | 
|  | } | 
|  |  | 
|  | function f_Acomp_init_CT() runs on Test_CT { | 
|  | if (not v_initialized) { | 
|  | f_EPTF_Base_init_CT("EPTF_Base_Test_A"); | 
|  | v_initialized := true; | 
|  | f_EPTF_Base_registerCleanup(refers(f_Acomp_cleanup_CT)) | 
|  | setverdict(pass); | 
|  | } else { | 
|  | log("Error: the component allready initialized") | 
|  | setverdict(fail); | 
|  | } | 
|  | } | 
|  |  | 
|  | function f_A_behaviour() runs on Test_CT { | 
|  | timer t; | 
|  | f_Acomp_init_CT(); | 
|  | t.start(10.0); | 
|  | t.timeout; | 
|  | log("Error: A component not stopped by MTC"); | 
|  | setverdict(fail); | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | } | 
|  | function f_cleanup1() runs on Test_CT { | 
|  | if(v_counter1 == 0) { | 
|  | if(v_cleanupOrder == 2) { | 
|  | setverdict(pass); | 
|  | } else { | 
|  | log("Error: wrong cleanup function calling order!"); | 
|  | setverdict(fail); | 
|  | } | 
|  | v_counter1 := v_counter1 + 1; | 
|  | v_cleanupOrder := v_cleanupOrder -1; | 
|  | } | 
|  | if (v_counter1 == 1) { | 
|  | if(v_cleanupOrder == 1) { | 
|  | setverdict(pass); | 
|  | } else { | 
|  | log("Error: wrong cleanup function calling order!"); | 
|  | setverdict(fail); | 
|  | } | 
|  | v_counter1 := v_counter1 + 1; | 
|  | v_cleanupOrder := v_cleanupOrder -1; | 
|  | } | 
|  | } | 
|  |  | 
|  | function f_cleanup2() runs on Test_CT { | 
|  | if(v_cleanupOrder == 3) { | 
|  | setverdict(pass); | 
|  | } else { | 
|  | log("Error: wrong cleanup function calling order!"); | 
|  | setverdict(fail); | 
|  | } | 
|  | v_cleanupOrder := v_cleanupOrder - 1; | 
|  | f_cleanup1(); | 
|  | v_counter2 := v_counter2 + 1; | 
|  | } | 
|  |  | 
|  | ///////////////////////////////////////////// | 
|  | // needed for tc_EPTF_Base_Test_executeShel | 
|  | /////////////////////////////////////////////l | 
|  | altstep as_EPTF_Base_Test_timeout() runs on Test_CT { | 
|  | [] t_wait1.timeout{ | 
|  | v_counter1 := v_counter1+1; | 
|  | } | 
|  | } | 
|  |  | 
|  | } //end of module |