fio: fix aio trim completion latencies
[fio.git] / crc / test.c
index 6453a72bbf336cf2a5717535e091d8dbc27b3fb9..b57f07a4d718f3b623920528d74cde69740f7820 100644 (file)
@@ -1,11 +1,12 @@
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "../fio.h"
 #include "../gettime.h"
 #include "../fio_time.h"
-#include "../verify.h"
+#include "../lib/rand.h"
+#include "../os/os.h"
 
 #include "../crc/md5.h"
 #include "../crc/crc64.h"
 #include "../crc/sha1.h"
 #include "../crc/sha256.h"
 #include "../crc/sha512.h"
+#include "../crc/sha3.h"
 #include "../crc/xxhash.h"
 #include "../crc/murmur3.h"
+#include "../crc/fnv.h"
 #include "../hash.h"
 
 #include "test.h"
@@ -45,6 +48,11 @@ enum {
        T_XXHASH        = 1U << 9,
        T_MURMUR3       = 1U << 10,
        T_JHASH         = 1U << 11,
+       T_FNV           = 1U << 12,
+       T_SHA3_224      = 1U << 13,
+       T_SHA3_256      = 1U << 14,
+       T_SHA3_384      = 1U << 15,
+       T_SHA3_512      = 1U << 16,
 };
 
 static void t_md5(struct test_type *t, void *buf, size_t size)
@@ -66,7 +74,7 @@ static void t_crc64(struct test_type *t, void *buf, size_t size)
        int i;
 
        for (i = 0; i < NR_CHUNKS; i++)
-               fio_crc64(buf, size);
+               t->output += fio_crc64(buf, size);
 }
 
 static void t_crc32(struct test_type *t, void *buf, size_t size)
@@ -74,7 +82,7 @@ static void t_crc32(struct test_type *t, void *buf, size_t size)
        int i;
 
        for (i = 0; i < NR_CHUNKS; i++)
-               fio_crc32(buf, size);
+               t->output += fio_crc32(buf, size);
 }
 
 static void t_crc32c(struct test_type *t, void *buf, size_t size)
@@ -82,7 +90,7 @@ static void t_crc32c(struct test_type *t, void *buf, size_t size)
        int i;
 
        for (i = 0; i < NR_CHUNKS; i++)
-               fio_crc32c(buf, size);
+               t->output += fio_crc32c(buf, size);
 }
 
 static void t_crc16(struct test_type *t, void *buf, size_t size)
@@ -90,7 +98,7 @@ static void t_crc16(struct test_type *t, void *buf, size_t size)
        int i;
 
        for (i = 0; i < NR_CHUNKS; i++)
-               fio_crc16(buf, size);
+               t->output += fio_crc16(buf, size);
 }
 
 static void t_crc7(struct test_type *t, void *buf, size_t size)
@@ -98,7 +106,7 @@ static void t_crc7(struct test_type *t, void *buf, size_t size)
        int i;
 
        for (i = 0; i < NR_CHUNKS; i++)
-               fio_crc7(buf, size);
+               t->output += fio_crc7(buf, size);
 }
 
 static void t_sha1(struct test_type *t, void *buf, size_t size)
@@ -109,8 +117,10 @@ static void t_sha1(struct test_type *t, void *buf, size_t size)
 
        fio_sha1_init(&ctx);
 
-       for (i = 0; i < NR_CHUNKS; i++)
+       for (i = 0; i < NR_CHUNKS; i++) {
                fio_sha1_update(&ctx, buf, size);
+               fio_sha1_final(&ctx);
+       }
 }
 
 static void t_sha256(struct test_type *t, void *buf, size_t size)
@@ -139,12 +149,68 @@ static void t_sha512(struct test_type *t, void *buf, size_t size)
                fio_sha512_update(&ctx, buf, size);
 }
 
