crc/test.c: fix include of time.h
[fio.git] / crc / test.c
index 5812b358a65e8f6d14ae93fd57d0a7c1d5bd2567..3773b714782adf9e2eab1eb81fda731ba897a1bf 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "../fio.h"
 #include "../gettime.h"
-#include "../time.h"
+#include "../fio_time.h"
 #include "../verify.h"
 
 #include "../crc/md5.h"
@@ -16,6 +16,9 @@
 #include "../crc/sha1.h"
 #include "../crc/sha256.h"
 #include "../crc/sha512.h"
+#include "../crc/xxhash.h"
+
+#include "test.h"
 
 #define CHUNK          131072U
 #define NR_CHUNKS        2048U
@@ -36,6 +39,7 @@ enum {
        T_SHA1          = 1U << 6,
        T_SHA256        = 1U << 7,
        T_SHA512        = 1U << 8,
+       T_XXHASH        = 1U << 9,
 };
 
 static void randomize_buf(void *buf, unsigned int size, int seed)
@@ -233,6 +237,29 @@ static uint64_t t_sha512(void)
        return ret;
 }
 
+static uint64_t t_xxhash(void)
+{
+       void *state;
+       struct timeval s;
+       uint64_t ret;
+       void *buf;
+       int i;
+
+       state = XXH32_init(0x8989);
+
+       buf = malloc(CHUNK);
+       randomize_buf(buf, CHUNK, 0x8989);
+
+       fio_gettime(&s, NULL);
+       for (i = 0; i < NR_CHUNKS; i++)
+               XXH32_update(state, buf, CHUNK);
+
+       XXH32_digest(state);
+       ret = utime_since_now(&s);
+       free(buf);
+       return ret;
+}
+
 static struct test_type t[] = {
        {
                .name = "md5",
@@ -279,6 +306,11 @@ static struct test_type t[] = {
                .mask = T_SHA512,
                .fn = t_sha512,
        },
+       {
+               .name = "xxhash",
+               .mask = T_XXHASH,
+               .fn = t_xxhash,
+       },
        {
                .name = NULL,
        },
@@ -306,6 +338,16 @@ static unsigned int get_test_mask(const char *type)
        return mask;
 }
 
+static int list_types(void)
+{
+       int i;
+
+       for (i = 0; t[i].name; i++)
+               printf("%s\n", t[i].name);
+
+       return 0;
+}
+
 int fio_crctest(const char *type)
 {
        unsigned int test_mask = 0;
@@ -316,6 +358,8 @@ int fio_crctest(const char *type)
 
        if (!type)
                test_mask = ~0U;
+       else if (!strcmp(type, "help") || !strcmp(type, "list"))
+               return list_types();
        else
                test_mask = get_test_mask(type);
 
@@ -331,5 +375,6 @@ int fio_crctest(const char *type)
                mb_sec /= (1.024 * 1.024);
                printf("%s:\t%.2f MB/sec\n", t[i].name, mb_sec);
        }
+
        return 0;
 }