def Skeleton_Delete(self): from ooflib.engine import mesh from ooflib.engine import skeletoncontext OOF.Microstructure.Create_From_ImageFile( filename=reference_file("ms_data","small.ppm"), microstructure_name="deltest", height=20.0, width=20.0) OOF.Image.AutoGroup(image="deltest:small.ppm") OOF.Skeleton.New( name="skeleton", microstructure="deltest", x_elements=8, y_elements=8, skeleton_geometry=QuadSkeleton(left_right_periodicity=False, top_bottom_periodicity=False)) OOF.Mesh.New(name="test", skeleton="deltest:skeleton", element_types=['T3_3', 'Q4_4']) # OOF.Skeleton.Delete(skeleton="deltest:skeleton") self.assertEqual(mesh.meshes.nActual(), 0) self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 0) self.assertEqual(femesh.get_globalFEMeshCount(), 0) self.assertEqual(cskeleton.get_globalNodeCount(), 0) self.assertEqual(cskeleton.get_globalElementCount(), 0) OOF.Microstructure.Delete(microstructure="deltest") self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)
def checktest(self, *args, **kwargs): # Run the test function. val = func(self, *args, **kwargs) # After running the function, delete the microstructures. from ooflib.common.IO.mainmenu import OOF for msname in _microstructures: OOF.Microstructure.Delete(microstructure=msname) # Exceptions can hold references to data. Since this file # tests for exceptions as well as memory leaks, it's # important to clear the exception state before checking # for leaks. sys.exc_clear() gc.collect() from ooflib.common.worker import allWorkers, allWorkerCores from ooflib.common.IO import whoville from ooflib.SWIG.common import cmicrostructure from ooflib.SWIG.common import threadstate from ooflib.SWIG.engine import cskeleton from ooflib.SWIG.engine import csubproblem from ooflib.SWIG.engine import femesh from ooflib.SWIG.engine import linearizedsystem self.assertEqual(whoville.getClass("Microstructure").nActual(), 0) self.assertEqual(whoville.getClass("Image").nActual(), 0) self.assertEqual(whoville.getClass("Skeleton").nActual(), 0) self.assertEqual(whoville.getClass("Mesh").nActual(), 0) self.assertEqual(whoville.getClass("SubProblem").nActual(), 0) self.assertEqual(linearizedsystem.get_globalLinSysCount(), 0) self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0) self.assertEqual(femesh.get_globalFEMeshCount(), 0) self.assertEqual(csubproblem.get_globalCSubProblemCount(), 0) self.assertEqual(cskeleton.get_globalNodeCount(), 0) self.assertEqual(cskeleton.get_globalElementCount(), 0) self.assertEqual(len(allWorkers), 0) ## TODO: For some reason, on some systems there is ## occasionally a leftover WorkerCore when this check is ## run. It doesn't seem to have any references, ## though... Since there are no extra ThreadStates, we're ## ignoring the leftover WorkerCore for now. # if len(allWorkerCores) > 0: # from ooflib.common import debug # debug.set_debug_mode() # print >> sys.stderr, "Referrers for", allWorkerCores.keys()[0],\ # "id=", id(allWorkerCores.keys()[0]) # debug.dumpReferrers(allWorkerCores.keys()[0], 2) # self.assertEqual(len(allWorkerCores), 0) # The main thread still exists, but all subthreads should # have finished. self.assertEqual(threadstate.nThreadStates(), 1) print >> sys.stderr, "Memory leak check passed." return val
def objectInventory(microstructures=0, nodes=0, elements=0, meshes=0): counts = (cmicrostructure.get_globalMicrostructureCount(), cskeleton.get_globalNodeCount(), cskeleton.get_globalElementCount(), femesh.get_globalFEMeshCount()) expected = (microstructures, nodes, elements, meshes) if counts != expected: print >> sys.stderr, \ "objectInventory failed. Expected (micro, nodes, elems, meshes) =",\ expected, "Got", counts return counts == expected
def checktest(self, *args, **kwargs): # Run the test function. val = func(self, *args, **kwargs) # After running the function, delete the microstructures. from ooflib.common.IO.mainmenu import OOF for msname in _microstructures: OOF.Microstructure.Delete(microstructure=msname) # Exceptions can hold references to data. Since this file # tests for exceptions as well as memory leaks, it's # important to clear the exception state before checking # for leaks. sys.exc_clear() gc.collect() from ooflib.common.worker import allWorkers, allWorkerCores from ooflib.common.IO import whoville from ooflib.SWIG.common import cmicrostructure from ooflib.SWIG.common import threadstate from ooflib.SWIG.engine import cskeleton from ooflib.SWIG.engine import csubproblem from ooflib.SWIG.engine import femesh from ooflib.SWIG.engine import linearizedsystem self.assertEqual(whoville.getClass("Microstructure").nActual(), 0) self.assertEqual(whoville.getClass("Image").nActual(), 0) self.assertEqual(whoville.getClass("Skeleton").nActual(), 0) self.assertEqual(whoville.getClass("Mesh").nActual(), 0) self.assertEqual(whoville.getClass("SubProblem").nActual(), 0) self.assertEqual(linearizedsystem.get_globalLinSysCount(),0) self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0) self.assertEqual(femesh.get_globalFEMeshCount(), 0) self.assertEqual(csubproblem.get_globalCSubProblemCount(), 0) self.assertEqual(cskeleton.get_globalNodeCount(), 0) self.assertEqual(cskeleton.get_globalElementCount(), 0) self.assertEqual(len(allWorkers), 0) ## TODO: For some reason, on some systems there is ## occasionally a leftover WorkerCore when this check is ## run. It doesn't seem to have any references, ## though... Since there are no extra ThreadStates, we're ## ignoring the leftover WorkerCore for now. # if len(allWorkerCores) > 0: # from ooflib.common import debug # debug.set_debug_mode() # print >> sys.stderr, "Referrers for", allWorkerCores.keys()[0],\ # "id=", id(allWorkerCores.keys()[0]) # debug.dumpReferrers(allWorkerCores.keys()[0], 2) # self.assertEqual(len(allWorkerCores), 0) # The main thread still exists, but all subthreads should # have finished. self.assertEqual(threadstate.nThreadStates(), 1) print >> sys.stderr, "Memory leak check passed." return val
def MS_Delete(self): OOF.Microstructure.Create_From_ImageFile( filename=reference_file("ms_data","small.ppm"), microstructure_name="deltest", height=20.0, width=20.0) OOF.Image.AutoGroup(image="deltest:small.ppm") OOF.Skeleton.New( name="skeleton", microstructure="deltest", x_elements=8, y_elements=8, skeleton_geometry=QuadSkeleton(left_right_periodicity=True, top_bottom_periodicity=True)) self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 1) OOF.Microstructure.Delete(microstructure="deltest") self.assertEqual(microstructure.microStructures.nActual(), 0) self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 0) self.assertEqual(imagecontext.imageContexts.nActual(), 0) self.assertEqual(cskeleton.get_globalNodeCount(), 0) self.assertEqual(cskeleton.get_globalElementCount(), 0) self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)