diff options
author | Sage Weil <sage@inktank.com> | 2013-09-03 17:59:30 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-09-04 16:05:27 -0700 |
commit | 3e90c2abc9dfa60d44c1b57fa315625dbf960c60 (patch) | |
tree | 3036ef98723c77d50e3ba4763a220b692a45580b | |
parent | 3233336cc3b6c2c1e89fe6c6d21d42e0f2cce142 (diff) | |
download | ceph-3e90c2abc9dfa60d44c1b57fa315625dbf960c60.tar.gz |
common: unit test for crc32c
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/test/common/test_crc32c.cc | 75 |
2 files changed, 80 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7d87c7b5f60..d93e63c4c4e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -779,6 +779,11 @@ unittest_arch_SOURCES = test/test_arch.c arch/intel.c arch/neon.c arch/probe.cc unittest_arch_CXXFLAGS = ${AM_CFLAGS} check_PROGRAMS += unittest_arch +unittest_crc32c_SOURCES = test/common/test_crc32c.cc arch/intel.c arch/neon.c arch/probe.cc +unittest_crc32c_CXXFLAGS = ${AM_CFLAGS} ${UNITTEST_CXXFLAGS} +unittest_crc32c_LDADD = libcrc.la ${UNITTEST_LDADD} ${LIBGLOBAL_LDA} +check_PROGRAMS += unittest_crc32c + unittest_sharedptr_registry_SOURCES = test/common/test_sharedptr_registry.cc unittest_sharedptr_registry_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS} unittest_sharedptr_registry_LDADD = libcommon.la ${LIBGLOBAL_LDA} ${UNITTEST_LDADD} diff --git a/src/test/common/test_crc32c.cc b/src/test/common/test_crc32c.cc new file mode 100644 index 00000000000..19a1dfb7284 --- /dev/null +++ b/src/test/common/test_crc32c.cc @@ -0,0 +1,75 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include <iostream> +#include <string.h> + +#include "include/types.h" +#include "include/crc32c.h" +#include "include/utime.h" +#include "common/Clock.h" + +#include "gtest/gtest.h" + +#include "common/sctp_crc32.h" +#include "common/crc32c_intel_baseline.h" + +TEST(Crc32c, Small) { + const char *a = "foo bar baz"; + const char *b = "whiz bang boom"; + ASSERT_EQ(4119623852u, ceph_crc32c(0, (unsigned char *)a, strlen(a))); + ASSERT_EQ(881700046u, ceph_crc32c(1234, (unsigned char *)a, strlen(a))); + ASSERT_EQ(2360230088u, ceph_crc32c(0, (unsigned char *)b, strlen(b))); + ASSERT_EQ(3743019208u, ceph_crc32c(5678, (unsigned char *)b, strlen(b))); +} + +TEST(Crc32c, Big) { + int len = 4096000; + char *a = (char *)malloc(len); + memset(a, 1, len); + ASSERT_EQ(31583199u, ceph_crc32c(0, (unsigned char *)a, len)); + ASSERT_EQ(1400919119u, ceph_crc32c(1234, (unsigned char *)a, len)); +} + +TEST(Crc32c, Performance) { + int len = 1000 * 1024 * 1024; + char *a = (char *)malloc(len); + std::cout << "populating large buffer" << std::endl; + for (int i=0; i<len; i++) + a[i] = i & 0xff; + std::cout << "calculating crc" << std::endl; + + { + utime_t start = ceph_clock_now(NULL); + unsigned val = ceph_crc32c(0, (unsigned char *)a, len); + utime_t end = ceph_clock_now(NULL); + float rate = (float)len / (float)(1024*1024) / (float)(end - start); + std::cout << "best choice = " << rate << " MB/sec" << std::endl; + ASSERT_EQ(261108528u, val); + } + { + utime_t start = ceph_clock_now(NULL); + unsigned val = ceph_crc32c(0xffffffff, (unsigned char *)a, len); + utime_t end = ceph_clock_now(NULL); + float rate = (float)len / (float)(1024*1024) / (float)(end - start); + std::cout << "best choice 0xffffffff = " << rate << " MB/sec" << std::endl; + ASSERT_EQ(3895876243u, val); + } + { + utime_t start = ceph_clock_now(NULL); + unsigned val = ceph_crc32c_sctp(0, (unsigned char *)a, len); + utime_t end = ceph_clock_now(NULL); + float rate = (float)len / (float)(1024*1024) / (float)(end - start); + std::cout << "sctp = " << rate << " MB/sec" << std::endl; + ASSERT_EQ(261108528u, val); + } + { + utime_t start = ceph_clock_now(NULL); + unsigned val = ceph_crc32c_intel_baseline(0, (unsigned char *)a, len); + utime_t end = ceph_clock_now(NULL); + float rate = (float)len / (float)(1024*1024) / (float)(end - start); + std::cout << "intel baseline = " << rate << " MB/sec" << std::endl; + ASSERT_EQ(261108528u, val); + } + +} |