ut_setup()
{
    const uint32_t chunk_size = 262144 / 512; /* Default value, in sectors */
    int i;

    os_random_init();

    for (i = 0; i < NUM_SPOF_GROUPS; i++)
    {
        exa_uuid_t rdev_uuid, nbd_uuid;
        spof_id_t spof_id = i + 1;

        uuid_generate(&rdev_uuid);
        uuid_generate(&nbd_uuid);

        rdevs[i] = make_fake_rdev(i, spof_id, &rdev_uuid, &nbd_uuid, RDEV_SIZE, true, true);
        rdevs[i]->index = i;
        UT_ASSERT(rdevs[i] != NULL);
    }

    sto = make_fake_storage(NUM_SPOF_GROUPS, chunk_size, rdevs, NUM_SPOF_GROUPS);
    UT_ASSERT(sto != NULL);

    rxg = make_fake_rxg(sto);
    UT_ASSERT(rxg != NULL);

    UT_ASSERT_EQUAL(0, memory_stream_open(&memory_stream, __buf, sizeof(__buf),
                                          STREAM_ACCESS_RW));

    UT_ASSERT_EQUAL(0, stat_stream_open(&stream, memory_stream, &stats));
}
UT_END_TEST


UT_START_TEST(test2)
{
	txc_tx_t     *txd;
	int          result;
	int          ret;
	char         *final_contents;
	volatile int test_retries;
	int          pipefd[2];
	char         buf[512];
	pthread_t    child_thread;


	UT_ASSERT_EQUAL(TXC_R_SUCCESS, _TXC_global_init());
	UT_ASSERT_EQUAL(TXC_R_SUCCESS, _TXC_thread_init());

	txd = txc_tx_get_txd();

	child_started = 0;
	XACT_BEGIN(xact_1)
		_XCALL(x_pthread_create)(&child_thread, NULL, child_routine, (void *) 0xDEADBEEF, NULL);
	XACT_END(xact_1)
	pthread_join(child_thread, NULL);
	UT_ASSERT_EQUAL(1, child_started);
}
Exemple #3
0
UT_END_TEST


