From 8f4c5a8955594b4f2dc31f9629af9ad3d4780c2c Mon Sep 17 00:00:00 2001 From: jcosborn Date: Wed, 1 Aug 2018 03:57:35 -0500 Subject: [PATCH] fixed #7894 (#8496) make system tests run properly --- lib/system/alloc.nim | 3 ++- tests/system/t7894.nim | 18 ++++++++++++++++ tests/system/talloc.nim | 43 ++++++++++++++++++++------------------ tests/system/talloc2.nim | 3 +++ tests/system/tdeepcopy.nim | 6 +++--- tests/system/tio.nim | 5 ++++- tests/system/tparams.nim | 15 +++++++------ 7 files changed, 62 insertions(+), 31 deletions(-) create mode 100644 tests/system/t7894.nim diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index ca2d76225b..ffb7aaf86c 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -436,8 +436,9 @@ proc requestOsChunks(a: var MemRegion, size: int): PBigChunk = a.nextChunkSize = PageSize*4 else: a.nextChunkSize = min(roundup(usedMem shr 2, PageSize), a.nextChunkSize * 2) - var size = size + a.nextChunkSize = min(a.nextChunkSize, MaxBigChunkSize) + var size = size if size > a.nextChunkSize: result = cast[PBigChunk](osAllocPages(size)) else: diff --git a/tests/system/t7894.nim b/tests/system/t7894.nim new file mode 100644 index 0000000000..2808e50200 --- /dev/null +++ b/tests/system/t7894.nim @@ -0,0 +1,18 @@ +discard """ +""" + +import os + +const size = 250000000 +var saved = newSeq[seq[int8]]() + +for i in 0..22: + # one of these is 0.25GB. + #echo i + var x = newSeq[int8](size) + sleep(10) + saved.add(x) + +for x in saved: + #echo x.len + doAssert x.len == size diff --git a/tests/system/talloc.nim b/tests/system/talloc.nim index 18396041d0..bf2cd97a86 100644 --- a/tests/system/talloc.nim +++ b/tests/system/talloc.nim @@ -1,54 +1,57 @@ +discard """ +""" + var x: ptr int x = cast[ptr int](alloc(7)) -assert x != nil +doAssert x != nil x = cast[ptr int](x.realloc(2)) -assert x != nil +doAssert x != nil x.dealloc() x = createU(int, 3) -assert x != nil +doAssert x != nil x.dealloc() x = create(int, 4) -assert cast[ptr array[4, int]](x)[0] == 0 -assert cast[ptr array[4, int]](x)[1] == 0 -assert cast[ptr array[4, int]](x)[2] == 0 -assert cast[ptr array[4, int]](x)[3] == 0 +doAssert cast[ptr array[4, int]](x)[0] == 0 +doAssert cast[ptr array[4, int]](x)[1] == 0 +doAssert cast[ptr array[4, int]](x)[2] == 0 +doAssert cast[ptr array[4, int]](x)[3] == 0 x = x.resize(4) -assert x != nil +doAssert x != nil x.dealloc() x = cast[ptr int](allocShared(100)) -assert x != nil +doAssert x != nil deallocShared(x) x = createSharedU(int, 3) -assert x != nil +doAssert x != nil x.deallocShared() x = createShared(int, 3) -assert x != nil -assert cast[ptr array[3, int]](x)[0] == 0 -assert cast[ptr array[3, int]](x)[1] == 0 -assert cast[ptr array[3, int]](x)[2] == 0 +doAssert x != nil +doAssert cast[ptr array[3, int]](x)[0] == 0 +doAssert cast[ptr array[3, int]](x)[1] == 0 +doAssert cast[ptr array[3, int]](x)[2] == 0 -assert x != nil +doAssert x != nil x = cast[ptr int](x.resizeShared(2)) -assert x != nil +doAssert x != nil x.deallocShared() x = create(int, 10) -assert x != nil +doAssert x != nil x = x.resize(12) -assert x != nil +doAssert x != nil x.dealloc() x = createShared(int, 1) -assert x != nil +doAssert x != nil x = x.resizeShared(1) -assert x != nil +doAssert x != nil x.deallocShared() x = cast[ptr int](alloc0(125 shl 23)) diff --git a/tests/system/talloc2.nim b/tests/system/talloc2.nim index c8cab78a1c..0757c07246 100644 --- a/tests/system/talloc2.nim +++ b/tests/system/talloc2.nim @@ -1,3 +1,6 @@ +discard """ +""" + const nmax = 2*1024*1024*1024 diff --git a/tests/system/tdeepcopy.nim b/tests/system/tdeepcopy.nim index f7a6e87fa4..383d2e8d13 100644 --- a/tests/system/tdeepcopy.nim +++ b/tests/system/tdeepcopy.nim @@ -65,7 +65,7 @@ proc main() = for val in table.values(): if myObj2.isNil: myObj2 = val - assert(myObj == myObj2) # passes + doAssert(myObj == myObj2) # passes var tableCopy: ListTableRef[int, SomeObj] deepCopy(tableCopy, table) @@ -80,7 +80,7 @@ proc main() = #echo cast[int](myObjCopy) #echo cast[int](myObjCopy2) - assert(myObjCopy == myObjCopy2) # fails + doAssert(myObjCopy == myObjCopy2) # fails type @@ -88,7 +88,7 @@ type counter, max: int data: array[0..99, (pointer, pointer)] -assert(sizeof(PtrTable) == 2*sizeof(int)+sizeof(pointer)*2*100) +doAssert(sizeof(PtrTable) == 2*sizeof(int)+sizeof(pointer)*2*100) main() echo "ok" diff --git a/tests/system/tio.nim b/tests/system/tio.nim index 3d4df806bd..7e9e189500 100644 --- a/tests/system/tio.nim +++ b/tests/system/tio.nim @@ -1,3 +1,6 @@ +discard """ +""" + import unittest, osproc, streams, os, strformat const STRING_DATA = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." @@ -36,7 +39,7 @@ proc verifyFileSize(sz: int64) = discard execProcess(&"dd if=/dev/zero of={fn} bs=1000000 count={size_in_mb}") doAssert os.getFileSize(fn) == sz # Verify OS filesize by string - + var f = open(fn) doAssert f.getFileSize() == sz # Verify file handle filesize f.close() diff --git a/tests/system/tparams.nim b/tests/system/tparams.nim index 1358212f2f..dd5511b8f7 100644 --- a/tests/system/tparams.nim +++ b/tests/system/tparams.nim @@ -1,3 +1,6 @@ +discard """ +""" + import os import osproc import parseopt2 @@ -7,12 +10,12 @@ let argv = commandLineParams() if argv == @[]: # this won't work with spaces - assert execShellCmd(getAppFilename() & " \"foo bar\" --aa:bar=a --a=c:d --ab -c --a[baz]:doo") == 0 + doAssert execShellCmd(getAppFilename() & " \"foo bar\" --aa:bar=a --a=c:d --ab -c --a[baz]:doo") == 0 else: let f = toSeq(getopt()) echo f.repr - assert f[0].kind == cmdArgument and f[0].key == "foo bar" and f[0].val == "" - assert f[1].kind == cmdLongOption and f[1].key == "aa" and f[1].val == "bar=a" - assert f[2].kind == cmdLongOption and f[2].key == "a=c" and f[2].val == "d" - assert f[3].kind == cmdLongOption and f[3].key == "ab" and f[3].val == "" - assert f[4].kind == cmdShortOption and f[4].key == "c" and f[4].val == "" + doAssert f[0].kind == cmdArgument and f[0].key == "foo bar" and f[0].val == "" + doAssert f[1].kind == cmdLongOption and f[1].key == "aa" and f[1].val == "bar=a" + doAssert f[2].kind == cmdLongOption and f[2].key == "a=c" and f[2].val == "d" + doAssert f[3].kind == cmdLongOption and f[3].key == "ab" and f[3].val == "" + doAssert f[4].kind == cmdShortOption and f[4].key == "c" and f[4].val == ""