Skip to content

Commit

Permalink
Unit test and enhancement
Browse files Browse the repository at this point in the history
[SharedMem]
* NEW: Add Unit Test functions  Strings and free/alloc
  • Loading branch information
justlostintime committed Aug 12, 2021
1 parent 273073b commit 5030329
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 60 deletions.
47 changes: 37 additions & 10 deletions .src/UnitTest/TeStringMemoryManagement.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,46 @@
Public Sub aStringGetsbigger()

With SharedMem
.Begin(450000)
.Begin(1450000)

.myString = "..........................................................................................."
.myint = 1
Dim mystring As SharedMemSymbol = ._Symbol("myString")
Print .mystring.len, .len("myString"), Len(.mystring), mystring.LastWriteLength, MyString.storageLength, MyString.dataLength
For i As Integer = 0 To 1000
.myString = .MyString & "++ "
Print .mystring.len, .len("myString"), Len(.mystring), mystring.LastWriteLength, MyString.storageLength, MyString.dataLength

Dim mystring As SharedMemSymbol = ._Symbol("myString") ' work with the symbol information

'Print .mystring.len, .len("myString"), Len(.mystring), mystring.LastWriteLength, MyString.storageLength, MyString.dataLength
Dim starttime As Float = Timer
For i As Integer = 0 To 100000
.["myString"] = .["MyString"] & "++ "
If MyString.storageLength < MyString.dataLength Then
Assert.Fail("invalid memory allocation for string")
Else If mystring.LastWriteLength <> .mystring.len Then
Assert.Fail("Invalid write length/possible data corruption")
Endif
Next
Assert.Equals(MyString.LastWriteLength, .mystring.len, "Grow String Time=" & Str(Timer - starttime) & " : " & .mystring.len & "," & .len("myString") & "," & Len(.mystring) & "," & mystring.LastWriteLength & "," & MyString.storageLength)
Dim oldstoragelen As Integer = MyString.storageLength
.MyString = "Hello"
Print .mystring.len, .len("myString"), Len(.mystring), mystring.LastWriteLength, MyString.storageLength
Assert.equals(oldStorageLen, MyString.storageLength, "Grow Shrink" & " : " & .mystring.len & "," & .len("myString") & "," & Len(.mystring) & "," & mystring.LastWriteLength & "," & MyString.storageLength)
Assert.equals(MyString.LastWriteLength, .mystring.len, "Verify that variable size shrinks")
'._print()
.End()
End With


Dim testString As String = "......................................."
Starttime = Timer
For i As Integer = 0 To 100000
testString = testString & "++ "
Next

Assert.Pass("Native String time = " & Str(Timer - starttime))

MyString.value = "................................................"
starttime = Timer
For i As Integer = 0 To 100000
MyString.value = MyString.value & "++ "
Next

Assert.Pass("ShmSymbolEntry no mutex protection time = " & Str(Timer - starttime))

.End()
End With
End
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
' Gambas test file

' Gambas module file

Const LoopCount As Integer = 1000
Private starttime As Float

Public Sub main()
Public Sub aALLOCFree()
With sharedmem
SharedMem.Begin(128000)
Print "Begin TestSetFree _____________________________________________________________________________________________________________________________"
Print "Will run : Iterations = "; LoopCount; " Total of "; LoopCount * 6; " Set and free operations"
starttime = Timer

.Begin(128000)

'begin does some stuff to remove for this test See- SharedMemWaitQueue _Begin
.ShmFree(.["NotifyList"])
.free("notifylist")


starttime = Timer
For i As Integer = 1 To LoopCount

SharedMem["ThisString"] = "This is a test string of this size"
Expand Down Expand Up @@ -55,20 +56,15 @@ For i As Integer = 1 To LoopCount
.free("d")

If SharedMem.used() <> 0 Then
Print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Print "Used Amount reports "; .used();; " After "; i;; "Loops"
SharedMem._print()
Print "\n\nFailed Total time = "; Timer - starttime; " total operations per second ="; (LoopCount * 6) / (Timer - starttime)
Print "End TestSetFree _______________________________________________________________________________________________________________________________"
Stop
Quit -1
'Print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
'Print "Used Amount reports "; .used();; " After "; i;; "Loops"
'SharedMem._print()
Assert.Fail("Used(" & .used() & ") Not zero Total time = " & Str(Timer - starttime) & " Ops/Sec =" & Str((LoopCount * 6) / (Timer - starttime)))
Endif

Next

Print "End TestSetFree _______________________________________________________________________________________________________________________________"
SharedMem._print()
Print "\n\nPassed Total time = "; Timer - starttime; " total operations per second ="; (LoopCount * 6) / (Timer - starttime)
Assert.Pass("Alloc/Free time = " & Str(Timer - starttime) & "Total Ops=" & Str(LoopCount * 6) & " Ops/Sec =" & Str((LoopCount * 6) / (Timer - starttime)))

SharedMem.End()
End With
Expand Down
34 changes: 0 additions & 34 deletions .src/vTestApps/TestChangeStringSize.module

This file was deleted.

0 comments on commit 5030329

Please sign in to comment.