Ejemplo n.º 1
0
static int cond_signaller1(void)
{
	EXPECT_ZERO(pthread_mutex_lock(&g_cslock1));
	EXPECT_ZERO(pthread_cond_signal(&g_cond1));
	EXPECT_ZERO(pthread_mutex_unlock(&g_cslock1));
	return 0;
}
Ejemplo n.º 2
0
static int test_bad_unlock_helper1(void)
{
	EXPECT_ZERO(pthread_mutex_lock(&g_test_bad_unlock_mutex));
	EXPECT_ZERO(sem_post(&g_test_bad_unlock_sem1));
	EXPECT_ZERO(sem_wait(&g_test_bad_unlock_sem2));
	EXPECT_ZERO(pthread_mutex_unlock(&g_test_bad_unlock_mutex));
	return 0;
}
Ejemplo n.º 3
0
static int inver_thread_b(void)
{
	EXPECT_ZERO(sem_wait(&g_inver_sem1));
	EXPECT_ZERO(pthread_mutex_lock(&g_lock2));
	EXPECT_EQ(pthread_mutex_trylock(&g_lock1), EBUSY);
	EXPECT_ZERO(sem_post(&g_inver_sem2));
	EXPECT_ZERO(pthread_mutex_unlock(&g_lock2));
	return 0;
}
Ejemplo n.º 4
0
static int test4(void)
{
	struct bob *b1 = JORM_INIT_bob();
	struct bob *b2 = JORM_INIT_bob();
	struct bob *b3 = JORM_INIT_bob();
	struct abbie **abbie_arr = NULL;

	EXPECT_NOT_EQUAL(b1, NULL);
	EXPECT_NOT_EQUAL(b2, NULL);
	EXPECT_NOT_EQUAL(b3, NULL);

	EXPECT_EQUAL(b3->a, JORM_INVAL_INT);
	b1->a = 101;
	EXPECT_ZERO(JORM_COPY_bob(b1, b3));
	EXPECT_EQUAL(b3->a, 101);

	b2->a = JORM_INVAL_INT;
	b2->b = 50;
	b2->d = JORM_INIT_abbie();
	b2->d->a = 9000;
	EXPECT_ZERO(JORM_COPY_bob(b2, b3));
	EXPECT_EQUAL(b3->b, 50);
	EXPECT_NOT_EQUAL(b3->d, NULL);
	EXPECT_EQUAL(b3->d->a, 9000);
	EXPECT_EQUAL(b3->a, 101);

	b1->f = calloc(3, sizeof(struct abbie*));
	EXPECT_NOT_EQUAL(b1->f, NULL);
	b1->f[0] = JORM_INIT_abbie();
	EXPECT_NOT_EQUAL(b1->f[0], NULL);
	b1->f[1] = JORM_INIT_abbie();
	EXPECT_NOT_EQUAL(b1->f[1], NULL);
	b1->f[2] = NULL;
	b1->f[0]->a = 100;
	b1->f[1]->a = 200;
	EXPECT_ZERO(JORM_COPY_bob(b1, b3));
	EXPECT_NOT_EQUAL(b3->f, NULL);
	EXPECT_NOT_EQUAL(b3->f[0], NULL);
	EXPECT_EQUAL(b3->f[0]->a, 100);
	EXPECT_NOT_EQUAL(b3->f[1], NULL);
	EXPECT_EQUAL(b3->f[1]->a, 200);
	EXPECT_EQUAL(b3->f[2], NULL);

	abbie_arr = JORM_ARRAY_COPY_abbie(b3->f);
	EXPECT_NOT_EQUAL(abbie_arr, NULL);
	EXPECT_NOT_EQUAL(abbie_arr[0], NULL);
	EXPECT_EQUAL(abbie_arr[0]->a, 100);
	EXPECT_NOT_EQUAL(abbie_arr[1], NULL);
	EXPECT_EQUAL(abbie_arr[1]->a, 200);
	EXPECT_EQUAL(abbie_arr[2], NULL);

	JORM_ARRAY_FREE_abbie(&abbie_arr);
	JORM_FREE_bob(b1);
	JORM_FREE_bob(b2);
	JORM_FREE_bob(b3);
	return 0;
}
Ejemplo n.º 5
0
/**
 * Verify that the fuse workload works on the local FS.
 *
 * @return        0 on success; error code otherwise
 */
