diff options
author | Vladimir Sadov <vsadov@microsoft.com> | 2019-06-03 20:55:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-03 20:55:42 -0700 |
commit | 9d4beb59887e94d3b6368cdc23e65c24fa0838fa (patch) | |
tree | 8f769952033d956a1e46cbd4daef1a54cfe4fc1c /tests/src | |
parent | a053e826dcb1ce3f58f7b368638b0ef03cf9f270 (diff) | |
download | coreclr-9d4beb59887e94d3b6368cdc23e65c24fa0838fa.tar.gz coreclr-9d4beb59887e94d3b6368cdc23e65c24fa0838fa.tar.bz2 coreclr-9d4beb59887e94d3b6368cdc23e65c24fa0838fa.zip |
Added scenario to test that CallGetTotalAllocatedBytes is monotonic in imprecise mode. (#24935)
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/GC/API/GC/GetTotalAllocatedBytes.cs | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/tests/src/GC/API/GC/GetTotalAllocatedBytes.cs b/tests/src/GC/API/GC/GetTotalAllocatedBytes.cs index e35bb41ca0..6e374432d4 100644 --- a/tests/src/GC/API/GC/GetTotalAllocatedBytes.cs +++ b/tests/src/GC/API/GC/GetTotalAllocatedBytes.cs @@ -12,6 +12,17 @@ using System.Threading.Tasks; public class Test { + struct Counts + { + public Counts(long precise, long imprecise) + { + this.precise = precise; + this.imprecise = imprecise; + } + public readonly long precise; + public readonly long imprecise; + } + static Random Rand = new Random(); static volatile object s_stash; // static volatile variable to keep the jit from eliding allocations or anything. @@ -31,7 +42,7 @@ public class Test return del; } - private static long CallGetTotalAllocatedBytes(long previous, out long differenceBetweenPreciseAndImprecise) + private static Counts CallGetTotalAllocatedBytes(Counts previous, out long differenceBetweenPreciseAndImprecise) { long precise = GetTotalAllocatedBytes(true); long imprecise = GetTotalAllocatedBytes(false); @@ -46,16 +57,21 @@ public class Test throw new Exception($"Imprecise total bytes allocated less than precise, imprecise is required to be a conservative estimate (that estimates high). imprecise = {imprecise}, precise = {precise}"); } - if (previous > precise) + if (previous.precise > precise) + { + throw new Exception($"Expected more memory to be allocated. previous.precise = {previous.precise}, precise = {precise}, difference = {previous.precise - precise}"); + } + + if (previous.imprecise > imprecise) { - throw new Exception($"Expected more memory to be allocated. previous = {previous}, precise = {precise}, difference = {previous - precise}"); + throw new Exception($"Expected more memory to be allocated. previous.imprecise = {previous.imprecise}, imprecise = {imprecise}, difference = {previous.imprecise - imprecise}"); } differenceBetweenPreciseAndImprecise = imprecise - precise; - return precise; + return new Counts(precise, imprecise); } - private static long CallGetTotalAllocatedBytes(long previous) + private static Counts CallGetTotalAllocatedBytes(Counts previous) { long differenceBetweenPreciseAndImprecise; previous = CallGetTotalAllocatedBytes(previous, out differenceBetweenPreciseAndImprecise); @@ -66,7 +82,7 @@ public class Test public static void TestSingleThreaded() { - long previous = 0; + Counts previous = default(Counts); for (int i = 0; i < 1000; ++i) { s_stash = new byte[1234]; @@ -76,7 +92,7 @@ public class Test public static void TestSingleThreadedLOH() { - long previous = 0; + Counts previous = default(Counts); for (int i = 0; i < 1000; ++i) { s_stash = new byte[123456]; @@ -108,7 +124,7 @@ public class Test } }); - long previous = 0; + Counts previous = default(Counts); for (int i = 0; i < 1000; ++i) { lock (lck) @@ -136,7 +152,7 @@ public class Test Thread thr = new Thread(() => { me.Wait(); - long previous = 0; + Counts previous = default(Counts); for (int i = 0; i < 2; ++i) { s_stash = new byte[123456]; |