From 59539420420e369427c2049d11402512f0a196f6 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 13 Nov 2022 17:27:23 +0300 Subject: [PATCH] Add crc32c test utility --- src/CMakeLists.txt | 8 ++++++++ src/test_crc32.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/test_crc32.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dca6dae88..aaf94014c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -263,6 +263,14 @@ target_link_libraries(test_cas vitastor_client ) +# test_crc32 +add_executable(test_crc32 + test_crc32.cpp +) +target_link_libraries(test_crc32 + vitastor_blk +) + # test_cluster_client add_executable(test_cluster_client test_cluster_client.cpp diff --git a/src/test_crc32.cpp b/src/test_crc32.cpp new file mode 100644 index 000000000..19aafeab2 --- /dev/null +++ b/src/test_crc32.cpp @@ -0,0 +1,28 @@ +// Copyright (c) Vitaliy Filippov, 2019+ +// License: VNPL-1.1 (see README.md for details) + +#include +#include +#include +#include + +#include "malloc_or_die.h" +#include "errno.h" +#include "crc32c.h" + +int main(int narg, char *args[]) +{ + int bufsize = 65536; + uint8_t *buf = (uint8_t*)malloc_or_die(bufsize); + uint32_t csum = 0; + while (1) + { + int r = read(0, buf, bufsize); + if (r <= 0 && errno != EAGAIN && errno != EINTR) + break; + csum = crc32c(csum, buf, r); + } + free(buf); + printf("%08x\n", csum); + return 0; +}