static int verifyFuseWorkload(void)
{
  char tempDir[PATH_MAX];

  EXPECT_ZERO(createTempDir(tempDir, sizeof(tempDir), 0755));
  EXPECT_ZERO(runFuseWorkload(tempDir, "test"));
  EXPECT_ZERO(recursiveDelete(tempDir));

  return 0;
}
Ejemplo n.º 6
0
static int test_thread_name_set_and_get_impl(void)
{
	const char * const MY_THREAD = "my_thread";
	const char *name;

	EXPECT_ZERO(lksmith_set_thread_name(MY_THREAD));
	name = lksmith_get_thread_name();
	EXPECT_NOT_EQ(name, NULL);
	EXPECT_ZERO(strcmp(MY_THREAD, name));
	return 0;
}
Ejemplo n.º 7
0
int main(POSSIBLY_UNUSED(int argc), char **argv)
{
	EXPECT_ZERO(utility_ctx_init(argv[0])); /* for g_fast_log_mgr */
	EXPECT_ZERO(test_alloc_free());
	EXPECT_ZERO(test_lookups());
	EXPECT_ZERO(test_pack());

	process_ctx_shutdown();

	return EXIT_SUCCESS;
}
Ejemplo n.º 8
0
/**
 * Test that we can create a MiniDFSCluster and shut it down.
 */
int main(void) {
    struct NativeMiniDfsCluster* cl;
    
    cl = nmdCreate(&conf);
    EXPECT_NONNULL(cl);
    EXPECT_ZERO(nmdWaitClusterUp(cl));
    EXPECT_ZERO(nmdShutdown(cl));
    nmdFree(cl);

    return 0;
}
Ejemplo n.º 9
0
static int test_destroy_while_same_thread_has_locked(void)
{
	pthread_mutex_t mutex;
	EXPECT_ZERO(pthread_mutex_init(&mutex, NULL));
	EXPECT_ZERO(pthread_mutex_lock(&mutex));
	EXPECT_EQ(pthread_mutex_destroy(&mutex), EBUSY);
	EXPECT_EQ(find_recorded_error(EBUSY), 1);
	EXPECT_ZERO(pthread_mutex_unlock(&mutex));
	EXPECT_ZERO(pthread_mutex_destroy(&mutex));
	clear_recorded_errors();

	return 0;
}
Ejemplo n.º 10
0
int main(POSSIBLY_UNUSED(int argc), char **argv)
{
	char st_trivial[PATH_MAX];

	EXPECT_ZERO(get_colocated_path(argv[0], "st_trivial",
			      st_trivial, sizeof(st_trivial)));
	EXPECT_ZERO(run_cmd(st_trivial, "-h", (char*)NULL));
	EXPECT_ZERO(run_cmd(st_trivial, "-f", (char*)NULL));
	snprintf(env_str, sizeof(env_str), "ST_ERROR=1");
	putenv(env_str);
	EXPECT_NONZERO(run_cmd(st_trivial, "-f", (char*)NULL));
	return 0;
}
Ejemplo n.º 11
0
/* A simple test of what POSIX rename does in a bunch of different
 * scenarios.  This doesn't test certain tricky corner cases like a rename
 * where both src and dst are a hardlink to the same file.  It's just your
 * basic directories and files.
 */
