Bug 1314870 - gtestify TestWebGLElementArrayCache.cpp. r=jgilbert.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 04 Nov 2016 14:38:59 +1100
changeset 321322 db20b5de138f842350bc8305c9a98e2bad8f94e3
parent 321321 4f657d9e8c8204d43f0cb73f942857f569cba215
child 321323 ad907a673389fb1d6b7b9690d8ed57b77e2c5aa0
push id83555
push usernnethercote@mozilla.com
push dateSun, 06 Nov 2016 23:14:13 +0000
treeherdermozilla-inbound@ad907a673389 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1314870
milestone52.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 1314870 - gtestify TestWebGLElementArrayCache.cpp. r=jgilbert.
dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp
dom/canvas/compiledtest/moz.build
dom/canvas/gtest/TestWebGLElementArrayCache.cpp
dom/canvas/gtest/moz.build
dom/canvas/moz.build
testing/cppunittest.ini
deleted file mode 100644
--- a/dom/canvas/compiledtest/moz.build
+++ /dev/null
@@ -1,13 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-GeckoCppUnitTests([
-    'TestWebGLElementArrayCache',
-])
-
-LOCAL_INCLUDES += [
-    '../',
-]
rename from dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp
rename to dom/canvas/gtest/TestWebGLElementArrayCache.cpp
--- a/dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp
+++ b/dom/canvas/gtest/TestWebGLElementArrayCache.cpp
@@ -1,39 +1,23 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Assertions.h"
 
-#include "WebGLElementArrayCache.cpp"
+#include "WebGLElementArrayCache.h"
 
 #include <cstdio>
 #include <cstdlib>
 #include "nscore.h"
 #include "nsTArray.h"
 
-int gTestsPassed = 0;
-
-void
-VerifyImplFunction(bool condition, const char* file, int line)
-{
-  if (condition) {
-    gTestsPassed++;
-  } else {
-    std::fprintf(stderr, "Test failed at %s:%d\n", file, line);
-    abort();
-  }
-}
-
-#define VERIFY(condition) \
-    VerifyImplFunction((condition), __FILE__, __LINE__)
-
 void
 MakeRandomVector(nsTArray<uint8_t>& a, size_t size)
 {
   a.SetLength(size);
   // only the most-significant bits of rand() are reasonably random.
   // RAND_MAX can be as low as 0x7fff, and we need 8 bits for the result, so we can only
   // ignore the 7 least significant bits.
   for (size_t i = 0; i < size; i++)
@@ -52,27 +36,27 @@ template<typename T>
 GLenum
 GLType()
 {
   switch (sizeof(T)) {
   case 4:  return LOCAL_GL_UNSIGNED_INT;
   case 2:  return LOCAL_GL_UNSIGNED_SHORT;
   case 1:  return LOCAL_GL_UNSIGNED_BYTE;
   default:
-    VERIFY(false);
+    MOZ_RELEASE_ASSERT(false);
     return 0;
   }
 }
 
 void
 CheckValidate(bool expectSuccess, mozilla::WebGLElementArrayCache& c, GLenum type,
               uint32_t maxAllowed, size_t first, size_t count)
 {
   const bool success = c.Validate(type, maxAllowed, first, count);
-  VERIFY(success == expectSuccess);
+  ASSERT_TRUE(success == expectSuccess);
 }
 
 template<typename T>
 void
 CheckValidateOneTypeVariousBounds(mozilla::WebGLElementArrayCache& c, size_t firstByte,
                                   size_t countBytes)
 {
   size_t first = firstByte / sizeof(T);
@@ -105,17 +89,17 @@ void CheckValidateAllTypes(mozilla::WebG
 template<typename T>
 void
 CheckSanity()
 {
   const size_t numElems = 64; // should be significantly larger than tree leaf size to
                         // ensure we exercise some nontrivial tree-walking
   T data[numElems] = {1,0,3,1,2,6,5,4}; // intentionally specify only 8 elements for now
   size_t numBytes = numElems * sizeof(T);
-  MOZ_RELEASE_ASSERT(numBytes == sizeof(data), "GFX: number of bytes from size of each element * number of elements equals size of data.");
+  ASSERT_TRUE(numBytes == sizeof(data));
 
   GLenum type = GLType<T>();
 
   mozilla::WebGLElementArrayCache c;
   c.BufferData(data, numBytes);
   CheckValidate(true,  c, type, 6, 0, 8);
   CheckValidate(false, c, type, 5, 0, 8);
   CheckValidate(true,  c, type, 3, 0, 3);
@@ -129,52 +113,51 @@ CheckSanity()
 
   // now test a somewhat larger size to ensure we exceed the size of a tree leaf
   for(size_t i = 0; i < numElems; i++)
     data[i] = numElems - i;
   c.BufferData(data, numBytes);
   CheckValidate(true,  c, type, numElems,     0, numElems);
   CheckValidate(false, c, type, numElems - 1, 0, numElems);
 
-  MOZ_RELEASE_ASSERT(numElems > 10, "GFX: Less than 10 elements in array cache");
+  ASSERT_TRUE(numElems > 10);
   CheckValidate(true,  c, type, numElems - 10, 10, numElems - 10);
   CheckValidate(false, c, type, numElems - 11, 10, numElems - 10);
 }
 
 template<typename T>
 void
 CheckUintOverflow()
 {
   // This test is only for integer types smaller than uint32_t
   static_assert(sizeof(T) < sizeof(uint32_t), "This test is only for integer types \
                 smaller than uint32_t");
 
   const size_t numElems = 64; // should be significantly larger than tree leaf size to
                               // ensure we exercise some nontrivial tree-walking
   T data[numElems];
   size_t numBytes = numElems * sizeof(T);
-  MOZ_RELEASE_ASSERT(numBytes == sizeof(data), "GFX: size of data doesnt equal number of bytes of each element multiplied by number of elements.");
+  ASSERT_TRUE(numBytes == sizeof(data));
 
   GLenum type = GLType<T>();
 
   mozilla::WebGLElementArrayCache c;
 
   for(size_t i = 0; i < numElems; i++)
     data[i] = numElems - i;
   c.BufferData(data, numBytes);
 
   // bug 825205
   uint32_t bigValWrappingToZero = uint32_t(T(-1)) + 1;
   CheckValidate(true,  c, type, bigValWrappingToZero,     0, numElems);
   CheckValidate(true,  c, type, bigValWrappingToZero - 1, 0, numElems);
   CheckValidate(false, c, type,                        0, 0, numElems);
 }
 
-int
-main(int argc, char* argv[])
+TEST(WebGLElementArrayCache, Test)
 {
   srand(0); // do not want a random seed here.
 
   CheckSanity<uint8_t>();
   CheckSanity<uint16_t>();
   CheckSanity<uint32_t>();
 
   CheckUintOverflow<uint8_t>();
@@ -214,13 +197,10 @@ main(int argc, char* argv[])
               subsize = RandomInteger<size_t>(0, size - offset);
               CheckValidateAllTypes(b, offset, subsize);
             }
           } // validateCalls
         } // bufferSubDataCalls
       } // j
     } // i
   } // maxBufferSize
