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

Side by Side Diff: fuzz/fuzz.cpp

Issue 1710183002: Do an in-place replacement of SkRandom with Fuzz for FilterFuzz (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: add comment Created 4 years, 8 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 | « fuzz/Fuzz.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 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Fuzz.h" 8 #include "Fuzz.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 371 }
372 SkCanvas canvas(bitmap); 372 SkCanvas canvas(bitmap);
373 canvas.drawPicture(pic); 373 canvas.drawPicture(pic);
374 SkDebugf("[terminated] Success! Decoded and rendered an SkPicture!\n"); 374 SkDebugf("[terminated] Success! Decoded and rendered an SkPicture!\n");
375 dump_png(bitmap); 375 dump_png(bitmap);
376 return 0; 376 return 0;
377 } 377 }
378 378
379 Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)), fNextByte(0) {} 379 Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)), fNextByte(0) {}
380 380
381 void Fuzz::signalBug () { raise(SIGSEGV); } 381 void Fuzz::signalBug () { SkDebugf("Signal bug\n"); raise(SIGSEGV); }
382 void Fuzz::signalBoring() { exit(0); } 382 void Fuzz::signalBoring() { SkDebugf("Signal boring\n"); exit(0); }
383 383
384 template <typename T> 384 template <typename T>
385 T Fuzz::nextT() { 385 T Fuzz::nextT() {
386 if (fNextByte + sizeof(T) > fBytes->size()) { 386 if (fNextByte + sizeof(T) > fBytes->size()) {
387 this->signalBoring(); 387 this->signalBoring();
388 } 388 }
389 389
390 T val; 390 T val;
391 memcpy(&val, fBytes->bytes() + fNextByte, sizeof(T)); 391 memcpy(&val, fBytes->bytes() + fNextByte, sizeof(T));
392 fNextByte += sizeof(T); 392 fNextByte += sizeof(T);
393 return val; 393 return val;
394 } 394 }
395 395
396 uint8_t Fuzz::nextB() { return this->nextT<uint8_t >(); } 396 uint8_t Fuzz::nextB() { return this->nextT<uint8_t >(); }
397 bool Fuzz::nextBool() { return nextB()&1; } 397 bool Fuzz::nextBool() { return nextB()&1; }
398 uint32_t Fuzz::nextU() { return this->nextT<uint32_t>(); } 398 uint32_t Fuzz::nextU() { return this->nextT<uint32_t>(); }
399 float Fuzz::nextF() { return this->nextT<float >(); } 399 float Fuzz::nextF() { return this->nextT<float >(); }
400 400
401 float Fuzz::nextF1() {
402 // This is the same code as is in SkRandom's nextF()
403 unsigned int floatint = 0x3f800000 | (this->nextU() >> 9);
404 float f = SkBits2Float(floatint) - 1.0f;
405 return f;
406 }
401 407
402 uint32_t Fuzz::nextRangeU(uint32_t min, uint32_t max) { 408 uint32_t Fuzz::nextRangeU(uint32_t min, uint32_t max) {
403 if (min > max) { 409 if (min > max) {
404 SkDebugf("Check mins and maxes (%d, %d)\n", min, max); 410 SkDebugf("Check mins and maxes (%d, %d)\n", min, max);
405 this->signalBoring(); 411 this->signalBoring();
406 } 412 }
407 uint32_t range = max - min + 1; 413 uint32_t range = max - min + 1;
408 if (0 == range) { 414 if (0 == range) {
409 return this->nextU(); 415 return this->nextU();
410 } else { 416 } else {
411 return min + this->nextU() % range; 417 return min + this->nextU() % range;
412 } 418 }
413 } 419 }
414 float Fuzz::nextRangeF(float min, float max) { 420 float Fuzz::nextRangeF(float min, float max) {
415 if (min > max) { 421 if (min > max) {
416 SkDebugf("Check mins and maxes (%f, %f)\n", min, max); 422 SkDebugf("Check mins and maxes (%f, %f)\n", min, max);
417 this->signalBoring(); 423 this->signalBoring();
418 } 424 }
419 float f = std::abs(this->nextF()); 425 float f = std::abs(this->nextF());
420 if (!std::isnormal(f) && f != 0.0) { 426 if (!std::isnormal(f) && f != 0.0) {
421 this->signalBoring(); 427 this->signalBoring();
422 } 428 }
423 return min + fmod(f, (max - min + 1)); 429 return min + fmod(f, (max - min + 1));
424 } 430 }
OLDNEW
« no previous file with comments | « fuzz/Fuzz.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698