UT_START_TEST(test2)
{
	txc_tx_t     *txd;
	int          fd;
	int          result;
	int          ret;
	volatile int test_retries;
	char         buf1[512];
	char         buf2[512];
	char         str1[512];
	char         str2[512];
	int          len1;
	int          len2;

	UT_ASSERT_EQUAL(TXC_R_SUCCESS, _TXC_global_init());
	UT_ASSERT_EQUAL(TXC_R_SUCCESS, _TXC_thread_init());

	txd = txc_tx_get_txd();

	UT_ASSERT_EQUAL(0, create_file(test_file, test_file_initial_contents));
	UT_ASSERT_EQUAL(UT_TRUE, file_equal_str(test_file, test_file_initial_contents));

	strncpy(str1, &test_file_initial_contents_tbl[0][0], 10);
	str1[10] = '\0';
	len1 = strlen(str1);
	strncpy(str2, &test_file_initial_contents_tbl[0][10], 10);
	str2[20] = '\0';
	len2 = strlen(str2);

	test_retries = 0;
	fd = _XCALL(x_open)(test_file, O_RDWR, S_IRUSR|S_IWUSR, NULL);
	XACT_BEGIN(xact_1)
		ret = _XCALL(x_read)(fd, buf1, len1, &result);
		ret = _XCALL(x_read)(fd, buf2, len2, &result);
		XACT_WAIVER {
			UT_ASSERT_STR_EQUAL(str1, buf1);
			UT_ASSERT_STR_EQUAL(str2, buf2);
		}
		XACT_WAIVER {
			if (test_retries++ < 8) {
				XACT_ABORT(TXC_ABORTREASON_USERRETRY);	
			}
		}	
	XACT_END(xact_1)
}
Exemple #4
0
ut_setup()
{
    int i;

    os_random_init();
    unlink(test_tokens_file);
    data.file = test_tokens_file;

    /* We generate two random ports as when two instances of this UT are run at
     * the same time, one can block the other as they try to open the same port.
     *
     * The operation done below with the modulo and the addition is to ensure
     * the value is bound between 1025 and 65535, which is the default
     * non-privileged user accessible ports range.
     */
    data.port = (os_process_id() % 64511) + 1025;
    data.priv_port = (data.port + 1) % 64511 + 1025;

    UT_ASSERT(data.port > 1024);
    UT_ASSERT(data.priv_port > 1024);
    UT_ASSERT(data.port != data.priv_port);

#ifdef WIN32
    data.logfile = "nul";
#else
    data.logfile = "/dev/null";
#endif

    os_thread_create(&server_thread, 0, token_manager_thread, &data);
    os_sleep(1);

    for (i = 0; i < NUM_TEST_CLUSTERS; i++)
        __setup_cluster(&clusters[i]);

    for (i = 0; i < NUM_TEST_CLUSTERS; i++)
    {
        UT_ASSERT_EQUAL(0, tm_init(&clusters[i].tms[0], "127.0.0.1", data.port));
        UT_ASSERT_EQUAL(0, tm_connect(clusters[i].tms[0]));
        UT_ASSERT_EQUAL(0, tm_init(&clusters[i].tms[1], "127.0.0.1", data.port));
        UT_ASSERT_EQUAL(0, tm_connect(clusters[i].tms[1]));
    }

    UT_ASSERT(tm_init(&user_tm, "127.0.0.1", data.priv_port) == 0);
    UT_ASSERT_EQUAL(0, tm_connect(user_tm));
}
static uint64_t __disk_size(const char *path)
{
    int fd;
    uint64_t size;

    fd = os_disk_open_raw(path, OS_DISK_READ);
    UT_ASSERT(fd >= 0);
    UT_ASSERT_EQUAL(0, os_disk_get_size(fd, &size));
    close(fd);

    return size;
}
static void __common_setup(void)
{
    const uint32_t slot_width = NUM_SPOF_GROUPS;
    const uint32_t chunk_size = 262144 / 512; /* Default value, in sectors */
    exa_uuid_t uuid;
    int i;

    os_random_init();

    for (i = 0; i < NUM_SPOF_GROUPS; i++)
    {
        exa_uuid_t rdev_uuid, nbd_uuid;
        spof_id_t spof_id = i + 1;

        uuid_generate(&rdev_uuid);
        uuid_generate(&nbd_uuid);

        rdevs[i] = make_fake_rdev(i, spof_id, &rdev_uuid, &nbd_uuid, RDEV_SIZE, true, true);
        UT_ASSERT(rdevs[i] != NULL);
    }

    sto = make_fake_storage(NUM_SPOF_GROUPS, chunk_size, rdevs, NUM_SPOF_GROUPS);
    UT_ASSERT(sto != NULL);

    /* Setup a valid assembly group (containing rdevs, etc) */
    ag = make_fake_ag(sto, slot_width);
    UT_ASSERT(ag != NULL);

    uuid_generate(&uuid);
    UT_ASSERT_EQUAL(0, assembly_group_reserve_volume(ag, &uuid, 5, &av[0], sto));
    UT_ASSERT(av[0] != NULL);

    uuid_generate(&uuid);
    UT_ASSERT_EQUAL(0, assembly_group_reserve_volume(ag, &uuid, 7, &av[1], sto));
    UT_ASSERT(av[1] != NULL);

    uuid_generate(&uuid);
    UT_ASSERT_EQUAL(0, assembly_group_reserve_volume(ag, &uuid, 2, &av[2], sto));
    UT_ASSERT(av[2] != NULL);
}
Exemple #7
0
UT_END_TEST


UT_START_TEST (test3)
{
	txc_tx_t *txd1;
	txc_tx_t *txd2;

	UT_ASSERT_EQUAL(TXC_R_SUCCESS, _TXC_global_init());
	UT_ASSERT_EQUAL(TXC_R_SUCCESS, txc_tx_create(txc_g_txmgr, &txd1));
	UT_ASSERT_EQUAL(TXC_R_SUCCESS, txc_tx_create(txc_g_txmgr, &txd2));
	UT_ASSERT_EQUAL(TXC_R_SUCCESS, txc_tx_exists(txc_g_txmgr, txd1));
	UT_ASSERT_EQUAL(TXC_R_SUCCESS, txc_tx_exists(txc_g_txmgr, txd2));
	UT_ASSERT_EQUAL(TXC_R_SUCCESS, txc_tx_destroy(&txd2));
	UT_ASSERT_EQUAL(TXC_R_SUCCESS, txc_tx_destroy(&txd1));
	UT_ASSERT_EQUAL(TXC_R_NOTEXISTS, txc_tx_exists(txc_g_txmgr, txd1));
	UT_ASSERT_EQUAL(TXC_R_NOTEXISTS, txc_tx_exists(txc_g_txmgr, txd2));
}
Exemple #8
0
ut_setup()
{
    UT_ASSERT_EQUAL(0, blockdevice_open(&bdev, dummy_ctx, &all_ops,
                                        BLOCKDEVICE_ACCESS_READ));
}
static void common_setup(blockdevice_access_t access)
{
    UT_ASSERT_EQUAL(0, sys_blockdevice_open(&bdev, TEST_PATH, access));
}
Exemple #10
0
ut_setup()
{
    UT_ASSERT_EQUAL(0, memory_stream_open(&rw_stream, __buf, sizeof(__buf),
                                          STREAM_ACCESS_RW));
}