From 0622fa7dee4c52718b841b54ad1766894ddaaa31 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 25 Jun 2024 11:01:35 +0200 Subject: [PATCH] [EDF30399] Keep same current directory in CrashProofMode --- src/Container/SALOME_PyNode.py | 14 ++++--- src/Launcher/Test/testCrashProofContainer.py | 43 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index d71e57c44..d5f10aa9d 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -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: diff --git a/src/Launcher/Test/testCrashProofContainer.py b/src/Launcher/Test/testCrashProofContainer.py index 00bc32b76..d05e72461 100644 --- a/src/Launcher/Test/testCrashProofContainer.py +++ b/src/Launcher/Test/testCrashProofContainer.py @@ -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() -- 2.39.2