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


Change subject: hnbgw: verify empty talloc asn1_context at end of tests
......................................................................

hnbgw: verify empty talloc asn1_context at end of tests

This allowed me to find massive memory leaks in osmo-hnbgw: at the end
of each test, run f_shutdown_helper(), and in it query 'show talloc' for
an empty asn1_context.

Hence verify that all the scenarios run in these ttcn3 tests have no
asn1 de/encoding memory leaks.

Change-Id: I2948ee6f167369a2252f85b493e9653b93c7e4e9
---
M hnbgw/HNBGW_Tests.ttcn
M library/Osmocom_VTY_Functions.ttcn
2 files changed, 73 insertions(+), 0 deletions(-)



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

diff --git a/hnbgw/HNBGW_Tests.ttcn b/hnbgw/HNBGW_Tests.ttcn
index 67d979b..66d0ef2 100644
--- a/hnbgw/HNBGW_Tests.ttcn
+++ b/hnbgw/HNBGW_Tests.ttcn
@@ -61,6 +61,8 @@
 import from PFCP_Templates all;
 import from PFCP_CodecPort all;

+import from TCCConversion_Functions all;
+
 modulepar {
        /* IP address at which the HNodeB can be reached */
        charstring mp_hnodeb_ip := "127.0.0.1";
@@ -372,6 +374,8 @@
 }

 friend function f_shutdown_helper() runs on test_CT {
+       f_verify_talloc_bytes(HNBGWVTY, {"asn1_context"}, 1);
+
        all component.stop;
        setverdict(pass);
        mtc.stop;
diff --git a/library/Osmocom_VTY_Functions.ttcn 
b/library/Osmocom_VTY_Functions.ttcn
index 1bbe647..160ea29 100644
--- a/library/Osmocom_VTY_Functions.ttcn
+++ b/library/Osmocom_VTY_Functions.ttcn
@@ -311,4 +311,57 @@
        return parts;
 }

+public function f_verify_talloc_bytes(TELNETasp_PT pt, ro_charstring 
object_strs, integer expect_bytes := 0,
+                                      integer attempts := 5, float wait_time 
:= 3.0)
+{
+       var charstring show_cmd := "show talloc-context application brief";
+
+       while (attempts > 0) {
+               attempts := attempts - 1;
+               var charstring ret := f_vty_transceive_ret(pt, show_cmd);
+
+               var ro_charstring lines := f_str_split(ret);
+
+               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 bytes := 0;
+
+                       for (var integer j := 0; j < lengthof(lines); j := j + 
1) {
+                               var charstring line := lines[j];
+                               if (f_strstr(line, object_str) < 0) {
+                                       continue;
+                               }
+                               var ro_charstring tokens := f_str_split(line, " 
");
+                               if (lengthof(tokens) < 4) {
+                                       continue;
+                               }
+                               if (tokens[3] != "bytes") {
+                                       continue;
+                               }
+                               bytes := f_str2int(tokens[2]);
+                       }
+
+                       if (bytes != expect_bytes) {
+                               ok := false;
+                               log("ERROR: talloc reports ", object_str, " = 
", bytes, " bytes, expecting ", expect_bytes,
+                                   " from VTY response ", lines);
+                       } else {
+                               log("ok: talloc reports ", object_str, " = ", 
bytes, " bytes");
+                       }
+               }
+               if (ok) {
+                       return;
+               }
+               if (attempts == 0) {
+                       break;
+               }
+               log("bytes count mismatch, retrying in ", wait_time);
+               f_sleep(wait_time);
+       }
+       setverdict(fail, "talloc bytes count mismatch");
+       mtc.stop;
+}
+
 }

--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/33479
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: I2948ee6f167369a2252f85b493e9653b93c7e4e9
Gerrit-Change-Number: 33479
Gerrit-PatchSet: 1
Gerrit-Owner: neels <[email protected]>
Gerrit-MessageType: newchange

Reply via email to