Change in osmo-ttcn3-hacks[master]: Osmocom_CTRL_Functions: add: retrieve and verify rate counters in bulk

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

neels gerrit-no-reply at lists.osmocom.org
Sat Jun 20 19:44:34 UTC 2020


neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/18932 )


Change subject: Osmocom_CTRL_Functions: add: retrieve and verify rate counters in bulk
......................................................................

Osmocom_CTRL_Functions: add: retrieve and verify rate counters in bulk

First user will be new MSC pooling tests in ttcn3-bsc-test, see
I2006f1def5352b4b73d0159bfcaa2da9c64bfe3f.

Change-Id: Ief0d9b096feeee7d37b5f2429dd3e80de0161806
---
M library/Osmocom_CTRL_Functions.ttcn
1 file changed, 113 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/32/18932/1

diff --git a/library/Osmocom_CTRL_Functions.ttcn b/library/Osmocom_CTRL_Functions.ttcn
index 22ed405..804a4f5 100644
--- a/library/Osmocom_CTRL_Functions.ttcn
+++ b/library/Osmocom_CTRL_Functions.ttcn
@@ -148,4 +148,117 @@
 	}
 
 
+	/* --- Retrieve and verify rate counter values in bulk ---
+	 *
+	 * BSC_Tests.ttcn shows a nice way to conveniently shorten the code needed to use these functions, see
+	 * f_ctrs_msc_init() and f_ctrs_msc_expect().
+	 *
+	 * Here also a full usage example:
+	 *
+	 * const CounterNameVals my_counternames := {
+	 *         { "mscpool:subscr:new", 0 },
+	 *         { "mscpool:subscr:known", 0 },
+	 *         { "mscpool:subscr:attach_lost", 0 },
+	 * };
+	 *
+	 * var CounterNameValsList my_counters := f_counter_name_vals_get_n(instance_name := "msc", instance_count := 3, counternames := my_counternames);
+	 *
+	 * // run some tests that increment rate counters in the program,
+	 * // and increment expected counters accordingly:
+	 * my_counters := f_counter_name_vals_list_add(my_counters, instance_nr := 1, "mscpool:subscr:new", 7);
+	 * my_counters := f_counter_name_vals_list_add(my_counters, instance_nr := 2, "mscpool:subscr:attach_lost", 3);
+	 *
+	 * // verify that the program reflects the expected counters:
+	 * f_counter_name_vals_expect_n(instance_name := "msc", my_counters);
+	 *
+	 * // run some more tests...
+	 * my_counters := f_counter_name_vals_list_add(my_counters, instance_nr := 0, "mscpool:subscr:known");
+	 * // and verify again
+	 * f_counter_name_vals_expect_n(instance_name := "msc", my_counters);
+	 */
+
+	/* One counter value, e.g. { "name", 23 } */
+	type record CounterNameVal {
+		charstring name,
+		integer val
+	}
+
+	/* List of one instance's counters,
+	 * e.g. { {"foo",23}, {"bar",42} }
+	 */
+	type record of CounterNameVal CounterNameVals;
+
+	/* List of numerous instances' counters,
+	 * e.g. { { {"foo",23}, {"bar",42} },
+	 *        { {"foo",23}, {"bar",42} } }
+	 */
+	type record of CounterNameVals CounterNameValsList;
+
+	/* Retrieve one instance's rate counter values of the given names. */
+	function f_counter_name_vals_get(IPA_CTRL_PT pt, charstring instance_name, integer instance_nr, CounterNameVals counternames) return CounterNameVals {
+		var CounterNameVals vals;
+		for (var integer i := 0; i < lengthof(counternames); i := i + 1) {
+			vals[i] := {
+				name := counternames[i].name,
+				val := f_ctrl_get_ratectr_abs(pt, instance_name, instance_nr, counternames[i].name)
+			};
+		}
+		return vals;
+	}
+
+	/* Retrieve the first N instances' rate counter values of the given names */
+	function f_counter_name_vals_get_n(IPA_CTRL_PT pt, charstring instance_name := "msc", integer instance_count, CounterNameVals counternames) return CounterNameValsList {
+		var CounterNameValsList valslist;
+		for (var integer instance_nr := 0; instance_nr < instance_count; instance_nr := instance_nr + 1) {
+			valslist[instance_nr] := f_counter_name_vals_get(pt, instance_name, instance_nr, counternames);
+		}
+		log("retrieved rate counters: ", instance_name, ": ", valslist);
+		return valslist;
+	}
+
+	/* In a list of one instance's counters, increment a specifically named counter. */
+	function f_counter_name_vals_add(CounterNameVals vals, charstring countername, integer val := 1) return CounterNameVals{
+		for (var integer i := 0; i < lengthof(vals); i := i + 1) {
+			if (vals[i].name == countername) {
+				vals[i].val := vals[i].val + val;
+				return vals;
+			}
+		}
+		/* name not found, append */
+		vals[lengthof(vals)] := {
+			name := countername,
+			val := val
+		}
+		return vals;
+	}
+
+	/* In a list of several instances' counters, increment a specific instance's specifically named counter. */
+	function f_counter_name_vals_list_add(CounterNameValsList vals, integer idx, charstring countername, integer val := 1) return CounterNameValsList {
+		vals[idx] := f_counter_name_vals_add(vals[idx], countername, val);
+		return vals;
+	}
+
+	/* For a specific instance, call f_counter_name_vals_get() and compare with expected counter values.
+	 * Set the test verdict accordingly. */
+	function f_counter_name_vals_expect(IPA_CTRL_PT pt, charstring instance_name, integer instance_nr, CounterNameVals vals) {
+		var CounterNameVals now := f_counter_name_vals_get(pt, instance_name, instance_nr, vals);
+		for (var integer i := 0; i < lengthof(vals); i := i + 1) {
+			if (now[i].name != vals[i].name) {
+				setverdict(fail, "Internal error");
+			}
+			if (now[i].val != vals[i].val) {
+				setverdict(fail, "Rate counter mismatch: ", instance_name, " ", instance_nr, " ", vals[i].name, " is at ", now[i].val, " but expected ", vals[i].val);
+			}
+		}
+		setverdict(pass);
+	}
+
+	/* For N instances, call f_counter_name_vals_get() and compare with expected counter values.
+	 * Set the test verdict accordingly. The number of instances is given by lengthof(valslist). */
+	function f_counter_name_vals_expect_n(IPA_CTRL_PT pt, charstring instance_name, CounterNameValsList valslist) {
+		for (var integer instance_nr := 0; instance_nr < lengthof(valslist); instance_nr := instance_nr + 1) {
+			f_counter_name_vals_expect(pt, instance_name, instance_nr, valslist[instance_nr]);
+		}
+	}
+
 }

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/18932
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ief0d9b096feeee7d37b5f2429dd3e80de0161806
Gerrit-Change-Number: 18932
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200620/ae7e4c9f/attachment.htm>


More information about the gerrit-log mailing list