Verified Commit 065fe603 authored by Steffen Michels's avatar Steffen Michels Committed by Camil Staps

add memory leak tests

parent c7e17f21
......@@ -88,6 +88,7 @@ Tests/Interactive/GenericEditors/TestReal
Tests/Interactive/GenericEditors/TestRecordWithADT
Tests/Interactive/GenericEditors/TestSingleRecord
Tests/Interactive/GenericEditors/TestString
Tests/MemoryLeaks
Tests/TestAsyncTask
Tests/Unit/iTasks.Extensions.FileCollection.UnitTests
Tests/Unit/iTasks.Extensions.Process.UnitTests
......
module MemoryLeaks
import StdEnv
import Data.Func, Data.Either, Data.Functor
from Data.List import instance Foldable []
import qualified Data.Foldable as DF
import qualified Data.Set as Set
import qualified Data.Map as Map
import Text
import Testing.TestEvents
import graph_copy
import iTasks, iTasks.Testing.Unit, iTasks.Internal.Task, iTasks.Internal.TaskIO
Start world = runUnitTests tests world
repetitions :: Int
repetitions =: 1000
tests :: [UnitTest]
tests =:
[ memoryConsumptionOf "recursive step" recursiveStep
, memoryConsumptionOf "local share" localShare
, memoryConsumptionOf "parallel task" parallelTask
, memoryConsumptionOf "shared interaction task" sharedInteraction
]
recursiveStep :: Task [Int]
recursiveStep =: sequence $ repeatn repetitions getIWorldSize
localShare :: Task [Int]
localShare =: sequence $ repeatn repetitions (withShared 3 \_ -> getIWorldSize)
parallelTask :: Task [Int]
parallelTask =: sequence $ repeatn repetitions (viewInformation [] 3 ||- getIWorldSize)
sharedInteraction :: Task [Int]
sharedInteraction =:
sequence $ repeatn repetitions (withShared 3 \sds -> viewSharedInformation [] sds ||- getIWorldSize)
memoryConsumptionOf :: !String !(Task [Int]) -> UnitTest
memoryConsumptionOf label task =
testTaskResult
("memory consumption of " +++ label) task events [] iWorldSizeIsNotIncreasing
where
events = [Left ResetEvent]
iWorldSizeIsNotIncreasing :: [Int] ![Int] -> EndEventType
iWorldSizeIsNotIncreasing _ iWorldSizes
| endSize <= initSize = Passed
| otherwise =
Failed $
?Just $
CustomFailReason $
concat ["Memory consumption increased by ", toString $ endSize - initSize, " bytes."]
where
// As there is some variation in the size, we use the max of the first 10% of the sizes as initial value.
initSize = 'DF'.maximum $ take (repetitions / 10) iWorldSizes
endSize = last iWorldSizes
getIWorldSize :: Task Int
getIWorldSize = mkInstantTask \_ iworld
# iworldString = copy_to_string iworld
# (iworldSize, iworldString) = usize iworldString
-> (Ok iworldSize, fst $ copy_from_string iworldString)
Version: 1.4
Global
ProjectRoot: .
Target: iTasks
Exec: {Project}*MemoryLeaks
ByteCode: {Project}*MemoryLeaks.bc
CodeGen
CheckStacks: False
CheckIndexes: True
OptimiseABC: True
GenerateByteCode: True
Application
HeapSize: 20971520
StackSize: 2048000
ExtraMemory: 8192
IntialHeapSize: 204800
HeapSizeMultiplier: 4096
ShowExecutionTime: False
ShowGC: False
ShowStackSize: False
MarkingCollector: False
DisableRTSFlags: False
StandardRuntimeEnv: True
Profile
Memory: False
MemoryMinimumHeapSize: 0
Time: False
Stack: False
Dynamics: True
GenericFusion: False
DescExL: True
Output
Output: NoConsole
Font: Monaco
FontSize: 9
WriteStdErr: False
Link
LinkMethod: Static
GenerateRelocations: False
GenerateSymbolTable: True
GenerateLinkMap: False
LinkResources: False
ResourceSource:
GenerateDLL: False
ExportedNames:
StripByteCode: True
KeepByteCodeSymbols: True
PrelinkByteCode: True
Paths
Path: {Project}
Path: {Project}*..*..*Libraries
Path: {Application}*lib*Dynamics
Path: {Application}*lib*GraphCopy
Path: {Application}*lib*ABCInterpreter
Path: {Application}*lib*StdEnv
Path: {Application}*lib*TCPIP
Path: {Application}*lib*Platform
Path: {Application}*lib*Platform*Deprecated*StdLib
Precompile:
Postlink:
MainModule
Name: MemoryLeaks
Dir: {Project}
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment