bts: Fix race condition during init_rsl receiving from multiple TRX

When several TRX are set up, it can be that in between a RSLEM_EV_TRX_UP
event and the related tr_RSL_RF_RES_IND for that TRX, we receive a
RSLEM_EV_TRX_UP from another TRX which got just connected in parallel.

Change-Id: I1296c76c1d97e6704340484994ff3921975146b9
diff --git a/bts/BTS_Tests.ttcn b/bts/BTS_Tests.ttcn
index 0ce611a..ae2d2e0 100644
--- a/bts/BTS_Tests.ttcn
+++ b/bts/BTS_Tests.ttcn
@@ -194,8 +194,11 @@
 
 private function f_init_rsl(charstring id) runs on test_CT {
 	var bitstring trx_mask := '00000000'B;
+	var bitstring rfind_mask := '00000000'B;
 	var integer trx_count := 0;
+	var integer rfind_count := 0;
 	var RSLEm_Event ev;
+	var ASP_RSL_Unitdata rx_ud;
 	timer T;
 
 	vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
@@ -220,14 +223,28 @@
 				log2str("Duplicate RSL stream ID (", ev.sid, ")"));
 		}
 
-		/* This message (RF RESource INDication) is sent by the IUT itself */
-		RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ev.sid));
 		trx_mask[enum2int(ev.sid)] := '1'B;
 		trx_count := trx_count + 1;
 
 		log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
-		if (trx_count < mp_transceiver_num) { repeat; }
+		repeat;
 		}
+	/* This message (RF RESource INDication) is sent by the IUT itself */
+	[] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
+		if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
+			Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
+				log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
+		}
+		if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
+			Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
+				log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
+		}
+
+		rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
+		rfind_count := rfind_count + 1;
+		log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
+		if (rfind_count < mp_transceiver_num) { repeat; }
+	}
 	/* osmo-bts may send us CCCH LOAD INDication or whatever else */
 	[] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
 	[] T.timeout {