Add more SI scheduling testing code, towards a real test suite
diff --git a/sysinfo/Test.ttcn b/sysinfo/Test.ttcn
index 2a11047..3ef4730 100644
--- a/sysinfo/Test.ttcn
+++ b/sysinfo/Test.ttcn
@@ -10,10 +10,32 @@
 	const octetstring si2 := '59061a00000000000000000000000000000000ffe50400'O;
 	const octetstring si3 := '49061b000062f22404d2490301275d40e50400392b2b2b'O;
 	const octetstring si4 := '31061c62f22404d25d40e504002b2b2b2b2b2b2b2b2b2b'O;
+	const octetstring c_si2bis := '550602bfe809b3ff00000000000000000000007900002b'O;
+	const octetstring c_si2ter := '010603bf66b0aa0a00000002000000000000002b2b2b2b'O;
+	const octetstring c_si2quater := '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O;
 
 	type component dummy_CT {
 		port GSMTAP_PT GSMTAP;
 		port TELNETasp_PT BSCVTY;
+		var boolean initialized := false;
+		var SystemInformationConfig si_cfg := {
+			bcch_extended := false,
+			si1_present := true,
+			si2bis_present := false,
+			si2ter_present := false,
+			si2quater_present := false,
+			si7_present := false,
+			si8_present := false,
+			si9_present := false,
+			si13_present := false,
+			si13alt_present := false,
+			si15_present := false,
+			si16_present := false,
+			si17_present := false,
+			si2n_present := false,
+			si21_present := false,
+			si22_present := false
+		};
 	};
 
 	testcase TC_si1() runs on dummy_CT {
@@ -21,6 +43,7 @@
 		log("SI: ", dec_SystemInformation(si2));
 		log("SI: ", dec_SystemInformation(si3));
 		log("SI: ", dec_SystemInformation(si4));
+		setverdict(pass);
 	}
 
 	template GsmtapHeader t_GsmtapHeader := {
@@ -345,6 +368,9 @@
 			si_per_tc[i] := {};
 		}
 
+		/* flush all previous/buffered elements */
+		pt.clear
+
 		T.start;
 		alt {
 			[] pt.receive(t_recvfrom(GSMTAP_CHANNEL_BCCH)) -> value rf {
@@ -362,36 +388,140 @@
 		return si_per_tc;
 	}
 
-	testcase TC_gsmtap() runs on dummy_CT {
-		var SystemInformationVectorPerTc si_per_tc;
-		var SystemInformationConfig si_cfg := {
-			bcch_extended := false,
-			si1_present := true,
-			si2bis_present := false,
-			si2ter_present := false,
-			si2quater_present := false,
-			si7_present := false,
-			si8_present := false,
-			si9_present := false,
-			si13_present := false,
-			si13alt_present := false,
-			si15_present := false,
-			si16_present := false,
-			si17_present := false,
-			si2n_present := false,
-			si21_present := false,
-			si22_present := false
-		};
-
+	function f_init() runs on dummy_CT {
+		if (initialized) {
+			return;
+		}
+		/* GSMTAP initialization */
 		map(self:GSMTAP, system:GSMTAP);
 		IPL4_GSMTAP_CtrlFunct.f_IPL4_listen(GSMTAP, "0.0.0.0", GSMTAP_PORT, {udp := {}});
 
+		/* VTY initialization */
+		map(self:BSCVTY, system:BSCVTY);
+		f_vty_set_prompts(BSCVTY)
+
+		initialized := true;
+	}
+
+	testcase TC_si_default() runs on dummy_CT {
+		var SystemInformationVectorPerTc si_per_tc;
+
+		f_init();
+
 		si_per_tc := f_gsmtap_sample_si(GSMTAP);
 		log("SI per TC: ", si_per_tc);
 		f_validate_si_scheduling(si_cfg, si_per_tc);
+
 		setverdict(pass);
 	}
 
+	testcase TC_si_sched_2bis() runs on dummy_CT {
+		var SystemInformationVectorPerTc si_per_tc;
+		f_init();
+
+		/* Enable SI2bis + validate scheduling */
+		f_vty_enter_cfg_bts(BSCVTY, 0);
+		f_vty_si_static(BSCVTY, 0, "2bis", c_si2bis);
+		f_vty_si_resend(BSCVTY, 0);
+		f_vty_transceive(BSCVTY, "do write terminal");
+		si_cfg.si2bis_present := true;
+		si_per_tc := f_gsmtap_sample_si(GSMTAP);
+		f_validate_si_scheduling(si_cfg, si_per_tc);
+
+		/* cleanup */
+		f_vty_si_computed(BSCVTY, 0, "2bis");
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si2bis_present := false;
+
+		setverdict(pass);
+	}
+
+	testcase TC_si_sched_2ter() runs on dummy_CT {
+		var SystemInformationVectorPerTc si_per_tc;
+		f_init();
+
+		/* Enable SI2ter + validate scheduling */
+		f_vty_enter_cfg_bts(BSCVTY, 0);
+		f_vty_si_static(BSCVTY, 0, "2ter", c_si2ter);
+		f_vty_transceive(BSCVTY, "write terminal");
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si2ter_present := true;
+		si_per_tc := f_gsmtap_sample_si(GSMTAP);
+		f_validate_si_scheduling(si_cfg, si_per_tc);
+
+		/* cleanup */
+		f_vty_si_computed(BSCVTY, 0, "2ter");
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si2ter_present := false;
+
+		setverdict(pass);
+	}
+
+	testcase TC_si_sched_2ter_2bis() runs on dummy_CT {
+		var SystemInformationVectorPerTc si_per_tc;
+		f_init();
+
+		/* Enable SI2bis + SI2ter + validate scheduling */
+		f_vty_enter_cfg_bts(BSCVTY, 0);
+		f_vty_si_static(BSCVTY, 0, "2bis", c_si2bis);
+		f_vty_si_static(BSCVTY, 0, "2ter", c_si2ter);
+		f_vty_transceive(BSCVTY, "write terminal");
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si2bis_present := true;
+		si_cfg.si2ter_present := true;
+		si_per_tc := f_gsmtap_sample_si(GSMTAP);
+		f_validate_si_scheduling(si_cfg, si_per_tc);
+
+		/* cleanup */
+		f_vty_si_computed(BSCVTY, 0, "2bis");
+		f_vty_si_computed(BSCVTY, 0, "2ter");
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si2bis_present := false;
+		si_cfg.si2ter_present := false;
+
+		setverdict(pass);
+	}
+
+	testcase TC_si_sched_2quater() runs on dummy_CT {
+		var SystemInformationVectorPerTc si_per_tc;
+		f_init();
+
+		/* Enable SI2quater + validate scheduling */
+		f_vty_si2q_add_uarfcn(BSCVTY, 0, 23, 42);
+		f_vty_transceive(BSCVTY, "write terminal");
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si2quater_present := true;
+		si_per_tc := f_gsmtap_sample_si(GSMTAP);
+		f_validate_si_scheduling(si_cfg, si_per_tc);
+
+		/* cleanup */
+		f_vty_si2q_del_uarfcn(BSCVTY, 0, 23, 42);
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si2quater_present := false;
+
+		setverdict(pass);
+	}
+
+	testcase TC_si_sched_13() runs on dummy_CT {
+		var SystemInformationVectorPerTc si_per_tc;
+		f_init();
+
+		/* Enable SI2ter + validate scheduling */
+		f_vty_enter_cfg_bts(BSCVTY, 0);
+		f_vty_gprs_mode(BSCVTY, 0, "gprs");
+		f_vty_transceive(BSCVTY, "write terminal");
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si13_present := true;
+		si_per_tc := f_gsmtap_sample_si(GSMTAP);
+		f_validate_si_scheduling(si_cfg, si_per_tc);
+
+		/* cleanup */
+		f_vty_gprs_mode(BSCVTY, 0, "none");
+		f_vty_si_resend(BSCVTY, 0);
+		si_cfg.si13_present := false;
+
+		setverdict(pass);
+	}
 
 
 	/* permitted prompts on VTY */
@@ -442,8 +572,9 @@
 			[] pt.receive(NORMAL_PROMPT) { };
 			[] pt.receive(ENABLE_PROMPT) { };
 			[] pt.receive(config_pattern) { };
+			/* FIXME: "% Unknown command" and the like! */
 			[] pt.receive(charstring:?) -> value rx { buf := buf & rx; repeat };
-			[] T.timeout { setverdict(fail, "Timeout"); return ""};
+			[] T.timeout { setverdict(fail, "VTY Timeout for prompt"); return ""};
 		}
 		T.stop;
 		return buf;
@@ -455,26 +586,95 @@
 		return f_vty_wait_for_prompt(pt);
 	}
 
