Change in osmo-gsm-tester[master]: srs-enb: adds support to the malloc interceptor.

pespin gerrit-no-reply at lists.osmocom.org
Fri Jun 11 11:49:11 UTC 2021


pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-gsm-tester/+/24284 )

Change subject: srs-enb: adds support to the malloc interceptor.
......................................................................

srs-enb: adds support to the malloc interceptor.

Adds support to the malloc interceptor for the SRS eNodeB. This interceptor will generate a log file that lists the mallocs, reallocs and frees produced by the srsenb.

Change-Id: I0078020468f58bdd70b0b5de879eb58192f947a6
---
M src/osmo_gsm_tester/obj/enb_srs.py
M src/osmo_gsm_tester/obj/run_node.py
A sysmocom/scenarios/cfg-enb-malloc-interceptor.conf
3 files changed, 40 insertions(+), 2 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved



diff --git a/src/osmo_gsm_tester/obj/enb_srs.py b/src/osmo_gsm_tester/obj/enb_srs.py
index 69aa095..93272c4 100644
--- a/src/osmo_gsm_tester/obj/enb_srs.py
+++ b/src/osmo_gsm_tester/obj/enb_srs.py
@@ -37,6 +37,7 @@
     schema.register_resource_schema('enb', resource_schema)
 
     config_schema = {
+        'enable_malloc_interceptor': schema.BOOL_STR,
         'enable_pcap': schema.BOOL_STR,
         'enable_tracing': schema.BOOL_STR,
         'enable_ul_qam64': schema.BOOL_STR,
@@ -60,6 +61,7 @@
     S1AP_PCAPFILE = 'srsenb_s1ap.pcap'
     TRACINGFILE = 'srsenb_tracing.log'
     METRICSFILE = 'srsenb_metrics.csv'
+    INTERCEPTORFILE = 'srsenb_minterceptor.log'
 
     def __init__(self, testenv, conf):
         super().__init__(testenv, conf, srsENB.BINFILE)
@@ -72,6 +74,7 @@
         self.config_rr_file = None
         self.config_drb_file = None
         self.tracing_file = None
+        self.interceptor_file = None
         self.log_file = None
         self.pcap_file = None
         self.s1ap_pcap_file = None
@@ -87,9 +90,11 @@
         self.remote_s1ap_pcap_file = None
         self.remote_tracing_file = None
         self.remote_metrics_file = None
+        self.remote_interceptor_file = None
         self.enable_pcap = False
         self.enable_ul_qam64 = False
         self.enable_tracing = False
+        self.enable_malloc_interceptor = False
         self.metrics_file = None
         self.have_metrics_file = False
         self.stop_sleep_time = 6 # We require at most 5s to stop
@@ -134,6 +139,12 @@
             except Exception as e:
                 self.log(repr(e))
 
+        if self.enable_malloc_interceptor:
+            try:
+                self.rem_host.scpfrom('scp-back-interceptor', self.remote_interceptor_file, self.interceptor_file)
+            except Exception as e:
+                self.log(repr(e))
+
         # Collect KPIs for each TC
         self.testenv.test().set_kpis(self.get_kpi_tree())
         # Clean up for parent class:
@@ -244,10 +255,23 @@
 
     def start_remotely(self):
         remote_env = { 'LD_LIBRARY_PATH': self.remote_inst.child('lib') }
+        # Add the malloc interceptor env variable when it's required.
+        if self.enable_malloc_interceptor:
+            path = self._run_node.lib_path_malloc_interceptor()
+            if not path:
+                raise log.Error('Could not get the environment variables. Aborting')
+
+            self.log(f'Setting LD_PRELOAD var to value: {path}')
+            remote_env['LD_PRELOAD'] = path
+
         remote_binary = self.remote_inst.child('bin', srsENB.BINFILE)
         args = (remote_binary, self.remote_config_file)
         args += tuple(self._additional_args)
 
+        # Force the output of the malloc interceptor to the interceptor_file.
+        if self.enable_malloc_interceptor:
+            args += tuple([f" 2> {self.remote_interceptor_file}"])
+
         self.process = self.rem_host.RemoteProcessSafeExit(srsENB.BINFILE, self.remote_run_dir, args, remote_env=remote_env, wait_time_sec=7)
         self.testenv.remember_to_stop(self.process)
         self.process.launch()
@@ -287,6 +311,7 @@
         self.s1ap_pcap_file = self.run_dir.child(srsENB.S1AP_PCAPFILE)
         self.metrics_file = self.run_dir.child(srsENB.METRICSFILE)
         self.tracing_file = self.run_dir.child(srsENB.TRACINGFILE)
+        self.interceptor_file = self.run_dir.child(srsENB.INTERCEPTORFILE)
 
         if not self._run_node.is_local():
             self.rem_host = remote.RemoteHost(self.run_dir, self._run_node.ssh_user(), self._run_node.ssh_addr())
@@ -310,6 +335,7 @@
             self.remote_s1ap_pcap_file = self.remote_run_dir.child(srsENB.S1AP_PCAPFILE)
             self.remote_metrics_file = self.remote_run_dir.child(srsENB.METRICSFILE)
             self.remote_tracing_file = self.remote_run_dir.child(srsENB.TRACINGFILE)
+            self.remote_interceptor_file = self.remote_run_dir.child(srsENB.INTERCEPTORFILE)
 
         values = super().configure(['srsenb'])
 
@@ -331,6 +357,9 @@
                                              s1ap_pcap_filename=s1ap_pcapfile,
                                              )))
 
