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

Unified Diff: fuzzers/fuzzer_utils.h

Issue 1995823002: [libfuzzer] moving icu fuzzers to //third_party/icu, additional fuzzers. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: nits Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: fuzzers/fuzzer_utils.h
diff --git a/fuzzers/fuzzer_utils.h b/fuzzers/fuzzer_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..3c0dedab360f5b864df62a21fd479f7325a65c08
--- /dev/null
+++ b/fuzzers/fuzzer_utils.h
@@ -0,0 +1,34 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+
+#ifndef THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_
+#define THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_
+
+#include <assert.h>
+#include <random>
+#include "base/at_exit.h"
+#include "base/i18n/icu_util.h"
+#include "third_party/icu/source/common/unicode/locid.h"
+
+struct IcuEnvironment {
+ IcuEnvironment() {
+ base::i18n::InitializeICU();
+ }
+};
+
+// Create RNG and seed it from data.
+std::mt19937_64 CreateRng(const uint8_t* data, size_t size) {
+ std::mt19937_64 rng;
+ std::string str = std::string(reinterpret_cast<const char*>(data), size);
+ std::size_t data_hash = std::hash<std::string>()(str);
+ rng.seed(data_hash);
+ return rng;
+}
+
+const icu::Locale& GetRandomLocale(std::mt19937_64* rng) {
+ int32_t num_locales;
+ assert(num_locales > 0);
+ const icu::Locale* locales = icu::Locale::getAvailableLocales(num_locales);
+ return locales[(*rng)() % num_locales];
+}
+
+#endif // THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_

Powered by Google App Engine
This is Rietveld 408576698