Home | History | Annotate | Download | only in src
      1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include <gflags/gflags.h>
      6 #include <stdio.h>
      7 #include <stdlib.h>
      8 #include <string.h>
      9 #include <ctime>
     10 
     11 #include "arraysize.h"
     12 #include "glinterface.h"
     13 #include "main.h"
     14 #include "utils.h"
     15 
     16 #include "all_tests.h"
     17 #include "testbase.h"
     18 
     19 using std::string;
     20 using std::vector;
     21 
     22 DEFINE_int32(
     23     duration,
     24     0,
     25     "Run all tests again and again in a loop for at least this many seconds.");
     26 DEFINE_string(tests,
     27               "",
     28               "Colon-separated list of tests to run; all tests if omitted.");
     29 DEFINE_string(blacklist, "", "colon-separated list of tests to disable");
     30 DEFINE_bool(
     31     hasty,
     32     false,
     33     "Run a smaller set of tests with less accurate results. "
     34     "Useful for running in BVT or debugging a failure.  Implies notemp");
     35 DEFINE_bool(list, false, "List available tests");
     36 DEFINE_bool(notemp, false, "Skip temperature checking");
     37 DEFINE_bool(verbose, false, "Print extra debugging messages");
     38 
     39 bool g_verbose;
     40 GLint g_max_texture_size;
     41 bool g_hasty;
     42 bool g_notemp;
     43 
     44 bool test_is_enabled(glbench::TestBase* test,
     45                      const vector<string>& enabled_tests) {
     46   if (enabled_tests.empty())
     47     return true;
     48 
     49   const char* test_name = test->Name();
     50   for (vector<string>::const_iterator i = enabled_tests.begin();
     51        i != enabled_tests.end(); ++i) {
     52     // This is not very precise, but will do until there's a need for something
     53     // more flexible.
     54     if (strstr(test_name, i->c_str()))
     55       return true;
     56   }
     57 
     58   return false;
     59 }
     60 
     61 bool test_is_disabled(glbench::TestBase* test,
     62                       const vector<string>& disabled_tests) {
     63   if (disabled_tests.empty())
     64     return false;
     65 
     66   const char* test_name = test->Name();
     67   for (vector<string>::const_iterator i = disabled_tests.begin();
     68        i != disabled_tests.end(); ++i) {
     69     // This is not very precise, but will do until there's a need for something
     70     // more flexible.
     71     if (strstr(test_name, i->c_str()))
     72       return true;
     73   }
     74 
     75   return false;
     76 }
     77 
     78 void printDateTime(void) {
     79   struct tm* ttime;
     80   time_t tm = time(0);
     81   char time_string[64];
     82   ttime = localtime(&tm);
     83   strftime(time_string, 63, "%c", ttime);
     84   printf("# DateTime: %s\n", time_string);
     85 }
     86 
     87 bool PassesSanityCheck(void) {
     88   GLint size[2];
     89   glGetIntegerv(GL_MAX_VIEWPORT_DIMS, size);
     90   printf("# MAX_VIEWPORT_DIMS=(%d, %d)\n", size[0], size[1]);
     91   if (size[0] < g_width || size[1] < g_height) {
     92     printf("# Error: MAX_VIEWPORT_DIMS=(%d, %d) are too small.\n", size[0],
     93            size[1]);
     94     return false;
     95   }
     96   glGetIntegerv(GL_MAX_TEXTURE_SIZE, size);
     97   printf("# GL_MAX_TEXTURE_SIZE=%d\n", size[0]);
     98   if (size[0] < g_width || size[0] < g_height) {
     99     printf("# Error: MAX_TEXTURE_SIZE=%d is too small.\n", size[0]);
    100     return false;
    101   }
    102   g_max_texture_size = size[0];
    103 
    104   return true;
    105 }
    106 
    107 int main(int argc, char* argv[]) {
    108   SetBasePathFromArgv0(argv[0], "src");
    109   gflags::ParseCommandLineFlags(&argc, &argv, false);
    110 
    111   g_verbose = FLAGS_verbose;
    112 
    113   g_main_gl_interface.reset(GLInterface::Create());
    114   if (!g_main_gl_interface->Init()) {
    115     printf("# Error: Failed to initialize %s.\n", argv[0]);
    116     return 1;
    117   }
    118 
    119   printf("# board_id: %s - %s\n", glGetString(GL_VENDOR),
    120          glGetString(GL_RENDERER));
    121   if (!PassesSanityCheck())
    122     return 1;
    123   g_main_gl_interface->Cleanup();
    124 
    125   if (argc == 1) {
    126     printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n",
    127            argv[0]);
    128   } else {
    129     printf("# Running: ");
    130     for (int i = 0; i < argc; i++)
    131       printf("%s ", argv[i]);
    132     printf("\n");
    133   }
    134   printDateTime();
    135 
    136   g_hasty = FLAGS_hasty;
    137   g_notemp = FLAGS_notemp || g_hasty;
    138 
    139   if (!g_notemp)
    140     g_initial_temperature = GetMachineTemperature();
    141 
    142   vector<string> enabled_tests = SplitString(FLAGS_tests, ":", true);
    143   vector<string> disabled_tests = SplitString(FLAGS_blacklist, ":", true);
    144 
    145   glbench::TestBase* tests[] = {
    146       // Please add new tests at the end of this list as tests are known to
    147       // bleed state. Reordering them or inserting a new test may cause a
    148       // change in the output images and MD5 causing graphics_GLBench failures.
    149       // TODO(ihf): Fix this.
    150       glbench::GetSwapTest(),
    151       glbench::GetContextTest(),
    152       glbench::GetClearTest(),
    153       glbench::GetFillRateTest(),
    154       glbench::GetWindowManagerCompositingTest(false),
    155       glbench::GetWindowManagerCompositingTest(true),
    156       glbench::GetTriangleSetupTest(),
    157       glbench::GetYuvToRgbTest(),
    158       glbench::GetReadPixelTest(),
    159       glbench::GetAttributeFetchShaderTest(),
    160       glbench::GetVaryingsAndDdxyShaderTest(),
    161       glbench::GetTextureReuseTest(),
    162       glbench::GetTextureUpdateTest(),
    163       glbench::GetTextureUploadTest(),
    164       glbench::GetFboFillRateTest(),
    165       glbench::GetDrawSizeTest(),
    166       glbench::GetTextureRebindTest(),
    167       glbench::GetBufferUploadTest(),
    168       glbench::GetBufferUploadSubTest(),
    169   };
    170 
    171   if (FLAGS_list) {
    172     for (unsigned int i = 0; i < arraysize(tests); i++)
    173       printf("%s\n", tests[i]->Name());
    174     return 0;
    175   }
    176 
    177   uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
    178   do {
    179     for (unsigned int i = 0; i < arraysize(tests); i++) {
    180       if (!test_is_enabled(tests[i], enabled_tests) ||
    181           test_is_disabled(tests[i], disabled_tests))
    182         continue;
    183       if (!g_main_gl_interface->Init()) {
    184         printf("Initialize failed\n");
    185         return 1;
    186       }
    187       glbench::ClearBuffers();
    188       tests[i]->Run();
    189       g_main_gl_interface->Cleanup();
    190     }
    191   } while (GetUTime() < done);
    192 
    193   for (unsigned int i = 0; i < arraysize(tests); i++) {
    194     delete tests[i];
    195     tests[i] = NULL;
    196   }
    197 
    198   printDateTime();
    199   // Signal to harness that we finished normally.
    200   printf("@TEST_END\n");
    201 
    202   return 0;
    203 }
    204