pcu: Fix race condition in TC_cs_max_dl waiting for timer first DL data after X2002

Since recently osmo-pcu arms the X2002 in a more fitting place (later,
when paging.cnf is received from osmo-bts over PCUIF).
Since we use same X2002 value in TTCN3 to wait for the timer to trigger,
in the past it was always fine (the X2002 at osmo-pcu always already had
triggered before the one in ttcn3 after receiving the ImmAss).

However, now the timer is roughly set at the same time in both places (ttcn3 and
osmo-pcu) and hence there may be race conditions where we request a
DL data block before the X2002 triggered at osmo-pcu, in which case we
receive a DL dummy block because the TBF is not yet in the FLOW state.

Change-Id: If7121473a3580b40d3a658dc38b9bb1421196127
diff --git a/pcu/GPRS_Components.ttcn b/pcu/GPRS_Components.ttcn
index e248860..37dcc97 100644
--- a/pcu/GPRS_Components.ttcn
+++ b/pcu/GPRS_Components.ttcn
@@ -1200,6 +1200,30 @@
 	return dl_fn;
 }
 
+/* Keep getting dl_block until first non RLCMAC Dummy is received, then return it */
+function f_rx_rlcmac_dl_block_skip_dummy(out RlcmacDlBlock dl_block,
+					 integer max_dummy := -1,
+					 template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum)
+runs on MS_BTS_IFACE_CT return uint32_t {
+	var integer i;
+	var uint32_t dl_fn;
+
+	while (true) {
+		f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr);
+		if (not match(dl_block, tr_RLCMAC_DL_DUMMY_CTRL)) {
+			/* Received first data, starting processing: */
+			break;
+		}
+		i := i + 1;
+		if (max_dummy >= 0 and i > max_dummy) {
+			setverdict(fail, "Didn't receive DL data after receiving ", i, " dummy blocks");
+			f_shutdown(__BFILE__, __LINE__);
+			break;
+		}
+	}
+	return dl_fn;
+}
+
 function f_rx_rlcmac_dl_block_exp_pkt_pag_req(out RlcmacDlBlock dl_block,
 					      template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum)
 runs on MS_BTS_IFACE_CT {
diff --git a/pcu/PCU_Tests.ttcn b/pcu/PCU_Tests.ttcn
index af84821..38c50be 100644
--- a/pcu/PCU_Tests.ttcn
+++ b/pcu/PCU_Tests.ttcn
@@ -1089,9 +1089,11 @@
 	/* Wait timer X2002 and DL block is available after CCCH IMM ASS */
 	f_sleep(X2002);
 
+	/* Skip potential dummy blocks before X2002 triggers at PCU after us: */
+	fn := f_rx_rlcmac_dl_block_skip_dummy(dl_block, max_dummy := 10);
+
 	for (var integer i := 0; i < 800; i := i + 1) {
 		bsn := i mod bsn_mod;
-		f_rx_rlcmac_dl_block(dl_block, fn);
 
 		if (match(dl_block, tr_RLCMAC_DL_DUMMY_CTRL)) {
 			/* No more data to receive, done */
@@ -1114,6 +1116,7 @@
 			}
 		}
 		prev_dl_block := dl_block;
+		f_rx_rlcmac_dl_block(dl_block, fn);
 	}
 
 	bsn := (bsn + (bsn_mod-1)) mod bsn_mod; /* previous bsn: bsn -1 */