示例#1
0
        private static void LoopRunTest(Fixture fixture, int testRuns)
        {
            IList <Exception> exceptionList = new List <Exception>();

            LoopRun(fixture, testRuns, exceptionList);

            if (exceptionList.Count > 0)
            {
                // We saw exceptions. Run it 99 more times, and then verify that our false deadlock rate is less than 2%.
                int additionalRuns = testRuns * 99;
                LoopRun(fixture, additionalRuns, exceptionList);
                double totalRuns   = additionalRuns + testRuns;
                double failures    = exceptionList.Count;
                double failureRate = failures / totalRuns;
                if (failureRate > 0.02)
                {
                    // We have more than 2% failures. Report it!
                    AssertionError error = new AssertionError("False deadlock failure rate of " + failureRate + " is greater than 2%");
                    foreach (Exception th in exceptionList)
                    {
                        error.addSuppressed(th);
                    }
                    throw error;
                }
            }
        }
示例#2
0
        private static void ThrowBadAccess(long pointer, int size, KeyValuePair <long, Allocation> fentry, KeyValuePair <long, Allocation> centry)
        {
            long now                      = System.nanoTime();
            long faddr                    = fentry == null ? 0 : fentry.Key;
            long fsize                    = fentry == null ? 0 : fentry.Value.sizeInBytes;
            long foffset                  = pointer - (faddr + fsize);
            long caddr                    = centry == null ? 0 : centry.Key;
            long csize                    = centry == null ? 0 : centry.Value.sizeInBytes;
            long coffset                  = caddr - (pointer + size);
            bool floorIsNearest           = foffset < coffset;
            long naddr                    = floorIsNearest ? faddr : caddr;
            long nsize                    = floorIsNearest ? fsize : csize;
            long noffset                  = floorIsNearest ? foffset : coffset;
            IList <FreeTrace> recentFrees = java.util.freeTraces.Where(Objects.nonNull).Where(trace => trace.contains(pointer)).OrderBy(c => c).ToList();
            AssertionError    error       = new AssertionError(format("Bad access to address 0x%x with size %s, nearest valid allocation is " + "0x%x (%s bytes, off by %s bytes). " + "Recent relevant frees (of %s) are attached as suppressed exceptions.", pointer, size, naddr, nsize, noffset, _freeCounter.get()));

            foreach (FreeTrace recentFree in recentFrees)
            {
                recentFree.ReferenceTime = now;
                error.addSuppressed(recentFree);
            }
            throw error;
        }