1/*
2 * Copyright (c) 2014, University of Washington.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include <stdio.h>
11#include <string.h>
12#include <barrelfish/barrelfish.h>
13#include <storage/storage.h>
14#include <tenaciousd/log.h>
15
16#define ITERATIONS      2
17#define VSA_SIZE        (10*1024*1024)          // 10MB
18
19static struct storage_vsa vsa;
20static struct storage_vsic vsic;
21static uint64_t durations[ITERATIONS][2];
22
23int main(int argc, char *argv[])
24{
25    // XXX: Need to support multiple backend drivers eventually
26    errval_t err = storage_vsic_driver_init(argc, (const char **)argv, &vsic);
27    assert(err_is_ok(err));
28
29    err = storage_vsa_alloc(&vsa, VSA_SIZE);
30    assert(err_is_ok(err));
31
32    struct tenaciousd_log *log = tenaciousd_log_new(&vsa, &vsic);
33    assert(log != NULL);
34
35    size_t size = 32;
36    struct tenaciousd_log_entry *entry = tenaciousd_log_entry_new(log, &size);
37    assert(entry != NULL);
38
39    char *str = (char *)entry->data;
40    strcpy(str, "This is a test...");
41
42    for(int i = 0; i < ITERATIONS; i++) {
43        uint64_t start = rdtsc();
44
45        err = tenaciousd_log_append(log, entry);
46        assert(err_is_ok(err));
47
48        uint64_t middle = rdtsc();
49        durations[i][0] = middle - start;
50
51        err = vsic.ops.wait(&vsic);
52        assert(err_is_ok(err));
53
54        uint64_t end = rdtsc();
55        durations[i][1] = end - middle;
56    }
57
58    err = tenaciousd_log_delete(log);
59    assert(err_is_ok(err));
60
61    for(int i = 0; i < ITERATIONS; i++) {
62        printf("iteration %d = %" PRIu64 " %" PRIu64 "\n",
63               i, durations[i][0], durations[i][1]);
64    }
65
66    return 0;
67}
68