bsc: CBSP code refcator: Add f_exp_rsl_etws()

This function reduces code duplication between CBSP tests.

Change-Id: I69bedd43bc88bc619b80bf9038da901bbff9f04b
diff --git a/bsc/BSC_Tests_CBSP.ttcn b/bsc/BSC_Tests_CBSP.ttcn
index 5f470ab..48769aa 100644
--- a/bsc/BSC_Tests_CBSP.ttcn
+++ b/bsc/BSC_Tests_CBSP.ttcn
@@ -868,6 +868,37 @@
 	}
 }
 
+private function f_exp_rsl_etws(integer rsl_idx := 0, boolean enabled) runs on cbsp_test_CT {
+	var template (present) octetstring tr_apdu;
+	timer T := 5.0;
+	T.start;
+
+	if (enabled) {
+		tr_apdu := f_gen_etws_pn(g_cbsp_ser_no, g_cbsp_msg_id);
+	} else {
+		tr_apdu := ''O;
+	}
+
+	alt {
+	[] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_OSMO_ETWS_CMD(t_RslChanNr_PCH_AGCH(0), tr_apdu))) {
+		setverdict(pass);
+		}
+	[] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_OSMO_ETWS_CMD(?,?))) {
+		setverdict(fail, "Received unexpected OSMO_ETWS_CMD");
+		mtc.stop;
+		}
+	[] IPA_RSL[rsl_idx].receive { repeat; }
+	[] T.timeout {
+		if (enabled) {
+			setverdict(fail, "Timeout waiting for RSL_OSMO_ETWS_CMD (enable)");
+		} else {
+			setverdict(fail, "Timeout waiting for RSL_OSMO_ETWS_CMD (disable)");
+		}
+		mtc.stop;
+		}
+	}
+}
+
 /* Write ETWS PN to single BTS; verify it arrives on CCHAN */
 testcase TC_cbsp_emerg_write_bts_cgi_cchan() runs on cbsp_test_CT {
 	var CBSP_IEs pages := {f_gen_page()};
@@ -879,23 +910,8 @@
 
 	cell_list := ts_BSSMAP_CIL_CGI({bssmap_cgi(mp_cgi_bts0)});
 	f_cbsp_write_emerg(g_cbsp_msg_id, g_cbsp_ser_no, cell_list);
-	var template (present) octetstring tr_apdu := f_gen_etws_pn(g_cbsp_ser_no, g_cbsp_msg_id);
-	timer T := 5.0;
-	T.start;
-	alt {
-	[] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_OSMO_ETWS_CMD(t_RslChanNr_PCH_AGCH(0), tr_apdu))) {
-		setverdict(pass);
-		}
-	[] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_OSMO_ETWS_CMD(?,?))) {
-		setverdict(fail, "Received unexpected OSMO_ETWS_CMD");
-		mtc.stop;
-		}
-	[] IPA_RSL[0].receive { repeat; }
-	[] T.timeout {
-		setverdict(fail, "Timeout waiting for RSL_OSMO_ETWS_CMD");
-		mtc.stop;
-		}
-	}
+
+	f_exp_rsl_etws(0, true);
 }
 
 /* Write ETWS PN to single BTS; verify it arrives on CCHAN */
@@ -911,40 +927,10 @@
 	f_cbsp_write_emerg(g_cbsp_msg_id, g_cbsp_ser_no, cell_list);
 
 	/* first expect the PN to be enabled */
-	var template (present) octetstring tr_apdu := f_gen_etws_pn(g_cbsp_ser_no, g_cbsp_msg_id);
-	timer T := 5.0;
-	T.start;
-	alt {
-	[] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_OSMO_ETWS_CMD(t_RslChanNr_PCH_AGCH(0), tr_apdu))) {
-		setverdict(pass);
-		}
-	[] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_OSMO_ETWS_CMD(?,?))) {
-		setverdict(fail, "Received unexpected OSMO_ETWS_CMD");
-		mtc.stop;
-		}
-	[] IPA_RSL[0].receive { repeat; }
-	[] T.timeout {
-		setverdict(fail, "Timeout waiting for RSL_OSMO_ETWS_CMD (enable)");
-		mtc.stop;
-		}
-	}
+	f_exp_rsl_etws(0, true);
 
 	/* then expect it to be disabled after the warning period (5s) */
-	T.start;
-	alt {
-	[] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_OSMO_ETWS_CMD(t_RslChanNr_PCH_AGCH(0), ''O))) {
-		setverdict(pass);
-		}
-	[] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_OSMO_ETWS_CMD(?,?))) {
-		setverdict(fail, "Received unexpected OSMO_ETWS_CMD");
-		mtc.stop;
-		}
-	[] IPA_RSL[0].receive { repeat; }
-	[] T.timeout {
-		setverdict(fail, "Timeout waiting for RSL_OSMO_ETWS_CMD (disable)");
-		mtc.stop;
-		}
-	}
+	f_exp_rsl_etws(0, false);
 }
 
 /* Send a MSG STATUS QUERY for an unknown message; expect no completion list and present failure list */