Merge branch 'dev' of https://github.com/smartxworks/fio
[fio.git] / t / lfsr-test.c
index 193a7f9f77ea5929936b986be179d15111ffb88c..ea8c8ddbde9a3429624ddde9cb9615a24c7b8c9b 100644 (file)
@@ -1,15 +1,13 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <time.h>
 #include <math.h>
 #include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 
 #include "../lib/lfsr.h"
+#include "../gettime.h"
+#include "../fio_time.h"
 
-void usage()
+static void usage(void)
 {
        printf("Usage: lfsr-test 0x<numbers> [seed] [spin] [verify]\n");
        printf("-------------------------------------------------------------\n");
@@ -36,12 +34,17 @@ int main(int argc, char *argv[])
        void *v = NULL, *v_start;
        double total, mean;
 
+       arch_init(argv);
+
        /* Read arguments */
        switch (argc) {
                case 5: if (strncmp(argv[4], "verify", 7) == 0)
-                                       verify = 1;
+                               verify = 1;
+                       /* fall through */
                case 4: spin = atoi(argv[3]);
+                       /* fall through */
                case 3: seed = atol(argv[2]);
+                       /* fall through */
                case 2: numbers = strtol(argv[1], NULL, 16);
                                break;
                default: usage();
@@ -65,18 +68,18 @@ int main(int argc, char *argv[])
        printf("LFSR specs\n");
        printf("==========================\n");
        printf("Size is         %u\n", 64 - __builtin_clzl(fl->cached_bit));
-       printf("Max val is      %lu\n", fl->max_val);
-       printf("XOR-mask is     0x%lX\n", fl->xormask);
-       printf("Seed is         %lu\n", fl->last_val);
+       printf("Max val is      %lu\n", (unsigned long) fl->max_val);
+       printf("XOR-mask is     0x%lX\n", (unsigned long) fl->xormask);
+       printf("Seed is         %lu\n", (unsigned long) fl->last_val);
        printf("Spin is         %u\n", fl->spin);
-       printf("Cycle length is %lu\n", fl->cycle_length);
+       printf("Cycle length is %lu\n", (unsigned long) fl->cycle_length);
 
        /* Create verification table */
        if (verify) {
                v_size = numbers * sizeof(uint8_t);
                v = malloc(v_size);
                memset(v, 0, v_size);
-               printf("\nVerification table is %lf KBs\n", (double)(v_size) / 1024);
+               printf("\nVerification table is %lf KiB\n", (double)(v_size) / 1024);
        }
        v_start = v;
 
@@ -86,21 +89,24 @@ int main(int argc, char *argv[])
         * negligible overhead.
         */
        fprintf(stderr, "\nTest initiated... ");
-       clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
-       while (!lfsr_next(fl, &i, fl->max_val)) {
+       fio_gettime(&start, NULL);
+       while (!lfsr_next(fl, &i)) {
                if (verify)
                        *(uint8_t *)(v + i) += 1;
        }
-       clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
+       fio_gettime(&end, NULL);
        fprintf(stderr, "finished.\n");
 
+
        /* Check if all expected numbers within range have been calculated */
        r = 0;
        if (verify) {
                fprintf(stderr, "Verifying results... ");
                for (i = 0; i < numbers; i++) {
-                       if (*(uint8_t *)(v + 1) != 1) {
-                               fprintf(stderr, "failed.\n");
+                       if (*(uint8_t *)(v + i) != 1) {
+                               fprintf(stderr, "failed (%lu = %d).\n",
+                                               (unsigned long) i,
+                                               *(uint8_t *)(v + i));
                                r = 1;
                                break;
                        }
@@ -110,16 +116,15 @@ int main(int argc, char *argv[])
        }
 
        /* Calculate elapsed time and mean time per number */
-       total = (end.tv_sec - start.tv_sec) * pow(10,9) +
-               end.tv_nsec - start.tv_nsec;
+       total = utime_since(&start, &end);
        mean = total / fl->num_vals;
 
        printf("\nTime results ");
        if (verify)
                printf("(slower due to verification)");
        printf("\n==============================\n");
-       printf("Elapsed: %lf s\n", total / pow(10,9));
-       printf("Mean:    %lf ns\n", mean);
+       printf("Elapsed: %lf s\n", total / pow(10,6));
+       printf("Mean:    %lf us\n", mean);
 
        free(v_start);
        free(fl);