-
-  std::fprintf(stderr, "%s: all %d tests passed\n", argv[0], gTestsPassed);
-  return 0;
 }
 
--- a/dom/canvas/gtest/moz.build
+++ b/dom/canvas/gtest/moz.build
@@ -1,16 +1,17 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 UNIFIED_SOURCES += [
     'TestImageBitmapColorUtils.cpp',
+    'TestWebGLElementArrayCache.cpp',
 ]
 
 LOCAL_INCLUDES += [
     '/dom/canvas',
     '/media/libyuv/include'
 ]
 
 FINAL_LIBRARY = 'xul-gtest'
--- a/dom/canvas/moz.build
+++ b/dom/canvas/moz.build
@@ -1,16 +1,15 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 TEST_DIRS += [
-    'compiledtest',
     'gtest'
 ]
 
 # Change the following line(s) to avoid bug 1081323 (clobber after changing a manifest):
 # * Implement ReadPixel with PBOs.
 
 MOCHITEST_MANIFESTS += [
     'test/crash/mochitest.ini',
--- a/testing/cppunittest.ini
+++ b/testing/cppunittest.ini
@@ -69,17 +69,16 @@ skip-if = os == 'b2g'  #Bug 919595
 [TestTypeTraits]
 [TestTypedEnum]
 [TestUDPSocket]
 [TestUniquePtr]
 [TestVariant]
 [TestVector]
 [TestVolatileBuffer]
 [TestWeakPtr]
-[TestWebGLElementArrayCache]
 [TestXorShift128PlusRNG]
 [buffered_stun_socket_unittest]
 [ice_unittest]
 [test_nr_socket_unittest]
 [jsapi-tests]
 skip-if = os == 'b2g'  #Bug 1068946
 [mediaconduit_unittests]
 [mediapipeline_unittest]