bts: Add Test for receiving PCUIF_TIME_IND on BTS PCU interface

Change-Id: Ib6b99a52790162b0227847d9aec5143cf959e2d0
Related: OS#4023
diff --git a/bts/BTS_Tests.ttcn b/bts/BTS_Tests.ttcn
index 27ed81c..a879f75 100644
--- a/bts/BTS_Tests.ttcn
+++ b/bts/BTS_Tests.ttcn
@@ -3538,6 +3538,60 @@
 	setverdict(pass);
 }
 
+/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
+testcase TC_pcu_time_ind() runs on test_CT {
+	var PCUIF_send_data pcu_sd;
+	var integer num_time_ind := 0;
+	var integer first_fn, last_fn;
+	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_TIME_IND(0, ?))) -> value pcu_sd {
+		num_time_ind := num_time_ind + 1;
+		if (not isbound(first_fn)) {
+			first_fn := pcu_sd.data.u.time_ind.fn;
+		}
+		last_fn := pcu_sd.data.u.time_ind.fn;
+		repeat;
+		}
+	[] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
+		setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
+		repeat;
+		}
+	[] PCU.receive {
+		repeat;
+		}
+	[] T.timeout {}
+	}
+	var integer fn_expired := last_fn - first_fn;
+	log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
+
+	/* 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);
+	}
+
+	/* There are three TIME.ind in every fn MOD 13 */
+	var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
+	/* Add some tolerance */
+	var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
+	if (not match(num_time_ind, t_time_ind_exp)) {
+		setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
+	}
+
+	setverdict(pass);
+}
+
+
 /***********************************************************************
  * Osmocom Style Dynamic Timeslot Support
  ***********************************************************************/
@@ -4766,7 +4820,6 @@
 * error handling
 ** IE duplicated?
 * PCU interface
-** TIME_IND from BTS->PCU
 ** DATA_IND from BTS->PCU
 ** verification of PCU-originated DATA_REQ arrival on Um/MS side
 
@@ -4839,6 +4892,7 @@
 		execute( TC_pcu_rach_content() );
 		execute( TC_pcu_ext_rach_content() );
 		execute( TC_pcu_paging_from_rsl() );
+		execute( TC_pcu_time_ind() );
 	} else {
 		log("PCU socket path not available, skipping PCU tests");
 	}