From 7418059a6a2af899495a0624d353a10cecb4bccf Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Sat, 20 Jun 2020 21:40:52 +0200 Subject: 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 --- library/Osmocom_CTRL_Functions.ttcn | 123 ++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/library/Osmocom_CTRL_Functions.ttcn b/library/Osmocom_CTRL_Functions.ttcn index 22ed4058..ee7025c9 100644 --- a/library/Osmocom_CTRL_Functions.ttcn +++ b/library/Osmocom_CTRL_Functions.ttcn @@ -148,4 +148,127 @@ module Osmocom_CTRL_Functions { } + /* --- 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 instance_nr, + charstring countername, integer val := 1) + return CounterNameValsList { + vals[instance_nr] := f_counter_name_vals_add(vals[instance_nr], 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]); + } + } + } -- cgit v1.2.3