glbench: Fix several simple linter issues.

This is a first pass to make glbench code pass cros lint step. md5.cc
and png_helper.cc were left alone and some other linter check will be
fixed in a follow up CL.

BUG=chromium:394034
TEST=FEATURES=test emerge-link glbench

Change-Id: I53f39f66182742e5b043ea68e0deed979f4f3943
Reviewed-on: https://chromium-review.googlesource.com/245604
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/glbench/all_tests.h b/glbench/all_tests.h
index f9dead6..a8d7595 100644
--- a/glbench/all_tests.h
+++ b/glbench/all_tests.h
@@ -1,3 +1,7 @@
+// Copyright 2015 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
 #ifndef GLBENCH_ALL_TESTS_H_
 #define GLBENCH_ALL_TESTS_H_
 
@@ -20,6 +24,6 @@
 TestBase* GetWindowManagerCompositingTest(bool scissor);
 TestBase* GetYuvToRgbTest();
 
-} // namespace glbench
+}  // namespace glbench
 
 #endif  // GLBENCH_ALL_TESTS_H_
diff --git a/glbench/attributefetchtest.cc b/glbench/attributefetchtest.cc
index b8a88ce..e28ece6 100644
--- a/glbench/attributefetchtest.cc
+++ b/glbench/attributefetchtest.cc
@@ -147,4 +147,4 @@
   return new AttributeFetchShaderTest();
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/cleartest.cc b/glbench/cleartest.cc
index 063bd81..39294e8 100644
--- a/glbench/cleartest.cc
+++ b/glbench/cleartest.cc
@@ -62,4 +62,4 @@
   return new ClearTest;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/contexttest.cc b/glbench/contexttest.cc
index ad1f45d..54b1bb9 100644
--- a/glbench/contexttest.cc
+++ b/glbench/contexttest.cc
@@ -58,4 +58,4 @@
   return new ContextTest;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/egl_stuff.cc b/glbench/egl_stuff.cc
index 6b0c894..eda2158 100644
--- a/glbench/egl_stuff.cc
+++ b/glbench/egl_stuff.cc
@@ -69,9 +69,9 @@
     CheckError();
   }
 
-  // TODO: for some reason on some systems EGL_NATIVE_VISUAL_ID returns an ID
-  // that XVisualIDFromVisual cannot find.  Use default visual until this is
-  // resolved.
+  // TODO(amarinichev): for some reason on some systems EGL_NATIVE_VISUAL_ID
+  // returns an ID that XVisualIDFromVisual cannot find.  Use default visual
+  // until this is resolved.
 #if 0
   EGLint visual_id;
   eglGetConfigAttrib(display_, config_, EGL_NATIVE_VISUAL_ID, &visual_id);
@@ -87,7 +87,7 @@
   int nitems = 0;
   XVisualInfo* ret = XGetVisualInfo(g_xlib_display, VisualIDMask,
                                     &vinfo_template, &nitems);
-  CHECK(nitems == 1);
+  CHECK_EQ(nitems, 1);
   return ret;
 }
 
diff --git a/glbench/egl_stuff.h b/glbench/egl_stuff.h
index 0ca7ead..d5ffe1a 100644
--- a/glbench/egl_stuff.h
+++ b/glbench/egl_stuff.h
@@ -11,7 +11,6 @@
 
 class EGLInterface : public GLInterface {
  public:
-
   EGLInterface() : display_(EGL_NO_DISPLAY),
                    config_(NULL),
                    surface_(NULL),
diff --git a/glbench/fillratetest.cc b/glbench/fillratetest.cc
index d3c2c62..39c0230 100644
--- a/glbench/fillratetest.cc
+++ b/glbench/fillratetest.cc
@@ -187,7 +187,7 @@
   // Start with 32x32 textures and go up from there.
   int size_log2 = 5;
   for (int size = 1 << size_log2; size <= max_size; size *= 2) {
-    sprintf(name, "fbofill_tex_bilinear_%d", size);
+    snprintf(name, sizeof(name), "fbofill_tex_bilinear_%d", size);
 
     // Setup texture for FBO.
     GLuint destination_texture = 0;
@@ -249,4 +249,4 @@
   return new FboFillRateTest;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/glinterfacetest.cc b/glbench/glinterfacetest.cc
index 91ecc69..5a4bfc4 100644
--- a/glbench/glinterfacetest.cc
+++ b/glbench/glinterfacetest.cc
@@ -4,6 +4,8 @@
 
 #include "glbench/glinterfacetest.h"
 
+#include <string>
+
 #include "base/bind.h"
 
 namespace glbench {
@@ -64,13 +66,15 @@
 
   // Run test without GL commands.
   render_func_.Reset();
-  RunTest(this, (test_name_base + "nogl").c_str(), 1.0, g_width, g_height, false);
+  RunTest(this, (test_name_base + "nogl").c_str(), 1.0, g_width, g_height,
+          false);
 
   // Run main test with simple GL commands.
   SetupGLRendering();
   render_func_ = base::Bind(&GLInterfaceTest::RenderGLSimple,
                             base::Unretained(this));
-  RunTest(this, (test_name_base + "glsimple").c_str(), 1.0, g_width, g_height, false);
+  RunTest(this, (test_name_base + "glsimple").c_str(), 1.0, g_width, g_height,
+          false);
   CleanupGLRendering();
 
   // TODO(sque): Run with complex GL commands. See crosbug.com/36746.
@@ -81,4 +85,4 @@
   glDrawElements(GL_TRIANGLES, num_indices_, GL_UNSIGNED_SHORT, 0);
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/glinterfacetest.h b/glbench/glinterfacetest.h
index e53694a..243b02a 100644
--- a/glbench/glinterfacetest.h
+++ b/glbench/glinterfacetest.h
@@ -46,6 +46,6 @@
   DISALLOW_COPY_AND_ASSIGN(GLInterfaceTest);
 };
 
-} // namespace glbench
+}  // namespace glbench
 
 #endif  // GLBENCH_GLINTERFACETEST_H_
diff --git a/glbench/glx_stuff.cc b/glbench/glx_stuff.cc
index 2992c2b..3d60501 100644
--- a/glbench/glx_stuff.cc
+++ b/glbench/glx_stuff.cc
@@ -80,7 +80,7 @@
     int nelements;
     GLXFBConfig *fb_configs = glXChooseFBConfig(g_xlib_display, screen,
                                                 attrib, &nelements);
-    CHECK(nelements >= 1);
+    CHECK_GE(nelements, 1);
     fb_config_ = fb_configs[0];
     XFree(fb_configs);
   }
@@ -119,4 +119,4 @@
 
 void GLXInterface::CheckError() {
   CHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR));
-};
+}
diff --git a/glbench/main.cc b/glbench/main.cc
index 703f412..89af3dd 100644
--- a/glbench/main.cc
+++ b/glbench/main.cc
@@ -10,6 +10,8 @@
 #include <string.h>
 
 #include <ctime>
+#include <string>
+#include <vector>
 
 #include "base/logging.h"
 #include "base/strings/string_split.h"
@@ -25,13 +27,15 @@
 using std::vector;
 
 DEFINE_int32(duration, 0,
-             "Run all tests again and again in a loop for at least this many seconds.");
+             "Run all tests again and again in a loop for at least this many "
+             "seconds.");
 DEFINE_string(tests, "",
               "Colon-separated list of tests to run; all tests if omitted.");
 DEFINE_string(blacklist, "", "colon-separated list of tests to disable");
 DEFINE_bool(hasty, false,
             "Run a smaller set of tests with less accurate results. "
-            "Useful for running in BVT or debugging a failure.  Implies notemp");
+            "Useful for running in BVT or debugging a failure.  Implies "
+            "notemp");
 DEFINE_bool(list, false, "List available tests");
 DEFINE_bool(notemp, false, "Skip temperature checking");
 
@@ -45,11 +49,10 @@
     return true;
 
   const char* test_name = test->Name();
-  for (vector<string>::const_iterator i = enabled_tests.begin();
-       i != enabled_tests.end(); ++i) {
+  for (const std::string& test : enabled_tests) {
     // This is not very precise, but will do until there's a need for something
     // more flexible.
-    if (strstr(test_name, i->c_str()))
+    if (strstr(test_name, test.c_str()))
       return true;
   }
 
@@ -74,11 +77,11 @@
 }
 
 void printDateTime(void) {
-  struct tm *ttime;
+  struct tm ttime;
   time_t tm = time(0);
   char time_string[64];
-  ttime = localtime(&tm);
-  strftime(time_string, 63, "%c",ttime);
+  localtime_r(&tm, &ttime);
+  strftime(time_string, 63, "%c", &ttime);
   printf("# DateTime: %s\n", time_string);
 }
 
@@ -120,7 +123,8 @@
   g_main_gl_interface->Cleanup();
 
   if (argc == 1) {
-    printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n", argv[0]);
+    printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n",
+           argv[0]);
   } else {
     printf("# Running: ");
     for (int i = 0; i < argc; i++) printf("%s ", argv[i]);
diff --git a/glbench/readpixeltest.cc b/glbench/readpixeltest.cc
index 387f0b9..3b204ce 100644
--- a/glbench/readpixeltest.cc
+++ b/glbench/readpixeltest.cc
@@ -30,7 +30,7 @@
 
 bool ReadPixelTest::TestFunc(uint64_t iterations) {
   glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
-  CHECK(glGetError() == 0);
+  CHECK_EQ(glGetError(), GL_NO_ERROR);
   for (uint64_t i = 0; i < iterations - 1; i++)
     glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
   return true;
@@ -64,4 +64,4 @@
 }
 
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/swaptest.cc b/glbench/swaptest.cc
index 6f42d8d..daf0ab0 100644
--- a/glbench/swaptest.cc
+++ b/glbench/swaptest.cc
@@ -35,4 +35,4 @@
   return new SwapTest;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/synccontroltest.cc b/glbench/synccontroltest.cc
index f7f174f..0b778a2 100644
--- a/glbench/synccontroltest.cc
+++ b/glbench/synccontroltest.cc
@@ -92,4 +92,4 @@
   g_main_gl_interface->Cleanup();
 
   return ret_val ? 0 : 1;
-};
+}
diff --git a/glbench/synccontroltest_egl.cc b/glbench/synccontroltest_egl.cc
index 01b266d..8e1c1b8 100644
--- a/glbench/synccontroltest_egl.cc
+++ b/glbench/synccontroltest_egl.cc
@@ -68,7 +68,7 @@
   EGLInterface* interface_;
   PFNEGLGETSYNCVALUESCHROMIUMPROC egl_get_sync_values_;
 
-  EGLBoolean GetSyncValues(struct SyncValues &sync_values);
+  EGLBoolean GetSyncValues(struct SyncValues* sync_values);
   bool TestAgainstSystem(khronos_uint64_t ust);
 };
 
@@ -107,7 +107,7 @@
   glClearColor(kFillValueRed, kFillValueGreen, kFillValueBlue, 0.0);
   glClear(GL_COLOR_BUFFER_BIT);
 
-  ret = GetSyncValues(first_call);
+  ret = GetSyncValues(&first_call);
 
   if (!ret) {
     LOG(ERROR) << "Failure: First eglGetSyncValuesCHROMIUM returned false.\n";
@@ -120,7 +120,7 @@
 
   interface_->SwapBuffers();
   usleep(interval);
-  ret = GetSyncValues(second_call);
+  ret = GetSyncValues(&second_call);
 
   if (!ret) {
     LOG(ERROR) << "Failure: Second eglGetSyncValuesCHROMIUM returned false.\n";
@@ -175,13 +175,13 @@
   return test_val;
 }
 
-EGLBoolean EGLSyncControlTest::GetSyncValues(struct SyncValues &sync_values) {
+EGLBoolean EGLSyncControlTest::GetSyncValues(struct SyncValues *sync_values) {
   EGLBoolean ret;
   ret = egl_get_sync_values_(interface_->display(),
                              interface_->surface(),
-                             &sync_values.ust,
-                             &sync_values.msc,
-                             &sync_values.sbc);
+                             &sync_values->ust,
+                             &sync_values->msc,
+                             &sync_values->sbc);
   interface_->CheckError();
   return ret;
 }
diff --git a/glbench/synccontroltest_glx.cc b/glbench/synccontroltest_glx.cc
index dec37bc..37283c4 100644
--- a/glbench/synccontroltest_glx.cc
+++ b/glbench/synccontroltest_glx.cc
@@ -17,9 +17,7 @@
   return new GLXSyncControlTest();
 }
 
-GLXSyncControlTest::GLXSyncControlTest() {
-
-}
+GLXSyncControlTest::GLXSyncControlTest() { }
 
 void GLXSyncControlTest::Init() { }
 
diff --git a/glbench/teartest.cc b/glbench/teartest.cc
index 529d76d..1e29957 100644
--- a/glbench/teartest.cc
+++ b/glbench/teartest.cc
@@ -5,12 +5,15 @@
 #include "glbench/teartest.h"
 
 #include <gflags/gflags.h>
-#include <map>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
 
+#include <map>
+#include <string>
+#include <vector>
+
 #include "base/logging.h"
 #include "base/strings/string_split.h"
 #include "base/strings/string_util.h"
@@ -94,7 +97,8 @@
                           AllPlanes, ZPixmap);
   CHECK(xim != NULL);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g_height, g_width, 0,
-               GL_RGBA, GL_UNSIGNED_BYTE, (void*)(&xim->data[0]));
+               GL_RGBA, GL_UNSIGNED_BYTE,
+               reinterpret_cast<void*>(&xim->data[0]));
   XDestroyImage(xim);
 }
 
@@ -148,7 +152,8 @@
 
   virtual bool Loop(int shift) {
     UpdatePixmap(pixmap_, shift);
-    // TODO: it's probably much cheaper to not use Pixmap and XImage.
+    // TODO(amarinichev): it's probably much cheaper to not use Pixmap and
+    // XImage.
     CopyPixmapToTexture(pixmap_);
     return true;
   }
@@ -218,11 +223,8 @@
   base::SplitString(FLAGS_tests, ',', &tests);
 
   int return_code = 0;
-  for (std::vector<std::string>::iterator it = tests.begin();
-       it != tests.end();
-       it++)
-  {
-    Test* t = test_map[*it];
+  for (const std::string& test : tests) {
+    Test* t = test_map[test];
     if (!t || !t->Start()) {
       return_code = 1;
       continue;
@@ -232,8 +234,7 @@
     uint64_t wait_until = GetUTime() + 1000000ULL * FLAGS_seconds_to_run;
     for (int x = 0;
          !got_event && GetUTime() < wait_until;
-         x = (x + 4) % (2 * g_width))
-    {
+         x = (x + 4) % (2 * g_width)) {
       const int shift = x < g_width ? x : 2 * g_width - x;
 
       t->Loop(shift);
@@ -254,7 +255,7 @@
     t->Stop();
   }
 
-  // TODO: cleaner teardown.
+  // TODO(amarinichev): cleaner teardown.
 
   glDeleteTextures(1, &texture);
   g_main_gl_interface->Cleanup();
diff --git a/glbench/testbase.cc b/glbench/testbase.cc
index 554a193..d2349fe 100644
--- a/glbench/testbase.cc
+++ b/glbench/testbase.cc
@@ -59,7 +59,8 @@
   // numbers right, so we don't wait at all.
   if (!::g_notemp) {
     wait = WaitForCoolMachine(initial_temperature + 5.0, 30.0, &temperature);
-    printf("Bench: Cooled down to %.1f'C (initial=%.1f'C) after waiting %.1fs.\n",
+    printf("Bench: Cooled down to %.1f'C (initial=%.1f'C) after waiting "
+           "%.1fs.\n",
            temperature, initial_temperature, wait);
     if (temperature > initial_temperature + 10.0)
       printf("Warning: Machine did not cool down enough for next test!");
@@ -144,8 +145,8 @@
         // translate to hexadecimal ASCII of MD5
         sprintf(pixmd5,
           "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
-          d[ 0],d[ 1],d[ 2],d[ 3],d[ 4],d[ 5],d[ 6],d[ 7],
-          d[ 8],d[ 9],d[10],d[11],d[12],d[13],d[14],d[15]);
+          d[ 0], d[ 1], d[ 2], d[ 3], d[ 4], d[ 5], d[ 6], d[ 7],
+          d[ 8], d[ 9], d[10], d[11], d[12], d[13], d[14], d[15]);
         sprintf(name_png, "%s.pixmd5-%s.png", testname, pixmd5);
 
         if (FLAGS_save)
@@ -182,19 +183,18 @@
 
 void DrawArraysTestFunc::FillRateTestNormalSubWindow(const char* name,
                                                      const int width,
-                                                     const int height)
-{
+                                                     const int height) {
   RunTest(this, name, width * height, width, height, true);
 }
 
 
 void DrawArraysTestFunc::FillRateTestBlendDepth(const char *name) {
-  const int buffer_len = 64;
-  char buffer[buffer_len];
+  const int kBufferLen = 64;
+  char buffer[kBufferLen];
 
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glEnable(GL_BLEND);
-  snprintf(buffer, buffer_len, "%s_blended", name);
+  snprintf(buffer, kBufferLen, "%s_blended", name);
   RunTest(this, buffer, g_width * g_height, g_width, g_height, true);
   glDisable(GL_BLEND);
 
@@ -202,14 +202,14 @@
   // Fragments should have depth 0.
   glEnable(GL_DEPTH_TEST);
   glDepthFunc(GL_NOTEQUAL);
-  snprintf(buffer, buffer_len, "%s_depth_neq", name);
+  snprintf(buffer, kBufferLen, "%s_depth_neq", name);
   RunTest(this, buffer, g_width * g_height, g_width, g_height, true);
 
   // The DrawArrays call invoked by this test shouldn't render anything
   // because every fragment will fail the depth test.  Therefore we
   // should see the clear color.
   glDepthFunc(GL_NEVER);
-  snprintf(buffer, buffer_len, "%s_depth_never", name);
+  snprintf(buffer, kBufferLen, "%s_depth_never", name);
   RunTest(this, buffer, g_width * g_height, g_width, g_height, true);
   glDisable(GL_DEPTH_TEST);
 }
@@ -226,4 +226,4 @@
   return true;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/testbase.h b/glbench/testbase.h
index 3bdb8df..eb1b835 100644
--- a/glbench/testbase.h
+++ b/glbench/testbase.h
@@ -92,6 +92,6 @@
   GLsizei count_;
 };
 
-} // namespace glbench
+}  // namespace glbench
 
 #endif  // GLBENCH_TESTBASE_H_
diff --git a/glbench/texturereusetest.cc b/glbench/texturereusetest.cc
index d3bf1f8..63123a2 100644
--- a/glbench/texturereusetest.cc
+++ b/glbench/texturereusetest.cc
@@ -60,4 +60,4 @@
   return new TextureReuseTest;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/texturetest.cc b/glbench/texturetest.cc
index a13f993..973840a 100644
--- a/glbench/texturetest.cc
+++ b/glbench/texturetest.cc
@@ -4,6 +4,8 @@
 
 #include "glbench/texturetest.h"
 
+#include <string>
+
 #include "base/logging.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/string_util.h"
@@ -68,10 +70,10 @@
   // Textures formats
   // TODO(djkurtz): Other formats such as GL_BGRA, GL_RGB, GL_BGR, ... ?
   const GLenum kTexelFormats[] =
-     { GL_LUMINANCE, GL_RGBA }; // , GL_BGRA, GL_RGB, GL_BGR };
-  const unsigned int kTexelFormatSizes[] = { 1, 4 }; // , 4, 3, 3 };
+     { GL_LUMINANCE, GL_RGBA };  // , GL_BGRA, GL_RGB, GL_BGR };
+  const unsigned int kTexelFormatSizes[] = { 1, 4 };  // , 4, 3, 3 };
   const std::string kTexelFormatNames[] =
-      { "luminance", "rgba" }; // , "bgra", "rgb", "bgr" };
+      { "luminance", "rgba" };  // , "bgra", "rgb", "bgr" };
 
   // Texture upload commands
   UpdateFlavor kFlavors[] = { TEX_IMAGE, TEX_SUBIMAGE };
@@ -114,7 +116,8 @@
         RunTest(this, name.c_str(), buffer_size, g_width, g_height, true);
         GLenum error = glGetError();
         if (error != GL_NO_ERROR) {
-          printf("# GL error code %d after RunTest() with %dx%d %d-byte texture.\n",
+          printf("# GL error code %d after RunTest() with %dx%d %d-byte "
+                 "texture.\n",
                  error, width_, height_, texel_size);
        }
       }
@@ -128,4 +131,4 @@
   return true;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/texturetest.h b/glbench/texturetest.h
index 96e60a3..bde8978 100644
--- a/glbench/texturetest.h
+++ b/glbench/texturetest.h
@@ -41,9 +41,11 @@
   GLuint textures_[kNumberOfTextures];
   UpdateFlavor flavor_;
   GLenum texel_gl_format_;
+
+ private:
   DISALLOW_COPY_AND_ASSIGN(TextureTest);
 };
 
-} // namespace glbench
+}  // namespace glbench
 
 #endif  // GLBENCH_TEXTURETEST_H_
diff --git a/glbench/textureupdatetest.cc b/glbench/textureupdatetest.cc
index 26cf686..d41348f 100644
--- a/glbench/textureupdatetest.cc
+++ b/glbench/textureupdatetest.cc
@@ -48,4 +48,4 @@
   return new TextureUpdateTest;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/textureuploadtest.cc b/glbench/textureuploadtest.cc
index 91188ad..4bd0607 100644
--- a/glbench/textureuploadtest.cc
+++ b/glbench/textureuploadtest.cc
@@ -46,4 +46,4 @@
   return new TextureUploadTest;
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/trianglesetuptest.cc b/glbench/trianglesetuptest.cc
index e673076..1111f35 100644
--- a/glbench/trianglesetuptest.cc
+++ b/glbench/trianglesetuptest.cc
@@ -73,7 +73,8 @@
                             index_buffer_size, indices);
     RunTest(this, "triangle_setup", count_ / 3, g_width, g_height, true);
     glEnable(GL_CULL_FACE);
-    RunTest(this, "triangle_setup_all_culled", count_ / 3, g_width, g_height, true);
+    RunTest(this, "triangle_setup_all_culled", count_ / 3, g_width, g_height,
+            true);
     glDisable(GL_CULL_FACE);
 
     glDeleteBuffers(1, &index_buffer);
@@ -90,7 +91,8 @@
     index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
                             index_buffer_size, indices);
     glEnable(GL_CULL_FACE);
-    RunTest(this, "triangle_setup_half_culled", count_ / 3, g_width, g_height, true);
+    RunTest(this, "triangle_setup_half_culled", count_ / 3, g_width, g_height,
+            true);
 
     glDeleteBuffers(1, &index_buffer);
     delete[] indices;
@@ -108,4 +110,4 @@
 }
 
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/utils.cc b/glbench/utils.cc
index 2cbb11c..fbffe69 100644
--- a/glbench/utils.cc
+++ b/glbench/utils.cc
@@ -51,7 +51,7 @@
     return NULL;
 
   struct stat sb;
-  CHECK(fstat(fd, &sb) != -1);
+  CHECK_NE(fstat(fd, &sb), -1);
 
   char *mmap_ptr = static_cast<char *>(
     mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0));
@@ -73,7 +73,7 @@
   if (count != 1) {
     printf("Error: could not read integer from file. (%s)\n",
            filename.value().c_str());
-    if(count != 1)
+    if (count != 1)
       return false;
   }
   fclose(fd);
@@ -225,8 +225,7 @@
 
 // Generates a lattice symmetric around the origin (all quadrants).
 void CreateLattice(GLfloat **vertices, GLsizeiptr *size,
-                   GLfloat size_x, GLfloat size_y, int width, int height)
-{
+                   GLfloat size_x, GLfloat size_y, int width, int height) {
   GLfloat *vptr = *vertices = new GLfloat[2 * (width + 1) * (height + 1)];
   GLfloat shift_x = size_x * width;
   GLfloat shift_y = size_y * height;
@@ -244,10 +243,10 @@
 // vertices in the mesh.
 int CreateMesh(GLushort **indices, GLsizeiptr *size,
                int width, int height, int culled_ratio) {
-  srand(0);
+  unsigned int seed = 0;
 
   // We use 16 bit indices for compatibility with GL ES
-  CHECK(height * width + width + height <= 65535);
+  CHECK_LE(height * width + width + height, 65535);
 
   GLushort *iptr = *indices = new GLushort[2 * 3 * (width * height)];
   const int swath_height = 4;
@@ -262,7 +261,7 @@
         GLushort third = first + (width + 1);
         GLushort fourth = third + 1;
 
-        bool flag = rand() < culled_ratio;
+        bool flag = rand_r(&seed) < culled_ratio;
         *iptr++ = first;
         *iptr++ = flag ? second : third;
         *iptr++ = flag ? third : second;
@@ -278,8 +277,7 @@
   return iptr - *indices;
 }
 
-static void print_info_log(int obj, bool shader)
-{
+static void print_info_log(int obj, bool shader) {
   char info_log[4096];
   int length;
 
@@ -300,13 +298,11 @@
   }
 }
 
-static void print_shader_log(int shader)
-{
+static void print_shader_log(int shader) {
   print_info_log(shader, true);
 }
 
-static void print_program_log(int program)
-{
+static void print_program_log(int program) {
   print_info_log(program, false);
 }
 
@@ -368,4 +364,4 @@
   glClearColor(0, 0, 0.f, 0.f);
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/utils.h b/glbench/utils.h
index 6d2b325..dbad632 100644
--- a/glbench/utils.h
+++ b/glbench/utils.h
@@ -49,6 +49,6 @@
                                     const char* fragment_src);
 void ClearBuffers();
 
-} // namespace glbench
+}  // namespace glbench
 
 #endif  // GLBENCH_UTILS_H_
