]> SALOME platform Git repositories - modules/kernel.git/blob - src/Launcher/Test/testPerfLogManager1.py
Salome HOME
[EDF29150] : fix testPerfLogManager1.py for environment without SALOME_FILE_BIG_OBJ_D...
[modules/kernel.git] / src / Launcher / Test / testPerfLogManager1.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2024  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import unittest
22 import os
23 import salome
24 import Engines
25 import pylauncher
26 import SALOME_PyNode
27
28 import pickle
29 import tempfile
30 import logging
31
32 def flush():
33     import sys
34     sys.stdout.flush()
35     sys.stderr.flush()
36
37 def unProxyfy( objs ):
38     """
39     objs is a list of SenderByte
40     """
41     ret = []
42     fileNamesProxyOut = []
43     for ret2 in objs:
44         ret3 = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret2).data() )
45         ret4 = ret3
46         fileNameProxyOut = None
47         if SALOME_PyNode.GetBigObjectOnDiskThreshold() != -1:
48             if isinstance( ret3, SALOME_PyNode.BigObjectOnDiskBase ):
49                 ret4 = ret3.get()
50             else:
51                 raise RuntimeError("Oooops")
52             ret3.unlinkOnDestructor()
53             fileNameProxyOut = ret3.getFileName()
54         logging.debug("Prxy file : {}".format( fileNameProxyOut ))
55         ret.append( ret3 )
56         fileNamesProxyOut.append( fileNameProxyOut )
57     return ret, fileNamesProxyOut
58
59 class testPerfLogManager1(unittest.TestCase):
60     def testPerfLogManager0(self):
61         """
62         [EDF29150] : This test checks measure performance methods
63         """
64         hostname = "localhost"
65         cp = pylauncher.GetRequestForGiveContainer(hostname,"container_test")
66         #PROXY_THRES = "-1"
67         PROXY_THRES = "1"
68         with tempfile.TemporaryDirectory() as tmpdirname:
69             val_for_big_obj = str( tmpdirname )
70             os.environ["SALOME_FILE_BIG_OBJ_DIR"] = val_for_big_obj
71             # Override environement for all containers launched
72             salome.cm.SetOverrideEnvForContainersSimple(env = [("SALOME_FILE_BIG_OBJ_DIR",val_for_big_obj),("SALOME_BIG_OBJ_ON_DISK_THRES",PROXY_THRES)])
73             salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 250 )
74             cont = salome.cm.GiveContainer(cp)
75             logging.debug("{} {}".format(40*"*",cont.getPID()))
76             script_st = """
77 import logging
78 import sys
79 import KernelBasis
80 cst = KernelBasis.GetTimeAdjustmentCst()
81 logging.debug("constant = {}".format(cst))
82 nbcore = 3
83 print("coucou {} {}".format(len(zeinput0),len(zeinput1)))
84 logging.debug("debug or not debug")
85 ob = [ [ bytes(3000000) ] ]
86 pihm, ts = KernelBasis.HeatMarcel(1 * nbcore * cst,nbcore)
87 print("Time ellapse spent : {} s".format(ts))
88 ob2 = [ [ bytes(100000) ] ]
89 pihm, ts = KernelBasis.HeatMarcel(1 * nbcore * cst,nbcore)
90 print("Time ellapse spent : {} s".format(ts))
91 sys.stderr.write("fake error message\\n")
92 """
93             poa = salome.orb.resolve_initial_references("RootPOA")
94             zeinput0 = [ bytes(100000000) ]
95             if SALOME_PyNode.GetBigObjectOnDiskThreshold() != -1:
96                 zeinput0 = SALOME_PyNode.ProxyfyPickeled( zeinput0 )
97                 zeinput0.unlinkOnDestructor()
98             obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["zeinput0"],{"zeinput0": [zeinput0], "zeinput1": [ [zeinput0], [zeinput0] ] }) ))
99             id_o = poa.activate_object(obj)
100             refPtr = poa.id_to_reference(id_o)
101             pyscript2 = cont.createPyScriptNode("testScript2",script_st)
102             pyscript2.executeFirst(refPtr)
103             ret2 = pyscript2.executeSecond(["ob","ob2"])# generate a DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats on debian11 ?
104             ret3, fileNamesProxyOut = unProxyfy( ret2 )
105             logging.getLogger().debug("test logging 1")
106             logging.debug("test logging 2")
107             logging.debug( salome.orb.object_to_string( salome.logm ) )
108             a = salome.logm.NaiveFetch()
109             logging.debug(a)
110             logging.debug(a[0][1][0])
111             logging.debug( a[0][1][0].get()._input_hdd_mem._data[0]._data[0]._hdd_mem ) # important
112             logging.debug( a[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
113             fileNameProxyIn = a[0][1][0].get()._input_hdd_mem._data[0]._data[0]._file_name
114             logging.debug( fileNameProxyIn )
115             del zeinput0
116             del ret3
117             import gc ; gc.collect()
118             if fileNameProxyIn is not None:
119                 if os.path.exists(fileNameProxyIn):
120                     raise RuntimeError("Oooops 2")
121             for fileNameProxyOut in fileNamesProxyOut:
122                 if fileNameProxyOut is not None:
123                     if os.path.exists(fileNameProxyOut):
124                         raise RuntimeError("Oooops 3")
125
126             # execution #2 inside last
127             script_st2 = """
128 import logging
129 b = 7+a
130 logging.debug("Execution 2")
131 import time
132 time.sleep(1)
133 """
134             obj2 = SALOME_PyNode.SenderByte_i(poa,pickle.dumps((["a"],{"a":3})))
135             id2_o = poa.activate_object(obj2)
136             refPtr2 = poa.id_to_reference(id2_o)
137             pyscript2.assignNewCompiledCode(script_st2)
138             pyscript2.executeFirst(refPtr2)
139             ret2_0 = pyscript2.executeSecond(["b"])
140             ret2_1, fileNamesProxyOut2 = unProxyfy( ret2_0 )
141             logging.debug( fileNamesProxyOut2 )
142             a = salome.logm.NaiveFetch()
143             del ret2_1
144             import gc ; gc.collect()
145             for fileNameProxyOut in fileNamesProxyOut2:
146                 if fileNameProxyOut is not None:
147                     if os.path.exists(fileNameProxyOut):
148                         raise RuntimeError("Oooops 3")
149             #
150             fname = os.path.join(str( tmpdirname ),"perf.log")
151             salome.logm.DumpInFile( fname )
152             logManagerInst0 = salome.logm.LoadFromFile( fname )
153             logging.debug( logManagerInst0[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
154             logManagerInst = salome.logm.Fetch(True)
155             logManagerInst2 = salome.logm.Fetch(True)
156             logging.debug( logManagerInst[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
157             self.assertTrue( logManagerInst2[0][1][0].get() is None )
158             self.assertTrue( logManagerInst[0][1][1].get()._output_hdd_mem._data[0]._file_name == fileNamesProxyOut2[0] )
159             logging.debug( logManagerInst[0][1][1].log() )
160             cont.Shutdown()
161
162 if __name__ == '__main__':
163     from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose
164     salome.standalone()
165     salome.salome_init()
166     setVerboseLevel(logging.DEBUG)
167     positionVerbosityOfLoggerRegardingState()
168     unittest.main()