+        # Retrieve the malloc interceptor option.
+        self.enable_malloc_interceptor = util.str2bool(values['enb'].get('enable_malloc_interceptor', 'false'))
+
         # Convert parsed boolean string to Python boolean:
         self.enable_pcap = util.str2bool(values['enb'].get('enable_pcap', 'false'))
         config.overlay(values, dict(enb={'enable_pcap': self.enable_pcap}))
diff --git a/src/osmo_gsm_tester/obj/run_node.py b/src/osmo_gsm_tester/obj/run_node.py
index 676c262..3549fc5 100644
--- a/src/osmo_gsm_tester/obj/run_node.py
+++ b/src/osmo_gsm_tester/obj/run_node.py
@@ -30,7 +30,7 @@
     T_LOCAL = 'local'
     T_REM_SSH = 'ssh'
 
-    def __init__(self, type=None, run_addr=None, ssh_user=None, ssh_addr=None, run_label=None, label=None, ssh_port=None, adb_serial_id=None):
+    def __init__(self, type=None, run_addr=None, ssh_user=None, ssh_addr=None, run_label=None, label=None, ssh_port=None, adb_serial_id=None, lib_path_malloc_interceptor=None):
         super().__init__(log.C_RUN, 'runnode')
         self._type = type
         self._run_addr = run_addr
@@ -40,6 +40,7 @@
         self._label = label
         self._ssh_port = ssh_port
         self._adb_serial_id = adb_serial_id
+        self._lib_path_malloc_interceptor = lib_path_malloc_interceptor
         if not self._type:
             raise log.Error('run_type not set')
         if not self._run_addr:
@@ -59,7 +60,8 @@
         return cls(conf.get('run_type', None), conf.get('run_addr', None),
                    conf.get('ssh_user', None), conf.get('ssh_addr', None),
                    conf.get('run_label', None), conf.get('label', None),
-                   conf.get('ssh_port', None), conf.get('adb_serial_id', None))
+                   conf.get('ssh_port', None), conf.get('adb_serial_id', None),
+                   conf.get('lib_path_malloc_interceptor', None))
 
     @classmethod
     def schema(cls):
@@ -72,6 +74,7 @@
             'label': schema.STR,
             'ssh_port': schema.STR,
             'adb_serial_id': schema.STR,
+            'lib_path_malloc_interceptor': schema.STR,
             }
         return resource_schema
 
@@ -105,4 +108,7 @@
     def adb_serial_id(self):
         return self._adb_serial_id
 
+    def lib_path_malloc_interceptor(self):
+        return self._lib_path_malloc_interceptor
+
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/sysmocom/scenarios/cfg-enb-malloc-interceptor.conf b/sysmocom/scenarios/cfg-enb-malloc-interceptor.conf
new file mode 100644
index 0000000..9f8cc0a
--- /dev/null
+++ b/sysmocom/scenarios/cfg-enb-malloc-interceptor.conf
@@ -0,0 +1,3 @@
+config:
+  enb:
+    enable_malloc_interceptor: true

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/24284
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Change-Id: I0078020468f58bdd70b0b5de879eb58192f947a6
Gerrit-Change-Number: 24284
Gerrit-PatchSet: 3
Gerrit-Owner: alealcon <alejandro.leal at srs.io>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210611/d60b8d07/attachment.htm>


More information about the gerrit-log mailing list