Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: client/deps/glbench/src/testbase.cc

Issue 2794002: Added gflags switches: duration, tests, save, out. (Closed) Base URL: ssh://git@chromiumos-git//autotest.git
Patch Set: addressed comments Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/deps/glbench/src/testbase.h ('k') | client/deps/glbench/src/textureupdatetest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <gflags/gflags.h>
5 #include <stdio.h> 6 #include <stdio.h>
6 7
8 #include "base/scoped_ptr.h"
9 #include "base/file_util.h"
10
7 #include "testbase.h" 11 #include "testbase.h"
12 #include "utils.h"
13
14 DEFINE_bool(save, false, "save images after each test case");
15 DEFINE_string(out, "out", "directory to save images");
8 16
9 namespace glbench { 17 namespace glbench {
10 18
11 uint64_t TimeTest(TestBase* test, int iter) { 19 uint64_t TimeTest(TestBase* test, int iter) {
12 SwapBuffers(); 20 SwapBuffers();
13 glFinish(); 21 glFinish();
14 uint64_t time1 = GetUTime(); 22 uint64_t time1 = GetUTime();
15 if (!test->TestFunc(iter)) 23 if (!test->TestFunc(iter))
16 return ~0; 24 return ~0;
17 glFinish(); 25 glFinish();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 if (count < 2) { 63 if (count < 2) {
56 *slope = 0.f; 64 *slope = 0.f;
57 *bias = 0; 65 *bias = 0;
58 } 66 }
59 *slope = static_cast<float>(sum_x * sum_y - count * sum_xy) / 67 *slope = static_cast<float>(sum_x * sum_y - count * sum_xy) /
60 (sum_x * sum_x - count * sum_x2); 68 (sum_x * sum_x - count * sum_x2);
61 *bias = (sum_x * sum_xy - sum_x2 * sum_y) / (sum_x * sum_x - count * sum_x2); 69 *bias = (sum_x * sum_xy - sum_x2 * sum_y) / (sum_x * sum_x - count * sum_x2);
62 return true; 70 return true;
63 } 71 }
64 72
65 void RunTest(TestBase* test, const char *name, 73 void SaveImage(const char* name) {
74 const int size = g_width * g_height * 4;
75 scoped_array<char> pixels(new char[size]);
76 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE,
77 pixels.get());
78 FilePath dirname = GetBasePath().Append(FLAGS_out);
79 file_util::CreateDirectory(dirname);
80 FilePath filename = dirname.Append(name);
81 file_util::WriteFile(filename, pixels.get(), size);
82 }
83
84 void RunTest(TestBase* test, const char* name,
66 float coefficient, bool inverse) { 85 float coefficient, bool inverse) {
67 float slope; 86 float slope;
68 int64_t bias; 87 int64_t bias;
69 88
70 GLenum err = glGetError(); 89 GLenum err = glGetError();
71 if (err != 0) { 90 if (err != 0) {
72 printf("# %s failed, glGetError returned 0x%x.\n", name, err); 91 printf("# %s failed, glGetError returned 0x%x.\n", name, err);
73 // float() in python will happily parse Nan. 92 // float() in python will happily parse Nan.
74 printf("%s: Nan\n", name); 93 printf("%s: Nan\n", name);
75 } else { 94 } else {
76 if (Bench(test, &slope, &bias)) { 95 if (Bench(test, &slope, &bias)) {
96 if (FLAGS_save)
97 SaveImage(name);
77 printf("%s: %g\n", name, coefficient * (inverse ? 1.f / slope : slope)); 98 printf("%s: %g\n", name, coefficient * (inverse ? 1.f / slope : slope));
78 } else { 99 } else {
79 printf("# %s is too slow, returning zero.\n", name); 100 printf("# %s is too slow, returning zero.\n", name);
80 printf("%s: 0\n", name); 101 printf("%s: 0\n", name);
81 } 102 }
82 } 103 }
83 } 104 }
84 105
85 bool DrawArraysTestFunc::TestFunc(int iter) { 106 bool DrawArraysTestFunc::TestFunc(int iter) {
86 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 107 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 bool DrawElementsTestFunc::TestFunc(int iter) { 154 bool DrawElementsTestFunc::TestFunc(int iter) {
134 glDrawElements(GL_TRIANGLES, count_, GL_UNSIGNED_INT, 0); 155 glDrawElements(GL_TRIANGLES, count_, GL_UNSIGNED_INT, 0);
135 glFlush(); 156 glFlush();
136 for (int i = 0 ; i < iter-1; ++i) { 157 for (int i = 0 ; i < iter-1; ++i) {
137 glDrawElements(GL_TRIANGLES, count_, GL_UNSIGNED_INT, 0); 158 glDrawElements(GL_TRIANGLES, count_, GL_UNSIGNED_INT, 0);
138 } 159 }
139 return true; 160 return true;
140 } 161 }
141 162
142 } // namespace glbench 163 } // namespace glbench
OLDNEW
« no previous file with comments | « client/deps/glbench/src/testbase.h ('k') | client/deps/glbench/src/textureupdatetest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698