+	type integer BtsNr (0..255);
+	type integer BtsTrxNr (0..255);
+	type integer BtsTimeslotNr (0..7);
+
+	type charstring BtsGprsMode ("none", "gprs", "egrps");
+
 	/* enter the'confiugration' mode of the VTY */
 	function f_vty_enter_config(TELNETasp_PT pt) {
 		f_vty_transceive(pt, "enable");
 		f_vty_transceive(pt, "configure terminal")
 	}
 
-	testcase TC_telnet() runs on dummy_CT {
+	function f_vty_enter_cfg_network(TELNETasp_PT pt) {
+		f_vty_enter_config(pt);
+		f_vty_transceive(pt, "network")
+	}
 
-		map(self:BSCVTY, system:BSCVTY);
-		f_vty_set_prompts(BSCVTY)
+	function f_vty_enter_cfg_bts(TELNETasp_PT pt, BtsNr bts := 0) {
+		f_vty_enter_cfg_network(pt);
+		f_vty_transceive(pt, "bts " & int2str(bts));
+	}
+
+	function f_vty_enter_cfg_trx(TELNETasp_PT pt, BtsNr bts := 0, BtsTrxNr trx := 0) {
+		f_vty_enter_cfg_bts(pt, bts);
+		f_vty_transceive(pt, "trx " & int2str(trx));
+	}
+
+	function f_vty_enter_cfg_ts(TELNETasp_PT pt, BtsNr bts := 0, BtsTrxNr trx := 0, BtsTimeslotNr ts) {
+		f_vty_enter_cfg_trx(pt, bts, trx);
+		f_vty_transceive(pt, "timeslot " & int2str(ts));
+	}
+
+	function f_vty_si_static(TELNETasp_PT pt, BtsNr bts, charstring si, octetstring bytes) {
+		f_vty_enter_cfg_bts(pt, bts);
+		f_vty_transceive(pt, "system-information " & si & " mode static");
+		f_vty_transceive(pt, "system-information " & si & " static " & hex2str(oct2hex(bytes)));
+		f_vty_transceive(pt, "end");
+	}
+
+	function f_vty_si_computed(TELNETasp_PT pt, BtsNr bts, charstring si) {
+		f_vty_enter_cfg_bts(pt, bts);
+		f_vty_transceive(pt, "system-information " & si & " mode computed");
+		f_vty_transceive(pt, "end");
+	}
+
+	function f_vty_si_resend(TELNETasp_PT pt, BtsNr bts := 0) {
+		f_vty_transceive(pt, "bts " & int2str(bts) & " resend-system-information");
+		/* wait for 2s until changes propagate */
+		timer T := 2.0;
+		T.start;
+		T.timeout;
+	}
+
+	function f_vty_gprs_mode(TELNETasp_PT pt, integer bts, BtsGprsMode mode) {
+		f_vty_enter_cfg_bts(pt, bts);
+		f_vty_transceive(pt, "gprs mode " & mode);
+		f_vty_transceive(pt, "end");
+	}
+
+	function f_vty_si2q_add_uarfcn(TELNETasp_PT pt, BtsNr bts, UmtsArfcn uarfcn, UmtsScramblingCode sc, integer diversity := 0) {
+		f_vty_enter_cfg_bts(pt, bts);
+		f_vty_transceive(pt, "si2quater neighbor-list add uarfcn " & int2str(uarfcn) & " " & int2str(sc) & " " & int2str(diversity));
+		f_vty_transceive(pt, "end");
+	}
+
+	function f_vty_si2q_del_uarfcn(TELNETasp_PT pt, BtsNr bts, UmtsArfcn uarfcn, UmtsScramblingCode sc) {
+		f_vty_enter_cfg_bts(pt, bts);
+		f_vty_transceive(pt, "si2quater neighbor-list del uarfcn " & int2str(uarfcn) & " " & int2str(sc));
+		f_vty_transceive(pt, "end");
+	}
+
+	testcase TC_telnet() runs on dummy_CT {
+		f_init();
 
 		f_vty_transceive(BSCVTY, "show network")
-		f_vty_enter_config(BSCVTY)
 		f_vty_transceive(BSCVTY, "network")
 		f_vty_transceive(BSCVTY, "bts 0")
+		f_vty_transceive(BSCVTY, "end")
+		setverdict(pass);
 	}
 
 	control {
 		execute(TC_si1());
-		execute(TC_gsmtap());
 		execute(TC_telnet());
+		execute(TC_si_default());
+		execute(TC_si_sched_2bis());
+		execute(TC_si_sched_2ter());
+		execute(TC_si_sched_2ter_2bis());
+		execute(TC_si_sched_2quater());
+		execute(TC_si_sched_13());
 	}
 }