diff mbox

[Branch,~glcompbench-dev/glcompbench/trunk] Rev 34: Add special CompositeTestDefaultOptions class used for changing default options at runtime.

Message ID 20110623142315.3922.63077.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org June 23, 2011, 2:23 p.m. UTC
------------------------------------------------------------
revno: 34
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Thu 2011-06-23 16:52:16 +0300
message:
  Add special CompositeTestDefaultOptions class used for changing default options at runtime.
added:
  src/composite-test-default-options.cc
modified:
  src/composite-canvas.cc
  src/composite-test.cc
  src/composite-test.h
  src/glcompbench.cc


--
lp:glcompbench
https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk

You are subscribed to branch lp:glcompbench.
To unsubscribe from this branch go to https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/composite-canvas.cc'
--- src/composite-canvas.cc	2011-06-23 13:32:36 +0000
+++ src/composite-canvas.cc	2011-06-23 13:52:16 +0000
@@ -595,29 +595,32 @@ 
     {
         Benchmark *benchmark = *benchIt;
         current_test_ = &benchmark->setup_test();
-        load_current_test_options();
-        reshape(width_, height_);
-        Log::info("Running test: '%s'\n", current_test_->name().c_str());
-
-        while (true) {
-            if (handle_xevent()) {
-                if (Options::force_tex_update)
-                    update_all_textures();
-
-                if (Options::draw) {
-                    profiler_draw_pair_.sample_start();
-                    current_test_->draw(this->window_list_);
-                    profiler_draw_pair_.sample_end();
-                    profiler_screen_update_pair_.sample_start();
-                    update_screen();
-                    profiler_screen_update_pair_.sample_end();
-                }
-
-                benchmark_update(next_iteration);
-                if (next_iteration) {
-                    break;
-                }
-
+
+        if (!current_test_->name().empty()) {
+            load_current_test_options();
+            reshape(width_, height_);
+            Log::info("Running test: '%s'\n", current_test_->name().c_str());
+
+            while (true) {
+                if (handle_xevent()) {
+                    if (Options::force_tex_update)
+                        update_all_textures();
+
+                    if (Options::draw) {
+                        profiler_draw_pair_.sample_start();
+                        current_test_->draw(this->window_list_);
+                        profiler_draw_pair_.sample_end();
+                        profiler_screen_update_pair_.sample_start();
+                        update_screen();
+                        profiler_screen_update_pair_.sample_end();
+                    }
+
+                    benchmark_update(next_iteration);
+                    if (next_iteration) {
+                        break;
+                    }
+
+                }
             }
         }
 

=== added file 'src/composite-test-default-options.cc'
--- src/composite-test-default-options.cc	1970-01-01 00:00:00 +0000
+++ src/composite-test-default-options.cc	2011-06-23 13:52:16 +0000
@@ -0,0 +1,55 @@ 
+/*
+ * Copyright © 2011 Linaro Limited
+ *
+ * This file is part of glcompbench.
+ *
+ * glcompbench is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * glcompbench is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with glcompbench.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis <alexandros.frantzis@linaro.org>
+ *  Jesse Barker <jesse.barker@linaro.org>
+ */
+
+#include "composite-test.h"
+#include "options.h"
+#include "benchmark.h"
+
+/**
+ * Prepares the test for a test run.
+ */
+void
+CompositeTestDefaultOptions::prepare_for_run()
+{
+    const std::map<std::string, CompositeTest *> &tests = Benchmark::tests();
+
+    for (std::list<std::pair<std::string, std::string> >::const_iterator iter = default_options_.begin();
+         iter != default_options_.end();
+         iter++)
+    {
+        for (std::map<std::string, CompositeTest *>::const_iterator test_iter = tests.begin();
+             test_iter != tests.end();
+             test_iter++)
+        {
+            test_iter->second->set_option_default(iter->first, iter->second);
+        }
+    }
+}
+
+bool
+CompositeTestDefaultOptions::set_option(const std::string &opt,
+                                        const std::string &val)
+{
+    default_options_.push_back(std::pair<std::string, std::string>(opt, val));
+    return true;
+}

=== modified file 'src/composite-test.cc'
--- src/composite-test.cc	2011-06-23 13:10:17 +0000
+++ src/composite-test.cc	2011-06-23 13:52:16 +0000
@@ -83,3 +83,15 @@ 
     }
 }
 
+bool
+CompositeTest::set_option_default(const string &opt, const string &val)
+{
+    map<string, Option>::iterator iter = options_.find(opt);
+
+    if (iter == options_.end())
+        return false;
+
+    iter->second.default_value = val;
+
+    return true;
+}

=== modified file 'src/composite-test.h'
--- src/composite-test.h	2011-06-23 13:32:36 +0000
+++ src/composite-test.h	2011-06-23 13:52:16 +0000
@@ -63,8 +63,9 @@ 
         std::string description;
     };
 
-    bool set_option(const std::string &opt, const std::string &val);
+    virtual bool set_option(const std::string &opt, const std::string &val);
     void reset_options();
+    bool set_option_default(const std::string &opt, const std::string &val);
     const std::map<std::string, Option> &options() { return options_; }
 
     static CompositeTest &dummy()
@@ -87,6 +88,18 @@ 
     std::map<std::string, Option> options_;
 };
 
+class CompositeTestDefaultOptions : public CompositeTest
+{
+public:
+    CompositeTestDefaultOptions() : CompositeTest("") {}
+
+    virtual void prepare_for_run();
+    virtual bool set_option(const std::string &opt, const std::string &val);
+
+protected:
+    std::list<std::pair<std::string, std::string> > default_options_;
+};
+
 class CompositeTestSimpleBase : public CompositeTest
 {
 public:

=== modified file 'src/glcompbench.cc'
--- src/glcompbench.cc	2011-06-23 11:25:34 +0000
+++ src/glcompbench.cc	2011-06-23 13:52:16 +0000
@@ -50,6 +50,9 @@ 
          test_iter++)
     {
         CompositeTest *test = test_iter->second;
+        if (test->name().empty())
+            continue;
+
         Log::info("[Test] %s\n", test->name().c_str());
 
         const map<string, CompositeTest::Option> &options = test->options();
@@ -107,6 +110,7 @@ 
         return 0;
     }
 
+    Benchmark::register_test(*new CompositeTestDefaultOptions());
     Benchmark::register_test(*new CompositeTestSimpleDefault());
     Benchmark::register_test(*new CompositeTestSimpleBrick());