diff --git a/glbench/varyingsandddxytest.cc b/glbench/varyingsandddxytest.cc
index b22dcd3..e71953d 100644
--- a/glbench/varyingsandddxytest.cc
+++ b/glbench/varyingsandddxytest.cc
@@ -225,4 +225,4 @@
 }
 
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/windowmanagercompositingtest.cc b/glbench/windowmanagercompositingtest.cc
index 1e0499a..41a4fbe 100644
--- a/glbench/windowmanagercompositingtest.cc
+++ b/glbench/windowmanagercompositingtest.cc
@@ -16,7 +16,7 @@
 
 class WindowManagerCompositingTest : public TestBase {
  public:
-  WindowManagerCompositingTest(bool scissor)
+  explicit WindowManagerCompositingTest(bool scissor)
       : scissor_(scissor),
       compositing_background_program_(0),
       compositing_foreground_program_(0) {}
@@ -55,7 +55,8 @@
     testname = "compositing_no_fill";
   }
   InitializeCompositing();
-  RunTest(this, testname, kScreenScaleFactor, WINDOW_WIDTH, WINDOW_HEIGHT, true);
+  RunTest(this, testname, kScreenScaleFactor, WINDOW_WIDTH, WINDOW_HEIGHT,
+          true);
   TeardownCompositing();
   return true;
 }
@@ -379,4 +380,4 @@
                GL_RGBA, GL_UNSIGNED_BYTE, texture_update_);
 }
 
-} // namespace glbench
+}  // namespace glbench
diff --git a/glbench/windowmanagertest.cc b/glbench/windowmanagertest.cc
index 1341041..f514391 100644
--- a/glbench/windowmanagertest.cc
+++ b/glbench/windowmanagertest.cc
@@ -155,7 +155,7 @@
       continue;
 
     // State change. Perform action.
-    switch(state) {
+    switch (state) {
       case kStateScreenShot1:
         ignore_result(system(FLAGS_screenshot1_cmd.c_str()));
         break;
@@ -169,7 +169,6 @@
     // Advance to next state
     last_event_time = GetUTime();
     state = static_cast<State>(state + 1);
-
   } while (state != kStateExit);
 
   glDeleteTextures(1, &texture);
diff --git a/glbench/xlib_window.cc b/glbench/xlib_window.cc
index aadef0b..580f2f1 100644
--- a/glbench/xlib_window.cc
+++ b/glbench/xlib_window.cc
@@ -43,8 +43,9 @@
   g_height = g_height == -1 ? attributes.height : g_height;
   XVisualInfo* xlib_visinfo = g_main_gl_interface->GetXVisual();
 
-  unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask |
-    CWOverrideRedirect;
+  unsigned long mask =  // NOLINT(runtime/int)
+      CWBackPixel | CWBorderPixel | CWColormap | CWEventMask |
+      CWOverrideRedirect;
   XSetWindowAttributes attr;
   attr.background_pixel = 0;
   attr.border_pixel = 0;
diff --git a/glbench/yuvtest.cc b/glbench/yuvtest.cc
index 2189ceb..9b53512 100644
--- a/glbench/yuvtest.cc
+++ b/glbench/yuvtest.cc
@@ -260,4 +260,4 @@
   return new YuvToRgbTest();
 }
 
-} // namespace glbench
+}  // namespace glbench