Do not use for now since a regression in userspace master deadlock java agent
[deliverable/lttng-ivc.git] / lttng_ivc / utils / runtime.py
index ac19e107b8db88ea70fc9b55ed483ec68a06ab25..52258e8388b589f4d85bc13a61408f8381dcaca1 100644 (file)
@@ -49,7 +49,7 @@ class Runtime(object):
         self._run_command_count = 0
 
         self.special_env_variables = {"LTTNG_UST_DEBUG": "1",
-                                      #"LTTNG_APP_SOCKET_TIMEOUT": "-1",
+                                      "LTTNG_APP_SOCKET_TIMEOUT": "-1",
                                       #"LTTNG_UST_REGISTER_TIMEOUT": "-1",
                                       "LTTNG_NETWORK_SOCKET_TIMEOUT": "-1"}
 
@@ -114,13 +114,13 @@ class Runtime(object):
         with open(env_path, 'w') as env_out:
             pprint.pprint(env, stream=env_out)
 
-        p = subprocess.Popen(args, stdout=stdout, stderr=stderr, env=env)
+        p = subprocess.Popen(args, stdout=stdout, stderr=stderr, env=env, cwd=cwd)
         self.__subprocess[tmp_id] = p
         self.__stdout_stderr[tmp_id] = (stdout, stderr)
         _logger.debug("Spawned sub pid: {} args: {} stdout: {} stderr{}".format(p.pid, p.args, out_path, err_path))
         return tmp_id
 
-    def run(self, command_line, cwd=None, check_return=True):
+    def run(self, command_line, cwd=None, check_return=True, ld_preload="", classpath=""):
         """
         Run the command and return a tuple of a (CompletedProcess, stdout_path,
         stderr_path). The subprocess is already executed and returned. The
@@ -129,6 +129,12 @@ class Runtime(object):
         args = shlex.split(command_line)
         env = self.get_env()
 
+        if ld_preload:
+            env['LD_PRELOAD'] = ld_preload
+        if classpath:
+            env['CLASSPATH'] = classpath
+
+
         tmp_id = self._run_command_count
         self._run_command_count += 1
 
@@ -143,7 +149,8 @@ class Runtime(object):
 
         env_path = os.path.join(self.__runtime_log, str(tmp_id) + ".env")
         with open(env_path, 'w') as env_out:
-            pprint.pprint(env, stream=env_out)
+            for key, value in env.items():
+                env_out.write('{}={}\n'.format(key, value))
 
         cp = subprocess.run(args, stdout=stdout, stderr=stderr, env=env, cwd=cwd)
         _logger.debug("Command #{} args: {} stdout: {} stderr{}".format(tmp_id, cp.args, out_path, err_path))
@@ -227,6 +234,14 @@ class Runtime(object):
                     env[var] = value
         return env
 
+    def load_test_module(self):
+        # Base directory is provided by env
+        self.run("modprobe lttng-test")
+
+    def unload_test_module(self, check_return=True):
+        # Base directory is provided by env
+        self.run("modprobe -r lttng-test", check_return=check_return)
+
     def close(self):
         for key, subp in self.__subprocess.items():
             subp.terminate()
@@ -237,6 +252,10 @@ class Runtime(object):
             stdout.close()
             stderr.close()
 
+        # Always try to remove test module but do not perform check on return
+        # value.
+        self.unload_test_module(False)
+
         # Copy the lttng_home used at runtime using hardlink to prevent useless
         # data duplication
         shutil.copytree(self.lttng_home, self.__post_runtime_lttng_home_path, copy_function=os.link)
This page took 0.025807 seconds and 5 git commands to generate.