]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF30399] Keep same current directory in CrashProofMode
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 25 Jun 2024 09:01:35 +0000 (11:01 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 25 Jun 2024 09:01:35 +0000 (11:01 +0200)
src/Container/SALOME_PyNode.py
src/Launcher/Test/testCrashProofContainer.py

index d71e57c447a9043a7b7b684325b33c503a587baa..d5f10aa9d8d048a173e356a2b34d56206ddb2779 100644 (file)
@@ -826,10 +826,14 @@ FinalCode = """import pickle
 from SALOME_PyNode import LogOfCurrentExecutionSession,MY_PERFORMANCE_LOG_ENTRY_IN_GLBS
 import CORBA
 import Engines
+import os
+# WorkDir may be important to replay : "{}"
 orb = CORBA.ORB_init([''])
-codeFileName = "{}"
-inputFileName = "{}"
-outputFileName = "{}"
+caseDirectory = "{}"
+codeFileName = os.path.join( caseDirectory, "{}" )
+inputFileName = os.path.join( caseDirectory, "{}" )
+outputFileName = os.path.join( caseDirectory, "{}" )
+del os
 outputsKeys = {}
 exec( "{{}} = LogOfCurrentExecutionSession( orb.string_to_object( \\"{}\\" ) )".format(MY_PERFORMANCE_LOG_ENTRY_IN_GLBS) )
 with open(inputFileName,"rb") as f:
@@ -972,11 +976,11 @@ sys.stderr.flush()""".format( MY_KEY_TO_DETECT_FINISH ) )
       resFileName = os.path.join( dirForReplayFiles, "outcontextsafe_{}.pckl".format( RetrieveUniquePartFromPfx( codeFileName  ) ) )
       mainExecFileName = os.path.join( dirForReplayFiles, "mainexecsafe_{}.py".format( RetrieveUniquePartFromPfx( codeFileName  ) ) )
       with open(mainExecFileName,"w") as f:
-        f.write( FinalCode.format( codeFileName, contextFileName, resFileName, outargsname, iorScriptLog ) )
+        f.write( FinalCode.format( os.getcwd(), dirForReplayFiles, codeFileName, contextFileName, resFileName, outargsname, iorScriptLog ) )
       for iTry in range( KernelBasis.GetNumberOfRetry() ):
         if iTry > 0:
           print( "WARNING : Retry # {}. Following code has generated non zero return code ( {} ). Trying again ... \n{}".format( iTry, returnCode, code ) )
-        p = sp.Popen(["python3", mainExecFileName],cwd = dirForReplayFiles,stdout = sp.PIPE, stderr = sp.PIPE)
+        p = sp.Popen(["python3", mainExecFileName],cwd = os.getcwd(),stdout = sp.PIPE, stderr = sp.PIPE)
         stdout, stderr = p.communicate()
         returnCode = p.returncode
         if returnCode == 0:
index 00bc32b76d4fdc5902e32d45b797fd5b1bff7f12..d05e72461614f212321905698383cdbf75d05825 100644 (file)
@@ -68,6 +68,21 @@ j = 9 * i * a
 print("OKKKKKK3333")
 """
 
+killMeAtTheEnd2 = """import atexit
+import KernelServices
+import os
+
+def ErrorAtexit():
+    KernelServices.GenerateViolentMemoryFaultForTestPurpose()
+
+atexit.register(ErrorAtexit)
+
+print("OKKKKKK")
+j = 9 * i * a
+k = os.getcwd()
+print("OKKKKKK3333")
+"""
+
 class testPerfLogManager1(unittest.TestCase):
     def test0(self):
         """
@@ -205,6 +220,34 @@ class testPerfLogManager1(unittest.TestCase):
                 self.assertTrue( "WARNING : Following code has generated non zero return code" in logCont )# should report something into the container
             cont.Shutdown()
 
+    def test4(self):
+        """
+        EDF30399 : Check current directory
+        """
+        with tempfile.TemporaryDirectory() as tmpdirname:
+            os.chdir( tmpdirname )
+            KernelBasis.SetForwardCurrentDirectoryStatus( True ) # key point
+            salome.salome_init()
+            assert(isinstance(KernelBasis.GetAllPyExecutionModes(),tuple))
+            KernelBasis.SetPyExecutionMode("OutOfProcessNoReplayFT") # the aim of test is here
+            hostname = "localhost"
+            cp = pylauncher.GetRequestForGiveContainer(hostname,"container_crash_test_2")
+            salome.cm.SetCodeOnContainerStartUp("""a = 2""")
+            salome.cm.SetBigObjOnDiskThreshold(1000)
+            salome.cm.SetOverrideEnvForContainersSimple(env = [])
+            salome.cm.SetDirectoryForReplayFiles( str( tmpdirname ) )
+            cont = salome.cm.GiveContainer(cp)
+            poa = salome.orb.resolve_initial_references("RootPOA")
+            obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o)
+            pyscript = cont.createPyScriptNode("testScript4",killMeAtTheEnd2)
+            pyscript.executeFirst(refPtr)
+            ret = pyscript.executeSecond(["j","k"])
+            ret0 = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() )
+            self.assertEqual(ret0,54)
+            ret2 = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[1]).data() )
+            self.assertEqual( ret2, str(tmpdirname) )
+            cont.Shutdown()
+
 if __name__ == '__main__':
     from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose
     salome.standalone()