diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dca6dae8..aaf94014 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 00000000..19aafeab --- /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; +}