Change in osmo-ttcn3-hacks[master]: vty: add f_verify_talloc_count()

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
Fri Dec 17 13:55:51 UTC 2021


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


Change subject: vty: add f_verify_talloc_count()
......................................................................

vty: add f_verify_talloc_count()

Counts talloc objects via VTY and waits for a specific object count.
Useful to test against leaks.

The intended use is to check against leakage of bsc_subscr and
gsm_subscriber_connection after each BSC_Tests.*, see patch in 'Related'
below.

Related: OS#5337
Related: I69d4c5c6f8d499bb7f0b96a48af045361433c57b (osmo-ttcn3-hacks)
Change-Id: Iafe720a4931270e868f40c4f623d10bb9c14dc80
---
M library/Osmocom_VTY_Functions.ttcn
1 file changed, 63 insertions(+), 0 deletions(-)



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

diff --git a/library/Osmocom_VTY_Functions.ttcn b/library/Osmocom_VTY_Functions.ttcn
index 49f587d..083c70c 100644
--- a/library/Osmocom_VTY_Functions.ttcn
+++ b/library/Osmocom_VTY_Functions.ttcn
@@ -14,6 +14,7 @@
 	import from Misc_Helpers all;
 	import from TELNETasp_PortType all;
 	import from Osmocom_Types all;
+	import from TCCConversion_Functions all;
 
 	modulepar {
 		charstring mp_prompt_prefix := "OpenBSC";
@@ -226,4 +227,66 @@
 	return "";
 }
 
+function f_strstr_count(in charstring str, in charstring sub_str) return integer
+{
+	var integer count := 0;
+	var integer pos := 0;
+
+	while (true) {
+		var integer at := f_strstr(str, sub_str, pos);
+		if (at < 0) {
+			break;
+		}
+		count := count + 1;
+		pos := at + 1;
+	}
+	return count;
+}
+
+type record of charstring StrList;
+
+/* Perform a 'show talloc-context' to get a count of the given object_strs that are still allocated.
+ * Retry 'attempts' times until the actual talloc object count matches 'expect_count'.
+ * Useful to ensure that no mem leaks remain after running a test. */
+function f_verify_talloc_count(TELNETasp_PT pt, StrList object_strs, integer expect_count := 0,
+				       integer attempts := 5, float wait_time := 3.0)
+{
+	var charstring show_cmd := "show talloc-context application full filter "
+	for (var integer i := 0; i < lengthof(object_strs); i := i + 1) {
+		var charstring obj_str := object_strs[i];
+		/* spaces confuse the VTY command */
+		obj_str := f_replaceEveryOccurenceOfSubstring(obj_str, " ", ".");
+		/* In the regexp, expect word start and word end to bound the obj name */
+		obj_str := "\\<" & obj_str & "\\>";
+		if (i > 0) {
+			show_cmd := show_cmd & "\\|";
+		}
+		show_cmd := show_cmd & obj_str;
+	}
+
+	while (attempts > 0) {
+		attempts := attempts - 1;
+		var charstring ret := f_vty_transceive_ret(pt, show_cmd);
+
+		var boolean ok := true;
+		for (var integer i := 0; i < lengthof(object_strs); i := i + 1) {
+			var charstring object_str := object_strs[i];
+			var integer count := f_strstr_count(ret, object_str);
+			log("talloc reports ", object_str, " x ", count, ", expecting ", expect_count);
+			if (count != expect_count) {
+				ok := false;
+			}
+		}
+		if (ok) {
+			return;
+		}
+		if (attempts == 0) {
+			break;
+		}
+		log("count mismatch, retrying in ", wait_time);
+		f_sleep(wait_time);
+	}
+	setverdict(fail, "talloc count mismatch");
+}
+
 }

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/26618
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: Iafe720a4931270e868f40c4f623d10bb9c14dc80
Gerrit-Change-Number: 26618
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/20211217/2117c7b0/attachment.htm>


More information about the gerrit-log mailing list