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

Side by Side Diff: unit_test/unit_test.cc

Issue 1662453003: fix for ubsan on unittest.h fastrand() (Closed) Base URL: https://chromium.googlesource.com/libyuv/libyuv@master
Patch Set: fix lint warning: Weird number of spaces at line-start. Created 4 years, 10 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 | « unit_test/unit_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "../unit_test/unit_test.h" 11 #include "../unit_test/unit_test.h"
12 12
13 #include <stdlib.h> // For getenv() 13 #include <stdlib.h> // For getenv()
14 14
15 #include <cstring> 15 #include <cstring>
16 16
17 #include "gflags/gflags.h" 17 #include "gflags/gflags.h"
18 18
19 // Change this to 1000 for benchmarking. 19 // Change this to 1000 for benchmarking.
20 // TODO(fbarchard): Add command line parsing to pass this as option. 20 // TODO(fbarchard): Add command line parsing to pass this as option.
21 #define BENCHMARK_ITERATIONS 1 21 #define BENCHMARK_ITERATIONS 1
22 22
23 int fastrand_seed = 0xfb; 23 unsigned int fastrand_seed = 0xfb;
24 24
25 DEFINE_int32(libyuv_width, 0, "width of test image."); 25 DEFINE_int32(libyuv_width, 0, "width of test image.");
26 DEFINE_int32(libyuv_height, 0, "height of test image."); 26 DEFINE_int32(libyuv_height, 0, "height of test image.");
27 DEFINE_int32(libyuv_repeat, 0, "number of times to repeat test."); 27 DEFINE_int32(libyuv_repeat, 0, "number of times to repeat test.");
28 DEFINE_int32(libyuv_flags, 0, "cpu flags for reference code. 0 = C -1 = asm"); 28 DEFINE_int32(libyuv_flags, 0, "cpu flags for reference code. 0 = C -1 = asm");
29 DEFINE_int32(libyuv_cpu_info, -1, 29 DEFINE_int32(libyuv_cpu_info, -1,
30 "cpu flags for benchmark code. -1 = SIMD, 1 = C"); 30 "cpu flags for benchmark code. -1 = SIMD, 1 = C");
31 31
32 // For quicker unittests, default is 128 x 72. But when benchmarking, 32 // For quicker unittests, default is 128 x 72. But when benchmarking,
33 // default to 720p. Allow size to specify. 33 // default to 720p. Allow size to specify.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 118 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
119 } 119 }
120 if (FLAGS_libyuv_flags) { 120 if (FLAGS_libyuv_flags) {
121 disable_cpu_flags_ = FLAGS_libyuv_flags; 121 disable_cpu_flags_ = FLAGS_libyuv_flags;
122 } 122 }
123 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 123 const char* cpu_info = getenv("LIBYUV_CPU_INFO");
124 if (cpu_info) { 124 if (cpu_info) {
125 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 125 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
126 } 126 }
127 if (FLAGS_libyuv_cpu_info) { 127 if (FLAGS_libyuv_cpu_info) {
128 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 128 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
129 } 129 }
130 benchmark_pixels_div256_ = static_cast<int>(( 130 benchmark_pixels_div256_ = static_cast<int>((
131 static_cast<double>(Abs(benchmark_width_)) * 131 static_cast<double>(Abs(benchmark_width_)) *
132 static_cast<double>(Abs(benchmark_height_)) * 132 static_cast<double>(Abs(benchmark_height_)) *
133 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 133 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0);
134 benchmark_pixels_div1280_ = static_cast<int>(( 134 benchmark_pixels_div1280_ = static_cast<int>((
135 static_cast<double>(Abs(benchmark_width_)) * 135 static_cast<double>(Abs(benchmark_width_)) *
136 static_cast<double>(Abs(benchmark_height_)) * 136 static_cast<double>(Abs(benchmark_height_)) *
137 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 137 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0);
138 } 138 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 170 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
171 } 171 }
172 if (FLAGS_libyuv_flags) { 172 if (FLAGS_libyuv_flags) {
173 disable_cpu_flags_ = FLAGS_libyuv_flags; 173 disable_cpu_flags_ = FLAGS_libyuv_flags;
174 } 174 }
175 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 175 const char* cpu_info = getenv("LIBYUV_CPU_INFO");
176 if (cpu_info) { 176 if (cpu_info) {
177 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 177 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
178 } 178 }
179 if (FLAGS_libyuv_cpu_info) { 179 if (FLAGS_libyuv_cpu_info) {
180 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 180 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
181 } 181 }
182 benchmark_pixels_div256_ = static_cast<int>(( 182 benchmark_pixels_div256_ = static_cast<int>((
183 static_cast<double>(Abs(benchmark_width_)) * 183 static_cast<double>(Abs(benchmark_width_)) *
184 static_cast<double>(Abs(benchmark_height_)) * 184 static_cast<double>(Abs(benchmark_height_)) *
185 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 185 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0);
186 benchmark_pixels_div1280_ = static_cast<int>(( 186 benchmark_pixels_div1280_ = static_cast<int>((
187 static_cast<double>(Abs(benchmark_width_)) * 187 static_cast<double>(Abs(benchmark_width_)) *
188 static_cast<double>(Abs(benchmark_height_)) * 188 static_cast<double>(Abs(benchmark_height_)) *
189 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 189 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0);
190 } 190 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 222 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
223 } 223 }
224 if (FLAGS_libyuv_flags) { 224 if (FLAGS_libyuv_flags) {
225 disable_cpu_flags_ = FLAGS_libyuv_flags; 225 disable_cpu_flags_ = FLAGS_libyuv_flags;
226 } 226 }
227 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 227 const char* cpu_info = getenv("LIBYUV_CPU_INFO");
228 if (cpu_info) { 228 if (cpu_info) {
229 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 229 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
230 } 230 }
231 if (FLAGS_libyuv_cpu_info) { 231 if (FLAGS_libyuv_cpu_info) {
232 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 232 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
233 } 233 }
234 benchmark_pixels_div256_ = static_cast<int>(( 234 benchmark_pixels_div256_ = static_cast<int>((
235 static_cast<double>(Abs(benchmark_width_)) * 235 static_cast<double>(Abs(benchmark_width_)) *
236 static_cast<double>(Abs(benchmark_height_)) * 236 static_cast<double>(Abs(benchmark_height_)) *
237 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 237 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0);
238 benchmark_pixels_div1280_ = static_cast<int>(( 238 benchmark_pixels_div1280_ = static_cast<int>((
239 static_cast<double>(Abs(benchmark_width_)) * 239 static_cast<double>(Abs(benchmark_width_)) *
240 static_cast<double>(Abs(benchmark_height_)) * 240 static_cast<double>(Abs(benchmark_height_)) *
241 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 241 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0);
242 } 242 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 274 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
275 } 275 }
276 if (FLAGS_libyuv_flags) { 276 if (FLAGS_libyuv_flags) {
277 disable_cpu_flags_ = FLAGS_libyuv_flags; 277 disable_cpu_flags_ = FLAGS_libyuv_flags;
278 } 278 }
279 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 279 const char* cpu_info = getenv("LIBYUV_CPU_INFO");
280 if (cpu_info) { 280 if (cpu_info) {
281 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 281 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
282 } 282 }
283 if (FLAGS_libyuv_cpu_info) { 283 if (FLAGS_libyuv_cpu_info) {
284 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 284 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
285 } 285 }
286 benchmark_pixels_div256_ = static_cast<int>(( 286 benchmark_pixels_div256_ = static_cast<int>((
287 static_cast<double>(Abs(benchmark_width_)) * 287 static_cast<double>(Abs(benchmark_width_)) *
288 static_cast<double>(Abs(benchmark_height_)) * 288 static_cast<double>(Abs(benchmark_height_)) *
289 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 289 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0);
290 benchmark_pixels_div1280_ = static_cast<int>(( 290 benchmark_pixels_div1280_ = static_cast<int>((
291 static_cast<double>(Abs(benchmark_width_)) * 291 static_cast<double>(Abs(benchmark_width_)) *
292 static_cast<double>(Abs(benchmark_height_)) * 292 static_cast<double>(Abs(benchmark_height_)) *
293 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 293 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0);
294 } 294 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 326 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
327 } 327 }
328 if (FLAGS_libyuv_flags) { 328 if (FLAGS_libyuv_flags) {
329 disable_cpu_flags_ = FLAGS_libyuv_flags; 329 disable_cpu_flags_ = FLAGS_libyuv_flags;
330 } 330 }
331 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 331 const char* cpu_info = getenv("LIBYUV_CPU_INFO");
332 if (cpu_info) { 332 if (cpu_info) {
333 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 333 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
334 } 334 }
335 if (FLAGS_libyuv_cpu_info) { 335 if (FLAGS_libyuv_cpu_info) {
336 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 336 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
337 } 337 }
338 benchmark_pixels_div256_ = static_cast<int>(( 338 benchmark_pixels_div256_ = static_cast<int>((
339 static_cast<double>(Abs(benchmark_width_)) * 339 static_cast<double>(Abs(benchmark_width_)) *
340 static_cast<double>(Abs(benchmark_height_)) * 340 static_cast<double>(Abs(benchmark_height_)) *
341 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0); 341 static_cast<double>(benchmark_iterations_) + 255.0) / 256.0);
342 benchmark_pixels_div1280_ = static_cast<int>(( 342 benchmark_pixels_div1280_ = static_cast<int>((
343 static_cast<double>(Abs(benchmark_width_)) * 343 static_cast<double>(Abs(benchmark_width_)) *
344 static_cast<double>(Abs(benchmark_height_)) * 344 static_cast<double>(Abs(benchmark_height_)) *
345 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0); 345 static_cast<double>(benchmark_iterations_) + 1279.0) / 1280.0);
346 } 346 }
347 347
348 int main(int argc, char** argv) { 348 int main(int argc, char** argv) {
349 ::testing::InitGoogleTest(&argc, argv); 349 ::testing::InitGoogleTest(&argc, argv);
350 // AllowCommandLineParsing allows us to ignore flags passed on to us by 350 // AllowCommandLineParsing allows us to ignore flags passed on to us by
351 // Chromium build bots without having to explicitly disable them. 351 // Chromium build bots without having to explicitly disable them.
352 google::AllowCommandLineReparsing(); 352 google::AllowCommandLineReparsing();
353 google::ParseCommandLineFlags(&argc, &argv, true); 353 google::ParseCommandLineFlags(&argc, &argv, true);
354 return RUN_ALL_TESTS(); 354 return RUN_ALL_TESTS();
355 } 355 }
OLDNEW
« no previous file with comments | « unit_test/unit_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698