示例#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 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;
}
示例#3
0
TEST(ZXTestCAssertionTest, AssertStrEq) {
    const char* str1 = "a";
    const char* str2 = "a";

    EXPECT_STR_EQ(str1, str2, "ASSERT_STR_EQ failed to identify equal strings.");
    EXPECT_STR_EQ(str1, str1, "ASSERT_STR_EQ failed to identify equal strings.");
    ASSERT_STR_EQ(str1, str2, "ASSERT_STR_EQ failed to identify equal strings.");
    ASSERT_STR_EQ(str1, str1, "ASSERT_STR_EQ failed to identify equal strings.");
    // No failures
    ZX_ASSERT_MSG(!_ZXTEST_ABORT_IF_ERROR, "Assert was did not abort test.");
}
示例#4
0
static int test_span_id_round_trip(const char *str)
{
    struct htrace_span_id id;
    char err[512], str2[HTRACE_SPAN_ID_STRING_LENGTH + 1];
    size_t err_len = sizeof(err);

    err[0] = '\0';
    htrace_span_id_parse(&id, str, err, err_len);
    EXPECT_STR_EQ("", err);
    EXPECT_INT_EQ(1, htrace_span_id_to_str(&id, str2, sizeof(str2)));
    EXPECT_STR_EQ(str, str2);
    return 0;
}
示例#5
0
TEST(Telecom, Non_valid_Call) {
    Device samsungA6;
    Centre Relay_1(20);
    Relay_1.add_device(samsungA6);
    std::string str = "Ezen a szamon elofizeto nem kapcsolhato.";
    EXPECT_STR_EQ(samsungA6.Call(121).message.c_str(), str.c_str());
} END
示例#6
0
bool TestList() {
    BEGIN_TEST;
    PathFixture fixture;
    ASSERT_TRUE(fixture.Create());

    Path path;
    ASSERT_EQ(ZX_OK, path.Push(fixture.path("foo")));

    fbl::unique_ptr<StringList> list;
    list = path.List();
    EXPECT_STR_EQ(list->first(), "ba");
    EXPECT_NULL(list->next());

    ASSERT_EQ(ZX_OK, path.Push("ba"));
    list = path.List();

    EXPECT_EQ(list->length(), 2);
    list->erase_if("r");
    list->erase_if("z");
    EXPECT_TRUE(list->is_empty());

    ASSERT_EQ(ZX_OK, path.Push("z/qu/ux"));
    list = path.List();
    EXPECT_TRUE(list->is_empty());

    END_TEST;
}
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;
}
示例#8
0
int span_table_get(struct span_table *st, struct htrace_span **out,
                   const char *desc, const char *trid)
{
    struct htable *ht = (struct htable *)st;
    struct htrace_span *span;

    span = htable_get(ht, desc);
    EXPECT_NONNULL(span);
    EXPECT_STR_EQ(desc, span->desc);
    EXPECT_UINT64_GE(span->begin_ms, span->end_ms);
    EXPECT_TRUE(0 !=
        htrace_span_id_compare(&INVALID_SPAN_ID, &span->span_id));
    EXPECT_NONNULL(span->trid);
    EXPECT_STR_EQ(trid, span->trid);
    *out = span;
    return EXIT_SUCCESS;
}
bool close_multiple_present_handles_with_some_invalid() {
    BEGIN_TEST;

    zx_handle_t* channels_0 = new zx_handle_t[3];
    // Capture the extra handles here; these will not be cleaned by fidl_close_handles
    zx::channel channels_1[3] = {};

    // Unsafely open a few channels, which should be closed automatically by fidl_close_handles
    for (int i = 0; i < 3; i++) {
        zx_handle_t out0, out1;
        EXPECT_EQ(zx_channel_create(0, &out0, &out1), ZX_OK);
        channels_0[i] = out0;
        channels_1[i] = zx::channel(out1);
    }

    EXPECT_TRUE(helper_expect_peer_valid(channels_1[0].get()));
    EXPECT_TRUE(helper_expect_peer_valid(channels_1[1].get()));
    EXPECT_TRUE(helper_expect_peer_valid(channels_1[2].get()));

    // Make the second handle invalid
    multiple_nonnullable_handles_message_layout message = {};
    message.inline_struct.handle_0 = channels_0[0];
    message.inline_struct.handle_1 = ZX_HANDLE_INVALID;
    message.inline_struct.handle_2 = channels_0[2];

    const char* error = nullptr;
    auto status = fidl_close_handles(&multiple_nonnullable_handles_message_type, &message, &error);

    // Since the message is invalid, fidl_close_handles will error, but all the handles
    // in the message must still be closed despite the error.
    EXPECT_EQ(status, ZX_ERR_INVALID_ARGS);
    const char expected_error_msg[] = "message is missing a non-nullable handle";
    EXPECT_STR_EQ(expected_error_msg, error, "wrong error msg");

    // Second channel should remain valid, since it was inaccessible to fidl_close_handles
    EXPECT_TRUE(helper_expect_peer_invalid(channels_1[0].get()));
    EXPECT_TRUE(helper_expect_peer_valid(channels_1[1].get()));
    EXPECT_TRUE(helper_expect_peer_invalid(channels_1[2].get()));

    // The handles have been closed; it is now an error to re-close them.
    EXPECT_EQ(zx_handle_close(channels_0[0]), ZX_ERR_BAD_HANDLE);
    EXPECT_EQ(zx_handle_close(channels_0[1]), ZX_OK);
    EXPECT_EQ(zx_handle_close(channels_0[2]), ZX_ERR_BAD_HANDLE);

    EXPECT_EQ(message.inline_struct.data_0, 0u);
    EXPECT_EQ(message.inline_struct.data_1, 0u);
    EXPECT_EQ(message.inline_struct.data_2, 0u);
    // Handles in the message struct are released.
    EXPECT_EQ(message.inline_struct.handle_0, ZX_HANDLE_INVALID);
    EXPECT_EQ(message.inline_struct.handle_1, ZX_HANDLE_INVALID);
    EXPECT_EQ(message.inline_struct.handle_2, ZX_HANDLE_INVALID);

    delete[] channels_0;

    END_TEST;
}
示例#10
0
} END

TEST(Telecom, Valid_Call) {
    Device samsungA6;
    Device iphone6s;
    Centre Relay_1(20);
    Relay_1.add_device(samsungA6);
    Relay_1.add_device(iphone6s);
    std::string message = samsungA6.Call(10000002).message;
    std::string str = "A kapcsolat letrejott 10000001 es 10000002 kozott.";
    std::cout<<std::endl;
    EXPECT_STR_EQ(message.c_str(), str.c_str());
} END
示例#11
0
bool TestReset() {
    BEGIN_TEST;
    PathFixture fixture;
    ASSERT_TRUE(fixture.Create());

    Path path;
    ASSERT_EQ(ZX_OK, path.Push(fixture.path()));

    path.Reset();
    EXPECT_STR_EQ(path.c_str(), "/");

    END_TEST;
}
示例#12
0
} END

TEST(Telecom, Check_Busy) {
    Device samsungA6;
    Device iphone6s;
    Device lgspirit;
    Centre Relay_1(20);
    Relay_1.add_device(samsungA6);
    Relay_1.add_device(iphone6s);
    Relay_1.add_device(lgspirit);
    samsungA6.Call(10000002);
    std::string message = lgspirit.Call(10000002).message;
    std::string str = "A szam foglalt.";
    std::cout<<std::endl;
    EXPECT_STR_EQ(message.c_str(), str.c_str());
} END