pcu: Introduce test TC_multitrx_multims_alloc

Related: OS#1775
Change-Id: I6b20fded6b2a1896fb7ec47c7c5dcbdcbe27f771
diff --git a/library/GSM_Types.ttcn b/library/GSM_Types.ttcn
index ee6635b..bcf2794 100644
--- a/library/GSM_Types.ttcn
+++ b/library/GSM_Types.ttcn
@@ -46,6 +46,15 @@
 	}
 }
 
+const GprsTlli TLLI_UNUSED := 'FFFFFFFF'O;
+function f_gen_tlli() return GprsTlli {
+	var GprsTlli tlli := f_rnd_octstring(4);
+	if (tlli == TLLI_UNUSED) {
+		tlli := 'EEEEEEEE'O;
+	}
+	return tlli;
+}
+
 /* 10.5.2.8 */
 type enumerated ChannelNeeded {
 	CHAN_NEED_ANY	(0),
diff --git a/pcu/GPRS_Components.ttcn b/pcu/GPRS_Components.ttcn
index 2807b92..6f3e3e2 100644
--- a/pcu/GPRS_Components.ttcn
+++ b/pcu/GPRS_Components.ttcn
@@ -121,7 +121,7 @@
 
 template (value) GprsMS t_GprsMS_def := {
         imsi := f_gen_imsi(42),
-        tlli := '00000001'O,
+        tlli := f_gen_tlli(),
         ra := bit2int(chan_req_def),
         ra_is_11bit := 0,
         burst_type := BURST_TYPE_0,
@@ -147,16 +147,18 @@
 	/* Connection to the BTS component (one for now) */
 	port RAW_PCU_MSG_PT BTS;
 
-	/* Support only 1 ms for now */
-	var GprsMS g_ms[1];
+	/* Support only 8 ms for now */
+	var GprsMS g_ms[8];
 
 	/* Value at which Countdown Procedure starts. Announced by network (GPRS Cell Options as per TS 04.60 Chapter 12.24) */
 	var uint4_t g_bs_cv_max := 4;
 }
 
-function f_init_gprs_ms(template (value) GprsMS ms_params := t_GprsMS_def) runs on MS_BTS_IFACE_CT
+function f_init_gprs_ms(integer num_ms := 1, template (value) GprsMS ms_params := t_GprsMS_def) runs on MS_BTS_IFACE_CT
 {
-	g_ms[0] := valueof(ms_params);
+	for (var integer i := 0; i < num_ms; i := i + 1 ) {
+		g_ms[i] := valueof(ms_params);
+	}
 }
 
 
diff --git a/pcu/PCU_Tests.ttcn b/pcu/PCU_Tests.ttcn
index ea3e6ba..1c46151 100644
--- a/pcu/PCU_Tests.ttcn
+++ b/pcu/PCU_Tests.ttcn
@@ -2472,6 +2472,52 @@
 	f_shutdown(__BFILE__, __LINE__, final := true);
 }
 
+/* Verify allocation of several MS along PDCH ts of several TRX. See OS#1775, SYS#5030 */
+testcase TC_multitrx_multims_alloc() runs on RAW_PCU_Test_CT {
+	var PCUIF_info_ind info_ind;
+	var integer i;
+	const integer num_ms := 8;
+
+	/* Initialize NS/BSSGP side */
+	f_init_bssgp();
+	/* Initialize GPRS MS side */
+	f_init_gprs_ms(num_ms);
+
+	info_ind := valueof(ts_PCUIF_INFO_default);
+	/* Only the 3 first TRX are enabled. The enabled ones all have same
+	   amount of resources, hence same amount of initial resources. */
+	for (i := 0; i < lengthof(info_ind.trx.v10); i := i + 1) {
+		info_ind.trx.v10[i].pdch_mask := '00000000'B;
+	}
+	info_ind.trx.v10[0].pdch_mask := '00000011'B;
+	info_ind.trx.v10[1].pdch_mask := '00001100'B;
+	info_ind.trx.v10[2].pdch_mask := '11000000'B;
+
+	/* Initialize the PCU interface abstraction */
+	f_init_raw(testcasename(), info_ind);
+
+	/* Establish BSSGP connection to the PCU */
+	f_bssgp_establish();
+	for (i := 0; i < num_ms; i := i + 1) {
+		f_bssgp_client_llgmm_assign(TLLI_UNUSED, g_ms[i].tlli);
+	}
+
+	/* Establish an Uplink TBF for each MS. They should be allocated on
+	  different TRX in an uniform way. */
+	for (i := 0; i < num_ms; i := i + 1) {
+		f_ms_establish_ul_tbf(g_ms[i]);
+
+		var uint10_t arfcn := g_ms[i].ul_tbf.rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.arfcn;
+		if (arfcn != info_ind.trx.v10[i mod 3].arfcn) {
+			setverdict(fail, "Got assigned ARFCN ", arfcn, " vs exp ",
+				   info_ind.trx.v10[i mod 3].arfcn);
+			f_shutdown(__BFILE__, __LINE__);
+		}
+	}
+
+	f_shutdown(__BFILE__, __LINE__, final := true);
+}
+
 control {
 	execute( TC_pcuif_suspend() );
 	execute( TC_ta_ptcch_idle() );
@@ -2524,6 +2570,7 @@
 		/* Packet Uplink/Downlink Assignment on PACCH */
 		execute( TC_pcuif_fh_pkt_ass_ul() );
 		execute( TC_pcuif_fh_pkt_ass_dl() );
+		execute( TC_multitrx_multims_alloc() );
 	}
 
 	execute( TC_pcuif_info_ind_subsequent() );