static int do_rename(const char *src_base, const char *src_suffix,
		     const char *dst_base, const char *dst_suffix)
{
	char src[PATH_MAX], dst[PATH_MAX];

	EXPECT_ZERO(zsnprintf(src, PATH_MAX, "%s/%s", src_base, src_suffix));
	EXPECT_ZERO(zsnprintf(dst, PATH_MAX, "%s/%s", dst_base, dst_suffix));
	if (rename(src, dst) < 0) {
		int err = -errno;
		return err;
	}
	return 0;
}
Ejemplo n.º 12
0
static int test_canonicalize_path(const char *path, const char *expected)
{
	char epath[PATH_MAX];

	EXPECT_ZERO(zsnprintf(epath, PATH_MAX, "%s", path));
	if (!expected) {
		EXPECT_NONZERO(canonicalize_path(epath));
	}
	else {
		EXPECT_ZERO(canonicalize_path(epath));
		EXPECT_ZERO(strcmp(epath, expected));
	}
	return 0;
}
Ejemplo n.º 13
0
static int test_copy_fd_to_fd(const char *tempdir, int *next_id,
				const char *buf)
{
	size_t buf_len = strlen(buf);
	ssize_t res;
	char *nbuf, src_file[PATH_MAX], dst_file[PATH_MAX];
	FILE *ifp, *ofp;
	int ret;
	EXPECT_ZERO(zsnprintf(src_file, sizeof(src_file),
		      "%s/src_file.%d", tempdir, *next_id));
	EXPECT_ZERO(zsnprintf(dst_file, sizeof(dst_file),
		      "%s/dst_file.%d", tempdir, *next_id));
	*next_id = *next_id + 1;
	ifp = fopen(src_file, "w");
	if (!ifp) {
		ret = errno;
		return ret;
	}
	EXPECT_EQUAL(fwrite(buf, 1, buf_len, ifp), buf_len);
	ifp = freopen(src_file, "r", ifp);
	if (!ifp) {
		ret = errno;
		return ret;
	}
	ofp = fopen(dst_file, "w");
	if (!ofp) {
		ret = errno;
		fclose(ifp);
		return ret;
	}
	ret = copy_fd_to_fd(fileno(ifp), fileno(ofp));
	EXPECT_ZERO(ret);
	fclose(ofp);
	fclose(ifp);

	nbuf = calloc(1, buf_len + 1);
	EXPECT_NOT_EQUAL(nbuf, NULL);
	res = simple_io_read_whole_file_zt(dst_file, nbuf, buf_len + 1);
	if (res < 0) {
		free(nbuf);
		return res;
	}
	if ((res > 0) && (memcmp(buf, nbuf, buf_len - 1))) {
		free(nbuf);
		return -EIO;
	}
	free(nbuf);
	return 0;
}
Ejemplo n.º 14
0
static int test_do_basename(const char *fname, const char *expected)
{
	char bname[PATH_MAX] = { 0 };

	EXPECT_ZERO(do_basename(bname, PATH_MAX, fname));
	return strcmp(bname, expected);
}
Ejemplo n.º 15
0
static int test_signal_handler(const char *argv0, const char *tempdir, int sig)
{
	int ret, pid, status;
	char err[512] = { 0 };
	char crash_log_path[PATH_MAX];
	snprintf(crash_log_path, sizeof(crash_log_path), "%s/crash.log.%d",
		 tempdir, rand());
	pid = fork();
	if (pid == -1) {
		ret = errno;
		return ret;
	}
	else if (pid == 0) {
		struct logc lc;
		memset(&lc, 0, sizeof(lc));
		lc.crash_log_path = crash_log_path;
		signal_init(argv0, err, sizeof(err), &lc);
		if (err[0]) {
			fprintf(stderr, "signal_init error: %s\n", err);
			_exit(1);
		}
		raise(sig);
		_exit(1);
	}
	RETRY_ON_EINTR(ret, waitpid(pid, &status, 0));

	EXPECT_ZERO(validate_crash_log(crash_log_path, sig));
	return 0;
}
Ejemplo n.º 16
0
/**
 * Test that we can write a file with libhdfs and then read it back
 */
