bts: Add TC_pcu_rts_req() to verify PCUIF_RTS_REQ

This new test verifies that the expected amount of PCUIF_RTS_REQ are
observed on the PCU Interface for both PTCCH and PDTCH.

Change-Id: Ic27cdd4f4adf11f871b84bd72692a03280274fe2
Related: OS#4023
diff --git a/bts/BTS_Tests.ttcn b/bts/BTS_Tests.ttcn
index c89eeb1..12e1a3a 100644
--- a/bts/BTS_Tests.ttcn
+++ b/bts/BTS_Tests.ttcn
@@ -3595,6 +3595,79 @@
 	setverdict(pass);
 }
 
+/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
+testcase TC_pcu_rts_req() runs on test_CT {
+	var PCUIF_send_data pcu_sd;
+	var integer first_fn, last_fn;
+	var integer num_rts_pdtch := 0;
+	var integer num_rts_ptcch := 0;
+	var float test_duration := 5.0;
+	timer T;
+
+	f_init_pcu_test();
+	f_TC_pcu_act_req(0, 0, 7, true);
+
+	PCU.clear;
+	T.start(test_duration);
+	alt {
+	[] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
+			-> value pcu_sd {
+		num_rts_pdtch := num_rts_pdtch + 1;
+		if (not isbound(first_fn)) {
+			first_fn := pcu_sd.data.u.rts_req.fn;
+		}
+		last_fn := pcu_sd.data.u.rts_req.fn;
+		repeat;
+		}
+	[] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
+			-> value pcu_sd {
+		num_rts_ptcch := num_rts_ptcch + 1;
+		if (not isbound(first_fn)) {
+			first_fn := pcu_sd.data.u.rts_req.fn;
+		}
+		last_fn := pcu_sd.data.u.rts_req.fn;
+		repeat;
+		}
+	[] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
+		setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
+		repeat;
+		}
+	[] PCU.receive {
+		repeat;
+		}
+	[] T.timeout {}
+	}
+	var integer fn_expired := last_fn - first_fn;
+	log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
+		", num_rts_ptcch=", num_rts_ptcch);
+
+	/* verify the number of frames expired matches our expectation */
+	const float c_GSM_FN_DURATION_MS := 4.61538;
+	var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
+	var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
+	if (not match(fn_expired, t_fn_expected)) {
+		setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
+	}
+
+	/* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
+	var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
+	var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
+	if (not match(num_rts_ptcch, t_ptcch_exp)) {
+		setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
+				t_ptcch_exp);
+	}
+
+	/* We have 12 PDTCH blocks every 52-multiframe */
+	var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
+	var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
+	if (not match(num_rts_pdtch, t_pdtch_exp)) {
+		setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
+				t_pdtch_exp);
+	}
+
+	setverdict(pass);
+}
+
 /* test for generating Abis side OML ALERT from the PCU */
 testcase TC_pcu_oml_alert() runs on test_CT {
 	var PCUIF_send_data pcu_sd;
@@ -4921,6 +4994,7 @@
 		execute( TC_pcu_ext_rach_content() );
 		execute( TC_pcu_paging_from_rsl() );
 		execute( TC_pcu_time_ind() );
+		execute( TC_pcu_rts_req() );
 		execute( TC_pcu_oml_alert() );
 	} else {
 		log("PCU socket path not available, skipping PCU tests");