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

Unified Diff: third_party/grpc/test/core/support/murmur_hash_test.c

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: third_party/grpc/test/core/support/murmur_hash_test.c
diff --git a/third_party/WebKit/Source/core/layout/OrderIterator.cpp b/third_party/grpc/test/core/support/murmur_hash_test.c
similarity index 51%
copy from third_party/WebKit/Source/core/layout/OrderIterator.cpp
copy to third_party/grpc/test/core/support/murmur_hash_test.c
index 8813561b862d5882183732d768d453e309737a4f..562b9567e719f05161d8247ea63202106c35aa93 100644
--- a/third_party/WebKit/Source/core/layout/OrderIterator.cpp
+++ b/third_party/grpc/test/core/support/murmur_hash_test.c
@@ -1,5 +1,7 @@
/*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -26,66 +28,61 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
*/
-#include "core/layout/OrderIterator.h"
+#include "src/core/support/murmur_hash.h"
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include "test/core/util/test_config.h"
-#include "core/layout/LayoutBox.h"
+#include <string.h>
-namespace blink {
+typedef uint32_t (*hash_func)(const void *key, size_t len, uint32_t seed);
-OrderIterator::OrderIterator(const LayoutBox* containerBox)
- : m_containerBox(containerBox)
- , m_currentChild(nullptr)
- , m_isReset(false)
-{
-}
+/* From smhasher:
+ This should hopefully be a thorough and uambiguous test of whether a hash
+ is correctly implemented on a given platform */
-LayoutBox* OrderIterator::first()
-{
- reset();
- return next();
-}
+static void verification_test(hash_func hash, uint32_t expected) {
+ uint8_t key[256];
+ uint32_t hashes[256];
+ uint32_t final = 0;
+ size_t i;
-LayoutBox* OrderIterator::next()
-{
- do {
- if (!m_currentChild) {
- if (m_orderValuesIterator == m_orderValues.end())
- return nullptr;
+ memset(key, 0, sizeof(key));
+ memset(hashes, 0, sizeof(hashes));
- if (!m_isReset) {
- ++m_orderValuesIterator;
- if (m_orderValuesIterator == m_orderValues.end())
- return nullptr;
- } else {
- m_isReset = false;
- }
+ /* Hash keys of the form {0}, {0,1}, {0,1,2}... up to N=255,using 256-N as
+ the seed */
- m_currentChild = m_containerBox->firstChildBox();
- } else {
- m_currentChild = m_currentChild->nextSiblingBox();
- }
- } while (!m_currentChild || m_currentChild->style()->order() != *m_orderValuesIterator);
+ for (i = 0; i < 256; i++) {
+ key[i] = (uint8_t)i;
+ hashes[i] = hash(key, i, (uint32_t)(256u - i));
+ }
- return m_currentChild;
-}
+ /* Then hash the result array */
-void OrderIterator::reset()
-{
- m_currentChild = nullptr;
- m_orderValuesIterator = m_orderValues.begin();
- m_isReset = true;
-}
+ final = hash(hashes, sizeof(hashes), 0);
-OrderIteratorPopulator::~OrderIteratorPopulator()
-{
- m_iterator.reset();
-}
+ /* The first four bytes of that hash, interpreted as a little-endian integer,
+ is our
+ verification value */
-void OrderIteratorPopulator::collectChild(const LayoutBox* child)
-{
- m_iterator.m_orderValues.insert(child->style()->order());
+ if (expected != final) {
+ gpr_log(GPR_INFO, "Verification value 0x%08X : Failed! (Expected 0x%08x)",
+ final, expected);
+ abort();
+ } else {
+ gpr_log(GPR_INFO, "Verification value 0x%08X : Passed!", final);
+ }
}
-} // namespace blink
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ /* basic tests to verify that things don't crash */
+ gpr_murmur_hash3("", 0, 0);
+ gpr_murmur_hash3("xyz", 3, 0);
+ verification_test(gpr_murmur_hash3, 0xB0F57EE3);
+ return 0;
+}
« no previous file with comments | « third_party/grpc/test/core/support/log_test.c ('k') | third_party/grpc/test/core/support/slice_buffer_test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698