int main(int argc, const char *args[])
{
    int i, tlhNumThreads;
    const char *tlhNumThreadsStr;
    struct tlhThreadInfo ti[TLH_MAX_THREADS];
    
    if (argc != 2) {
        fprintf(stderr, "usage: test_libwebhdfs_threaded <username>\n");
        exit(1);
    }
    user = args[1];
    
    struct NativeMiniDfsConf conf = {
        .doFormat = 1, .webhdfsEnabled = 1, .namenodeHttpPort = 50070,
    };
    cluster = nmdCreate(&conf);
    EXPECT_NONNULL(cluster);
    EXPECT_ZERO(nmdWaitClusterUp(cluster));
    
    tlhNumThreadsStr = getenv("TLH_NUM_THREADS");
    if (!tlhNumThreadsStr) {
        tlhNumThreadsStr = "3";
    }
    tlhNumThreads = atoi(tlhNumThreadsStr);
    if ((tlhNumThreads <= 0) || (tlhNumThreads > TLH_MAX_THREADS)) {
        fprintf(stderr, "testLibHdfs: must have a number of threads "
                "between 1 and %d inclusive, not %d\n",
                TLH_MAX_THREADS, tlhNumThreads);
        return EXIT_FAILURE;
    }
    memset(&ti[0], 0, sizeof(ti));
    for (i = 0; i < tlhNumThreads; i++) {
        ti[i].threadIdx = i;
    }
    
    for (i = 0; i < tlhNumThreads; i++) {
        EXPECT_ZERO(pthread_create(&ti[i].thread, NULL,
                                   testHdfsOperations, &ti[i]));
    }
    for (i = 0; i < tlhNumThreads; i++) {
        EXPECT_ZERO(pthread_join(ti[i].thread, NULL));
    }
    
    EXPECT_ZERO(nmdShutdown(cluster));
    nmdFree(cluster);
    return checkFailures(ti, tlhNumThreads);
}
Ejemplo n.º 17
0
int main(void)
{
	EXPECT_ZERO(test_canonicalize_path("", NULL));
	EXPECT_ZERO(test_canonicalize_path("./foo", NULL));
	EXPECT_ZERO(test_canonicalize_path("/tmp//foo", "/tmp/foo"));
	EXPECT_ZERO(test_canonicalize_path("////tmp/////foo/", "/tmp/foo"));
	EXPECT_ZERO(test_canonicalize_path("/tmp/foo", "/tmp/foo"));
	EXPECT_ZERO(test_canonicalize_path("/long/path/that/ends/in/a/slash/",
			       "/long/path/that/ends/in/a/slash"));
	EXPECT_ZERO(test_canonicalize_path("/", "/"));

	EXPECT_ZERO(test_do_dirname("/", "/"));
	EXPECT_ZERO(test_do_dirname("/tmp/foo", "/tmp"));
	EXPECT_ZERO(test_do_dirname("/longer/path/here", "/longer/path"));

	return EXIT_SUCCESS;
}
Ejemplo n.º 18
0
int main(void)
{
	char tempdir[PATH_MAX];
	char glitch_log_path[PATH_MAX];
	struct logc lc;

	EXPECT_ZERO(get_tempdir(tempdir, PATH_MAX, 0700));
	EXPECT_ZERO(register_tempdir_for_cleanup(tempdir));
	snprintf(glitch_log_path, sizeof(glitch_log_path),
			"%s/glitch_log.txt", tempdir);
	memset(&lc, 0, sizeof(struct logc));
	lc.glitch_log_path = glitch_log_path;
	EXPECT_ZERO(test_stderr_output(tempdir));
	configure_glitch_log(&lc);
	EXPECT_ZERO(test_log_output(lc.glitch_log_path));
	return EXIT_SUCCESS;
}
Ejemplo n.º 19
0
static int read_then_write_file(const char *tempdir, int *next_id,
		const char *contents, int buf_sz)
{
	ssize_t res;
	FILE *fp;
	char *buf, file_name[PATH_MAX];
	EXPECT_ZERO(zsnprintf(file_name, PATH_MAX,"%s/outfile.%d",
			      tempdir, *next_id));
	*next_id = *next_id + 1;

	fp = fopen(file_name, "w");
	if (!fp) {
		int ret = errno;
		fprintf(stderr, "failed to open '%s': error %d\n",
			file_name, ret);
		return ret;
	}
	if (fprintf(fp, "%s", contents) < 0) {
		int ret = errno;
		fprintf(stderr, "failed to write to '%s': error %d\n",
			file_name, ret);
		return ret;
	}
	EXPECT_ZERO(fclose(fp));
	buf = calloc(1, buf_sz);
	if (!buf) {
		return -ENOMEM;
	}
	res = simple_io_read_whole_file_zt(file_name, buf, buf_sz);
	if (res < 0) {
		free(buf);
		fprintf(stderr, "simple_io_read_whole_file_zt failed with "
			"error %Zd\n", res);
		return res;
	}
	if ((buf_sz > 0) && (strncmp(contents, buf, buf_sz - 1))) {
		fprintf(stderr, "got contents: '%s'; expected first "
			"%d characters of: '%s' \n",
			buf, buf_sz - 1, contents);
		free(buf);
		return -EIO;
	}
	free(buf);
	return 0;
}
Ejemplo n.º 20
0
static int msgr_test_simple_send(int num_sends)
{
	int i, res;
	struct msgr *foo_msgr, *bar_msgr;
	char err[512] = { 0 };
	size_t err_len = sizeof(err);
	struct listen_info linfo;

	EXPECT_ZERO(sem_init(&g_msgr_test_simple_send_sem, 0, 0));

	foo_msgr = msgr_init_helper(10, 10, 360, "foo_msgr");
	bar_msgr = msgr_init_helper(10, 10, 360, "bar_msgr");
	memset(&linfo, 0, sizeof(linfo));
	linfo.cb = bar_cb;
	linfo.priv = NULL;
	linfo.port = MSGR_UNIT_PORT;
	msgr_listen(bar_msgr, &linfo, err, err_len);
	if (err[0])
		goto handle_error;
	msgr_start(foo_msgr, err, err_len);
	if (err[0])
		goto handle_error;
	msgr_start(bar_msgr, err, err_len);
	if (err[0])
		goto handle_error;
	for (i = 0; i < num_sends; ++i) {
		EXPECT_ZERO(send_foo_tr(foo_msgr, foo_cb, i + 1));
	}
	for (i = 0; i < num_sends; ++i) {
		RETRY_ON_EINTR(res, sem_wait(&g_msgr_test_simple_send_sem));
	}
	EXPECT_ZERO(sem_destroy(&g_msgr_test_simple_send_sem));

	msgr_shutdown(foo_msgr);
	msgr_shutdown(bar_msgr);
	msgr_free(foo_msgr);
	msgr_free(bar_msgr);
	return 0;

handle_error:
	fprintf(stderr, "msgr_test_simple_send: got error %s\n", err);
	return 1;
}
Ejemplo n.º 21
0
static int do_test_mkdir(const char *base, const char *suffix)
{
	char path[PATH_MAX];

	EXPECT_ZERO(zsnprintf(path, PATH_MAX, "%s/%s", base, suffix));
	if (mkdir(path, 0755) < 0) {
		return -errno;
	}
	return 0;
}
Ejemplo n.º 22
0
int test_str_to_int(void)
{
	int i;
	char err[512] = { 0 };

	err[0] = '\0';
	str_to_int("123", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 123);

	err[0] = '\0';
	str_to_int("0", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 0);

	err[0] = '\0';
	str_to_int("", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("10b", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("f", 16, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 15);

	err[0] = '\0';
	str_to_int("8589934592", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("2147483647", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 2147483647);

	err[0] = '\0';
	str_to_int("blah", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	return 0;
}
Ejemplo n.º 23
0
/**
 * Test that we can write a file with libhdfs and then read it back
 */
int main(void)
{
    int i, tlhNumThreads;
    const char *tlhNumThreadsStr;
    struct tlhThreadInfo ti[TLH_MAX_THREADS];
    struct NativeMiniDfsConf conf = {
        1, /* doFormat */
    };

    tlhNumThreadsStr = getenv("TLH_NUM_THREADS");
    if (!tlhNumThreadsStr) {
        tlhNumThreadsStr = "3";
    }
    tlhNumThreads = atoi(tlhNumThreadsStr);
    if ((tlhNumThreads <= 0) || (tlhNumThreads > TLH_MAX_THREADS)) {
        fprintf(stderr, "testLibHdfs: must have a number of threads "
                "between 1 and %d inclusive, not %d\n",
                TLH_MAX_THREADS, tlhNumThreads);
        return EXIT_FAILURE;
    }
    memset(&ti[0], 0, sizeof(ti));
    for (i = 0; i < tlhNumThreads; i++) {
        ti[i].threadIdx = i;
    }

    tlhCluster = nmdCreate(&conf);
    EXPECT_NONNULL(tlhCluster);
    EXPECT_ZERO(nmdWaitClusterUp(tlhCluster));

    for (i = 0; i < tlhNumThreads; i++) {
        ti[i].theThread.start = testHdfsOperations;
        ti[i].theThread.arg = &ti[i];
        EXPECT_ZERO(threadCreate(&ti[i].theThread));
    }
    for (i = 0; i < tlhNumThreads; i++) {
        EXPECT_ZERO(threadJoin(&ti[i].theThread));
    }

    EXPECT_ZERO(nmdShutdown(tlhCluster));
    nmdFree(tlhCluster);
    return checkFailures(ti, tlhNumThreads);
}
Ejemplo n.º 24
0
static int test_lookups(void)
{
	struct udata *udata;
	struct user *u;

	udata = udata_create_default();
	EXPECT_NOT_ERRPTR(udata);
	EXPECT_ZERO(do_test_lookups(udata));
	u = udata_lookup_user(udata, RF_NOBODY_NAME);
	if (IS_ERR(u))
		return PTR_ERR(u);
	EXPECT_EQ(user_in_gid(u, RF_SUPERUSER_GID), 0);
	EXPECT_ZERO(user_add_segid(udata, RF_NOBODY_NAME, 0));
	u = udata_lookup_user(udata, RF_NOBODY_NAME);
	if (IS_ERR(u))
		return PTR_ERR(u);
	EXPECT_EQ(user_in_gid(u, RF_SUPERUSER_GID), 1);
	udata_free(udata);
	return 0;
}
Ejemplo n.º 25
0
int main(POSSIBLY_UNUSED(int argc), char **argv)
{
	timer_t timer;
	time_t t;

	EXPECT_ZERO(utility_ctx_init(argv[0]));
	t = mt_time() + 600;
	EXPECT_ZERO(mt_set_alarm(t, "msgr_unit timed out", &timer));
	EXPECT_ZERO(get_localhost_ipv4(&g_localhost));
	EXPECT_ZERO(msgr_test_init_shutdown(0));
	EXPECT_ZERO(msgr_test_init_shutdown(1));
	EXPECT_ZERO(msgr_test_simple_send(1));
	EXPECT_ZERO(msgr_test_simple_send(100));
	EXPECT_ZERO(msgr_test_conn_timeout());
	EXPECT_ZERO(msgr_test_conn_shutdown());
	EXPECT_ZERO(mt_deactivate_alarm(timer));
	process_ctx_shutdown();

	return EXIT_SUCCESS;
}
Ejemplo n.º 26
0
static int ostoru_thread1(struct redfish_thread *rt)
{
	char buf[1024];
	struct ostor *ostor = rt->priv;

	EXPECT_ZERO(ostor_write(ostor, rt->fb, 123, TEST_DATA1,
		strlen(TEST_DATA1)));
	sem_post(&ostoru_threaded_test_sem2);
	sem_wait(&ostoru_threaded_test_sem1);
	EXPECT_EQ(ostor_read(ostor, rt->fb, 123, 0, buf, sizeof(buf)),
		-ENOENT);
	EXPECT_EQ(ostor_unlink(ostor, rt->fb, 123), -ENOENT);
	EXPECT_ZERO(ostor_write(ostor, rt->fb, 456, TEST_DATA2,
		strlen(TEST_DATA2)));
	sem_post(&ostoru_threaded_test_sem2);
	sem_wait(&ostoru_threaded_test_sem1);
	ostor_shutdown(ostor);
	sem_post(&ostoru_threaded_test_sem2);
	return 0;
}
Ejemplo n.º 27
0
static int msgr_test_conn_shutdown(void)
{
	int res;
	struct msgr *baz1_msgr, *baz2_msgr;
	char err[512] = { 0 };
	size_t err_len = sizeof(err);
	struct listen_info linfo;

	EXPECT_ZERO(sem_init(&g_msgr_test_baz_sem, 0, 0));

	baz1_msgr = msgr_init_helper(10, 10, 360, "baz1_msgr");
	baz2_msgr = msgr_init_helper(10, 10, 360, "baz2_msgr");
	memset(&linfo, 0, sizeof(linfo));
	linfo.cb = baz_cb;
	linfo.priv = NULL;
	linfo.port = MSGR_UNIT_PORT;
	msgr_listen(baz2_msgr, &linfo, err, err_len);
	if (err[0])
		goto handle_error;
	msgr_start(baz1_msgr, err, err_len);
	if (err[0])
		goto handle_error;
	msgr_start(baz2_msgr, err, err_len);
	if (err[0])
		goto handle_error;
	EXPECT_ZERO(send_foo_tr(baz1_msgr, baz_cb, ECANCELED));
	msgr_shutdown(baz1_msgr);
	EXPECT_ZERO(send_foo_tr(baz1_msgr, baz_cb, ECANCELED));
	RETRY_ON_EINTR(res, sem_wait(&g_msgr_test_baz_sem));
	RETRY_ON_EINTR(res, sem_wait(&g_msgr_test_baz_sem));
	EXPECT_ZERO(sem_destroy(&g_msgr_test_baz_sem));

	msgr_shutdown(baz2_msgr);
	msgr_free(baz1_msgr);
	msgr_free(baz2_msgr);
	return 0;

handle_error:
	fprintf(stderr, "msgr_test_conn_shutdown: got error %s\n", err);
	return 1;
}
Ejemplo n.º 28
0
TEST(cstr, ultohex)
{
	char buf[TFW_ULTOA_BUF_SIZ + 1] = {0};

	EXPECT_EQ(tfw_ultohex(0, buf, TFW_ULTOA_BUF_SIZ), 1);
	EXPECT_ZERO(tfw_cstricmp(buf, "0", 2));

	memset(buf, 0, TFW_ULTOA_BUF_SIZ + 1);
	EXPECT_EQ(tfw_ultohex(5, buf, TFW_ULTOA_BUF_SIZ), 1);
	EXPECT_ZERO(tfw_cstricmp(buf, "5", 2));

	memset(buf, 0, TFW_ULTOA_BUF_SIZ + 1);
	EXPECT_EQ(tfw_ultohex(0x58743, buf, TFW_ULTOA_BUF_SIZ), 5);
	EXPECT_ZERO(tfw_cstricmp(buf, "58743", 6));

	memset(buf, 0, TFW_ULTOA_BUF_SIZ + 1);
	EXPECT_EQ(tfw_ultohex(0xaabbccff, buf, TFW_ULTOA_BUF_SIZ), 8);
	EXPECT_ZERO(tfw_cstricmp(buf, "aabbccff", 9));

	memset(buf, 0, TFW_ULTOA_BUF_SIZ + 1);
	EXPECT_EQ(tfw_ultohex(0xf84467440abf095eUL, buf, TFW_ULTOA_BUF_SIZ),
		  16);
	EXPECT_ZERO(tfw_cstricmp(buf, "f84467440abf095e", 17));

	EXPECT_ZERO(tfw_ultohex(0x589, buf, 2));
}
Ejemplo n.º 29
0
TEST(cstr, ultoa)
{
	char buf[TFW_ULTOA_BUF_SIZ + 1] = {0};

	EXPECT_EQ(tfw_ultoa(0, buf, TFW_ULTOA_BUF_SIZ), 1);
	EXPECT_ZERO(tfw_cstricmp(buf, "0", 2));

	memset(buf, 0, TFW_ULTOA_BUF_SIZ + 1);
	EXPECT_EQ(tfw_ultoa(5, buf, TFW_ULTOA_BUF_SIZ), 1);
	EXPECT_ZERO(tfw_cstricmp(buf, "5", 2));

	memset(buf, 0, TFW_ULTOA_BUF_SIZ + 1);
	EXPECT_EQ(tfw_ultoa(58743, buf, TFW_ULTOA_BUF_SIZ), 5);
	EXPECT_ZERO(tfw_cstricmp(buf, "58743", 6));

	memset(buf, 0, TFW_ULTOA_BUF_SIZ + 1);
	EXPECT_EQ(tfw_ultoa(0xaabbccff, buf, TFW_ULTOA_BUF_SIZ), 10);
	EXPECT_ZERO(tfw_cstricmp(buf, "2864434431", 11));

	memset(buf, 0, TFW_ULTOA_BUF_SIZ + 1);
	EXPECT_EQ(tfw_ultoa(18446744073709551615UL, buf, TFW_ULTOA_BUF_SIZ),
		  20);
	EXPECT_ZERO(tfw_cstricmp(buf, "18446744073709551615", 21));

	EXPECT_ZERO(tfw_ultoa(589, buf, 2));
}
Ejemplo n.º 30
0
static int ostoru_threaded_test(const char *ostor_path, int max_open)
{
	struct ostorc *oconf;
	struct ostor *ostor;
	struct redfish_thread thread1, thread2;

	sem_init(&ostoru_threaded_test_sem1, 0, 0);
	sem_init(&ostoru_threaded_test_sem2, 0, 0);
	oconf = JORM_INIT_ostorc();
	EXPECT_NOT_ERRPTR(oconf);
	oconf->ostor_max_open = max_open;
	oconf->ostor_timeo = 10;
	oconf->ostor_path = strdup(ostor_path);
	EXPECT_NOT_EQ(oconf->ostor_path, NULL);
	ostor = ostor_init(oconf);
	EXPECT_NOT_ERRPTR(ostor);
	EXPECT_ZERO(redfish_thread_create(g_fast_log_mgr, &thread1,
			ostoru_thread1, ostor));
	EXPECT_ZERO(redfish_thread_create(g_fast_log_mgr, &thread2,
			ostoru_thread2, ostor));
	EXPECT_ZERO(redfish_thread_join(&thread1));
	EXPECT_ZERO(redfish_thread_join(&thread2));
	EXPECT_ZERO(sem_destroy(&ostoru_threaded_test_sem1));
	EXPECT_ZERO(sem_destroy(&ostoru_threaded_test_sem2));
	ostor_free(ostor);
	JORM_FREE_ostorc(oconf);
	return 0;
}