Example #1
0
static int test_span_id_compare(int isLess,
                                const char *sa, const char *sb)
{
    struct htrace_span_id a, b;
    char err[512];
    size_t err_len = sizeof(err);
    int cmp;

    err[0] = '\0';

    htrace_span_id_parse(&a, sa, err, err_len);
    EXPECT_STR_EQ("", err);

    htrace_span_id_parse(&b, sb, err, err_len);
    EXPECT_STR_EQ("", err);

    cmp = htrace_span_id_compare(&a, &b);
    if (isLess) {
        EXPECT_INT_GT(cmp, 0);
    } else {
        EXPECT_INT_ZERO(cmp);
    }
    cmp = htrace_span_id_compare(&b, &a);
    if (isLess) {
        EXPECT_INT_GT(0, cmp);
    } else {
        EXPECT_INT_ZERO(cmp);
    }
    return 0;
}
static int local_file_rcv_test(struct rtest *rt)
{
    char err[512];
    size_t err_len = sizeof(err);
    char *local_path, *tdir, *conf_str = NULL;
    struct span_table *st;

    st = span_table_alloc();
    tdir = create_tempdir("local_file_rcv-unit", 0777, err, err_len);
    EXPECT_STR_EQ("", err);
    register_tempdir_for_cleanup(tdir);
    EXPECT_INT_GE(0, asprintf(&local_path, "%s/%s", tdir, "spans.json"));
    EXPECT_INT_GE(0, asprintf(&conf_str, "%s=%s;%s=%s",
                HTRACE_SPAN_RECEIVER_KEY, "local.file",
                HTRACE_LOCAL_FILE_RCV_PATH_KEY, local_path));
    EXPECT_INT_ZERO(rt->run(rt, conf_str));
    EXPECT_INT_GE(0, load_trace_span_file(local_path, st));
    EXPECT_INT_ZERO(rt->verify(rt, st));
    free(conf_str);
    free(local_path);
    free(tdir);
    span_table_free(st);

    return EXIT_SUCCESS;
}
static int htraced_rcv_test(struct rtest *rt)
{
    char err[512], *conf_str, *json_path;
    size_t err_len = sizeof(err);
    struct mini_htraced_params params;
    struct mini_htraced *ht = NULL;
    struct span_table *st;
    uint64_t start_ms;

    params.name = rt->name;
    params.confstr = "";
    mini_htraced_build(&params, &ht, err, err_len);
    EXPECT_STR_EQ("", err);

    EXPECT_INT_GE(0, asprintf(&json_path, "%s/%s",
                ht->root_dir, "spans.json"));
    EXPECT_INT_GE(0, asprintf(&conf_str, "%s=%s;%s=%s",
                HTRACE_SPAN_RECEIVER_KEY, "htraced",
                HTRACED_ADDRESS_KEY, ht->htraced_hrpc_addr));
    EXPECT_INT_ZERO(rt->run(rt, conf_str));
    start_ms = monotonic_now_ms(NULL);
    //
    // It may take a little while for htraced to commit the incoming spans sent
    // via RPC to its data store.  htraced does not have read-after-write
    // consistency, in other words.  This isn't normally an issue since trace
    // collection is done in the background.
    //
    // For this unit test, it means that we want to retry if we find too few
    // spans the first time we dump the htraced data store contents.
    //
    while (1) {
        int nspans;

        // This uses the bin/htracedTool program to dump the spans to a json file.
        mini_htraced_dump_spans(ht, err, err_len, json_path);
        EXPECT_STR_EQ("", err);
        st = span_table_alloc();
        EXPECT_NONNULL(st);
        nspans = load_trace_span_file(json_path, st);
        EXPECT_INT_GE(0, nspans);
        if (nspans >= rt->spans_created) {
            break;
        }
        span_table_free(st);
        st = NULL;
        EXPECT_UINT64_GE(start_ms, monotonic_now_ms(NULL) + 30000);
        sleep_ms(100);
        fprintf(stderr, "htraced_test_app1: retrying htrace dumpAll...\n");
    }
    EXPECT_INT_ZERO(rt->verify(rt, st));
    free(conf_str);
    free(json_path);
    span_table_free(st);
    mini_htraced_stop(ht);
    mini_htraced_free(ht);

    return EXIT_SUCCESS;
}
Example #4
0
static int test_snappend(void)
{
    char buf[16];
    char canary[16];
    char all_zero[16];

    memset(buf, 0, sizeof(buf));
    memset(canary, 0, sizeof(canary));
    memset(all_zero, 0, sizeof(all_zero));
    snappend(buf, sizeof(buf), "abracadabrafoomanchucalifrag");
    EXPECT_INT_ZERO(strcmp(buf, "abracadabrafoom"));
    EXPECT_INT_ZERO(memcmp(canary, all_zero, sizeof(canary)));
    snappend(buf, sizeof(buf), "other stuff");
    EXPECT_INT_ZERO(strcmp(buf, "abracadabrafoom"));
    EXPECT_INT_ZERO(memcmp(canary, all_zero, sizeof(canary)));
    memset(buf, 0, sizeof(buf));
    snappend(buf, sizeof(buf), "%d", 123);
    EXPECT_INT_ZERO(strcmp(buf, "123"));
    snappend(buf, sizeof(buf), "456");
    EXPECT_INT_ZERO(strcmp(buf, "123456"));
    snappend(buf, sizeof(buf), "789");
    EXPECT_INT_ZERO(strcmp(buf, "123456789"));

    return 0;
}
Example #5
0
int main(void)
{
    EXPECT_INT_ZERO(test_span_id_round_trip("0123456789abcdef0011223344556677"));
    EXPECT_INT_ZERO(test_span_id_round_trip("a919f3d62ce111e5b345feff819cdc9f"));
    EXPECT_INT_ZERO(test_span_id_round_trip("00000000000000000000000000000000"));
    EXPECT_INT_ZERO(test_span_id_round_trip("ba85631c2ce111e5b345feff819cdc9f"));
    EXPECT_INT_ZERO(test_span_id_round_trip("ffffffffffffffffffffffffffffffff"));
    EXPECT_INT_ZERO(test_span_id_round_trip("ba85631c2ce111e5b345feff819cdc9f"));

    EXPECT_INT_ZERO(test_span_id_less("a919f3d62ce111e5b345feff819cdc9e",
                                      "a919f3d62ce111e5b345feff819cdc9f"));
    EXPECT_INT_ZERO(test_span_id_eq("a919f3d62ce111e5b345feff819cdc9f",
                                    "a919f3d62ce111e5b345feff819cdc9f"));
    EXPECT_INT_ZERO(test_span_id_eq("ffffffff2ce111e5b345feff819cdc9f",
                                    "ffffffff2ce111e5b345feff819cdc9f"));
    EXPECT_INT_ZERO(test_span_id_less("1919f3d62ce111e5b345feff819cdc9f",
                                      "f919f3d62ce111e5b345feff81900000"));
    return EXIT_SUCCESS;
}
Example #6
0
int main(void)
{
    EXPECT_INT_ZERO(test_snappend());

    return EXIT_SUCCESS;
}