Bug 1170045 - part 0 - modify TestSegmentedVectors to use explicitly-updated counts; r=erahm
authorNathan Froyd <froydnj@mozilla.com>
Fri, 04 Mar 2016 12:00:33 -0500
changeset 323185 a9609f981f978909be000e7025e84eff5209d05c
parent 323184 80c48500bf8ff8e02c8d8e16032c05e415120620
child 323186 00d7f8217cc249d9e358661f8a2f67e4b3de5fcf
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1170045
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1170045 - part 0 - modify TestSegmentedVectors to use explicitly-updated counts; r=erahm The scheme in TestSegmentedVectors to use manually-annotated points and magic numbers corresponding to those annotations works OK for small numbers of operations. But for testing bulk push and pop, we're going to be doing many more operations, so let's move to recording explicitly in code the operations we expect to see, and checking those instead.
mfbt/tests/TestSegmentedVector.cpp
--- a/mfbt/tests/TestSegmentedVector.cpp
+++ b/mfbt/tests/TestSegmentedVector.cpp
@@ -115,38 +115,53 @@ struct NonPOD
   NonPOD(NonPOD&&)        { gNumMoveCtors++; }
   ~NonPOD()               { gNumDtors++; }
 };
 
 // This tests how segmented vectors with non-POD elements construct and
 // destruct those elements.
 void TestConstructorsAndDestructors()
 {
+  size_t defaultCtorCalls = 0;
+  size_t explicitCtorCalls = 0;
+  size_t copyCtorCalls = 0;
+  size_t moveCtorCalls = 0;
+  size_t dtorCalls = 0;
+
   {
     // A SegmentedVector with a non-POD element type.
     NonPOD x(1);                          // explicit constructor called
+    explicitCtorCalls++;
     SegmentedVector<NonPOD, 64, InfallibleAllocPolicy> v;
                                           // default constructor called 0 times
     MOZ_RELEASE_ASSERT(v.IsEmpty());
     gDummy = v.Append(x);                 // copy constructor called
+    copyCtorCalls++;
     NonPOD y(1);                          // explicit constructor called
+    explicitCtorCalls++;
     gDummy = v.Append(mozilla::Move(y));  // move constructor called
+    moveCtorCalls++;
     NonPOD z(1);                          // explicit constructor called
+    explicitCtorCalls++;
     v.InfallibleAppend(mozilla::Move(z)); // move constructor called
+    moveCtorCalls++;
     v.PopLast();                          // destructor called 1 time
-    MOZ_RELEASE_ASSERT(gNumDtors == 1);
+    dtorCalls++;
+    MOZ_RELEASE_ASSERT(gNumDtors == dtorCalls);
     v.Clear();                            // destructor called 2 times
+    dtorCalls += 2;
 
-    MOZ_RELEASE_ASSERT(gNumDefaultCtors  == 0);
-    MOZ_RELEASE_ASSERT(gNumExplicitCtors == 3);
-    MOZ_RELEASE_ASSERT(gNumCopyCtors     == 1);
-    MOZ_RELEASE_ASSERT(gNumMoveCtors     == 2);
-    MOZ_RELEASE_ASSERT(gNumDtors         == 3);
+    MOZ_RELEASE_ASSERT(gNumDefaultCtors  == defaultCtorCalls);
+    MOZ_RELEASE_ASSERT(gNumExplicitCtors == explicitCtorCalls);
+    MOZ_RELEASE_ASSERT(gNumCopyCtors     == copyCtorCalls);
+    MOZ_RELEASE_ASSERT(gNumMoveCtors     == moveCtorCalls);
+    MOZ_RELEASE_ASSERT(gNumDtors         == dtorCalls);
   }                                       // destructor called for x, y, z
-  MOZ_RELEASE_ASSERT(gNumDtors == 6);
+  dtorCalls += 3;
+  MOZ_RELEASE_ASSERT(gNumDtors == dtorCalls);
 }
 
 struct A { int mX; int mY; };
 struct B { int mX; char mY; double mZ; };
 struct C { A mA; B mB; };
 struct D { char mBuf[101]; };
 struct E { };