+static void t_sha3_224(struct test_type *t, void *buf, size_t size)
+{
+       uint8_t sha[SHA3_224_DIGEST_SIZE];
+       struct fio_sha3_ctx ctx = { .sha = sha };
+       int i;
+
+       fio_sha3_224_init(&ctx);
+
+       for (i = 0; i < NR_CHUNKS; i++) {
+               fio_sha3_update(&ctx, buf, size);
+               fio_sha3_final(&ctx);
+       }
+}
+
+static void t_sha3_256(struct test_type *t, void *buf, size_t size)
+{
+       uint8_t sha[SHA3_256_DIGEST_SIZE];
+       struct fio_sha3_ctx ctx = { .sha = sha };
+       int i;
+
+       fio_sha3_256_init(&ctx);
+
+       for (i = 0; i < NR_CHUNKS; i++) {
+               fio_sha3_update(&ctx, buf, size);
+               fio_sha3_final(&ctx);
+       }
+}
+
+static void t_sha3_384(struct test_type *t, void *buf, size_t size)
+{
+       uint8_t sha[SHA3_384_DIGEST_SIZE];
+       struct fio_sha3_ctx ctx = { .sha = sha };
+       int i;
+
+       fio_sha3_384_init(&ctx);
+
+       for (i = 0; i < NR_CHUNKS; i++) {
+               fio_sha3_update(&ctx, buf, size);
+               fio_sha3_final(&ctx);
+       }
+}
+
+static void t_sha3_512(struct test_type *t, void *buf, size_t size)
+{
+       uint8_t sha[SHA3_512_DIGEST_SIZE];
+       struct fio_sha3_ctx ctx = { .sha = sha };
+       int i;
+
+       fio_sha3_512_init(&ctx);
+
+       for (i = 0; i < NR_CHUNKS; i++) {
+               fio_sha3_update(&ctx, buf, size);
+               fio_sha3_final(&ctx);
+       }
+}
+
 static void t_murmur3(struct test_type *t, void *buf, size_t size)
 {
        int i;
 
        for (i = 0; i < NR_CHUNKS; i++)
-               murmurhash3(buf, size, 0x8989);
+               t->output += murmurhash3(buf, size, 0x8989);
 }
 
 static void t_jhash(struct test_type *t, void *buf, size_t size)
@@ -155,6 +221,14 @@ static void t_jhash(struct test_type *t, void *buf, size_t size)
                t->output += jhash(buf, size, 0x8989);
 }
 
+static void t_fnv(struct test_type *t, void *buf, size_t size)
+{
+       int i;
+
+       for (i = 0; i < NR_CHUNKS; i++)
+               t->output += fnv(buf, size, 0x8989);
+}
+
 static void t_xxhash(struct test_type *t, void *buf, size_t size)
 {
        void *state;
@@ -229,6 +303,31 @@ static struct test_type t[] = {
                .mask = T_JHASH,
                .fn = t_jhash,
        },
+       {
+               .name = "fnv",
+               .mask = T_FNV,
+               .fn = t_fnv,
+       },
+       {
+               .name = "sha3-224",
+               .mask = T_SHA3_224,
+               .fn = t_sha3_224,
+       },
+       {
+               .name = "sha3-256",
+               .mask = T_SHA3_256,
+               .fn = t_sha3_256,
+       },
+       {
+               .name = "sha3-384",
+               .mask = T_SHA3_384,
+               .fn = t_sha3_384,
+       },
+       {
+               .name = "sha3-512",
+               .mask = T_SHA3_512,
+               .fn = t_sha3_512,
+       },
        {
                .name = NULL,
        },
@@ -274,6 +373,7 @@ int fio_crctest(const char *type)
        int i, first = 1;
        void *buf;
 
+       crc32c_arm64_probe();
        crc32c_intel_probe();
 
        if (!type)
@@ -289,11 +389,11 @@ int fio_crctest(const char *type)
        }
 
        buf = malloc(CHUNK);
-       init_rand_seed(&state, 0x8989);
+       init_rand_seed(&state, 0x8989, 0);
        fill_random_buf(&state, buf, CHUNK);
 
        for (i = 0; t[i].name; i++) {
-               struct timeval tv;
+               struct timespec ts;
                double mb_sec;
                uint64_t usec;
                char pre[3];
@@ -310,17 +410,20 @@ int fio_crctest(const char *type)
                        t[i].fn(&t[i], buf, CHUNK);
                }
 
-               fio_gettime(&tv, NULL);
+               fio_gettime(&ts, NULL);
                t[i].fn(&t[i], buf, CHUNK);
-               usec = utime_since_now(&tv);
-
-               mb_sec = (double) mb / (double) usec;
-               mb_sec /= (1.024 * 1.024);
-               if (strlen(t[i].name) >= 7)
-                       sprintf(pre, "\t");
-               else
-                       sprintf(pre, "\t\t");
-               printf("%s:%s%8.2f MB/sec\n", t[i].name, pre, mb_sec);
+               usec = utime_since_now(&ts);
+
+               if (usec) {
+                       mb_sec = (double) mb / (double) usec;
+                       mb_sec /= (1.024 * 1.024);
+                       if (strlen(t[i].name) >= 7)
+                               sprintf(pre, "\t");
+                       else
+                               sprintf(pre, "\t\t");
+                       printf("%s:%s%8.2f MiB/sec\n", t[i].name, pre, mb_sec);
+               } else
+                       printf("%s:inf MiB/sec\n", t[i].name);
                first = 0;
        }