[incident #1878954] test created: DTE in CLL: EPTF_CLL_CLI_Functions.ttcn:531(function:f_EPTF_CLI_executeCommand) Dynamic test case error: Index overflow

Change-Id: Ida5a22acaa4b42404874dd1b3ba5b73d9a966050
Signed-off-by: József Gyürüsi <jozsef.gyurusi@ericsson.com>
diff --git a/test/CommandLineInterface/EPTF_CLI_Test.ttcn b/test/CommandLineInterface/EPTF_CLI_Test.ttcn
index b7291dc..4c6aa63 100644
--- a/test/CommandLineInterface/EPTF_CLI_Test.ttcn
+++ b/test/CommandLineInterface/EPTF_CLI_Test.ttcn
@@ -36,6 +36,7 @@
 import from EPTF_CLL_Base_Functions all;
 import from EPTF_CLL_Common_Definitions all;
 //import from TELNETasp_PortType all;
+import from EPTF_CLL_Semaphore_Functions all;
 import from EPTF_CLI_Test_Definitions all;
 import from EPTF_CLI_Test_Functions all;
 modulepar charstring tsp_EPTF_CLI_Test_prompt :="TTCN> "
@@ -526,6 +527,76 @@
 
 } //~group ExecuteParallelCommands
 
+group ExecuteCommand_During_Semaphore_Timeout {
+
+  // Wait for a semaphore, but response does not unlock the semaphore in time => waitForUnlock returns with timeout
+  // After the semaphore timeouts, execute CLI command (with slow response).
+  // (In case of bug: it gets the same semaphore ID as timedOut.)
+  // Before the CLI command resonse arrives, the response for the original semaphore arrives which deletes the semaphore
+  // (In case of bug, this semaphore ID will be the same as for the CLI command)
+  // After that, the response of the CLI command arrives, but the semaphore it uses is deleted by the semaphore handler
+  // (In case of bug: DTE happens: "Dynamic test case error: Index overflow in a value of type @PreGenRecordOf.PREGEN_RECORD_OF_CHARSTRING: The index is 0, but the value has only 0 elements.")
+  
+  type component EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout_CT extends EPTF_CLI_Test_CT {
+    timer t_trigger_cli_command := 0.0;
+    timer t_trigger_semaphore_response := 0.5;
+    var integer v_semaphoreId := -1;
+  }
+
+  
+  altstep as_EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout() runs on EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout_CT {
+  // triggers the CLI command execution
+    [] t_trigger_cli_command.timeout {
+        // start the echo command with 2 sec timeout
+        log(">echo -t 1 AAA: ", f_EPTF_CLI_executeCommand("echo -t 2 AAA"));
+        repeat;
+    }
+    [] t_trigger_semaphore_response.timeout {
+      // the response arrives:
+      f_EPTF_Semaphore_delete(v_semaphoreId);
+      log("Answer arrived late, semaphore deleted: ", v_semaphoreId);
+      repeat;
+    }
+  }
+  
+  testcase tc_EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout() runs on EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout_CT {
+    f_EPTF_CLI_init_CT("CLI_Test");
+    f_EPTF_CLI_Client_init_CT("CLI_Test", self);
+    f_EPTF_Semaphore_init_CT("CLI_Test");
+    activate(as_EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout());
+    
+    // this should be successful
+    if(not registerOK==f_EPTF_CLI_Client_registerCommand(
+        "echo",
+        "echoes its arguments",
+        refers(f_EPTF_CLI_Client_echoHandler)
+      )) {
+      setverdict(fail,"Test FAILED: Command echo cannot be registered!");
+    }
+    
+    v_semaphoreId := f_EPTF_Semaphore_new();
+    
+    // wait for the semaphore with timeout
+    if (f_EPTF_Semaphore_waitForUnlock(v_semaphoreId, 0.10)) {
+      // max wait time expired before response received:
+      log(log2str(%definitionId&": Semaphore timed out before answer received: ",v_semaphoreId));
+    }
+
+    // trigger the echo command instantly with 2 sec timeout
+    t_trigger_cli_command.start;
+    
+    // trigger semaphore response after 0.5 sec:
+    t_trigger_semaphore_response.start(0.5);
+    
+    timer t_wait_for_CLI := 2.5;
+    t_wait_for_CLI.start; t_wait_for_CLI.timeout;
+    
+    // DTE should not happen, so this line should be reached:
+    f_EPTF_Base_stop(pass);
+  }
+  
+} //~group ExecuteCommand_During_Semaphore_Timeout
+
 testcase tc_EPTF_CLI_Test_stopCommand() runs on EPTF_CLI_Test_Parallel_CT {
 
   f_EPTF_CLI_init_CT("CLI_Test");
@@ -1211,6 +1282,8 @@
   execute(tc_EPTF_CLI_Test_executeCustomCommand());
   execute(tc_EPTF_CLI_Test_executeCommandSetCommands());
   execute(tc_EPTF_CLI_Test_executeParallelCommands());
+  execute(tc_EPTF_CLI_Test_executeCommand_During_Semaphore_Timeout());
+  
   execute(tc_EPTF_CLI_Test_splitString());
 
   execute(tc_EPTF_CLI_Test_stopCommand());